Created
September 8, 2017 15:48
-
-
Save John-Lin/0dee0efdf2f8bdb68636e033a427d145 to your computer and use it in GitHub Desktop.
SDN application for NORMAL action
This file contains hidden or 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 CONFIG_DISPATCHER | |
from ryu.controller.handler import set_ev_cls | |
from ryu.ofproto import ofproto_v1_3 | |
class Switch(app_manager.RyuApp): | |
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] | |
def __init__(self, *args, **kwargs): | |
super(Switch, self).__init__(*args, **kwargs) | |
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) | |
def switch_features_handler(self, ev): | |
datapath = ev.msg.datapath | |
ofproto = datapath.ofproto | |
parser = datapath.ofproto_parser | |
# install a NORMAL flow entry | |
match = parser.OFPMatch() | |
actions = [parser.OFPActionOutput(ofproto.OFPP_NORMAL)] | |
self.add_flow(datapath, 0, 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)] | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment