3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
11 from testmodule import TestModule
16 class ForwardingRuleManager(TestModule):
18 Test for the forwarding rule manager.
19 Start 2-layer tree topology network. e.g., in Mininet, run 'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'
22 def __init__(self, restSubContext='/controller/nb/v2/flowprogrammer', user=DEFAULT_USER, password=DEFAULT_PWD,
23 container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX):
24 super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix)
28 The name is suggested to match the NB API.
31 return super(self.__class__, self).get_entries('')
33 def add_flow_to_node(self, node_type, node_id, name, body):
34 suffix = 'node/' + node_type + '/' + node_id + '/staticFlow'
35 r = super(self.__class__, self).add_entry(suffix, name, body)
37 def remove_flow_from_node(self, node_type, node_id, name):
38 suffix = 'node/' + node_type + '/' + node_id + '/staticFlow'
39 r = super(self.__class__, self).remove_entry(suffix, name)
41 def test_flow_operations(self, node_type, node_id, name, body):
43 Test the add,remove,show actions on flows.
44 >>> body = {'installInHw':'true','name':'flow1','node':{'id':'00:00:00:00:00:00:00:02','type':'OF'},'priority':'1','etherType':'0x800','nwDst':'10.0.0.1/32','actions':['OUTPUT=1']}
45 >>> ForwardingRuleManager().test_flow_operations('OF','00:00:00:00:00:00:00:02','flow1',body)
47 >>> body = {'installInHw':'true','name':'flow2','node':{'id':'00:00:00:00:00:00:00:02','type':'OF'},'priority':'1','etherType':'0x800','nwDst':'10.0.0.2/32','actions':['OUTPUT=2']}
48 >>> ForwardingRuleManager().test_flow_operations('OF','00:00:00:00:00:00:00:02','flow2',body)
52 #current flow table should be empty.
54 result.append(body not in r['flowConfig'])
56 self.add_flow_to_node(node_type, node_id, name, body)
58 result.append(body in r['flowConfig'])
59 #Remove the flow and test if succeed
60 if result == [True, True]:
61 self.remove_flow_from_node(node_type, node_id, name)
63 result.append(body not in r['flowConfig'])
64 return result == [True, True, True]