Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 In ONOS we use the term pipeconf (short of pipeline configuration) to describe the ensemble of P4 compiler artifacts and ONOS driver for a specific P4 program. A pipeconf is the entity that allows ONOS to deploy and control a given P4 program. A pipeconf is defined as an ONOS application that can be loaded at runtime. Example of pipeconfs 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.pipelines/.

We suggest starting by looking at the basic pipeconf. This one provides basic forwarding capabilities along with packet-in/out support, counters, etc. Among others, this pipeconf defines two important classes, an interpreter implementation, and a pipeconf loader.

Interpreter

The interpreter is what enables ONOS to understand the specific constructs of your P4 Program. For example, the Interpreter enables the translation from Traffic ONOS traffic treatments into to P4-defined Actionsactions.

You can see an example of an interpreter for the default.p4 program in the DefaultP4Interpreter.java class. 

PiPipeconfFactory

The PiPipeconfFactory is where you piece together all the needed elements for ONOS to understand your P4 program.

You need:

The interpreter implementation for the basic pipeconf can be found here

Pipeconf loader

This class is usually defined as an OSGi runtime component and is used to register the pipeconf at runtime. As part of this operation, this class is responsible for putting together all the pieces of a pipeconf, such as:

  • 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. 

Code Block
languagebash
titlebmv2 json and P4Info
p4c-bm2-ss default.p4 --p4-16 -o default.json --p4runtime-file default.p4info --p4runtime-format text

This command uses the frontend compiler only.

The Tofino.tofino.bin and the context.json can be generated only with a the Barefoot SDE and the attached Tofino specific backend compiler. For more information write to onos-dev@onosproject.org 

An example of a Pipeconf builder:

Code Block
languagejava
titlePipeconf Builder
return DefaultPiPipeconf.builder()
        .withId(new PiPipeconfId(format(PIPECONF_ID_BASE, system)))
        .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl))
        .addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class)
        .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
        .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
        .addExtension(P4_INFO_TEXT, p4InfoUrl)
        .addExtension(BMV2_JSON, jsonUrl)
        .addExtension(TOFINO_BIN, tofinoUrl)
        .addExtension(TOFINO_CONTEXT_JSON, contextUrl)
        .build();

, which is not open-source. For this reason, while we provide the compiler output of the basic P4 program for BMv2 (generated using the publicly available p4c compiler), we cannot provide the tofino.bin and the context.json in the ONOS repository. For more information on how to generate the tofino.bin and the context.json please reach out to Barefoot.

Looking at the pipeconf loader implementation, you can see we can also add driver behaviors specific to that P4 program/pipeline, 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.

...

need to set a pipeconf ID, which has to be globally unique as it will be used to refer to that pipeconf in the netcfg JSON later.

Walkthrough

Moving to the ONOS controller on the server, assuming you downloaded it and placed your pipeconf in it.

Run ONOS

You need to run it:

Code Block
languagebash
titleStart ONOS
$ buck run onos-local -- clean debug

...

Login into the ONOS CLI

Having Started started ONOS we need to login in it's its CLI.

Code Block
languagebash
onos localhost

Start the Pipeconf

Having Started ONOS we need to start the pipeconf.


Load the pipeconf

Code Block
languagebash
titleStart ONOS
onos> app activate <pipeconf_app_name>

To load the basic pipeconf use org.onosproject.pipelines.basic

Start the Barefoot driverHaving Started ONOS we need to start the toxin drivers.

Code Block
languagebash
titleActivate Drivers
onos> app activate org.onosproject.drivers.barefoot

This command brings in all the needed applications to interact with the Tofino-based switch.

Verify the active applications

please type

Code Block
languagebash
onos> apps -s -a

and verify Verify that these app apps at least are active in your ONOS environment:

...

First we need to create a .json file containing all the needed information such as IP/Port port of the P4Runtime server running on the device, it's its data plane ports and the pipeconf we want to deploy.

Code Block
{
  "devices": {
    "device:<name>tofino:1": {
      "generalprovider": {
        "p4runtime": {
          "ip": "<ip>ip.of.the.p4runtime.server",
          "portdeviceKeyId": "<port>"p4runtime:device:tofino:1",
          "port": 50051,
          "deviceId": <id_of_device>0
        }
      },
      "piPipeconf": {
        "piPipeconfId": "my.sample.pipeconf"
      },
      "ports": {
        "1/0": {
          "name": "1/0",
          "<name of your pipeconf>"speed": 100000,
          "enabled": true,
          "number": XXX,
          "removed": false,
          "type": "copper"
        },
        "ports2/0": {
          "name": "2/0",
    <ports of       "speed": 100000,
          "enabled": true,
          "number": XXX,
          "removed": false,
          "type": "copper"
        },
        "basic3/2": {
          "name": "<freindly_name>3/0",
          "latitudespeed": 4140000,
          "driverenabled": "tofino" true,
          "number": XXX,
          "removed": false,
        "longitude": -107  "type": "copper"
        }
      },
      "basic": {
        "driver": "barefoot"
      }
    }
  }
}

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 arrayIn this example, we assumed the device has been configured with 3 data plane ports, for each port the "number" value corresponds to the DP value in the Barefoot SDE port manager (see section below). The port number by default on for the gRPC/P4Runtime server 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:

...

Code Block
<your_machine>~$ onos-netcfg localhost <path_to_your_json_configuration_file>

This configuration gets picked up by the GeneralDeviceProvider.java that 


Check the ONOS log for possible errors.

To check if the device has been discovered by Check if the device is present in ONOS:

Code Block
onos> devices

...

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, hence after having pushed the netcfg JSON to ONOS. Please refer to the Barefoot SDE documentation for more information on port management.

Code Block
bf-sde> pm
bf-sde.pm> show
bf-sde.pm> port-add 1/0 100G NONE
bf-sde.pm> port-enb 1/0

...

At this point if everything went smoothly well you should be able to push flow rules defined with PiCriterion and PiInstruction according to the P4 program deployed on the device.