diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-10-08 07:19:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-10-15 05:43:49 +0900 |
commit | e27741a4a15c81151e8922da26b14b80afc579a5 (patch) | |
tree | 836bb5a4fb3ec333423a7cd6ef1cbab693aaf212 | |
parent | 2494ab9abb685b5af6c37d06eaddfc9fa712bf8a (diff) |
simple_switch: use packet library
Also remove obsolete comments.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/simple_switch.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py index 400092c6..6667c080 100644 --- a/ryu/app/simple_switch.py +++ b/ryu/app/simple_switch.py @@ -22,15 +22,9 @@ from ryu.controller import ofp_event from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.ofproto import ofproto_v1_0 -from ryu.lib.mac import haddr_to_str - - -# TODO: we should split the handler into two parts, protocol -# independent and dependant parts. - -# TODO: can we use dpkt python library? - -# TODO: we need to move the followings to something like db +from ryu.lib.mac import haddr_to_bin +from ryu.lib.packet import packet +from ryu.lib.packet import ethernet class SimpleSwitch(app_manager.RyuApp): @@ -44,7 +38,7 @@ class SimpleSwitch(app_manager.RyuApp): ofproto = datapath.ofproto match = datapath.ofproto_parser.OFPMatch( - in_port=in_port, dl_dst=dst) + in_port=in_port, dl_dst=haddr_to_bin(dst)) mod = datapath.ofproto_parser.OFPFlowMod( datapath=datapath, match=match, cookie=0, @@ -59,14 +53,16 @@ class SimpleSwitch(app_manager.RyuApp): datapath = msg.datapath ofproto = datapath.ofproto - dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) + pkt = packet.Packet(msg.data) + eth = pkt.get_protocol(ethernet.ethernet) + + dst = eth.dst + src = eth.src dpid = datapath.id self.mac_to_port.setdefault(dpid, {}) - self.logger.info("packet in %s %s %s %s", - dpid, haddr_to_str(src), haddr_to_str(dst), - msg.in_port) + self.logger.info("packet in %s %s %s %s", dpid, src, dst, msg.in_port) # learn a mac address to avoid FLOOD next time. self.mac_to_port[dpid][src] = msg.in_port |