Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update simple_switch_13.py #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions ryu/app/simple_switch_13.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.lib.packet import ether_types
import json


class SimpleSwitch13(app_manager.RyuApp):
Expand Down Expand Up @@ -48,7 +49,7 @@ def switch_features_handler(self, ev):
ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions)

def add_flow(self, datapath, priority, match, actions, buffer_id=None):
def add_flow(self, datapath, priority, tableID=0, idle=0, hard=0, match, actions, buffer_id=None):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser

Expand All @@ -57,10 +58,13 @@ def add_flow(self, datapath, priority, match, actions, buffer_id=None):
if buffer_id:
mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,
priority=priority, match=match,
instructions=inst)
idle_timeout=idle, hard_timeout=hard,
instructions=inst, table_id=tableID)
else:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=match, instructions=inst)
idle_timeout=idle, hard_timeout=hard,
match=match, instructions=inst,
table_id=tableID)
datapath.send_msg(mod)

@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
Expand Down Expand Up @@ -88,7 +92,8 @@ def _packet_in_handler(self, ev):
dpid = format(datapath.id, "d").zfill(16)
self.mac_to_port.setdefault(dpid, {})

self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
self.logger.info("packet in %s src:%s dst:%s (on port: %s)", dpid, src, dst, in_port)
self.logger.info(json.dumps(self.mac_to_port, sort_keys=True, indent=4))

# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = in_port
Expand All @@ -103,13 +108,16 @@ def _packet_in_handler(self, ev):
# 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, eth_src=src)
_tabelID = 0
_idle = 0
_hard = 0
# 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)
self.add_flow(datapath, 1, _tableID, _idle, _hard, match, actions, msg.buffer_id)
return
else:
self.add_flow(datapath, 1, match, actions)
self.add_flow(datapath, 1, _tableID, _idle, _hard, match, actions)
data = None
if msg.buffer_id == ofproto.OFP_NO_BUFFER:
data = msg.data
Expand Down