Hi,

Ryu does not define the standard way to communicate between controllers,
but you have some options to achieve this.

Just an idea, the following implements REST API for sending the packet info
by using the json representation of packet library.

$ git diff
diff --git a/ryu/app/simple_switch_rest_13.py b/ryu/app/simple_switch_rest_13.py
index c37ee09..27eab32 100644
--- a/ryu/app/simple_switch_rest_13.py
+++ b/ryu/app/simple_switch_rest_13.py
@@ -14,14 +14,18 @@
  # limitations under the License.
  
  import json
+from six.moves import urllib
  
  from ryu.app import simple_switch_13
  from webob import Response
  from ryu.controller import ofp_event
-from ryu.controller.handler import CONFIG_DISPATCHER
+from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
  from ryu.controller.handler import set_ev_cls
  from ryu.app.wsgi import ControllerBase, WSGIApplication, route
  from ryu.lib import dpid as dpid_lib
+from ryu.lib.packet import packet
+from ryu.lib.packet import icmp
+
  
  simple_switch_instance_name = 'simple_switch_api_app'
  url = '/simpleswitch/mactable/{dpid}'
@@ -71,6 +75,28 @@ class SimpleSwitchRest13(simple_switch_13.SimpleSwitch13):
                  mac_table.update({entry_mac: entry_port})
          return mac_table
  
+    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
+    def _packet_in_handler(self, ev):
+        super(SimpleSwitchRest13, self)._packet_in_handler(ev)
+
+        msg = ev.msg
+        datapath = msg.datapath
+
+        pkt = packet.Packet(msg.data)
+        self.send_pkt_data(datapath.id, pkt)
+
+    def send_pkt_data(self, dpid, pkt):
+        url = 'http://localhost:8080/simpleswitch/packet/%d' % dpid
+        req = urllib.request.Request(url)
+        req.add_header('Content-Type', 'application/json')
+
+        data = json.dumps(pkt.to_jsondict())
+
+        urllib.request.urlopen(req, data)
+
+    def receive_pkt_data(self, dpid, pkt):
+        self.logger.info('dpid=%d, pkt=%s', dpid, pkt)
+
  
  class SimpleSwitchController(ControllerBase):
  
@@ -112,3 +138,20 @@ class SimpleSwitchController(ControllerBase):
              return Response(content_type='application/json', body=body)
          except Exception as e:
              return Response(status=500)
+
+    @route('simpleswitch', '/simpleswitch/packet/{dpid}', methods=['POST'])
+    def post_icmp_header(self, req, dpid, **kwargs):
+        simple_switch = self.simple_switch_app
+        dpid = int(str(dpid), 0)
+        try:
+            data = req.json if req.body else {}
+        except ValueError:
+            raise Response(status=400)
+
+        pkt = packet.Packet.from_jsondict(data[u'Packet'])
+
+        try:
+            simple_switch.receive_pkt_data(dpid, pkt)
+            return Response(status=200)
+        except Exception as e:
+            return Response(status=500, body=str(e))



$ ryu-manager ryu/app/simple_switch_rest_13.py
loading app ryu/app/simple_switch_rest_13.py
loading app ryu.controller.ofp_handler
creating context wsgi
instantiating app ryu.controller.ofp_handler of OFPHandler
instantiating app ryu/app/simple_switch_rest_13.py of SimpleSwitchRest13
(18949) wsgi starting up on http://0.0.0.0:8080
packet in 1 66:e2:14:08:98:cc ff:ff:ff:ff:ff:ff 1
(18949) accepted ('127.0.0.1', 54938)
dpid=1, 
pkt=ethernet(dst='ff:ff:ff:ff:ff:ff',ethertype=2054,src='66:e2:14:08:98:cc'), 
arp(dst_ip='10.0.0.2',dst_mac='00:00:00:00:00:00',hlen=6,hwtype=1,opcode=1,plen=4,proto=2048,src_ip='10.0.0.1',src_mac='66:e2:14:08:98:cc')
127.0.0.1 - - [01/Nov/2016 16:42:25] "POST /simpleswitch/packet/1 HTTP/1.1" 200 
134 0.003625
packet in 1 ee:55:c1:91:cf:5c 66:e2:14:08:98:cc 2
(18949) accepted ('127.0.0.1', 54940)
dpid=1, 
pkt=ethernet(dst='66:e2:14:08:98:cc',ethertype=2054,src='ee:55:c1:91:cf:5c'), 
arp(dst_ip='10.0.0.1',dst_mac='66:e2:14:08:98:cc',hlen=6,hwtype=1,opcode=2,plen=4,proto=2048,src_ip='10.0.0.2',src_mac='ee:55:c1:91:cf:5c')
127.0.0.1 - - [01/Nov/2016 16:42:25] "POST /simpleswitch/packet/1 HTTP/1.1" 200 
134 0.001449
packet in 1 66:e2:14:08:98:cc ee:55:c1:91:cf:5c 1
(18949) accepted ('127.0.0.1', 54942)
dpid=1, 
pkt=ethernet(dst='ee:55:c1:91:cf:5c',ethertype=2048,src='66:e2:14:08:98:cc'), 
ipv4(csum=9768,dst='10.0.0.2',flags=2,header_length=5,identification=127,offset=0,option=None,proto=1,src='10.0.0.1',tos=0,total_length=84,ttl=64,version=4),
 
icmp(code=0,csum=22789,data=echo(data='aG\x18X\x00\x00\x00\x00\x13{\t\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
 !"#$%&\'()*+,-./01234567',id=18956,seq=1),type=8)
127.0.0.1 - - [01/Nov/2016 16:42:25] "POST /simpleswitch/packet/1 HTTP/1.1" 200 
134 0.002070


Thanks,
Iwase


On 2016年10月30日 12:07, Jacob Cox wrote:
> Hello,
>
>
>
> Does Ryu have a feature for controller-to-controller(or server)
> communication? I'm trying to determine which packets if any send more than
> just the header information to the controller. The best I've accomplished so
> far is using the first 8 bytes of an ICMP packet's data field to pass
> information; however, that's a significant limitation.
>
>
>
> R,
>
> Jacob
>
>
>
> Respectfully,
>
>
>
> Jacob Cox
>
> (706) 951-9741
>
>  <https://www.linkedin.com/in/jacobcox74>
> https://www.linkedin.com/in/jacobcox74
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> The Command Line: Reinvented for Modern Developers
> Did the resurgence of CLI tooling catch you by surprise?
> Reconnect with the command line and become more productive.
> Learn the new .NET and ASP.NET CLI. Get your free copy!
> http://sdm.link/telerik
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to