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 <[email protected]>
---
 ryu/app/rest.py |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 66 insertions(+), 5 deletions(-)

diff --git a/ryu/app/rest.py b/ryu/app/rest.py
index 8d39aad..8642c30 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,13 +59,23 @@ 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.
 #
-
 
 class NetworkController(ControllerBase):
     def __init__(self, req, link, data, **config):
@@ -142,6 +153,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 +233,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']))
-- 
1.7.10.4


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to