Commit 94134b8e authored by cyq's avatar cyq
Browse files

add lab 3 materials

parent e563280c
#!/usr/bin/env python3
from switchyard.lib.address import *
from switchyard.lib.packet import *
from switchyard.lib.userlib import *
from threading import *
import time
def switchy_main(net):
my_interfaces = net.interfaces()
mymacs = [intf.ethaddr for intf in my_interfaces]
while True:
gotpkt = True
try:
timestamp,dev,pkt = net.recv_packet()
log_debug("Device is {}".format(dev))
except NoPackets:
log_debug("No packets available in recv_packet")
gotpkt = False
except Shutdown:
log_debug("Got shutdown signal")
break
if gotpkt:
log_debug("I got a packet from {}".format(dev))
log_debug("Pkt: {}".format(pkt))
net.shutdown()
#!/usr/bin/env python3
from switchyard.lib.address import *
from switchyard.lib.packet import *
from switchyard.lib.userlib import *
from random import randint
import time
def switchy_main(net):
my_intf = net.interfaces()
mymacs = [intf.ethaddr for intf in my_intf]
myips = [intf.ipaddr for intf in my_intf]
while True:
gotpkt = True
try:
#Timeout value will be parameterized!
timestamp,dev,pkt = net.recv_packet(timeout=0.15)
except NoPackets:
log_debug("No packets available in recv_packet")
gotpkt = False
except Shutdown:
log_debug("Got shutdown signal")
break
if gotpkt:
log_debug("I got a packet")
else:
log_debug("Didn't receive anything")
'''
Creating the headers for the packet
'''
pkt = Ethernet() + IPv4() + UDP()
pkt[1].protocol = IPProtocol.UDP
'''
Do other things here and send packet
'''
net.shutdown()
#!/usr/bin/env python3
from switchyard.lib.address import *
from switchyard.lib.packet import *
from switchyard.lib.userlib import *
from threading import *
from random import randint
import time
def switchy_main(net):
my_intf = net.interfaces()
mymacs = [intf.ethaddr for intf in my_intf]
myips = [intf.ipaddr for intf in my_intf]
while True:
gotpkt = True
try:
timestamp,dev,pkt = net.recv_packet()
log_debug("Device is {}".format(dev))
except NoPackets:
log_debug("No packets available in recv_packet")
gotpkt = False
except Shutdown:
log_debug("Got shutdown signal")
break
if gotpkt:
log_debug("I got a packet {}".format(pkt))
if dev == "middlebox-eth0":
log_debug("Received from blaster")
'''
Received data packet
Should I drop it?
If not, modify headers & send to blastee
'''
net.send_packet("middlebox-eth1", pkt)
elif dev == "middlebox-eth1":
log_debug("Received from blastee")
'''
Received ACK
Modify headers & send to blaster. Not dropping ACK packets!
net.send_packet("middlebox-eth0", pkt)
'''
else:
log_debug("Oops :))")
net.shutdown()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment