Basic Encapsulation Example (#64)
* 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.
This commit is contained in:
45
P4D2_2017_Fall/exercises/basic_tunnel/send.py
Executable file
45
P4D2_2017_Fall/exercises/basic_tunnel/send.py
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
import argparse
|
||||
import sys
|
||||
import socket
|
||||
import random
|
||||
import struct
|
||||
|
||||
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():
|
||||
|
||||
if len(sys.argv)<4:
|
||||
print 'pass 2 arguments: <ip_addr> <dst_nid> "<message>"'
|
||||
exit(1)
|
||||
|
||||
addr = socket.gethostbyname(sys.argv[1])
|
||||
dst_id = int(sys.argv[2])
|
||||
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]
|
||||
pkt.show2()
|
||||
# hexdump(pkt)
|
||||
# print "len(pkt) = ", len(pkt)
|
||||
sendp(pkt, iface=iface, verbose=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user