Versions Compared

Key

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

In this tutorial, you will learn how This guide does NOT provide detailed instructions, but rather, pointers to existing guides that should give you enough information to set up and an ONOS environment capable of controlling P4RuntimeStratum-enabled Intel/Barefoot Tofino-based devices. The following set of instructions have been tested with the EdgeCore Wedge-100BF.

Table of Contents

Requirements

  • 1 or more Tofino based switches with Barefoot SDE 8.9.0 or later installed
  • 1 server with ONOS version 2.1 or later.

Prepare the switch

With the SDE and all necessary tools installed the switch process can be started.

Code Block
languagebash
titleStart switchd
bf_switchd --install-dir $SDE_INSTALL --conf-file $SDE_INSTALL/share/p4/targets/tofino/skip_p4.conf --skip-p4

It's worth noting the configuration file (skip_p4.conf). This configuration option makes bf_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

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/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 ONOS traffic treatments to P4-defined actions.

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:

  • P4Info for your program. 
  • Tofino.bin binary file
  • Tofino context.json file

The tofino.bin and the context.json can be generated with the Barefoot SDE, 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, such as the Pipeliner and the PortStatisticsDiscovery. We also 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 are building ONOS and you placed your pipeconf in its source tree.

Run ONOS

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

It's worth noting that this start ONOS in a single instance cluster. The command also builds ONOS and purges any previous state. The debug option offers the possibility to attach the JVM debugger on port 5005. 

Login into the ONOS CLI

Having started ONOS we need to login in its CLI.

Code Block
languagebash
onos localhost

...

switches.

Stratum is a software agent that runs on the switch and exposes gRPC-based interfaces such as P4Runtime, gNMI, and gNOI. These interfaces are used by ONOS to control and configure the switch.

The steps to follow are the following:

  1. Learn the basics of the Stratum-ONOS stack by doing the Next-Gen SDN Tutorial (based on Mininet and the BMv2 software switch)
  2. Learn how to deploy an existing ONOS pipeconf to your Tofino switch
  3. Use the acquired knowledge and code to create a pipeconf and ONOS apps that work with your own P4 program

Learn the basics with the next-Gen SDN Tutorial

Before experimenting with real hardware, and facing all the complexities associated with making things work for the first time, we strongly encourage you to understand the basic concepts of the Stratum-ONOS stack by doing this hands-on tutorial based on Mininet and the BMv2 software switch. Most of the provided code and instructions can be applied to the case of a real Tofino-based switch.

The tutorial is organized around a sequence of hands-on exercises that show how to build an IPv6-based leaf-spine data center fabric using P4, Stratum, and ONOS. It provides an introduction to concepts such as:

  • Data plane programming and control via P4 and P4Runtime
  • Device/port configuration via YANG, OpenConfig, and gNMI
  • Using ONOS to deploy an arbitrary P4 program to the network switches
  • Implementing ONOS apps that provide the control plane logic of your P4 program 

The tutorial instructions, along with slides, are available at this URL:

https://github.com/opennetworkinglab/ngsdn-tutorial

Learn how to deploy the fabric.p4 pipeconf to your Tofino switch

fabric.p4 is a P4 program distributed as part of ONOS, designed to work with Trellis, a set of SDN applications running on top of ONOS to provide the control plane for an IP fabric based on MPLS segment-routing.

ONOS uses "pipeconfs" to deploy and manage a given P4 program on a device. Pipeconfs are distributed as ONOS applications, hence using the .oar packaging. This GitHub repository provide instructions on how to build and use a pipeconf for fabric.p4 that includes the output of the P4 compiler for Tofino.

https://github.com/opencord/fabric-tofino

...

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

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

Start the Barefoot 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

Code Block
languagebash
onos> apps -s -a

Verify that these apps 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 P4Runtime server running on the device, its data plane ports and the pipeconf we want to deploy.

Code Block
{
  "devices": {
    "device:my-tofino-switch": {
      "basic": {
        "managementAddress": "grpc://10.0.0.1:28000?device_id=0",
        "driver": "barefoot",
        "pipeconf": "<your-pipeconf-id>"
      },
      "ports": {
        "1/0": {
          "name": "1/0",
          "speed": 100000,
          "enabled": true,
          "number": XXX,
          "removed": false,
          "type": "copper"
        },
        "2/0": {
          "name": "2/0",
          "speed": 100000,
          "enabled": true,
          "number": XXX,
          "removed": false,
          "type": "copper"
        },
        "3/2": {
          "name": "3/0",
          "speed": 40000,
          "enabled": true,
          "number": XXX,
          "removed": false,
          "type": "copper"
        }
      }
    }
  }
}

In 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 for the gRPC/P4Runtime server is 28000, so unless you made any changes to that leave it as is.

Upload the configuration you just wrote to the instance of ONOS you are running:

Code Block
$ curl -X POST -H "content-type:application/json" http://localhost:8181/onos/v1/network/configuration -d @<path_to_your_json_configuration_file> --user onos:rocks

or 

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

...

To check if the device has been discovered by ONOS:

Code Block
onos> devices

...

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, 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

Use

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