Versions Compared

Key

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

 


Warning
titleDeprecated

Support for P4 devices is now available via P4 Runtime. Check this page for more information.

The content of this page is deprecated. Support for BMv2 and P4 as described here won't be available anymore starting from ONOS 1.11 (Loon). Instead, the recently started P4 Brigade  is working on official support for P4-enabled devices via P4Runtime. Please subscribe to the brigade's mailing list to receive updates, or check the wiki here.

In order If you still want to to try the P4 support as described in on this page please make sure to use ONOS 1.6 (Goldeneye).

...

Applications are expected to provide an implementation of such interface. While for criteria

Footnote Macro

ONOS wording to refer to the match fields of a flow rule

 and tables it is possible to specify a 1-to-1 relationship through a Java map, for instructions the same is not possible or at least it's not convenient. The reason is that instructions in ONOS are modeled after OpenFlow actions (which are protocol-dependent), while flow rule treatments

Footnote Macro

ONOS wording to refer to the ensemble of actions to be applied as a consequence of a flow table match

are defined as a list of multiple instructions. In P4 instead, actions are defined as a compound of low-level protocol-independent primitives (not expressible using ONOS instructions), and, most important, P4 allows to specify only one action per table entry. Extracting the "meaning" of a given treatment instance and mapping it to a P4 action is not straightforward and it's usually program-specific. That’s why we expect a P4 programmer using ONOS to write its own interpretation logic (i.e. Java code) that can map a given treatment instance to a BMv2 action instance.

...

Code Block
languagejava
titleCode example of BMv2 extension selectors and treatments
ApplicationId myAppId = ...;
DeviceId myDeviceId = ...;
Bmv2DeviceContext myContext = ...;

Bmv2Configuration myConfiguration = myContext.configuration();

Ip4Prefix dstPrefix = Ip4Prefix.valueOf("192.16.184.0/24");

ExtensionSelector extSelector = Bmv2ExtensionSelector.builder()
        .forConfiguration(myConfiguration)
        .matchExact("standard_metadata", "ingress_port", 10)
        .matchLpm("ipv4", "dstAddr", dstPrefix.address().toOctets(), dstPrefix.prefixLength())
        .build();

ExtensionTreatment extTreatment = Bmv2ExtensionTreatment.builder()
        .forConfiguration(myConfiguration)
        .setActionName("next_hop")
        .addParameter("nhop_id", 4)
        .build();

FlowRule rule = DefaultFlowRule.builder()
        .forDevice(myDeviceId)
        .fromApp(myAppId)
        .forTable(0)
        .withSelector(DefaultTrafficSelector.builder()
                              .extension(extSelector, myDeviceId)
                              .build())
        .withTreatment(DefaultTrafficTreatment.builder()
                               .extension(extTreatment, myDeviceId)
                               .build())
        .build();

...


Developers Guide

ONOS+P4 Development Environment (onos-p4-dev)

...

...


Info
titleExporting environment variables in the shell profile

To get the most from the tools and instructions discussed in the following sections,  it is highly recommended that you add this line to your shell configuration profile (.bash_aliases.profile, etc.):

Code Block
source /<path>/<to>/onos-p4-dev/tools/bash_profile

...

  1. Build and run ONOS. This how-to screencast is a good starting point to build and run ONOS locally on your development machine, for any other information please refer to the ONOS Developer Guide.

    Info
    titleImportant! Build using Maven

    We are transitioning our build system from Maven to BUCK. Most of ONOS 1.6 modules can be build using BUCK expect for the bmv2 modules which are built by Maven. Hence, be sure to build ONOS using the command:

    Code Block
    languagetext
    $ mvn clean install
  2. Activate the BMv2 drivers. This will activate the whole BMv2 southbound subsystem, including the BMv2 providers, controller, and distributed services. In the ONOS command line type:

    Code Block
    languagetext
    onos> app activate org.onosproject.drivers.bmv2
  3. Check that both the BMv2 providers and drivers have been loaded successfully. On the ONOS command line, type:

    Code Block
    languagetext
    onos> app -s -a

    You should see an output similar to this (depending on your startup apps defined in $ONOS_APPS)

    Code Block
    languagetext
    *   8 org.onosproject.bmv2                 1.6.1.SNAPSHOT BMv2 Providers
    *  18 org.onosproject.drivers              1.6.1.SNAPSHOT Default Device Drivers
    *  19 org.onosproject.drivers.bmv2         1.6.1.SNAPSHOT BMv2 Drivers
    *  26 org.onosproject.openflow-base        1.6.1.SNAPSHOT OpenFlow Provider
    *  27 org.onosproject.hostprovider         1.6.1.SNAPSHOT Host Location Provider
    *  28 org.onosproject.lldpprovider         1.6.1.SNAPSHOT LLDP Link Provider
    *  29 org.onosproject.openflow             1.6.1.SNAPSHOT OpenFlow Meta App
    *  41 org.onosproject.fwd                  1.6.1.SNAPSHOT Reactive Forwarding App
    *  80 org.onosproject.proxyarp             1.6.1.SNAPSHOT Proxy ARP/NDP App
  4. Start Mininet using the custom file bmv2.py included in onos-p4-dev. On your Mininet VM (the same where you have cloned onos-p4-dev) shell, type: 

    Code Block
    languagebash
    $ sudo -E mn --custom $BMV2_PY --switch onosbmv2 --controller remote,ip=192.168.57.1,port=40123

    This will run a simple Mininet topology with 2 hosts connected to a BMv2 switch, to use a different topology please refer to the Mininet guide. The -E argument in sudo ensures that all environment variables are exported to the root user, including $BMV2_EXE and $BMV2_JSON. $BMV2_PY is used to point to the location of the Mininet custom file bmv2.py. All these variables are exported automatically by the onos-p4-dev shell configuration script. In our case, ONOS is running on a machine reachable from the Mininet VM at the IP address 192.168.57.1. Be sure to use the correct IP address of your ONOS instance. 40123 is the default listening port of the BMv2 controller in ONOS. If successful, the output of the previous command should be similar to this:

    Code Block
    languagetext
    *** Creating network
    *** Adding controller
    *** Adding hosts:
    h1 h2
    *** Adding switches:
    s1
    *** Adding links:
    (h1, s1) (h2, s1)
    *** Configuring hosts
    h1 h2
    *** Starting controller
    c0
    *** Starting 1 switches
    s1
    Starting BMv2 target: /home/mininet/p4/onos-bmv2/targets/simple_switch/simple_switch --device-id 1 -i 1@s1-eth1 -i 2@s1-eth2 --thrift-port 38400 --log-console -Lwarn /home/mininet/p4/p4src/build/empty.json -- --controller-ip 192.168.57.1 --controller-port 40123
    *** Starting CLI:
    mininet>
  5. Check that the BMv2 switch is running. On the Mininet VM shell, type:

    Code Block
    languagetext
    $ p4log 1
    Calling target program-options parser
    Adding interface s1-eth1 as port 1
    Adding interface s1-eth2 as port 2

    This command shows the log of the BMv2 instance with device ID 1 (look for --device-id in the Mininet startup output).

    Info
    titleRunning BMv2 for the first time

    Be aware that when running BMv2 for the first time after building it, it may take a while (up to 30 seconds) before the software switch process is executed and the log file written.

     


    Another way to check if the switch is running is by using the native BMv2 runtime CLI. In this case, you can use the p4cli command to print some switch information:

    Code Block
    languagetext
    $ echo "switch_info" | p4cli 1
    Obtaining JSON from switch...
    Done
    Control utility for runtime P4 table manipulation
    RuntimeCmd:
    device_id                : 1
    thrift_port              : 38400
    notifications_socket     : ipc:///tmp/bmv2-1-notifications.ipc
    elogger_socket           : None
    debugger_socket          : None
  6. Check that the BMv2 switch has successfully connected to ONOS. On the ONOS command line, check the output of the following command.

    Code Block
    languagetext
    onos> devices
    id=bmv2:192.168.57.100:45674#1, available=true, role=NONE, type=SWITCH, mfr=p4.org, hw=bmv2, sw=1.0.0, serial=n/a, driver=bmv2-thrift, bmv2JsonConfigMd5=aefbfbd1543efbfbdefbfbdefbfbd121defbfbdefbfbd3468efbfbd76, bmv2ProcessInstanceId=-1811218096, protocol=bmv2-thrift

    From the output, we can see that our BMv2 switch is connected (available=true), along with the MD5 sum of the JSON configuration currently deployed (bmv2JsonConfigMd5) and a unique ID of the BMv2 process instance (bmv2ProcessInstanceId). The latter is assigned automatically at switch boot and is used by ONOS to distinguish between different executions of similar BMv2 instances (i.e. with the same device ID and MD5 sum) and to detect a potential state change of a device (e.g. a reboot after a crash of the BMv2 process), in which case ONOS will promptly re-establish network state (e.g. re-install flow rules).

    The MD5 sum you see here is the one of the default.json configuration that is deployed on each BMv2 switch when they first connect to ONOS.

    You can also use the ONOS web GUI to explore your network. Point your browser to http://localhost:8181/onos/ui/login.html and authenticate yourself using username karaf and password karaf. You should be able to see something similar to this (click to zoom):

     


  7. Check that the 2 hosts can ping each other. On the Mininet VM shell, use the pingall command and chek the output:

    Code Block
    languagetext
    mininet> pingall
    *** Ping: testing ping reachability
    h1 -> h2
    h2 -> h1
    *** Results: 0% dropped (2/2 received)

    If the hosts can't ping this is probably due to the fact that the "Reactive Forwarding" application is not running. Refer to the previous step to check the list of active apps, if not running you can do so by typing the following on the ONOS command line:

    Code Block
    languagetext
    onos> app activate org.onosproject.fwd

    Make sure that also the following applications are running: hostproviderlldpprovider, and proxyarp

...

  • When running a cluster with multiple instances of ONOS, a stack overflow Java exception will be thrown by Bmv2TableEntryService. This is due to a known bug of the Kryo serializer. This issue has been already fixed and is available in the latest master and onos-1.6 branch.
  • The current Bmv2FlowRuleTranslator implementation is able to translate only a few types of criterions (IN_PORT, ETH_SRC, ETH_DST, ETH_TYPE) to BMv2 match keys of only ternary type. Seeking community help to implement translation for other criterion types and to other BMv2 match types (exact, LPM, valid, etc.). Get in touch if interested.

...


...

Display Footnotes Macro