Add March 2021 VM based on Ubuntu 20.04 (#403)

* First draft of Ubuntu 20.04 Vagrantfile and scripts to install 2021-Mar
version of open source P4 development tools.

* Add more tracing output of what files have been installed at each step

* Don't do behavioral-model install_deps.sh before installing PI
This is an experiment to see if the end result will be able to run
tutorials basic exercise using Python3 only on an Ubuntu 20.04 system.
Just before this commit, `vagrant up` resulted in a system that failed
to run the basic exercise, because python3 failed to import
google.grpc (if I recall correctly -- it may have been a different
google.<something> Python3 module name).

* Add missing patch file

* Fix copy and paste mistake

* Add missing patch file

* Change how protobuf Python3 module files are installed

* Correct a few desktop icon file names, and add clean.sh script

* Enhance clean.sh script, and add README for manual steps in creating a VM

* Changes to try to always use Python3, never Python2, in tutorials

* Update README steps for preparing a VM

* More additions to README on steps to create a single file VM image

* Add empty-disk-block zeroing to clean.sh script

* Also install PTF

* Update versions of P4 dev tool source code to 2021-Apr-05
This includes a change to p4lang/PI that allows P4Runtime API clients
to send the shortest byte sequences necessary to encode integer
values, which I want for a PTF test that I have recently created.

* Update README for 2021-Apr-05 version of VM image

* Resolve Python 3 compatibility issues

Most of the Python 2 to 3 code translation changes
were automated with the 2to3 tool.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>

* Update commit SHAs for 4 p4lang repos to latest as of 2021-May-04

* Update Ubuntu 20.04 README.md for how I created 2021-May-04 version of VM

* mycontroller: Use Python 3 shebang line

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>

* Update Ubuntu 20.04 README.md for how I created 2021-Jun-01 version of VM

* Update commit SHAs for 4 p4lang repos to latest as of 2021-Jul-07

* Update Ubuntu 20.04 README.md for how I created 2021-Jul-07 version of VM

* Update commit SHAs for 4 p4lang repos to latest as of 2021-Aug-01

* Update Ubuntu 20.04 README.md for how I created 2021-Aug-01 version of VM

* Update commit SHAs for 4 p4lang repos to latest as of 2021-Sep-07

* Update Ubuntu 20.04 README.md for how I created 2021-Sep-07 version of VM

Co-authored-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Andy Fingerhut
2021-09-07 19:34:30 -07:00
committed by GitHub
parent 4914893445
commit c7f3139533
47 changed files with 1482 additions and 209 deletions

View File

@@ -25,7 +25,7 @@ class AppController:
assert entries
if sw: thrift_port = sw.thrift_port
print '\n'.join(entries)
print('\n'.join(entries))
p = subprocess.Popen(['simple_switch_CLI', '--thrift-port', str(thrift_port)], stdin=subprocess.PIPE)
p.communicate(input='\n'.join(entries))
@@ -33,8 +33,8 @@ class AppController:
if sw: thrift_port = sw.thrift_port
p = subprocess.Popen(['simple_switch_CLI', '--thrift-port', str(thrift_port)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate(input="register_read %s %d" % (register, idx))
reg_val = filter(lambda l: ' %s[%d]' % (register, idx) in l, stdout.split('\n'))[0].split('= ', 1)[1]
return long(reg_val)
reg_val = [l for l in stdout.split('\n') if ' %s[%d]' % (register, idx) in l][0].split('= ', 1)[1]
return int(reg_val)
def start(self):
shortestpath = ShortestPath(self.links)
@@ -54,7 +54,7 @@ class AppController:
for host_name in self.topo._host_links:
h = self.net.get(host_name)
for link in self.topo._host_links[host_name].values():
for link in list(self.topo._host_links[host_name].values()):
sw = link['sw']
#entries[sw].append('table_add send_frame rewrite_mac %d => %s' % (link['sw_port'], link['sw_mac']))
#entries[sw].append('table_add forward set_dmac %s => %s' % (link['host_ip'], link['host_mac']))
@@ -70,7 +70,7 @@ class AppController:
h.setDefaultRoute("via %s" % link['sw_ip'])
for h in self.net.hosts:
h_link = self.topo._host_links[h.name].values()[0]
h_link = list(self.topo._host_links[h.name].values())[0]
for sw in self.net.switches:
path = shortestpath.get(sw.name, h.name, exclude=lambda n: n[0]=='h')
if not path: continue
@@ -85,20 +85,20 @@ class AppController:
path = shortestpath.get(h.name, h2.name, exclude=lambda n: n[0]=='h')
if not path: continue
h_link = self.topo._host_links[h.name][path[1]]
h2_link = self.topo._host_links[h2.name].values()[0]
h2_link = list(self.topo._host_links[h2.name].values())[0]
h.cmd('ip route add %s via %s' % (h2_link['host_ip'], h_link['sw_ip']))
print "**********"
print "Configuring entries in p4 tables"
print("**********")
print("Configuring entries in p4 tables")
for sw_name in entries:
print
print "Configuring switch... %s" % sw_name
print()
print("Configuring switch... %s" % sw_name)
sw = self.net.get(sw_name)
if entries[sw_name]:
self.add_entries(sw=sw, entries=entries[sw_name])
print "Configuration complete."
print "**********"
print("Configuration complete.")
print("**********")
def stop(self):
pass

View File

@@ -6,9 +6,9 @@ class AppTopo(Topo):
log_dir="/tmp", bws={}, **opts):
Topo.__init__(self, **opts)
nodes = sum(map(list, zip(*links)), [])
host_names = sorted(list(set(filter(lambda n: n[0] == 'h', nodes))))
sw_names = sorted(list(set(filter(lambda n: n[0] == 's', nodes))))
nodes = sum(list(map(list, list(zip(*links)))), [])
host_names = sorted(list(set([n for n in nodes if n[0] == 'h'])))
sw_names = sorted(list(set([n for n in nodes if n[0] == 's'])))
sw_ports = dict([(sw, []) for sw in sw_names])
self._host_links = {}
@@ -23,7 +23,7 @@ class AppTopo(Topo):
self.addHost(host_name)
self._host_links[host_name] = {}
host_links = filter(lambda l: l[0]==host_name or l[1]==host_name, links)
host_links = [l for l in links if l[0]==host_name or l[1]==host_name]
sw_idx = 0
for link in host_links:

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# Copyright 2013-present Barefoot Networks, Inc.
#
@@ -84,7 +84,7 @@ def main():
conf = manifest['targets'][args.target]
params = conf['parameters'] if 'parameters' in conf else {}
os.environ.update(dict(map(lambda (k,v): (k, str(v)), params.iteritems())))
os.environ.update(dict([(k_v[0], str(k_v[1])) for k_v in iter(params.items())]))
def formatParams(s):
for param in params:
@@ -124,7 +124,7 @@ def main():
latencies[host_name+other] = host['latency']
for l in latencies:
if isinstance(latencies[l], (str, unicode)):
if isinstance(latencies[l], str):
latencies[l] = formatParams(latencies[l])
else:
latencies[l] = str(latencies[l]) + "ms"
@@ -160,7 +160,7 @@ def main():
if args.cli_message is not None:
with open(args.cli_message, 'r') as message_file:
print message_file.read()
print(message_file.read())
if args.cli or ('cli' in conf and conf['cli']):
CLI(net)
@@ -176,16 +176,16 @@ def main():
return cmd
def _wait_for_exit(p, host):
print p.communicate()
print(p.communicate())
if p.returncode is None:
p.wait()
print p.communicate()
print(p.communicate())
return_codes.append(p.returncode)
if host_name in stdout_files:
stdout_files[host_name].flush()
stdout_files[host_name].close()
print '\n'.join(map(lambda (k,v): "%s: %s"%(k,v), params.iteritems())) + '\n'
print('\n'.join(["%s: %s"%(k_v1[0],k_v1[1]) for k_v1 in iter(params.items())]) + '\n')
for host_name in sorted(conf['hosts'].keys()):
host = conf['hosts'][host_name]
@@ -195,7 +195,7 @@ def main():
stdout_filename = os.path.join(args.log_dir, h.name + '.stdout')
stdout_files[h.name] = open(stdout_filename, 'w')
cmd = formatCmd(host['cmd'])
print h.name, cmd
print(h.name, cmd)
p = h.popen(cmd, stdout=stdout_files[h.name], shell=True, preexec_fn=os.setpgrp)
if 'startup_sleep' in host: sleep(host['startup_sleep'])

View File

@@ -39,16 +39,16 @@ class P4Host(Host):
return r
def describe(self, sw_addr=None, sw_mac=None):
print "**********"
print "Network configuration for: %s" % self.name
print "Default interface: %s\t%s\t%s" %(
print("**********")
print("Network configuration for: %s" % self.name)
print("Default interface: %s\t%s\t%s" %(
self.defaultIntf().name,
self.defaultIntf().IP(),
self.defaultIntf().MAC()
)
))
if sw_addr is not None or sw_mac is not None:
print "Default route to switch: %s (%s)" % (sw_addr, sw_mac)
print "**********"
print("Default route to switch: %s (%s)" % (sw_addr, sw_mac))
print("**********")
class P4Switch(Switch):
"""P4 virtual switch"""
@@ -113,7 +113,7 @@ class P4Switch(Switch):
"Start up a new P4 switch"
info("Starting P4 switch {}.\n".format(self.name))
args = [self.sw_path]
for port, intf in self.intfs.items():
for port, intf in list(self.intfs.items()):
if not intf.IP():
args.extend(['-i', str(port) + "@" + intf.name])
if self.pcap_dump:

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# Copyright 2013-present Barefoot Networks, Inc.
#
@@ -64,11 +64,11 @@ class SingleSwitchTopo(Topo):
enable_debugger = False,
pcap_dump = pcap_dump)
for h in xrange(n):
for h in range(n):
host = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)
print "Adding host", str(host)
print("Adding host", str(host))
self.addLink(host, switch)
def main():
@@ -88,11 +88,11 @@ def main():
net.start()
sw_mac = ["00:aa:bb:00:00:%02x" % n for n in xrange(num_hosts)]
sw_mac = ["00:aa:bb:00:00:%02x" % n for n in range(num_hosts)]
sw_addr = ["10.0.%d.1" % n for n in xrange(num_hosts)]
sw_addr = ["10.0.%d.1" % n for n in range(num_hosts)]
for n in xrange(num_hosts):
for n in range(num_hosts):
h = net.get('h%d' % (n + 1))
if mode == "l2":
h.setDefaultRoute("dev %s" % h.defaultIntf().name)
@@ -100,30 +100,30 @@ def main():
h.setARP(sw_addr[n], sw_mac[n])
h.setDefaultRoute("dev %s via %s" % (h.defaultIntf().name, sw_addr[n]))
for n in xrange(num_hosts):
for n in range(num_hosts):
h = net.get('h%d' % (n + 1))
h.describe(sw_addr[n], sw_mac[n])
sleep(1)
if args.switch_config is not None:
print
print "Reading switch configuration script:", args.switch_config
print()
print("Reading switch configuration script:", args.switch_config)
with open(args.switch_config, 'r') as config_file:
switch_config = config_file.read()
print "Configuring switch..."
print("Configuring switch...")
proc = Popen(["simple_switch_CLI"], stdin=PIPE)
proc.communicate(input=switch_config)
print "Configuration complete."
print
print("Configuration complete.")
print()
print "Ready !"
print("Ready !")
if args.cli_message is not None:
with open(args.cli_message, 'r') as message_file:
print message_file.read()
print(message_file.read())
CLI( net )
net.stop()