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

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from switch import SwitchConnection
from .switch import SwitchConnection
from p4.tmp import p4config_pb2
@@ -21,7 +21,7 @@ def buildDeviceConfig(bmv2_json_file_path=None):
device_config = p4config_pb2.P4DeviceConfig()
device_config.reassign = True
with open(bmv2_json_file_path) as f:
device_config.device_data = f.read()
device_config.device_data = f.read().encode('utf-8')
return device_config

View File

@@ -29,10 +29,10 @@ def matchesMac(mac_addr_string):
return mac_pattern.match(mac_addr_string) is not None
def encodeMac(mac_addr_string):
return mac_addr_string.replace(':', '').decode('hex')
return bytes.fromhex(mac_addr_string.replace(':', ''))
def decodeMac(encoded_mac_addr):
return ':'.join(s.encode('hex') for s in encoded_mac_addr)
return ':'.join(s.hex() for s in encoded_mac_addr)
ip_pattern = re.compile('^(\d{1,3}\.){3}(\d{1,3})$')
def matchesIPv4(ip_addr_string):
@@ -52,10 +52,10 @@ def encodeNum(number, bitwidth):
num_str = '%x' % number
if number >= 2 ** bitwidth:
raise Exception("Number, %d, does not fit in %d bits" % (number, bitwidth))
return ('0' * (byte_len * 2 - len(num_str)) + num_str).decode('hex')
return bytes.fromhex('0' * (byte_len * 2 - len(num_str)) + num_str)
def decodeNum(encoded_number):
return int(encoded_number.encode('hex'), 16)
return int(encoded_number.hex(), 16)
def encode(x, bitwidth):
'Tries to infer the type of `x` and encode it'
@@ -116,4 +116,4 @@ if __name__ == '__main__':
enc_num = encodeNum(num, 8)
raise Exception("expected exception")
except Exception as e:
print e
print(e)

View File

@@ -73,20 +73,20 @@ def parseGrpcErrorBinaryDetails(grpc_error):
# batch) in order to print error code + user-facing message. See P4Runtime
# documentation for more details on error-reporting.
def printGrpcError(grpc_error):
print "gRPC Error", grpc_error.details(),
print("gRPC Error", grpc_error.details(), end=' ')
status_code = grpc_error.code()
print "({})".format(status_code.name),
print("({})".format(status_code.name), end=' ')
traceback = sys.exc_info()[2]
print "[{}:{}]".format(
traceback.tb_frame.f_code.co_filename, traceback.tb_lineno)
print("[{}:{}]".format(
traceback.tb_frame.f_code.co_filename, traceback.tb_lineno))
if status_code != grpc.StatusCode.UNKNOWN:
return
p4_errors = parseGrpcErrorBinaryDetails(grpc_error)
if p4_errors is None:
return
print "Errors in batch:"
print("Errors in batch:")
for idx, p4_error in p4_errors:
code_name = code_pb2._CODE.values_by_number[
p4_error.canonical_code].name
print "\t* At index {}: {}, '{}'\n".format(
idx, code_name, p4_error.message)
print("\t* At index {}: {}, '{}'\n".format(
idx, code_name, p4_error.message))

View File

@@ -18,7 +18,7 @@ import google.protobuf.text_format
from p4.v1 import p4runtime_pb2
from p4.config.v1 import p4info_pb2
from convert import encode
from .convert import encode
class P4InfoHelper(object):
def __init__(self, p4_info_filepath):
@@ -173,7 +173,7 @@ class P4InfoHelper(object):
if match_fields:
table_entry.match.extend([
self.get_match_field_pb(table_name, match_field_name, value)
for match_field_name, value in match_fields.iteritems()
for match_field_name, value in match_fields.items()
])
if default_action:
@@ -185,7 +185,7 @@ class P4InfoHelper(object):
if action_params:
action.params.extend([
self.get_action_param_pb(action_name, field_name, value)
for field_name, value in action_params.iteritems()
for field_name, value in action_params.items()
])
return table_entry

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright 2017-present Open Networking Foundation
#
@@ -19,15 +19,15 @@ import json
import os
import sys
import bmv2
import helper
from . import bmv2
from . import helper
def error(msg):
print >> sys.stderr, ' - ERROR! ' + msg
print(' - ERROR! ' + msg, file=sys.stderr)
def info(msg):
print >> sys.stdout, ' - ' + msg
print(' - ' + msg, file=sys.stdout)
class ConfException(Exception):
@@ -165,16 +165,13 @@ def insertTableEntry(sw, flow, p4info_helper):
sw.WriteTableEntry(table_entry)
# object hook for josn library, use str instead of unicode object
# https://stackoverflow.com/questions/956867/how-to-get-string-objects-instead-of-unicode-from-json
def json_load_byteified(file_handle):
return _byteify(json.load(file_handle, object_hook=_byteify),
ignore_dicts=True)
return json.load(file_handle)
def _byteify(data, ignore_dicts=False):
# if this is a unicode string, return its string representation
if isinstance(data, unicode):
if isinstance(data, str):
return data.encode('utf-8')
# if this is a list of values, return list of byteified values
if isinstance(data, list):
@@ -184,7 +181,7 @@ def _byteify(data, ignore_dicts=False):
if isinstance(data, dict) and not ignore_dicts:
return {
_byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True)
for key, value in data.iteritems()
for key, value in data.items()
}
# if it's anything else, return it in its original form
return data

View File

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from Queue import Queue
from queue import Queue
from abc import abstractmethod
from datetime import datetime
@@ -63,7 +63,7 @@ class SwitchConnection(object):
request.arbitration.election_id.low = 1
if dry_run:
print "P4Runtime MasterArbitrationUpdate: ", request
print("P4Runtime MasterArbitrationUpdate: ", request)
else:
self.requests_stream.put(request)
for item in self.stream_msg_resp:
@@ -81,7 +81,7 @@ class SwitchConnection(object):
request.action = p4runtime_pb2.SetForwardingPipelineConfigRequest.VERIFY_AND_COMMIT
if dry_run:
print "P4Runtime SetForwardingPipelineConfig:", request
print("P4Runtime SetForwardingPipelineConfig:", request)
else:
self.client_stub.SetForwardingPipelineConfig(request)
@@ -96,7 +96,7 @@ class SwitchConnection(object):
update.type = p4runtime_pb2.Update.INSERT
update.entity.table_entry.CopyFrom(table_entry)
if dry_run:
print "P4Runtime Write:", request
print("P4Runtime Write:", request)
else:
self.client_stub.Write(request)
@@ -110,7 +110,7 @@ class SwitchConnection(object):
else:
table_entry.table_id = 0
if dry_run:
print "P4Runtime Read:", request
print("P4Runtime Read:", request)
else:
for response in self.client_stub.Read(request):
yield response
@@ -127,7 +127,7 @@ class SwitchConnection(object):
if index is not None:
counter_entry.index.index = index
if dry_run:
print "P4Runtime Read:", request
print("P4Runtime Read:", request)
else:
for response in self.client_stub.Read(request):
yield response
@@ -141,7 +141,7 @@ class SwitchConnection(object):
update.type = p4runtime_pb2.Update.INSERT
update.entity.packet_replication_engine_entry.CopyFrom(pre_entry)
if dry_run:
print "P4Runtime Write:", request
print("P4Runtime Write:", request)
else:
self.client_stub.Write(request)