On Tue, 27 Aug 2013 20:24:15 +0100
Alan Barr <[email protected]> wrote:

> Hello,
> I encountered unexpected behaviour today with Ryu 2.0 and also after a
> pull. I was sending a Flow Mod as a test to a switch (the flow mod
> content itself is likely not valid).
> 
> Basically, I tried the following for convenience:
> 
>             eth_src_field = datapath.ofproto_parser.OFPMatchField.make(
> datapath.ofproto.OXM_OF_ETH_SRC,
> haddr_to_bin("AA:AA:AA:AA:AA:AA"))
>             actions =
>             [datapath.ofproto_parser.OFPActionSetField(eth_src_field)]
> 
>             inst =
>             [ofproto_par.OFPInstructionActions(ofproto.OFPIT_WRITE_ACTIONS,
>                                                       actions),
> ofproto_par.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
>                                                       actions)]
> 
> And found that by reusing OFPActionSetField, the second instruction,
> apply actions, would be corrupt in the packet. So it appears the
> OFPActionSetField class is being modified which I was not expecting.
> I have included some test code which should demonstrate this as well
> as a pcap file showing when the same actions class is used, the
> transmitted data varies by 8 bytes compared to when independent
> OFPActionSetField classes are used.
> 
> I wasn't too sure if what I was doing was considered correct behaviour
> or not - but presumably if it was not, a raised error would be
> preferred?

I don't have any idea why actions can not be reusable. It should be
reusable. The following code works.

=
from ryu.lib.mac import haddr_to_bin
from ryu.controller import handler
from ryu.controller import dpset
from ryu.controller import ofp_event
from ryu.ofproto import ofproto_v1_3
from ryu.ofproto import ofproto_v1_3_parser
from ryu.base import app_manager
from ryu.ofproto.ofproto_parser import MsgBase, msg_pack_into, msg_str_attr


class PacketTest(app_manager.RyuApp):
    _CONTEXTS = {'dpset': dpset.DPSet}
    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        super(PacketTest, self).__init__(*args, **kwargs)

    def delete_all_flows(self, dp):
        match = dp.ofproto_parser.OFPMatch()
        m = dp.ofproto_parser.OFPFlowMod(dp, 0, 0, 0xff,
                                         dp.ofproto.OFPFC_DELETE,
                                         0, 0, 0, 0xffffffff,
                                         dp.ofproto.OFPP_ANY, 0xffffffff,
                                         0, match, [])

        dp.send_msg(m)

    def add_actions(self, dp, match, inst, table_id=0):
        m = dp.ofproto_parser.OFPFlowMod(datapath=dp, table_id=table_id,
                                         match=match, instructions=inst)
        dp.send_msg(m)

    def test(self, dp):
        print "starting to add flows!"

        eth_src_field1 = dp.ofproto_parser.OFPMatchField.make(
            dp.ofproto.OXM_OF_ETH_SRC,
            haddr_to_bin("AA:AA:AA:AA:AA:AA"))
        actions = [dp.ofproto_parser.OFPActionSetField(eth_src_field1)]

        self.delete_all_flows(dp)

        match = dp.ofproto_parser.OFPMatch(in_port=1)
        inst = [dp.ofproto_parser.OFPInstructionActions(
                ofproto_v1_3.OFPIT_APPLY_ACTIONS, actions)]
        
        self.add_actions(dp, match, inst)

        match = dp.ofproto_parser.OFPMatch(in_port=2)
        inst2 = [dp.ofproto_parser.OFPInstructionActions(
                ofproto_v1_3.OFPIT_APPLY_ACTIONS, actions)]
        self.add_actions(dp, match, inst2)

    @handler.set_ev_cls(dpset.EventDP, dpset.DPSET_EV_DISPATCHER)
    def handler_datapath(self, ev):
        if ev.enter:
            self.test(ev.dp)


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to