summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/app/simple_switch_websocket_13.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/ryu/app/simple_switch_websocket_13.py b/ryu/app/simple_switch_websocket_13.py
index 2cee2387..3168d5bd 100644
--- a/ryu/app/simple_switch_websocket_13.py
+++ b/ryu/app/simple_switch_websocket_13.py
@@ -22,6 +22,24 @@ $ PYTHONPATH=. ./bin/ryu run --verbose ryu.app.simple_switch_websocket_13
Install and run websocket client(in other terminal):
$ pip install websocket-client
$ wsdump.py ws://127.0.0.1:8080/simpleswitch/ws
+< "ethernet(dst='ff:ff:ff:ff:ff:ff',ethertype=2054,src='32:1a:51:fb:91:77'), a
+rp(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='32:1a:51:fb:91:77')"
+< "ethernet(dst='32:1a:51:fb:91:77',ethertype=2054,src='26:8c:15:0c:de:49'), a
+rp(dst_ip='10.0.0.1',dst_mac='32:1a:51:fb:91:77',hlen=6,hwtype=1,opcode=2,plen
+=4,proto=2048,src_ip='10.0.0.2',src_mac='26:8c:15:0c:de:49')"
+< "ethernet(dst='26:8c:15:0c:de:49',ethertype=2048,src='32:1a:51:fb:91:77'), i
+pv4(csum=9895,dst='10.0.0.2',flags=2,header_length=5,identification=0,offset=0
+,option=None,proto=1,src='10.0.0.1',tos=0,total_length=84,ttl=64,version=4), i
+cmp(code=0,csum=43748,data=echo(data='`\\xb9uS\\x00\\x00\\x00\\x00\\x7f\\'\\x0
+1\\x00\\x00\\x00\\x00\\x00\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\
+x1a\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./01234567',id=14355,seq=1),type=
+8)"
+
+Get arp table:
+> {"jsonrpc": "2.0", "id": 1, "method": "get_arp_table", "params" : {}}
+< {"jsonrpc": "2.0", "id": 1, "result": {"1": {"32:1a:51:fb:91:77": 1, "26:8c:
+15:0c:de:49": 2}}}
"""
import json
@@ -29,6 +47,7 @@ import json
from webob import Response
from ryu.app import simple_switch_13
from ryu.app.wsgi import route, websocket, ControllerBase, WSGIApplication
+from ryu.app.wsgi import rpc_public, WebSocketRPCServer
from ryu.controller import ofp_event
from ryu.controller.handler import set_ev_cls
from ryu.lib import hub
@@ -61,6 +80,10 @@ class SimpleSwitchWebSocket13(simple_switch_13.SimpleSwitch13):
pkt = packet.Packet(ev.msg.data)
self._ws_manager.broadcast(str(pkt))
+ @rpc_public
+ def get_arp_table(self):
+ return self.mac_to_port
+
class SimpleSwitchWebSocketController(ControllerBase):
def __init__(self, req, link, data, **config):
@@ -72,8 +95,6 @@ class SimpleSwitchWebSocketController(ControllerBase):
def _websocket_handler(self, ws):
simple_switch = self.simple_switch_app
simple_switch.logger.debug('WebSocket connected: %s', ws)
- while True:
- msg = ws.wait()
- if msg is None:
- break
- simple_switch.logger.debug('WebSocket disconnected')
+ rpc_server = WebSocketRPCServer(ws, simple_switch)
+ rpc_server.serve_forever()
+ simple_switch.logger.debug('WebSocket disconnected: %s', ws)