From 2528c33ba61ef9436210b1f0bd7dae7a138d1c91 Mon Sep 17 00:00:00 2001 From: Benjamin Eggerstedt Date: Sat, 1 Nov 2014 05:13:49 +0100 Subject: [PATCH] simple_switch_13.py: Added ability to use buffer_id in FlowMod This avoids to send two packets (FlowMod & PacketOut). OF v1.3.1 (the specification most switch vendors implemented) mentions in A.3.4.1 on page 65 that this is a valid way to avoid two packets. Signed-off-by: Benny Eggerstedt Signed-off-by: FUJITA Tomonori --- ryu/app/simple_switch_13.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py index 0e1574fd..b9cbad0f 100644 --- a/ryu/app/simple_switch_13.py +++ b/ryu/app/simple_switch_13.py @@ -47,15 +47,19 @@ class SimpleSwitch13(app_manager.RyuApp): ofproto.OFPCML_NO_BUFFER)] self.add_flow(datapath, 0, match, actions) - def add_flow(self, datapath, priority, match, actions): + def add_flow(self, datapath, priority, match, actions, buffer_id=None): ofproto = datapath.ofproto parser = datapath.ofproto_parser inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)] - - mod = parser.OFPFlowMod(datapath=datapath, priority=priority, - match=match, instructions=inst) + if buffer_id: + mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id, + priority=priority, match=match, + instructions=inst) + else: + mod = parser.OFPFlowMod(datapath=datapath, priority=priority, + match=match, instructions=inst) datapath.send_msg(mod) @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) @@ -95,8 +99,13 @@ class SimpleSwitch13(app_manager.RyuApp): # install a flow to avoid packet_in next time if out_port != ofproto.OFPP_FLOOD: match = parser.OFPMatch(in_port=in_port, eth_dst=dst) - self.add_flow(datapath, 1, match, actions) - + # verify if we have a valid buffer_id, if yes avoid to send both + # flow_mod & packet_out + if msg.buffer_id != ofproto.OFP_NO_BUFFER: + self.add_flow(datapath, 1, match, actions, msg.buffer_id) + return + else: + self.add_flow(datapath, 1, match, actions) data = None if msg.buffer_id == ofproto.OFP_NO_BUFFER: data = msg.data