简体   繁体   中英

Creating TCP packet with POX

I'm trying to create a TCP packet with POX controller and sending it to one of the switches.

This is how the packet is created:

        payload = "MESSAGE"
        tcp_packet = tcp()
        tcp_packet.srcport = 10000
        tcp_packet.dstport = 10001
        tcp_packet.payload = payload
        tcp_packet.seq = 100

        ipv4_packet = ipv4()
        ipv4_packet.iplen = ipv4.MIN_LEN + len(tcp_packet)
        ipv4_packet.protocol = ipv4.TCP_PROTOCOL
        ipv4_packet.dstip = IPAddr('10.0.0.5')
        ipv4_packet.srcip = IPAddr('10.0.0.1')
        ipv4_packet.set_payload(tcp_packet)

        eth_packet = ethernet()
        eth_packet.set_payload(ipv4_packet)
        eth_packet.dst = EthAddr('00:00:00:00:00:05')
        eth_packet.src = EthAddr('00:00:00:00:00:01')
        eth_packet.type = ethernet.IP_TYPE

Afterwards, it's sent through one of the ports of a switch. When I try to capture the packet in PacketIn handler:

event.parsed.find('tcp')

returns None, as though there's no TCP packet. Capturing the traffic with Wireshark, I see the packet (wrapped in OF packet) but Wireshark warns that TCP header is zero.

Is this indeed the problem, with the header, and if it's how can I fix this ?

Thank you

The problem was that data offset field had not been set. Since, the minimal header length for TCP packet is 5 32bit words (20 bytes) and I've no options set in the header. So in order to fix this, I should had to add:

tcp_packet.off = 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM