3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
10 from restlib import * # noqa
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
20 'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'
23 def __init__(self, restSubContext='/controller/nb/v2/topology', 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)
27 def get_topology(self):
29 The name is suggested to match the NB API.
32 return super(self.__class__, self).get_entries()
34 def get_userlinks(self):
36 The name is suggested to match the NB API.
40 r = super(self.__class__, self).read(suffix)
44 def add_userlink(self, name, body):
49 r = super(self.__class__, self).update(suffix + '/' + name, body)
52 def remove_userlink(self, name):
57 r = super(self.__class__, self).delete(suffix + '/' + name)
60 def test_get_topology(self):
62 The name is suggested to match the NB API.
64 >>> TopologyManager().test_get_topology()
68 r = self.get_topology()
70 v = [e['edge'] for e in r['edgeProperties']]
71 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
72 u'type': u'OF', u'id': u'2'},
73 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
74 u'type': u'OF', u'id': u'3'}} in v)
75 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
76 u'type': u'OF', u'id': u'3'},
77 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
78 u'type': u'OF', u'id': u'2'}} in v)
79 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
80 u'type': u'OF', u'id': u'3'},
81 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
82 u'type': u'OF', u'id': u'1'}} in v)
83 result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
84 u'type': u'OF', u'id': u'1'},
85 u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
86 u'type': u'OF', u'id': u'3'}} in v)
87 print result == [True, True, True, True]
89 def test_userlink_operations(self, name, body):
91 Test userlink operations, like adding and removing.
92 >>> TopologyManager().test_userlink_operations('link1',
93 {'status':'Success','name':'link1',
94 'srcNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:02',
95 'dstNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:03'})
98 return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')