Updates to basic_tunnel and basic (#78)
* 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.
This commit is contained in:
@@ -4,6 +4,7 @@ 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
|
||||
@@ -23,18 +24,25 @@ def get_if():
|
||||
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()
|
||||
|
||||
if len(sys.argv)<4:
|
||||
print 'pass 3 arguments: <ip_addr> <dst_nid> "<message>"'
|
||||
exit(1)
|
||||
|
||||
addr = socket.gethostbyname(sys.argv[1])
|
||||
dst_id = int(sys.argv[2])
|
||||
addr = socket.gethostbyname(args.ip_addr)
|
||||
dst_id = args.dst_id
|
||||
iface = get_if()
|
||||
|
||||
print "sending on interface %s to id %s" % (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) / sys.argv[3]
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user