{PATCH] switches.py: Openflow 1.3 support
Signed-off-by: Raphael Vicente Rosa <[email protected]>
--- switches_old.py 2013-10-23 10:01:27.036248398 -0200
+++ switches.py 2013-10-29 09:33:44.340248878 -0200
@@ -25,9 +25,10 @@ from ryu.controller import ofp_event
from ryu.controller.handler import set_ev_cls
from ryu.controller.handler import MAIN_DISPATCHER, DEAD_DISPATCHER
from ryu.exception import RyuException
-from ryu.lib import addrconv, hub
+from ryu.lib import hub
from ryu.lib.mac import DONTCARE_STR
from ryu.lib.dpid import dpid_to_str, str_to_dpid
+from ryu.lib.mac import haddr_to_bin
from ryu.lib.port_no import port_no_to_str
from ryu.lib.packet import packet, ethernet, lldp
from ryu.ofproto.ether import ETH_TYPE_LLDP
@@ -73,7 +74,7 @@ class Port(object):
def is_down(self):
return (self._state & self._ofproto.OFPPS_LINK_DOWN) > 0 \
or (self._config & self._ofproto.OFPPC_PORT_DOWN) > 0
-
+
def is_live(self):
# NOTE: OF1.2 has OFPPS_LIVE state
# return (self._state & self._ofproto.OFPPS_LIVE) > 0
@@ -486,6 +487,12 @@ class Switches(app_manager.RyuApp):
switch.add_port(ofpport)
return switch
+ def _get_switches(self):
+ switches = []
+ for dp in self.dps.itervalues():
+ switches.append(self._get_switch(dp.id))
+ return switches
+
def _get_port(self, dpid, port_no):
switch = self._get_switch(dpid)
if switch:
@@ -537,14 +544,28 @@ class Switches(app_manager.RyuApp):
# TODO:XXX need other versions
if ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
rule = nx_match.ClsRule()
- rule.set_dl_dst(addrconv.mac.text_to_bin(
- lldp.LLDP_MAC_NEAREST_BRIDGE))
+
rule.set_dl_dst(haddr_to_bin(lldp.LLDP_MAC_NEAREST_BRIDGE))
rule.set_dl_type(ETH_TYPE_LLDP)
actions = [ofproto_parser.OFPActionOutput(
ofproto.OFPP_CONTROLLER, self.LLDP_PACKET_LEN)]
dp.send_flow_mod(
rule=rule, cookie=0, command=ofproto.OFPFC_ADD,
idle_timeout=0, hard_timeout=0, actions=actions)
+
+ elif ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
+ match = ofproto_parser.OFPMatch()
+
match.set_dl_dst(haddr_to_bin(lldp.LLDP_MAC_NEAREST_BRIDGE))
+ match.set_dl_type(ETH_TYPE_LLDP)
+ actions =
[ofproto_parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
self.LLDP_PACKET_LEN)]
+ inst =
[dp.ofproto_parser.OFPInstructionActions(dp.ofproto.OFPIT_APPLY_ACTIONS,
actions)]
+ m = ofproto_parser.OFPFlowMod(dp, 0, 0, 0,
+ dp.ofproto.OFPFC_ADD,
+ 0, 0, 0xff, 0xffffffff,
+ dp.ofproto.OFPP_ANY,
+ dp.ofproto.OFPG_ANY,
+ 0, match, inst)
+ dp.send_msg(m)
+
else:
LOG.error('cannot install flow. unsupported version.
%x',
dp.ofproto.OFP_VERSION)
@@ -640,6 +661,9 @@ class Switches(app_manager.RyuApp):
# TODO:XXX
if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
dp.send_packet_out(buffer_id, msg.in_port, [])
+ elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
+ in_port = msg.match['in_port']
+ dp.send_packet_out(buffer_id=buffer_id, in_port=in_port,
actions=[])
else:
LOG.error('cannot drop_packet. unsupported version. %x',
dp.ofproto.OFP_VERSION)
@@ -658,7 +682,15 @@ class Switches(app_manager.RyuApp):
return
dst_dpid = msg.datapath.id
- dst_port_no = msg.in_port
+ #dst_port_no = msg.in_port
+ if msg.datapath.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
+ dst_port_no = msg.in_port
+ elif msg.datapath.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
+ in_port = msg.match['in_port']
+ dst_port_no = in_port
+ else:
+ LOG.error('cannot drop_packet. unsupported version. %x',
+ msg.datapath.ofproto.OFP_VERSION)
src = self._get_port(src_dpid, src_port_no)
if not src or src.dpid == dst_dpid:
@@ -717,6 +749,14 @@ class Switches(app_manager.RyuApp):
if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
actions = [dp.ofproto_parser.OFPActionOutput(port.port_no)]
dp.send_packet_out(actions=actions, data=port_data.lldp_data)
+ elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
+ actions = [dp.ofproto_parser.OFPActionOutput(port.port_no,
+
len(port_data.lldp_data))]
+ buffer_id = dp.ofproto.OFP_NO_BUFFER
+ in_port = dp.ofproto.OFPP_CONTROLLER
+ packet_out = dp.ofproto_parser.OFPPacketOut(dp, buffer_id,
in_port,
+ actions,
port_data.lldp_data)
+ dp.send_msg(packet_out)
else:
LOG.error('cannot send lldp packet. unsupported version. %x',
dp.ofproto.OFP_VERSION)
On Fri, Oct 25, 2013 at 11:29 PM, FUJITA Tomonori <
[email protected]> wrote:
> Hi,
>
> On Wed, 23 Oct 2013 20:37:32 -0200
> Raphael Vicente Rosa <[email protected]> wrote:
>
> > Hi, sorry about it. This is the right version! I've tested it already.
> > Don't forget to use these options with ryu-manager: install-lldp-flow,
> > observe-links.
> > And now, maybe this could be used as a patch.
>
> Can you send this as a patch that can be applied to the master branch?
>
>
> Thanks!
>
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel