p4lang / p4app

Apache License 2.0
112 stars 58 forks source link

The scapy sniff can not work correctly? #79

Open ChengjunJia opened 4 years ago

ChengjunJia commented 4 years ago

Hi, all. I want to use scapy to write my own client and server in _multi_switchmininet.p4app. However, I find that if I modify the _echoserver.py to enable sniff() function and enable the pcap_dump in p4app.json. The pcap results will contain a strange packet: an IPv4+ICMP packet which container total IP+UDP packet in its payload! But from the sniff() result, the host received a UDP packet instead of IPv4+ICMP packet.

Here is the _echoserver.py codes:

import socket, sys
from scapy.all import *
import time

print("Start to sniff packets...")
sniffed = sniff(iface="h1-eth0", filter="ip", prn=custom_action, count = 5)
for pkt in sniffed:
        pkt.show()
time.sleep(5)

And here is the _echoclient.py codes:

import socket, sys
from scapy.all import *
import os

srv_addr = (sys.argv[1], int(sys.argv[2]))
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(sys.argv[3], srv_addr)

Anyone has any idea? Besides, the pcap result is a little confusing for me. s1-eth1_out.pcap means that the packets leave the s1 from eth1 or go into s1 from eth1?