Hi,
On 2016年12月21日 05:51, Garegin Grigoryan wrote:
> Thanks a lot!
>
> My other question is: how to add the application data to the udp packet?
>
> Here's my code. It doesn't work, the receiver doesn't read the payload.
> def send_udp_reply(self, dpid, datapath, eth, ipv4_pkt, udp_segment,
> out_port, message):
> ofproto = datapath.ofproto
> total_length = len(message) + 8
> print "UDP Length", total_length
>
> e = ethernet.ethernet(dst=eth.src, src=CONTROLLER_MAC,
> ethertype=ether.ETH_TYPE_IP)
> i = ipv4.ipv4(dst=ipv4_pkt.src, src=ipv4_pkt.dst, proto=17)
> u = udp.udp(src_port=udp_segment.dst_port,
> dst_port=udp_segment.src_port, total_length=total_length)
> p = packet.Packet()
> p.add_protocol(e)
> p.add_protocol(i)
> p.add_protocol(u)
> p.serialize()
>
> actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
> data = p.data
> data += message
>
> out = datapath.ofproto_parser.OFPPacketOut(datapath=datapath,
> buffer_id=0xffffffff,
> in_port=datapath.ofproto.OFPP_CONTROLLER,
> actions=actions, data=data)
> datapath.send_msg(out)
"message" contains your application data, right?
Then, please append that data into the end of packet.Packet() instance.
e.g.)
p = packet.Packet()
p.add_protocol(e)
p.add_protocol(i)
p.add_protocol(u)
p.add_protocol(message) # append your data(binary type)
p.serialize()
Thanks,
Iwase
>
>
>
> On Tue, Dec 20, 2016 at 1:37 AM, Iwase Yusuke <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hi,
>
> As you said, udp_pkt is a instance of UDP Header parser class.
> For getting the payload of UDP, please check pkt.protocols member, first.
> It should be contains each protocol header instance and payload data
> (might be binary type).
> e.g.)
> pkt.protocols might contain [ethernet(...), ipv4(..), udp(..), b'...']
>
> Thanks,
> Iwase
>
> On 2016年12月20日 15:26, Garegin Grigoryan wrote:
> > I think I can do it this way, because udp headers is 8 bytes:
> > udp_pointer = len(msg.data) - udp_segment.total_length + 8
> > print msg.data[udp_pointer:]
> >
> >
> >
> >
> > On Tue, Dec 20, 2016 at 1:08 AM, Garegin Grigoryan
> <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>> wrote:
> >
> > Thanks!
> >
> > But udp_pkt contains only the header, as I understand it.
> > I want to get the application data from the udp_segment and nothing
> else (no headers).
> >
> > On Tue, Dec 20, 2016 at 1:05 AM, Iwase Yusuke
> <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>> wrote:
> >
> > Hi,
> >
> >
> > On 2016年12月20日 14:18, Garegin Grigoryan wrote:
> > > Hi,
> > >
> > > What is the best way to parse UDP segments in ryu controller?
> I want to see the application data.
> > > I've tried this but it doesn't work:
> > >
> > > udp_parser = stream_parser.StreamParser()
> > > print udp_parser.parse(msg.data)
> >
> > Does "msg.data" mean the packet data of PacketIn message?
> >
> > The packet data of PacketIn message is the ethernet frame.
> > So you can use packet.Packet() instead.
> >
> > e.g.)
> > from ryu.lib.packet import packet
> > from ryu.lib.packet import ethernet
> > from ryu.lib.packet import udp
> > ...(snip)
> >
> > pkt = packet.Packet(msg.data)
> > udp_pkt = pkt.get_protocol(udp.udp)
> > if udp_pkt:
> > # do something
> > ...(snip)
> >
> >
> > Thanks,
> > Iwase
> >
> >
> > >
> > > TypeError: Can't instantiate abstract class StreamParser with
> abstract methods try_parse
> > >
> > >
> > > --
> > > Sincerely,
> > > Garegin Grigoryan
> > >
> > >
> > >
> ------------------------------------------------------------------------------
> > > Developer Access Program for Intel Xeon Phi Processors
> > > Access to Intel Xeon Phi processor-based developer platforms.
> > > With one year of Intel Parallel Studio XE.
> > > Training and support from Colfax.
> > > Order your platform today.http://sdm.link/intel
> > >
> > >
> > >
> > > _______________________________________________
> > > Ryu-devel mailing list
> > > [email protected]
> <mailto:[email protected]>
> <mailto:[email protected]
> <mailto:[email protected]>>
> > > https://lists.sourceforge.net/lists/listinfo/ryu-devel
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>
> > >
> >
> >
> >
> >
> > --
> > Sincerely,
> > Garegin Grigoryan
> >
> >
> >
> >
> > --
> > Sincerely,
> > Garegin Grigoryan
> >
> >
> >
> ------------------------------------------------------------------------------
> > Developer Access Program for Intel Xeon Phi Processors
> > Access to Intel Xeon Phi processor-based developer platforms.
> > With one year of Intel Parallel Studio XE.
> > Training and support from Colfax.
> > Order your platform today.http://sdm.link/intel
> >
> >
> >
> > _______________________________________________
> > Ryu-devel mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.sourceforge.net/lists/listinfo/ryu-devel
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
> >
>
>
>
>
> --
> Sincerely,
> Garegin Grigoryan
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today.http://sdm.link/intel
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel