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.
30 >>> TopologyManager().get_topology()
34 r = super(self.__class__, self).get_entries()
36 v = [e['edge'] for e in r['edgeProperties']]
37 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
38 u'type': u'OF', u'id': u'2'},
39 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
40 u'type': u'OF', u'id': u'3'}} in v)
41 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
42 u'type': u'OF', u'id': u'3'},
43 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
44 u'type': u'OF', u'id': u'2'}} in v)
45 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
46 u'type': u'OF', u'id': u'3'},
47 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
48 u'type': u'OF', u'id': u'1'}} in v)
49 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
50 u'type': u'OF', u'id': u'1'},
51 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
52 u'type': u'OF', u'id': u'3'}} in v)
53 print result == [True, True, True, True]
55 def get_userlinks(self):
57 The name is suggested to match the NB API.
61 r = super(self.__class__, self).read(suffix)
65 def add_userlink(self, name, body):
70 r = super(self.__class__, self).update(suffix + '/' + name, body)
73 def remove_userlink(self, name):
78 r = super(self.__class__, self).delete(suffix + '/' + name)
81 def test_userlink_operations(self, name, body):
83 Test userlink operations, like adding and removing.
84 >>> 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'})
87 return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')