Skip to content

Instantly share code, notes, and snippets.

@cannium
Last active December 14, 2015 22:19
Show Gist options
  • Save cannium/5157925 to your computer and use it in GitHub Desktop.
Save cannium/5157925 to your computer and use it in GitHub Desktop.
import gevent
from ryu.controller import handler
from ryu.controller import dpset
from ryu.controller import ofp_event
from ryu.ofproto import nx_match
from ryu.ofproto import ofproto_v1_0
from ryu.ofproto import ofproto_v1_0_parser
from ryu.base import app_manager
from ryu.ofproto.ofproto_parser import MsgBase, msg_pack_into, msg_str_attr
from ryu.lib import mac
from ryu.ofproto import ether
class NX(app_manager.RyuApp):
_CONTEXTS = {
'dpset': dpset.DPSet,
}
def __init__(self, *args, **kwargs):
super(NX, self).__init__(*args, **kwargs)
@staticmethod
def _make_command(table, command):
return table << 8 | command
def send_flow_mod(self, dp, command, rule, actions=None):
flow_mod = dp.ofproto_parser.NXTFlowMod(datapath=dp,
cookie=0, command=command, idle_timeout=0, hard_timeout=0,
priority=0x1, buffer_id=0xffffffff,
out_port=dp.ofproto.OFPP_NONE,
flags=0, rule=rule, actions=actions)
dp.send_msg(flow_mod)
def add_flow(self, dp, rule, actions):
command = self._make_command(0, dp.ofproto.OFPFC_ADD)
self.send_flow_mod(dp, command, rule, actions)
def test(self, dp):
rule = nx_match.ClsRule()
rule.set_dl_type(ether.ETH_TYPE_IPV6)
rule.set_ipv6_src([0x12345678, 0x22223333, 0x11111111, 0xff])
actions = []
actions.append(
dp.ofproto_parser.OFPActionOutput(dp.ofproto.OFPP_CONTROLLER))
self.add_flow(dp, rule, actions)
@handler.set_ev_cls(dpset.EventDP, dpset.DPSET_EV_DISPATCHER)
def handler_datapath(self, ev):
if ev.enter:
self.test(ev.dp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment