diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2013-02-08 12:28:03 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-02-08 22:55:16 +0900 |
commit | 9a145d1db1da9b80388f3af79ad96b4bddb32414 (patch) | |
tree | fd94031cfdbe0460c9ca718efb05d1c586eb01ac | |
parent | a523cd87458241916649455cbf9bbe00e8fd3f2e (diff) |
app/rest: add API to register/update mac address for a given port
Via this API, ryu knows that what mac address is associated with the port.
So ryu can pass/drop packets from the port.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/rest.py | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/ryu/app/rest.py b/ryu/app/rest.py index 8d39aadc..3ed1ecd2 100644 --- a/ryu/app/rest.py +++ b/ryu/app/rest.py @@ -24,6 +24,7 @@ from ryu.controller import network from ryu.exception import NetworkNotFound, NetworkAlreadyExist from ryu.exception import PortNotFound, PortAlreadyExist from ryu.lib import dpid as dpid_lib +from ryu.lib import mac as mac_lib ## TODO:XXX ## define db interface and store those information into db @@ -58,11 +59,22 @@ from ryu.lib import dpid as dpid_lib # # remove a set of dpid and port # DELETE /v1.0/networks/{network-id}/{dpid}_{port-id} - -# We store networks and ports like the following: # -# {network_id: [(dpid, port), ... -# {3: [(3,4), (4,7)], 5: [(3,6)], 1: [(5,6), (4,5), (4, 10)]} +# get the list of mac addresses of dpid and port +# GET /v1.0/networks/{network-id}/{dpid}_{port-id}/macs/ +# +# register a new mac address for dpid and port +# Fail if mac address is already registered or the mac address is used +# for other ports of the same network-id +# POST /v1.0/networks/{network-id}/{dpid}_{port-id}/macs/{mac} +# +# update a new mac address for dpid and port +# Success as nop even if same mac address is already registered. +# For now, changing mac address is not allows as it fails. +# PUT /v1.0/networks/{network-id}/{dpid}_{port-id}/macs/{mac} +# +# For now DELETE /v1.0/networks/{network-id}/{dpid}_{port-id}/macs/{mac} +# is not supported. mac address is released when port is deleted. # @@ -142,6 +154,41 @@ class PortController(ControllerBase): return Response(status=200) +class MacController(ControllerBase): + def __init__(self, req, link, data, **config): + super(MacController, self).__init__(req, link, data, **config) + self.nw = data + + def create(self, _req, network_id, dpid, port_id, mac_addr, **_kwargs): + mac = mac_lib.haddr_to_bin(mac_addr) + try: + self.nw.create_mac(network_id, int(dpid, 16), int(port_id), mac) + except PortNotFound: + return Response(status=404) + except network.MacAddressAlreadyExist: + return Response(status=409) + + return Response(status=200) + + def update(self, _req, network_id, dpid, port_id, mac_addr, **_kwargs): + mac = mac_lib.haddr_to_bin(mac_addr) + try: + self.nw.update_mac(network_id, int(dpid, 16), int(port_id), mac) + except PortNotFound: + return Response(status=404) + + return Response(status=200) + + def lists(self, _req, network_id, dpid, port_id, **_kwargs): + try: + body = json.dumps([mac_lib.haddr_to_str(mac_addr) for mac_addr in + self.nw.list_mac(int(dpid, 16), int(port_id))]) + except PortNotFound: + return Response(status=404) + + return Response(content_type='application/json', body=body) + + class RestAPI(app_manager.RyuApp): _CONTEXTS = { 'network': network.Network, @@ -187,3 +234,18 @@ class RestAPI(app_manager.RyuApp): conditions=dict(method=['PUT'])) s.connect(route_name, uri, action='delete', conditions=dict(method=['DELETE'])) + + wsgi.registory['MacController'] = self.nw + uri += '/macs' + mapper.connect('macs', uri, + controller=MacController, action='lists', + conditions=dict(method=['GET'])) + + uri += '/{mac_addr}' + mapper.connect('macs', uri, + controller=MacController, action='create', + conditions=dict(method=['POST'])) + + mapper.connect('macs', uri, + controller=MacController, action='update', + conditions=dict(method=['PUT'])) |