Hi, Does "msg" mean an instance of OFPPacketIn? http://ryu.readthedocs.io/en/latest/ofproto_v1_3_ref.html#ryu.ofproto.ofproto_v1_3_parser.OFPPacketIn
If so, you can parse the packet data which contained in OFPPacketIn with the Packet library. http://ryu.readthedocs.io/en/latest/library_packet.html For extracting the TCP src/dst port from msg.data: $ git diff diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py index 3e7c598..899fc01 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.lib.packet import tcp class SimpleSwitch13(app_manager.RyuApp): @@ -79,6 +80,11 @@ class SimpleSwitch13(app_manager.RyuApp): pkt = packet.Packet(msg.data) eth = pkt.get_protocols(ethernet.ethernet)[0] + pkt_tcp = pkt.get_protocol(tcp.tcp) + if pkt_tcp: # check if the received packet is TCP or not + self.logger.info('pkt_tcp.src_port=%d, pkt_tcp.dst_port=%s', + pkt_tcp.src_port, pkt_tcp.dst_port) + if eth.ethertype == ether_types.ETH_TYPE_LLDP: # ignore lldp packet return $ ryu-manager ryu/app/simple_switch_13.py loading app ryu/app/simple_switch_13.py loading app ryu.controller.ofp_handler instantiating app ryu.controller.ofp_handler of OFPHandler instantiating app ryu/app/simple_switch_13.py of SimpleSwitch13 ...(snip) pkt_tcp.src_port=50586, pkt_tcp.dst_port=80 ...(snip) Thanks, Iwase On 2016年09月27日 22:34, Aidin Kelki wrote: > Thank you for your reply. The thing is I need to also get the port number of > each flow in match section so in flow table ,I should have src_mac, > dst_mac,ip_proto, eth_type, tcp/udp_src,tcp/udp_dst. The problem is I have > all of other feature but cannot get tcp/udp_src, tcp_udp_dst. > > I also configured the switch for tcp to have: > > Ip_proto=6 > > Eth_type = 0x800 > > And for udp: > > Ip_proto = 17 > > Eth_type = 0x800 > > The portion of code that do the match for me is: > > ethtype = msg.match['eth_type'] > > if ethtype == 0x800 and ipproto in [ 1, 6, 17]: > ipsrc = msg.match['ipv4_src'] > ipdst = msg.match['ipv4_dst'] > match = ofparser.OFPMatch(eth_type=0x0800, eth_src= > src,eth_dst=dst, ip_proto = ipproto , ipv4_src = ipsrc,ipv4_dst = ipdst ) > else: > match = ofparser.OFPMatch(eth_type=ethtype, > eth_src= src,eth_dst=dst) > > > but I don't know how to add for example tcp/udp_src and tcp/udp_dst to the > msg because with print msg I see none of the mentioned feature. > I would appreciated if you point me into a right direction. > Thank you again. > > Best regards > AK > > ________________________________ > From: Iwase Yusuke <iwase.yusu...@gmail.com> > Sent: Tuesday, September 27, 2016 8:03 AM > To: aidin.ke...@hotmail.com > Cc: ryu-devel@lists.sourceforge.net > Subject: Re: [Ryu-devel] TCP_SRC/TCP_DST > > Hi, > > What exactly error did you get? > > For adding tcp_src/tcp_dst match fields, please check the "7.2.3.6 Flow > Match Field Prerequisite" in OpenFlow Spec 1.3, first. > > For example, if you want to add tcp_dst=80, you also need to specify > eth_type=0x0800 and ip_proto=6. > > > $ git diff > diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py > index 3e7c598..9f29041 100644 > --- a/ryu/app/simple_switch_13.py > +++ b/ryu/app/simple_switch_13.py > @@ -48,6 +48,11 @@ class SimpleSwitch13(app_manager.RyuApp): > ofproto.OFPCML_NO_BUFFER)] > self.add_flow(datapath, 0, match, actions) > > + match = parser.OFPMatch(eth_type=0x0800, ip_proto=6, tcp_dst=80) > + actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER, > + ofproto.OFPCML_NO_BUFFER)] > + self.add_flow(datapath, 0, match, actions) > + > def add_flow(self, datapath, priority, match, actions, buffer_id=None): > ofproto = datapath.ofproto > parser = datapath.ofproto_parser > > > $ sudo mn --controller remote > ...(snip) > mininet> sh ovs-ofctl dump-flows s1 > NXST_FLOW reply (xid=0x4): > cookie=0x0, duration=11.877s, table=0, n_packets=0, n_bytes=0, idle_age=11, > priority=0 actions=CONTROLLER:65535 > cookie=0x0, duration=11.877s, table=0, n_packets=0, n_bytes=0, idle_age=11, > priority=0,tcp,tp_dst=80 actions=CONTROLLER:65535 > > > Thanks, > Iwase > > > On 2016?09?23? 02:20, Aidin Kelki wrote: >> Hi guys >> >> >> I am trying to add tcp_src/tcp_dst to the flow table but whenever I run Ryu, >> it gives me error. also I checked the msg but there is no tcp(src_port, >> dst_port). I want to ask how to add tcp_src/tcp_dst to match so I can get >> that from the flow? >> >> >> Thank you >> >> >> >> ------------------------------------------------------------------------------ >> >> >> >> _______________________________________________ >> 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