Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/P4D2_2018_East/exercises/basic/topology.json b/P4D2_2018_East/exercises/basic/topology.json
- index e33477c..f101b9c 100644
- --- a/P4D2_2018_East/exercises/basic/topology.json
- +++ b/P4D2_2018_East/exercises/basic/topology.json
- @@ -1,16 +1,16 @@
- {
- - "hosts": [
- - "h1",
- - "h2",
- - "h3"
- + "stations": [
- + "sta1",
- + "sta2",
- + "sta3"
- ],
- - "switches": {
- - "s1": { "cli_input" : "s1-commands.txt" },
- - "s2": { "cli_input" : "s2-commands.txt" },
- - "s3": { "cli_input" : "s3-commands.txt" }
- + "aps": {
- + "ap1": { "cli_input" : "s1-commands.txt" },
- + "ap2": { "cli_input" : "s2-commands.txt" },
- + "ap3": { "cli_input" : "s3-commands.txt" }
- },
- "links": [
- - ["h1", "s1"], ["s1", "s2"], ["s1", "s3"],
- - ["s3", "s2"], ["s2", "h2"], ["s3", "h3"]
- + ["sta1", "ap1"], ["ap1", "ap2"], ["ap1", "ap3"],
- + ["ap3", "ap2"], ["ap2", "sta2"], ["ap3", "sta3"]
- ]
- }
- diff --git a/P4D2_2018_East/utils/mininet/p4_mininet.py b/P4D2_2018_East/utils/mininet/p4_mininet.py
- index 8abe79f..fc68d0a 100644
- --- a/P4D2_2018_East/utils/mininet/p4_mininet.py
- +++ b/P4D2_2018_East/utils/mininet/p4_mininet.py
- @@ -14,7 +14,7 @@
- #
- from mininet.net import Mininet
- -from mininet.node import Switch, Host
- +from mn_wifi.node import AP, Station
- from mininet.log import setLogLevel, info, error, debug
- from mininet.moduledeps import pathCheck
- from sys import exit
- @@ -23,7 +23,7 @@ import os
- import tempfile
- import socket
- -class P4Host(Host):
- +class P4Host(Station):
- def config(self, **params):
- r = super(P4Host, self).config(**params)
- @@ -50,7 +50,7 @@ class P4Host(Host):
- print "Default route to switch: %s (%s)" % (sw_addr, sw_mac)
- print "**********"
- -class P4Switch(Switch):
- +class P4Switch(AP):
- """P4 virtual switch"""
- device_id = 0
- diff --git a/P4D2_2018_East/utils/p4_mininet.py b/P4D2_2018_East/utils/p4_mininet.py
- index b7fbbcd..fdabd6c 100644
- --- a/P4D2_2018_East/utils/p4_mininet.py
- +++ b/P4D2_2018_East/utils/p4_mininet.py
- @@ -13,8 +13,8 @@
- # limitations under the License.
- #
- -from mininet.net import Mininet
- -from mininet.node import Switch, Host
- +from mn_wifi.net import Mininet_wifi
- +from mn_wifi.node import AP, Station
- from mininet.log import setLogLevel, info, error, debug
- from mininet.moduledeps import pathCheck
- from sys import exit
- @@ -27,9 +27,9 @@ from netstat import check_listening_on_port
- SWITCH_START_TIMEOUT = 10 # seconds
- -class P4Host(Host):
- +class P4Host(Station):
- def config(self, **params):
- - r = super(Host, self).config(**params)
- + r = super(Station, self).config(**params)
- self.defaultIntf().rename("eth0")
- @@ -54,7 +54,7 @@ class P4Host(Host):
- )
- print "**********"
- -class P4Switch(Switch):
- +class P4Switch(AP):
- """P4 virtual switch"""
- device_id = 0
- @@ -66,7 +66,7 @@ class P4Switch(Switch):
- device_id = None,
- enable_debugger = False,
- **kwargs):
- - Switch.__init__(self, name, **kwargs)
- + AP.__init__(self, name, **kwargs)
- assert(sw_path)
- assert(json_path)
- # make sure that the provided sw_path is valid
- diff --git a/P4D2_2018_East/utils/run_exercise.py b/P4D2_2018_East/utils/run_exercise.py
- index 84997d7..5542924 100755
- --- a/P4D2_2018_East/utils/run_exercise.py
- +++ b/P4D2_2018_East/utils/run_exercise.py
- @@ -24,10 +24,13 @@ from time import sleep
- from p4_mininet import P4Switch, P4Host
- -from mininet.net import Mininet
- -from mininet.topo import Topo
- +from mn_wifi.net import Mininet_wifi
- +from mn_wifi.topo import Topo_WiFi
- from mininet.link import TCLink
- -from mininet.cli import CLI
- +from mn_wifi.cli import CLI_wifi
- +
- +from mn_wifi.link import wmediumd
- +from mn_wifi.wmediumdConnector import interference
- from p4runtime_switch import P4RuntimeSwitch
- @@ -60,22 +63,29 @@ def configureP4Switch(**switch_args):
- def describe(self):
- print "%s -> Thrift port: %d" % (self.name, self.thrift_port)
- + #@classmethod
- + def renameIface(self, intf, newname):
- + "Rename interface"
- + self.pexec('ip link set %s down' % intf)
- + self.pexec('ip link set %s name %s' % (intf, newname))
- + self.pexec('ip link set %s up' % newname)
- +
- return ConfiguredP4Switch
- -class ExerciseTopo(Topo):
- +class ExerciseTopo(Topo_WiFi):
- """ The mininet topology class for the P4 tutorial exercises.
- A custom class is used because the exercises make a few topology
- assumptions, mostly about the IP and MAC addresses.
- """
- - def __init__(self, hosts, switches, links, log_dir, **opts):
- - Topo.__init__(self, **opts)
- + def __init__(self, stations, aps, links, log_dir, **opts):
- + Topo_WiFi.__init__(self, **opts)
- host_links = []
- switch_links = []
- self.sw_port_mapping = {}
- for link in links:
- - if link['node1'][0] == 'h':
- + if link['node2'][0] == 's':
- host_links.append(link)
- else:
- switch_links.append(link)
- @@ -85,22 +95,25 @@ class ExerciseTopo(Topo):
- host_links.sort(key=link_sort_key)
- switch_links.sort(key=link_sort_key)
- - for sw in switches:
- - self.addSwitch(sw, log_file="%s/%s.log" %(log_dir, sw))
- + aps = sorted(aps)
- + aps.sort(key=len, reverse=False)
- + for sw in aps:
- + sw_num = aps.index(sw) * 50 + 50
- + self.addAccessPoint(sw, log_file="%s/%s.log" %(log_dir, sw), position='%s,100,0' % sw_num)
- for link in host_links:
- - host_name = link['node1']
- - host_sw = link['node2']
- - host_num = int(host_name[1:])
- - sw_num = int(host_sw[1:])
- + host_name = link['node2']
- + host_sw = link['node1']
- + host_num = int(host_name[3:])
- + sw_num = int(host_sw[2:])
- host_ip = "10.0.%d.%d" % (sw_num, host_num)
- host_mac = '00:00:00:00:%02x:%02x' % (sw_num, host_num)
- # Each host IP should be /24, so all exercise traffic will use the
- # default gateway (the switch) without sending ARP requests.
- - self.addHost(host_name, ip=host_ip+'/24', mac=host_mac)
- + self.addStation(host_name, ip=host_ip+'/24', mac=host_mac, position='%s,50,0' % (host_num*50))
- self.addLink(host_name, host_sw,
- - delay=link['latency'], bw=link['bandwidth'],
- - addr1=host_mac, addr2=host_mac)
- + delay=link['latency'], bw=link['bandwidth']) #,
- + #addr1=host_mac, addr2=host_mac)
- self.addSwitchPort(host_sw, host_name)
- for link in switch_links:
- @@ -175,8 +188,9 @@ class ExerciseRunner:
- self.logger('Reading topology file.')
- with open(topo_file, 'r') as f:
- topo = json.load(f)
- - self.hosts = topo['hosts']
- - self.switches = topo['switches']
- +
- + self.stations = topo['stations']
- + self.aps = topo['aps']
- self.links = self.parse_links(topo['links'])
- # Ensure all the needed directories exist and are directories
- @@ -235,8 +249,8 @@ class ExerciseRunner:
- if len(link) > 3:
- link_dict['bandwidth'] = link[3]
- - if link_dict['node1'][0] == 'h':
- - assert link_dict['node2'][0] == 's', 'Hosts should be connected to switches, not ' + str(link_dict['node2'])
- + if link_dict['node1'][0] == 's':
- + assert link_dict['node2'][0] == 'a', 'Hosts should be connected to switches, not ' + str(link_dict['node2'])
- links.append(link_dict)
- return links
- @@ -250,7 +264,7 @@ class ExerciseRunner:
- """
- self.logger("Building mininet topology.")
- - self.topo = ExerciseTopo(self.hosts, self.switches.keys(), self.links, self.log_dir)
- + self.topo = ExerciseTopo(self.stations, self.aps.keys(), self.links, self.log_dir)
- switchClass = configureP4Switch(
- sw_path=self.bmv2_exe,
- @@ -258,12 +272,15 @@ class ExerciseRunner:
- log_console=True,
- pcap_dump=self.pcap_dir)
- - self.net = Mininet(topo = self.topo,
- - link = TCLink,
- - host = P4Host,
- - switch = switchClass,
- - controller = None)
- + self.net = Mininet_wifi(topo = self.topo,
- + station = P4Host,
- + accessPoint = switchClass,
- + controller = None,
- + link=wmediumd,
- + wmediumd_mode=interference,
- + plot=True)
- + self.net.plotGraph(max_x=300, max_y=300)
- def program_switches(self):
- """ If any command files were provided for the switches,
- @@ -275,7 +292,7 @@ class ExerciseRunner:
- been called.
- """
- cli = 'simple_switch_CLI'
- - for sw_name, sw_dict in self.switches.iteritems():
- + for sw_name, sw_dict in self.aps.iteritems():
- if 'cli_input' not in sw_dict: continue
- # get the port for this particular switch's thrift server
- sw_obj = self.net.get(sw_name)
- @@ -296,21 +313,21 @@ class ExerciseRunner:
- - A mininet instance is stored as self.net and self.net.start() has
- been called.
- """
- - for host_name in self.topo.hosts():
- + for host_name in self.topo.stations():
- h = self.net.get(host_name)
- h_iface = h.intfs.values()[0]
- link = h_iface.link
- sw_iface = link.intf1 if link.intf1 != h_iface else link.intf2
- # phony IP to lie to the host about
- - host_id = int(host_name[1:])
- + host_id = int(host_name[3:])
- sw_ip = '10.0.%d.254' % host_id
- # Ensure each host's interface name is unique, or else
- # mininet cannot shutdown gracefully
- - h.defaultIntf().rename('%s-eth0' % host_name)
- + h.defaultIntf().rename('%s-wlan0' % host_name)
- # static arp entries and default routes
- - h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac))
- + #h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac))
- h.cmd('ethtool --offload %s rx off tx off' % h_iface.name)
- h.cmd('ip route add %s dev %s' % (sw_ip, h_iface.name))
- h.setDefaultRoute("via %s" % sw_ip)
- @@ -323,9 +340,9 @@ class ExerciseRunner:
- - A mininet instance is stored as self.net and self.net.start() has
- been called.
- """
- - for s in self.net.switches:
- + for s in self.net.aps:
- s.describe()
- - for h in self.net.hosts:
- + for h in self.net.stations:
- h.describe()
- self.logger("Starting mininet CLI")
- # Generate a message that will be printed by the Mininet CLI to make
- @@ -347,10 +364,10 @@ class ExerciseRunner:
- print(' tail -f %s/<switchname>.log' % self.log_dir)
- print('')
- print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir)
- - print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap')
- + print(' for example run: sudo tcpdump -xxx -r ap1-eth1.pcap')
- print('')
- - CLI(self.net)
- + CLI_wifi(self.net)
- def get_args():
- @@ -371,8 +388,8 @@ def get_args():
- if __name__ == '__main__':
- - # from mininet.log import setLogLevel
- - # setLogLevel("info")
- + #from mininet.log import setLogLevel
- + #setLogLevel("debug")
- args = get_args()
- exercise = ExerciseRunner(args.topo, args.log_dir, args.pcap_dir,
Add Comment
Please, Sign In to add comment