Hello,
That problem is more related to OpenFlow protocol than Ryu controller
itself. One should remember that some of match fields have prerequisites
that need to be defined first for the flow to be added correctly, as
mentioned in OpenFlow specification ("Protocol-specic fields within
ofp_match will be ignored within a single table when the
corresponding protocol is not specified in the match. The MPLS match
fields will be ignored unless the Ethertype specified as either IPv4 or
ARP.", OpenFlow 1.1.0 spec, p.29). Therefore, your match should also
contain "dl_type=0x0800". Here is a code of simple app that demonstrates
IP address match (tested in OvS 2.5.0 and Ryu 4.5, OF 1.0).
__author__ = 'Michal Rzepka'
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
class L2Switch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(L2Switch, self).__init__(*args, **kwargs)
@set_ev_cls(ofp_event.EventOFPStateChange, MAIN_DISPATCHER)
def state_change_handler(self, ev):
dp = ev.datapath
ofproto = dp.ofproto
parser = dp.ofproto_parser
addressList = ('10.10.1.1', '10.10.1.2', '10.10.1.3')
for address in addressList:
actions = [parser.OFPActionOutput(ofproto.OFPP_NORMAL)]
match = parser.OFPMatch(dl_type=0x0800, nw_src=address)
self.add_flow(dp, match, actions, 1, 100)
def add_flow(self, datapath, match, act, priority=0,
idle_timeout=0):
parser = datapath.ofproto_parser
mod = parser.OFPFlowMod(datapath=datapath,
priority=priority,
match=match, actions=act,
idle_timeout=idle_timeout)
datapath.send_msg(mod)
The result is as expected:
cookie=0x0, duration=1.580s, table=0, n_packets=0, n_bytes=0,
idle_timeout=100, idle_age=1, priority=1,ip,nw_src=10.10.1.1
actions=NORMAL
cookie=0x0, duration=1.580s, table=0, n_packets=0, n_bytes=0,
idle_timeout=100, idle_age=1, priority=1,ip,nw_src=10.10.1.2
actions=NORMAL
cookie=0x0, duration=1.579s, table=0, n_packets=0, n_bytes=0,
idle_timeout=100, idle_age=1, priority=1,ip,nw_src=10.10.1.3
actions=NORMAL
Regards,
---
Michał Rzepka
W dniu 2016-09-29 07:03, Garegin Grigoryan napisał(a):
> Hi,
>
> I'm new to RYU controller and I'm trying to install some simple rules.
> I use Openflow 1.0.
>
> Here's my code:
>
> addressList = ('10.10.1.1', '10.10.1.2', '10.10.1.3')
> for address in addressList:
> actions = [parser.OFPActionOutput(ofproto.OFPP_NORMAL)]
> match = parser.OFPMatch(nw_src = address)
> self.add_flow(dp, match, actions, 1, 100)
>
> def add_flow(self, datapath, match, act, priority=0, idle_timeout=0):
> ofproto = datapath.ofproto
> parser = datapath.ofproto_parser
>
> mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
> match=match, actions=act, idle_timeout=idle_timeout)
> datapath.send_msg(mod)
>
> Here's what I see in OVS:
>
> cookie=0x0, duration=13.212s, table=0, n_packets=0, n_bytes=0,
> idle_timeout=100,priority=1 actions=NORMAL
>
> Why ip-source match was ignored?
>
> Thanks for your help!
>
> --
>
> Sincerely,
> Garegin Grigoryan
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel