Hi,

On 2015年12月08日 13:57, nitish nagesh wrote:
> Hello,
> 
>    I am trying to modify the existing example script to generate a packet out 
> for every packet-in. My requirement is to send a packet out message to the 
> switch with the Packet-Out payload containing a 802.1Q VLAN tag of the 
> controller VID. In other words, irrespective of what packet was sent in the 
> packet-in message i send this crafted packet in the packet-out with all hard 
> coded packet fields. Following is the handler function:
> /
> 
>     @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
>     def packet_in_handler(self, ev):
>         msg = ev.msg
>         dp = msg.datapath
>         ofp = dp.ofproto
>         ofp_parser = dp.ofproto_parser
> 
> /
> /        /* Construct payload packet */
> /
> /        e = ethernet.ethernet(DST_MAC_ADDRESS,
>                               SRC_MAC_ADDRESS,
>                               ether.ETH_TYPE_IP)
> 
>         ip = ipv4.ipv4(4, header_length, tos, total_length, identification,
>                            0, 0, IPV4_TTL, inet.IPPROTO_UDP, 0,
>                            primary_ip_address, IPV4_DST_ADDRESS)
>         p = packet.Packet()
>         p.add_protocol(e)
>         if vlan_id is not None:
>             vlan_ = vlan.vlan(0, 0, vlan_id, e.ethertype)
>             e.ethertype = ether.ETH_TYPE_8021Q
>             p.add_protocol(vlan_)
>         p.add_protocol(ip)
> 
> /
> /      */* HOW DO I ASSOCIATE Packet 'p' TO THE PKT-OUT PAYLOAD HERE? */*
> /
> /
>         actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)]
>         out = ofp_parser.OFPPacketOut(
>             datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port,
>             actions=actions)
>         dp.send_msg(out)/
> 
> 
> However i am unable to figure out how to associate the crafted packet (p) to 
> the packet-out payload. I am newbie to python/RYU programming. Please help.

First, please serialize packet.Packet() instance and set binary data into 
ofp_parser.OFPPacketOut() args.
Then, how about the following?

    /* Construct payload packet */
    ...
    ...
    p.add_protocol(ip)
    p.serialize()  # serialize packet data

    actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)]
    out = ofp_parser.OFPPacketOut(
        datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port,
        actions=actions, data=p.data)  # p.data is the binary packet data


For more infomations for packet library, please refer to this page.
  http://osrg.github.io/ryu-book/en/html/packet_lib.html


Thanks,
Iwase

> 
> Thanks,
> Nitish
> 
> 
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
> 
> 
> 
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to