Skip to content

Commit f5d9cc7

Browse files
committed
Added list_links to route handleres
1 parent 3bb4050 commit f5d9cc7

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

ControllerAdvanced-REST.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,28 @@
4141
This class is responsible for
4242
"""
4343
simple_switch_instance_name = 'simple_switch_api_app'
44-
url = '/simpleswitch/mactable/{dpid}'
45-
urll = '/mininet/topo/switches/'
44+
url = '/mininet/topo/'
4645
class RestHandler(ControllerBase):
4746
_CONTEXTS = { 'wsgi': WSGIApplication }
4847

4948
def __init__(self, req, link, data, **config):
5049
super(RestHandler, self).__init__(req, link, data, **config)
5150
self.simpl_switch_spp = data[simple_switch_instance_name]
5251

53-
@route('simpleswitch', urll, methods=['GET'])
54-
def list_mac_table(self, req, **kwargs):
52+
@route('simpleswitch', url+"switches/", methods=['GET'])
53+
def list_switches(self, req, **kwargs):
5554
simple_switch = self.simpl_switch_spp
5655

5756
body = json.dumps(simple_switch.topo_shape.get_switches_dpid())
5857
return Response(content_type='application/json', body=body)
5958

59+
@route('simpleswitch', url+"links/", methods=['GET'])
60+
def list_links(self, req, **kwargs):
61+
simple_switch = self.simpl_switch_spp
62+
63+
body = json.dumps(simple_switch.topo_shape.get_links_str())
64+
return Response(content_type='application/json', body=body)
65+
6066
"""
6167
This holds the hosts information and their connection to switches.
6268
An instance of this class is used in TopoStructure to save the topo info.
@@ -410,6 +416,16 @@ def print_switches(self, func_str=None):
410416
for p in s.ports:
411417
print ("\t\t\t " + str(p.hw_addr))
412418

419+
def get_links_str(self):
420+
"""
421+
Uses the built in __str__ function to print the links saved in the class `topo_raw_links`.
422+
Returns a list of link strings
423+
"""
424+
out = []
425+
for l in self.topo_raw_links:
426+
out.append(str(l))
427+
return out
428+
413429
def get_hw_addresses_for_dpid(self, in_dpid):
414430
"""
415431
For a specific dpid of switch it return a list of mac addresses for each port of that sw.

0 commit comments

Comments
 (0)