* Adding initial implementation of basic_encap example * Updated basic_encap example to count the number of valid packets * Updated basic_encap example to put encapsulation layer after Ethernet header. * Added solution file for basic_encap example * Changed the name of the basic_encap example to basic_tunnel and called the new header myTunnel. Also changed the myTunnel field names slightly. * Updated the README file for the basic_tunnel exercise. Also added topo.pdf image to serve as a reference during implementation. * Updated basic/README.md to point to basic_tunnel as the next exercise. * Updated the README for basic to point to basic_tunnel. Updated the starter code for basic_tunnel to look like basic solution with todo comments. Updated send.py and receive.py to be able to send both plain IP packets and tunneled IP packets. Updated basic_tunnel.p4 to have same control flow as p4runtime exercise.
54 lines
1.7 KiB
Python
Executable File
54 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import argparse
|
|
import sys
|
|
import socket
|
|
import random
|
|
import struct
|
|
import argparse
|
|
|
|
from scapy.all import sendp, send, get_if_list, get_if_hwaddr, hexdump
|
|
from scapy.all import Packet
|
|
from scapy.all import Ether, IP, UDP, TCP
|
|
from myTunnel_header import MyTunnel
|
|
|
|
def get_if():
|
|
ifs=get_if_list()
|
|
iface=None # "h1-eth0"
|
|
for i in get_if_list():
|
|
if "eth0" in i:
|
|
iface=i
|
|
break;
|
|
if not iface:
|
|
print "Cannot find eth0 interface"
|
|
exit(1)
|
|
return iface
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('ip_addr', type=str, help="The destination IP address to use")
|
|
parser.add_argument('message', type=str, help="The message to include in packet")
|
|
parser.add_argument('--dst_id', type=int, default=None, help='The myTunnel dst_id to use, if unspecified then myTunnel header will not be included in packet')
|
|
args = parser.parse_args()
|
|
|
|
addr = socket.gethostbyname(args.ip_addr)
|
|
dst_id = args.dst_id
|
|
iface = get_if()
|
|
|
|
if (dst_id is not None):
|
|
print "sending on interface {} to dst_id {}".format(iface, str(dst_id))
|
|
pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
|
|
pkt = pkt / MyTunnel(dst_id=dst_id) / IP(dst=addr) / args.message
|
|
else:
|
|
print "sending on interface {} to IP addr {}".format(iface, str(addr))
|
|
pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
|
|
pkt = pkt / IP(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535)) / args.message
|
|
|
|
pkt.show2()
|
|
# hexdump(pkt)
|
|
# print "len(pkt) = ", len(pkt)
|
|
sendp(pkt, iface=iface, verbose=False)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|