On Thu, 28 Mar 2013 16:28:59 +0100
Christopher Scherb <[email protected]> wrote:

> Hello,
> 
> I implemented the nw_src_mask and nw_src_mask according to the Flow
> Match Structures in the Openflow-Spec-v1.0.0, Section 5.2.3.
> (/* IP source address wildcard bit count. 0 is exact match, 1 ignores the
> * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
> * the entire field. This is the *opposite* of the usual convention where
> * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */)
> (http://www.openflow.org/documents/openflow-spec-v1.0.0.pdf)
> 
> As far as I see:
> Since there are only 6 bits (for the number between 0 and 32) in a
> Openflow message for a nw mask, only masking similar to CIDR is
> possible.
> If 32 bits as mask are used, the mask 0xff00ff00 can theoretic be
> used, but leads to undefined behavior,
> because only the number of bits which are wildcards can be spezified (see 
> CIDR).
> 
> I wrote another patch which applies a mask of 32bit. This patch will
> lead to the following behavior for the code below:
> rule.set_nw_src_masked(0x12345678, 0xffffff00) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0/24 actions=CONTROLLER:0
> rule.set_nw_src_masked(0x12345678, 0xfffff000) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0/20 actions=CONTROLLER:0
> rule.set_nw_src_masked(0x12345678, 0xffff0000) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0/16 actions=CONTROLLER:0
> rule.set_nw_src_masked(0x12345678, 0xffffffff) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0 actions=CONTROLLER:0
> rule.set_nw_src_masked(0x12345678, 0xfffffffe) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0/31 actions=CONTROLLER:0
> rule.set_nw_src_masked(0x12345678, 0xfffffffc) --> cookie=0x0,
> duration=1.879s, table=0, n_packets=0, n_bytes=0, idle_age=1,
> priority=1,ip,nw_src=18.52.86.0/30 actions=CONTROLLER:0
> etc.

Note that nx_match.py is for Nicira extensions. NX supports arbitrary
masks. So nw_src_mask could be something like 0xff00ff00.

match_tuple() that you are changing converts OF1.0 match when a
datapath doesn't support NX. So if you get a mask that is not
supported in OF1.0, then your choice would be:

1) ignore
2) do the best

> (Tested with PICA8 P3295 with PICOS 1.3)
> Note: As described above, a mask like 0xff00ff00 or 0xfff9fbf9 is not
> valid, because it does not match a CIDR mask.
> 
> 
> Christopher
> 
> 
> Patch:
> 
> diff -up nx_match.py.orig nx_match.py
> --- nx_match.py.orig  2013-03-27 19:31:48.000000000 +0100
> +++ nx_match.py       2013-03-28 16:16:23.306029449 +0100
> @@ -336,15 +336,15 @@ class ClsRule(object):
>          if self.flow.nw_proto != 0:
>              wildcards &= ~ofproto_v1_0.OFPFW_NW_PROTO
> 
> -        if self.flow.nw_src != 0:
> +        if self.wc.nw_src_mask != 0:
>              wildcards &= ~ofproto_v1_0.OFPFW_NW_SRC_MASK
> -            # maximum size of 32 to prevent changes on other bits
> -            wildcards |= (self.wc.nw_src_mask % 32) << 8
> +            maskbits = (bin(self.wc.nw_src_mask).count("0") - 1)
> +            wildcards |= (maskbits << ofproto_v1_0.OFPFW_NW_SRC_SHIFT)
> 
> -        if self.flow.nw_dst != 0:
> +        if self.wc.nw_dst_mask != 0:
>              wildcards &= ~ofproto_v1_0.OFPFW_NW_DST_MASK
> -            # maximum size of 32 to prevent changes on other bits
> -            wildcards |= (self.wc.nw_dst_mask % 32) << 14
> +            maskbits = (bin(self.wc.nw_dst_mask).count("0") - 1)
> +            wildcards |= (maskbits << ofproto_v1_0.OFPFW_NW_DST_SHIFT)
> 
>          if self.flow.tp_src != 0:
>              wildcards &= ~ofproto_v1_0.OFPFW_TP_SRC
> 
> 
> 
> 
> 2013/3/24 FUJITA Tomonori <[email protected]>:
>> On Sun, 24 Mar 2013 13:45:52 +0100
>> Christopher Scherb <[email protected]> wrote:
>>
>>> I extended the file nx_match.py (ryu/ryu/ofproto/nx_match.py).
>>
>> Great, thanks!
>>
>>> Changes:
>>> Extended the file nx_match.py:
>>> In line 317 of the file there was a FIXME ("FIXME: Add support for
>>> dl_vlan, fl_vlan_pcp, nw_tos, nw_proto, nw_src, nw_dst, tp_src and
>>> dp_dst to self").
>>> The function "match_tuple" of the class "ClsRule" changed to support
>>> "dl_vlan, fl_vlan_pcp, nw_tos, nw_proto, nw_src, nw_dst, tp_src and
>>> dp_dst".
>>> The class "Flow" was extended with fields for "dl_vlan" and "dl_vlan_pcp".
>>> The class "ClsRule" was extended with functions to set the "dl_vlan"
>>> and the "dl_vlan_pcp" (New functions: "set_dl_vlan" and
>>> "set_dl_vlan_pcp").
>>> In the functions "set_nw_src" and "set_nw_dst" where changed (mask is
>>> 0 for a exact match) to work correct with the mask added in the
>>> match_tuple function.
>>
>> The last part looks wrong. With your patch, I can't set nw_dst/nw_src
>> without a mask. MFField->putm does nothing if mask is zero.
>>
>> I think that nw_dst and nw_src with a mask works now like the
>> following. I'm not sure what you try to fix.
>>
>> fujita@node1:~$ sudo ovs-ofctl dump-flows dp0
>> NXST_FLOW reply (xid=0x4):
>>  cookie=0x0, duration=1.879s, table=0, n_packets=0, n_bytes=0,
>>  idle_age=1, priority=1,ip,nw_src=18.52.86.0/24 actions=CONTROLLER:0
>>
>>
>> I dropped the nw_src/nw_dst changes and applied this patch. If you
>> still see some problem in the latest code, please send another patch.
>>
>> Next time, please follow the instruction:
>>
>> https://github.com/osrg/ryu/blob/master/SubmittingPatches.rst
>>
>>
>> Thanks!
>>
>> =
>> 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_IP)
>>         rule.set_nw_src_masked(0x12345678, 0xffffff00)
>>
>>         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:
>>             print "start"
>>             self.test(ev.dp)
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Everyone hates slow websites. So do we.
>> Make your web apps faster with AppDynamics
>> Download AppDynamics Lite for free today:
>> http://p.sf.net/sfu/appdyn_d2d_mar
>> _______________________________________________
>> Ryu-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 
> ------------------------------------------------------------------------------
> Own the Future-Intel&reg; Level Up Game Demo Contest 2013
> Rise to greatness in Intel's independent game demo contest.
> Compete for recognition, cash, and the chance to get your game 
> on Steam. $5K grand prize plus 10 genre and skill prizes. 
> Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel

------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to