Hi, pkt.data contains the raw binary data of packets, so outputs of "print" is not human readable format.
To convert it human readable, how about using ryu.utils.binary_str()? $ git diff diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py index 3e7c598..f39b374 100644 --- a/ryu/app/simple_switch_13.py +++ b/ryu/app/simple_switch_13.py @@ -21,6 +21,7 @@ from ryu.ofproto import ofproto_v1_3 from ryu.lib.packet import packet from ryu.lib.packet import ethernet from ryu.lib.packet import ether_types +from ryu.utils import binary_str class SimpleSwitch13(app_manager.RyuApp): @@ -79,6 +80,9 @@ class SimpleSwitch13(app_manager.RyuApp): pkt = packet.Packet(msg.data) eth = pkt.get_protocols(ethernet.ethernet)[0] + print('pkt.data[:6]=%s' % pkt.data[:6]) + print('binary_str(pkt.data[:6])=%s' % binary_str(pkt.data[:6])) + if eth.ethertype == ether_types.ETH_TYPE_LLDP: # ignore lldp packet return $ ryu-manager ryu.app.simple_switch_13 loading app ryu.app.simple_switch_13 loading app ryu.controller.ofp_handler instantiating app ryu.app.simple_switch_13 of SimpleSwitch13 instantiating app ryu.controller.ofp_handler of OFPHandler pkt.data[:6]=������ binary_str(pkt.data[:6])=\xff\xff\xff\xff\xff\xff packet in 1 96:a4:5e:ec:aa:f3 ff:ff:ff:ff:ff:ff 1 pkt.data[:6]=��^�� binary_str(pkt.data[:6])=\x96\xa4\x5e\xec\xaa\xf3 packet in 1 56:8a:4e:de:66:ae 96:a4:5e:ec:aa:f3 2 pkt.data[:6]=V�N�f� binary_str(pkt.data[:6])=\x56\x8a\x4e\xde\x66\xae packet in 1 96:a4:5e:ec:aa:f3 56:8a:4e:de:66:ae 1 Thanks On 2016年03月31日 01:15, Gandhimathi Velusamy wrote: > Hi, > I trying to get first few bytes of payload of the packet_in. > if I use *pkt[-1]* to extract the payload, I am getting " 'tcp' object is not > iterable" error. > > other wise, if I use *pkt.data* , I am seeing some unknown symbols prepended > with payload. > > def_packet_in_handler(self, ev): > > # If you hit this you might want to increase > > # the "miss_send_length" of your switch > > ifev.msg.msg_len < ev.msg.total_len: > > self.logger.debug("packet truncated: only %s of %s bytes", > > ev.msg.msg_len, ev.msg.total_len) > > msg = ev.msg > > datapath = msg.datapath > > ofproto = datapath.ofproto > > parser = datapath.ofproto_parser > > in_port = msg.match['in_port'] > > > pkt = packet.Packet(msg.data) > > eth = pkt.get_protocols(ethernet.ethernet)[0] > > data = pkt.data > > ifdata: > > print"data:", data > > > ifeth.ethertype == ether_types.ETH_TYPE_LLDP: > > # ignore lldp packet > > return > > dst = eth.dst > > src = eth.src > > pkt_arp = pkt.get_protocol(arp.arp) > > pkt_ipv4 = pkt.get_protocol(ipv4.ipv4) > > ifpkt_ipv4: > > src_ip = pkt_ipv4.src > > dst_ip = pkt_ipv4.dst > > print"IP_SRC:", src_ip > > print"IP_DST:", dst_ip > > > pkt_tcp = pkt.get_protocol(tcp.tcp) > > ifpkt_tcp: > > tcp_src_port = pkt_tcp.src_port > > tcp_dst_port = pkt_tcp.dst_port > > print"TCP_Source_port:", tcp_src_port > > print"TCP_Dst_port:", tcp_dst_port > > > pkt_icmp = pkt.get_protocol(icmp.icmp) > > ifpkt_icmp: > > data= pkt_icmp.data > > print"ICMP Contains:", data > > > if( notpkt_arp): > > payload = bytearray(pkt.data) > > payload1 = pkt[-1] > > print"Payload by pkt[-1]:", payload1 > > ifpayload: > > print"Payload:", payload, "length_payload:", len(payload) > > print"Payload of six bytes:", payload[0:6] > > > > > *The output I am seeing when I am using netcat to send a text file from h1 to > h2 connected by OVS:* > > packet in 37769644528961 02:f6:aa:70:88:e7 02:e4:2e:e4:8a:23 5 > > packet truncated: only 170 of 1514 bytes > > data: ?.?#??p?E???@@B > > > > > > > ? > > '?,??G???Qi > > ??2?&?tadata field called Tunnel-ID associated with it (see A.2.3.7) > > IP_SRC: 10.10.1.1 > > IP_DST: 10.10.1.10 > > TCP_Source_port: 33292 > > TCP_Dst_port: 9999 > > Payload by pkt[-1]: tadata field called Tunnel-ID associated with it (see > A.2.3.7) > > Payload: ?.?#??p?E???@@B > > > > > > > ? > > '?,??G???Qi > > ??2?&?tadata field called Tunnel-ID associated with it (see A.2.3.7) > length_payload: 128 > > Payload of six bytes: ?.?# > > > May I please, know how to get first six bytes of payload? > > Thanks > > Gandhimathi > > > > ------------------------------------------------------------------------------ > Transform Data into Opportunity. > Accelerate data analysis in your applications with > Intel Data Analytics Acceleration Library. > Click to learn more. > http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140 > > > > _______________________________________________ > Ryu-devel mailing list > Ryu-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ryu-devel > ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140 _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel