Hi,

append_field() method is one of the "old" API for OFPMatch.
With old API, you need to convert IP/MAC address (string type)into binary type. 

e.g.)
>>> from ryu.lib import addrconv
>>> from ryu.ofproto import ofproto_v1_3 as ofproto
>>> from ryu.ofproto import ofproto_v1_3_parser as parser
>>> m = parser.OFPMatch()
>>> m.append_field(ofproto.OXM_OF_ETH_SRC, "02:a3:33:b2:2d:21")
>>> m
OFPMatch(oxm_fields={'eth_src': '30:32:3a:61:33:3a'})
>>> m.append_field(ofproto.OXM_OF_ETH_SRC, 
>>> addrconv.mac.text_to_bin("02:a3:33:b2:2d:21"))
>>> m
OFPMatch(oxm_fields={'eth_src': '02:a3:33:b2:2d:21'})


I recommend you to use the new API for OFPMatch.

e.g.)
>>> from ryu.ofproto import ofproto_v1_3 as ofproto
>>> from ryu.ofproto import ofproto_v1_3_parser as parser
>>> m = parser.OFPMatch(eth_src="02:a3:33:b2:2d:21")
>>> m
OFPMatch(oxm_fields={'eth_src': '02:a3:33:b2:2d:21'})
>>> kwargs = {'eth_src': '02:a3:33:b2:2d:21'}
>>> m = parser.OFPMatch(**kwargs)
>>> m
OFPMatch(oxm_fields={'eth_src': '02:a3:33:b2:2d:21'})

Thanks,
Iwase


On 2015年08月15日 11:33, Gandhimathi Velusamy wrote:
> Hi, 
> 
> I just tried to modify the code simple_switch_13.py in app folder of ryu.
> 
> When packet in happens,
>    I tried to modify the eth_src of the packet coming from port 1 with the 
> value "02:a3:33:b2:2d:21".
> It is working for me.
> Please, find attached the code and screen shot of Ryu output. 
> Inline images 1
> 
> Thanks
> Gandhimathi
> 
> 
> On 14 August 2015 at 17:47, A Sydney <asydney...@gmail.com 
> <mailto:asydney...@gmail.com>> wrote:
> 
>     Oops.. Looks like I inadvertently dropped ryu-devel from the thread..
> 
>     So below was correspondence between Gandhimathi and I (Ali).  Feel free 
> to provide feedback...
> 
> 
>     ### Gandhimathi  ###
> 
>     Have you tried with set_field()? 
>     page 167 from https://media.readthedocs.org/pdf/ryu/latest/ryu.pdf
> 
> 
> 
>     ### Ali ### 
> 
>     I've tried the following which works fine:
> 
>     match = parser.OFPMatch(eth_dst="02:a3:33:b2:2d:21")
> 
>     However, for my particular test case, I've got match conditions stored in 
> a config file and when a switch starts up, I read the config file and install 
> flows in the switch. Now my config file has things like:
> 
>     inport = 1
>     eth_src = "None"
>     eth_dst = "02:a3:33:b2:2d:21"
> 
>     And in my ryu application, I do something like (pseudo code):
> 
>     match = parser.OFPMatch()
> 
>     if inport != "None":
>       match.append_field(ofproto.OXM_OF_IN_PORT, inport)
> 
>     if eth_src != "None":
>       match.append_field(ofproto.OXM_OF_ETH_SRC, eth_src)
> 
>     if eth_dst != "None":
>       match.append_field(ofproto.OXM_OF_ETH_SRC, eth_dst)
> 
>     print "match:", match
> 
>     match: 1,  02:a3:33:b2:2d:21
> 
>     So if I don't have a value for a match condition (such as eth_src), I 
> insert "None" in the config file. Then when I create my match, if "None" 
> shows up for this parameter (like for eth_src), I don't add it to the match 
> condition. The the point here is that I append fields (inport, eth_src etc) 
> to the match condition iteratively. Hence, I can't use the form"match = 
> parser.OFPMatch(eth_dst="02:a3:33:b2:2d:21""
> 
>     ### Gandhimathi  ###
> 
>     I understand what you are trying to do. May be the syntax you are using 
> with match. append_field() is not correct? could you please, refer here:  
> https://github.com/FlowForwarding/LINC-Switch/commit/4c9aa3ad5ad1250f8357e04a65773b409fbe4b4c.
>  They used pointer data type to pass in append_field() method.
> 
> 
> 
>     ### Ali ### 
> 
>     Per your suggest, below is what I attempted:
> 
>     match = parser.OFPMatch()
>     
> test=[(ofproto.OXM_OF_IN_PORT,4),(ofproto.OXM_OF_ETH_SRC,"02:a3:33:b2:2d:21")]
>     for a in test:
>         match.append_field(*a)
>     print "matching:", match
> 
>     matching: OFPMatch(oxm_fields={'eth_src': '30:32:3a:61:33:3a', 'in_port': 
> 4})
> 
>     As shown, the mac address still has the same weird format as before
> 
>     I also tried the following:
> 
>     match = parser.OFPMatch()
>     match.set_in_port(4) 
>     match.set_dl_src("02:a3:33:b2:2d:21")
>     print "matching:", match
> 
>     matching: OFPMatch(oxm_fields={})
> 
>     But as shown, the output is empty
> 
>     REF:
>     https://github.com/osrg/ryu/blob/master/ryu/app/rest_router.py#L1722
> 
>     On Fri, Aug 14, 2015 at 2:13 PM, A Sydney <asydney...@gmail.com 
> <mailto:asydney...@gmail.com>> wrote:
> 
>         Any feedback?
> 
>         On Wed, Aug 12, 2015 at 5:29 PM, A Sydney <asydney...@gmail.com 
> <mailto:asydney...@gmail.com>> wrote:
> 
>             Hi Ryu folks,
>                                 This may be a trivial question...
> 
>             I'm using ryu 3.23.2 on CentOS 6.6 (OF 1.3). As shown below, when 
> I insert a mac address (02:a3:33:b2:2d:21), "appends_fields" seem to do 
> something smart that results in "30:32:3a:61:33:3a" in "match" (as opposed to 
> "02:a3:33:b2:2d:21").
> 
>             # Ryu app
>             match = parser.OFPMatch()
>             match.append_field(ofproto.OXM_OF_ETH_SRC, "02:a3:33:b2:2d:21")
>             print match
> 
>             # Output
>             OFPMatch(oxm_fields={'eth_src': '30:32:3a:61:33:3a'})
> 
>             How do I get the original mac address (02:a3:33:b2:2d:21) 
> inserted in "match"?
> 
>             Thanks,
>             Ali
> 
> 
> 
> 
>     
> ------------------------------------------------------------------------------
> 
>     _______________________________________________
>     Ryu-devel mailing list
>     Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 
> 
> 
> _______________________________________________
> Ryu-devel mailing list
> Ryu-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to