3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
10 from restlib import * # noqa
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
20 'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'
23 def __init__(self, restSubContext='/controller/nb/v2/flowprogrammer', user=DEFAULT_USER, password=DEFAULT_PWD,
24 container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX):
25 super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix)
29 The name is suggested to match the NB API.
32 return super(self.__class__, self).get_entries('')
34 def add_flow_to_node(self, node_type, node_id, name, body):
35 suffix = 'node/' + node_type + '/' + node_id + '/staticFlow'
36 super(self.__class__, self).add_entry(suffix, name, body)
38 def remove_flow_from_node(self, node_type, node_id, name):
39 suffix = 'node/' + node_type + '/' + node_id + '/staticFlow'
40 super(self.__class__, self).remove_entry(suffix, name)
42 def test_flow_operations(self, node_type, node_id, name, body):
44 Test the add,remove,show actions on flows.
45 >>> body = {'installInHw':'true','name':'flow1','node':
46 {'id':'00:00:00:00:00:00:00:02','type':'OF'},
47 'priority':'1','etherType':'0x800','nwDst':'10.0.0.1/32','actions':['OUTPUT=1']}
48 >>> ForwardingRuleManager().test_flow_operations('OF','00:00:00:00:00:00:00:02','flow1',body)
50 >>> body = {'installInHw':'true','name':'flow2','node':
51 {'id':'00:00:00:00:00:00:00:02','type':'OF'},
52 'priority':'1','etherType':'0x800','nwDst':'10.0.0.2/32','actions':['OUTPUT=2']}
53 >>> ForwardingRuleManager().test_flow_operations('OF','00:00:00:00:00:00:00:02','flow2',body)
57 # current flow table should be empty.
59 result.append(body not in r['flowConfig'])
61 self.add_flow_to_node(node_type, node_id, name, body)
63 result.append(body in r['flowConfig'])
64 # Remove the flow and test if succeed
65 if result == [True, True]:
66 self.remove_flow_from_node(node_type, node_id, name)
68 result.append(body not in r['flowConfig'])
69 return result == [True, True, True]