3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
11 from testmodule import TestModule
16 class TopologyManager(TestModule):
18 Test for the topology 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/topology', 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)
26 def get_topology(self):
28 The name is suggested to match the NB API.
31 return super(self.__class__, self).get_entries()
33 def get_userlinks(self):
35 The name is suggested to match the NB API.
39 r = super(self.__class__, self).read(suffix)
43 def add_userlink(self, name, body):
48 r = super(self.__class__, self).update(suffix + '/' + name, body)
51 def remove_userlink(self, name):
56 r = super(self.__class__, self).delete(suffix + '/' + name)
59 def test_get_topology(self):
61 The name is suggested to match the NB API.
63 >>> TopologyManager().test_get_topology()
67 r = self.get_topology()
69 v = [e['edge'] for e in r['edgeProperties']]
70 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
71 u'type': u'OF', u'id': u'2'},
72 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
73 u'type': u'OF', u'id': u'3'}} in v)
74 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
75 u'type': u'OF', u'id': u'3'},
76 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
77 u'type': u'OF', u'id': u'2'}} in v)
78 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
79 u'type': u'OF', u'id': u'3'},
80 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
81 u'type': u'OF', u'id': u'1'}} in v)
82 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
83 u'type': u'OF', u'id': u'1'},
84 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
85 u'type': u'OF', u'id': u'3'}} in v)
86 print result == [True, True, True, True]
88 def test_userlink_operations(self, name, body):
90 Test userlink operations, like adding and removing.
91 >>> TopologyManager().test_userlink_operations('link1', {'status':'Success','name':'link1','srcNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:02','dstNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:03'})
94 return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')