Versions Compared

Key

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

...

This walkthrough demonstrates the necessary steps and commands to run a network of BMv2 devices in Mininet, controlled by ONOS using P4Runtime.

In this example, the BMv2 devices will be configured with a sample P4 program that is provided by ONOS and is called , named basic.p4.

If not differently specified, the following commands have to be executed in a terminal shell of the VM.

  1. Build ONOS master

    Code Block
    languagebash
    $ cd ~/onos
    
    $ git pull origin master
    
    $ buck build onos
  2. Run ONOS

    Code Block
    languagebash
    $ export ONOS_APPS=drivers.bmv2,proxyarp,lldpprovider,hostprovider,fwd
    
    $ buck run onos-local -- clean

    The variable ONOS_APPS indicates which ONOS applications to execute at ONOS boot. The list includes the BMv2 drivers (based on P4Runtime), the Proxy ARP application, the LLDP Link Provider, the Host Location Provider, and the Reactive Forwarding application. These applications combined together provide ONOS with capabilities to discover the topology (via injection of LLDP packets), the hosts (by intercepting and handling ARP requests) and to provide basic point-to-point connectivity.

  3. On a second terminal shell, access the ONOS command line:

    onos losalhost
    Code Block
    languagebash
    $ onos localhost
  4. Check that all applications have been loaded successfully. On the ONOS command line, type:

    Code Block
    languagebash
    onos> apps -s -a

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

    * 10 org.onosproject.drivers 1.13.0.SNAPSHOT Default Drivers
    * 35 org.onosproject.generaldeviceprovider 1.13.0.SNAPSHOT General Device Provider
    * 36 org.onosproject.protocols.grpc 1.13.0.SNAPSHOT gRPC Protocol Subsystem
    * 37 org.onosproject.protocols.p4runtime 1.13.0.SNAPSHOT P4Runtime Protocol Subsystem
    * 38 org.onosproject.p4runtime 1.13.0.SNAPSHOT P4Runtime Provider
    * 39 org.onosproject.drivers.p4runtime 1.13.0.SNAPSHOT P4Runtime Drivers
    * 42 org.onosproject.proxyarp 1.13.0.SNAPSHOT Proxy ARP/NDP
    * 44 org.onosproject.hostprovider 1.13.0.SNAPSHOT Host Location Provider
    * 45 org.onosproject.lldpprovider 1.13.0.SNAPSHOT LLDP Link Provider
    * 73 org.onosproject.pipelines.basic 1.13.0.SNAPSHOT Basic Pipelines
    * 119 org.onosproject.drivers.bmv2 1.13.0.SNAPSHOT BMv2 Drivers
    * 146 org.onosproject.fwd 1.13.0.SNAPSHOT Reactive Forwarding

  5. 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: 
    . On third VM terminal shell, type: 
    Code Block
    languagebash
    $ sudo -E mn --custom $BMV2_MN_PY --switch onosbmv2 --controller remote
    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. $BMV2_MN_PY is used to point to the location of the Mininet custom file bmv2.py provided in ONOS. If successful, the output of the previous command should be similar to this:
    *** Creating network
    *** Adding controller
    *** Adding hosts:
    h1 h2
    *** Adding

    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:

    *** 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
    grpc --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>
     --thrift-port 38148 --no-p4 -- --cpu-port 255 --grpc-server-addr 0.0.0.0:37346
    [1] 2370

    *** Starting CLI:
    mininet>

  6. Check that the BMv2 switch is running. On the Mininet VM shell, type:

    $ 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).

    Running 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:

    $ 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

    Check that the BMv2 switch has successfully connected to ONOS. On the ONOS command line, check the output of the following command.

    onos> devices

    id=device:bmv2:

    192.168.57.100:45674#1

    1, available=

    true

    false, local-status=connected 9m33s ago, role=NONE, type=SWITCH, mfr=p4.org, hw=

    bmv2

    master, sw=

    1.0.0

    master, serial=

    n/a

    unknown, driver=bmv2

    -thrift, bmv2JsonConfigMd5=aefbfbd1543efbfbdefbfbdefbfbd121defbfbdefbfbd3468efbfbd76, bmv2ProcessInstanceId=-1811218096, protocol=bmv2-thrift

    :org.onosproject.pipelines.basic, locType=geo, name=device:bmv2:1, protocol=[p4runtime]

    From the output, we can see that our the 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):

Update P4Tools to latest version

  1. information on the P4 program (pipeconf) deployed (driver=bmv2:org.onosproject.pipelines.basic) and on the protocol used to control the switch (protocol=[p4runtime]).

  2. Check that the 2 hosts can ping each other. On the Mininet command line, use the pingall command check the output:

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

Update P4Tools to latest version

Since P4Runtime is a work-in-progress effort, we frequently update ONOS to support the most recent capabilities. Similarly, we update the version of the P4 tools (BMv2, P4Runtime, and p4c) in the VM. Use the following commands to update ONOS and the P4 tools to the latest version:It might be needed to update the P4Tools to the latest version. Please run these commands one at a time in the same terminal window inside you machine. This process is the same for both the pre-built VM and any machine built from scratch.

Code Block
languagebash
cd ~/onos/
git pull
cd origin ~master
onos-setup-p4-dev

Run the Developer Environment 

Start Mininet, using BMv2 simple_switch_grpc target. 

Go in the home directory:

Code Block
languagebash
cd ~

On your Mininet VM shell, type:

Code Block
languagebash
sudo -E mn --custom $BMV2_MN_PY --switch onosbmv2 --controller remote,ip=192.168.56.1

Be sure to use the correct IP address of your ONOS instance.The onos-setup-p4-dev will download and build the most recent version of the P4 tools. In case of errors, please remove any previsouly build artifacts