Flow

Import OPBNOS API

from opbclient import opb_api as opbapi

Initialize client

Use the appropriate JSON file that corresponds to the targetted device name. This JSON file should contain request body parameters corresponding to any potential configuration/post requests.

node = opbapi.connect_to('SN2010')

Configure flow information

In order to configure flow information, the API, configFlow(), must be invoked with appropriate parameters in dictionary format.

node.configFlow(flow = "flow1")

The API configFlow() requires only one parameter (flow alias) because the file SN2010.json contains all the required request body parameters in order to configure device flow. The content of the JSON file is in the following format:

        "flow1": {
                "configFlow": {
                        "alias": "flow1",
                        "status": "enable",
                        "comment": "vlan traffic test",
                        "from": ["Ethernet16_1","Ethernet17_1"],
                        "to": ["port-channel1"]
                }

The below table has a list of attributes that pertain to this particular API:

Attribute Values Description
"alias" "flow1" alias name for flow
"status" "enable|disable" indicates device status
"comment" "test" additional port channel/device related comments
"from" ["EthernetX_X"] indicates network ports
"to" ["EthernetY_Y"] indicates tool ports
"push-vlan" "vlan-id" pushing VLAN tags
"pop-vlan" "enable|disable" popping/removing VLAN tags

Configure flow rule information

In order to configure flow information, the API, configFlow(), must be invoked with appropriate parameters in dictionary format.

node.configFlowRules(flow = "flow1", r_id = "1")

The API configFlowRules() requires two parameters (flow alias and rule id) because the file SN2010.json contains all the required request body parameters in order to configure device flow. The content of the JSON file is in the following format:

        "flow1": {
                "configRules": {
                        "1": {
                                "rule_id": "1",
                                "action": "permit",
                                "vlan": "100",
                                "counters": "enable"
                        }
        }
    }

The below table has a list of attributes that can be listed in the JSON file (in this case 'SN2010'):

Attribute Values Description
"alias" "flow1" alias name for flow
"status" "enable|disable" indicates device status
"comment" "test" additional flow channel/device related comments
"vlan" int VLAN ID
"ethertype" "0x8100" indicates Ethertype in Ethernet frame
"src_ip" "1.1.1.1" source ip address
"src_mask" "255.XXX.XXX.0" source masking ip
"dst_ip" "2.2.2.2" destination ip address
"dst_mask" "255.YYY.YYY.0" destination ip masking
"dscp" "5" dscp code (network traffic)
"ttl" "4" 'time to live'
"protocol" "6" protocol code
"src_l4port" "56" source port number
"dst_l4port" "78" destination port number
"tcpctl" "0xX" tcp control
"tcpctl_mask" "0xff" tcp control filter mask
"tosval" "3" Type of Service Value
"match_all" "disable|enable" Match all the traffic flowing through
"counters" "enable|disable" Statistics/Counters Enable or Disable

Configure Flow All Rules information

In order to configure all the rules part of a flow added in config file, the API - configFlowAllRules() can be used.

node.configFlow(flow = "flow1")

Configure flow Override information

In order to override any information for a particular rule, the API - configOverride(), must be invoked with appropriate parameters in dictionary format.

node.configFlow(flow = "flow1", r_id=1, dt={"override-to":["Ethernet6_1","Ethernet7_1"],"override-push-vlan-tag":"100","override-pop-vlan":"disable"})

The below table has a list of attributes that pertain to this particular API:

Attribute Values Description
"override-to" "Interface list. Eg ["Ethernet6_1","Ethernet7_1"]" Tool ports override for particular flow
"override-push-vlan-tag" "500 to 4094" Push Vlan ID override for particular rule
"override-pop-vlan" "enable/disable" POP Vlan Behavior override for particular rule

Get/Show Flow

Retrieves device flow information with an 'alias'

node.execute(['show flow alias <alias>'])

Output

Note: Client will receive the below error messege if flow has not been configured.

b'{"[ERROR]": "Flow not configured!"}'

This will be the proper JSON output format if flow has been configured

b'{"flow1|1": {"name": "flow1", "status": "enable", "to": ["Ethernet16_1"], "from": ["Ethernet14_1"]}}'

The below table has a list of attributes that will appear as get flow output:

Attribute Values Description
"name" "flow1" alias name for flow
"status" "enable|disable" indicates device status
"config_mgr" "Rest-API" name of configuration manager
"to" ["EthernetX_X"] tool ports
"from" ["EthernetY_Y"] network ports
"comment" "vlan traffic test" additional flow/device related comments

Delete and Config Rule

This is a multifunctional API that deletes particular rule of given flow and configures a new flow rule based on user specified input.

node.deleteAndConfigFlowRule(flow = "flow1", r_id = 1)

Delete Rule

In order to delete Rule of any specific flow, the API, configDeleteRules(), must have parameters specifing the targetted flow alias and rule id as below.

node.configDeleteRules(flow = "flow1", r_id = 1)

Delete Flow

In order to delete flow, the API, configDelete(), must have one parameter specifing the targetted flow alias.

node.configDelete(flow = "flow1")

Output

Note: Client will receive the below status codes for both deleting funtions to indicate a successful request.

Status : 200 -> Response : b'200'

The status code '500' indicates a server error.