Last active
March 12, 2023 01:29
-
-
Save kmmanoj/e76f82c45c3fb39c9407bee849da9f2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ryu.base import app_manager | |
from ryu.controller import ofp_event | |
from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER | |
from ryu.controller.handler import set_ev_cls | |
from ryu.ofproto import ofproto_v1_3 | |
class Hub(app_manager.RyuApp): | |
OFP_VERSIONS = [ ofproto_v1_3.OFP_VERSION ] | |
@set_ev_cls(ofp_event.EventOFPSwitchFeatures , CONFIG_DISPATCHER) | |
def switch_features_handler(self , ev): | |
dp = ev.msg.datapath | |
ofproto = dp.ofproto | |
ofp_parser = dp.ofproto_parser | |
match = ofp_parser.OFPMatch() | |
actions = [ | |
ofp_parser.OFPActionOutput( | |
ofproto.OFPP_CONTROLLER, | |
ofproto.OFPCML_NO_BUFFER | |
) | |
] | |
ins = [ | |
ofp_parser.OFPInstructionActions( | |
ofproto.OFPIT_APPLY_ACTIONS, | |
actions | |
) | |
] | |
out = ofp_parser.OFPFlowMod(datapath=dp, match=match, instructions=ins) | |
dp.send_msg(out) | |
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) | |
def packet_in_handler(self, ev): | |
msg = ev.msg | |
dp = msg.datapath | |
ofp = dp.ofproto | |
ofp_parser = dp.ofproto_parser | |
actions = [ ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD) ] | |
data = None | |
if msg.buffer_id == ofp.OFP_NO_BUFFER: | |
data = msg.data | |
out = ofp_parser.OFPPacketOut( | |
datapath=dp, buffer_id=msg.buffer_id, | |
in_port=msg.match['in_port'], | |
actions=actions, data = data) | |
dp.send_msg(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment