Thanks for your answer, my doubt is that I print the packages before this
line, but they do not appear with tcp. Will it be a problem in my setup?
Em qua, 18 de jul de 2018 às 22:45, IWAMOTO Toshihiro <iwam...@valinux.co.jp>
escreveu:
> On Thu, 19 Jul 2018 07:34:36 +0900,
> Thomas William wrote:
> >
> > [1 <multipart/alternative (7bit)>]
> > [1.1 <text/plain; UTF-8 (7bit)>]
> > Hello, I've been having a problem for days, I can not capture tcp packets
> > with the controller.
> > My topology is below:
> >
> > +---------------------------+
> > | |
> > | C0 - Controller |
> > | |
> > +-------------+-------------+
> > c0-eth0
> > |
> > |
> > +-+--+--+-+ +-+--+--+
> > | Switch | ---------------- | H2 |
> > +-+--+--+-+ +-+--+--+
> > |
> > |
> > s1-eth0.2
> > +-------------+-------------+------+
> > | |
> > | S1 - OpenFlow AP |
> > | |
> > | |
> > +-+----------+----------+---+
> > s1-eth0.1
> > +
> > |
> > |
> > v
> > h1-eth0
> > +-+--+
> > | H1 |
> > +-+--+
> >
> > I want to modify tcp packets sent by server h1 to another h2 server
> > connected to the common switch, but when I print the packages, there is
> no
> > tcp package, just other types of packages like udp, dhcp, igmp, ipv4,
> ipv6. I
> > have no idea why, I'd like the opinion of you.
> >
> > My code is below, just an example to test here:
> >
> > from ryu.base import app_manager
> > # from ryu.ofproto import ofproto_v1_0
> > from ryu.ofproto import ofproto_v1_5
> > from ryu.lib.packet import packet
> > from ryu.lib.packet import ethernet
> > from ryu.lib.packet import ipv4
> > from ryu.lib.packet import tcp
> > from ryu.controller import ofp_event
> > from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
> > from ryu.controller.handler import set_ev_cls
> > from ryu.topology import event
> >
> > #iperf tcp example
> >
> > class L2Forwarding(app_manager.RyuApp):
> > # OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
> > OFP_VERSIONS = [ofproto_v1_5.OFP_VERSION]
> >
> > def __init__(self, *args, **kwargs):
> > super(L2Forwarding, self).__init__(*args, **kwargs)
> >
> > @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> > def switch_features_handler(self, ev):
> > datapath = ev.msg.datapath
> > ofproto = datapath.ofproto
> > parser = datapath.ofproto_parser
> > print("install the table-miss flow entry")
> > # install the table-miss flow entry.
> > match = parser.OFPMatch()
> > 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):
> > ofproto = datapath.ofproto
> > parser = datapath.ofproto_parser
> > print("construct flow_mod message and send it")
> > # construct flow_mod message and send it.
> > inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
> > actions)]
> > mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
> > match=match, instructions=inst)
> > datapath.send_msg(mod)
> >
> >
> > @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> > def packet_in_handler(self, ev):
> > msg = ev.msg # Object representing a packet_in data
> > structure.
> > datapath = msg.datapath # Switch Datapath ID
> > ofproto = datapath.ofproto # OpenFlow Protocol version the
> entities
> > negotiated. In our case OF1.3
> > parser = datapath.ofproto_parser
> > out_port = ofproto.OFPP_LOCAL
> > in_port = ofproto.OFPP_LOCAL
> >
> > pkt = packet.Packet(msg.data)
> > eth = pkt.get_protocol(ethernet.ethernet)
> >
> > dst = eth.dst
> > src = eth.src
> >
> > print(pkt.get_protocol)
> >
> > self.logger.info("packet in %s %s", src, dst)
> >
> > v4 = pkt.get_protocol(ipv4.ipv4)
> > if v4:
> > print("IPV4: %s ==> %s " % (v4.src, v4.dst))
> >
> > server_ip = v4.dst
> > in_port = msg.match['in_port']
> >
> > if pkt.get_protocol(tcp.tcp):
>
> You are discarding tcp packet data here.
> You'd want to:
>
> pkt_tcp = pkt.get_protocol(tcp.tcp)
> if pkt_tcp:
> src_port = pkt_tcp.src_port
>
> > src_port = pkt.src_port
> > print("TCP GET %s", "=" * 100)
> >
> > #Match in protocol tcp "in_proto=6" and ipv4
> > "eth_type=0x0800"
> > match_tcp = parser.OFPMatch(in_port=in_port,
> > eth_type=0x0800, ip_proto=6, tcp_flags=0x010, ipv4_dst=server_ip,
> > tcp_src=src_port)
> > actions =
> > [datapath.ofproto_parser.OFPActionOutput(out_port)]
> >
> > self.add_flow(datapath, 1, match_tcp, actions)
>
> --
> IWAMOTO Toshihiro
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel