In this tutorial, you will learn how to set up and ONOS environment capable of controlling P4Runtime-enabled Tofino-based devices. The following set of instructions have been tested with the EdgeCore Wedge-100BF.
- 1 or more Tofino based switches with Barefoot SDE 6.0.0 or later installed
- 1 server with the latest ONOS master downloaded. the version has to be 1.12-SNAPSHOT or later.
Prepare the switch
With the SDE and all necessary tools installed the switch process can be started.
It's worth noting the configuration file (skip_p4.conf). This configuration option makes switchd start with no P4 program deployed. The program will be later deployed by ONOS using P4Runtime. Please also note that the skip_p4.conf file will only be installed if the SDE is built & installed with the p4_examples. Otherwise, this file can be found in the p4_examples tarball in the SDE package with the name tofino_skip_p4.conf.in
Create a Pipeconf for your P4 program
To build a pipeconf for your p4 program and make ONOS capable of installing it on the device and controlling it you need to write an application
The application must live under onos/pipelines/<p4 program name> and must contain at least two classes:
- implementation of Interpreter.java
- implementation of PiPipeconfFactory.java
An example of such application can be found under onos/pipeconfs/default this contains the default.p4 P4_16 program, the DefaultPipeconf, DefaultInterpreter and other classes related to the Default.p4 program.
The interpreter is what enables ONOS to understand the specific constructs of your P4 Program. For example the Interpreter enables the translation from Traffic treatments into P4 defined Actions.
You can see an example of an interpreter for the default.p4 program in the DefaultP4Interpreter.java class.
The PiPipeconfFactory is where you piece together all the needed elements for ONOS to understand your P4 program.
- bmv2 generated json for your program.
- P4Info for your program.
- Tofino.bin binary file
- Tofino context.json file
The bmv2 json and the P4Info can be generated through.
This command uses the frontend compiler only.
The Tofino.bin and the context.json can be generated only with a Barefoot SDE and the attached Tofino specific backend compiler. For more information write to email@example.com
An example of a Pipeconf builder:
As you can see we are giving the 4 needed files. We are also compiling the pipeline model from the BMv2 json and adding the Interpreter behaviour. In the Pipeconf Builder you can also add other behaviours, specific to the P4 program such as the Pipeliner and the PortStatisticsDiscovery needed to leverage existing ONOS functionality.
We are also setting a PipeconfId, this is the unique Id ONOS will use to reference the Pipeconf and that we will use in the net-cfg.json later.
The Pipeconf factory can also be the component that reports the pipeconf to the PiPipeconfService through the registerPipeconf method.
Run ONOS and bring the Pipeconf
Moving to the ONOS controller on the server, assuming you downloaded it and placed your pipeconf in it.
You need to run it:
It's worth noting that this start ONOS in a single instance cluster. The command also build ONOS and purges any previous state. The debug option offers the possibility to attach the debugger on port 5005.
Login into the ONOS CLI
Having Started ONOS we need to login in it's CLI.
Start the Pipeconf
Having Started ONOS we need to start the pipeconf.
Start the Barefoot driver
Having Started ONOS we need to start the toxin drivers.
This command brings in all the needed applications to interact with the switch.
Verify the active applications
and verify that these app at least are active in your ONOS environment:
org.onosproject.generaldeviceprovider (General Device Provider)
org.onosproject.drivers (Default Drivers)
org.onosproject.protocols.grpc (gRPC Protocol Subsystem)
org.onosproject.protocols.p4runtime (P4Runtime Protocol Subsystem)
org.onosproject.p4runtime (P4Runtime Provider)
org.onosproject.drivers.p4runtime (P4Runtime Drivers)
org.onosproject.drivers.barefoot (Barefoot Drivers)
- your own pipeconf app.
Build and push a configuration json
Having all the needed components in ONOS in place we can now tell ONOS about the device(s) and let the interaction begin.
First we need to create a .json file containing all the needed information such as IP/Port of the device, it's ports and the pipeconf we want to deploy.
A working example is in $ONOS_ROOT/tools/test/topos/tofino-demo-simple.json. Change the IP both in the DeviceId at the top and in the devices array. The port number by default on gRPC is 50051, so unless you made any changes to that leave it as is.
Please note that you need to add the driver as "tofino" and the the piPipeconfId as the name of your pipeconf.
Upload the configuration you just wrote to the instance of ONOS you are running:
This configuration gets picked up by the GeneralDeviceProvider.java that
Check if the device is present in ONOS:
Configure ports on the device
The last step to perform is to configure the ports on the switch.
Please repeat the following command for all the ports that you need on your device. This needs to be done after having pushed the pipeline config.
At this point if everything went smoothly you should be able to push rules defined with PiCriterion and PiInstruction according to the P4 program deployed on the device.