Install Ubuntu 18 + P4 + onos from scratch

1. Install VMware Tools (there are too many tutorials on installing Ubuntu for VM virtual machine, so I won't write them)

First download from the virtual machine, then move the folder in the compressed package out (you can decompress or directly click the compressed package to move out of the VMware Tools District folder), enter the folder and execute

sudo ./

2. Replace the download source (you can search the domestic sources that are easier to use)

Find software & updates from the application, select Other, and change the download source.

3. Install P4

This step mainly refers to the tutorial of poohdang on the code cloud, and uses the shell script to automatically download, compile and install each experimental module, so as to avoid the version problems that may occur when installing the module.
The link is as follows:

a. Install Git

sudo apt install git

b. Set up working directory and clone warehouse

mkdir -p ~/P4 && echo "export P4_HOME=~/P4" >> ~/.bashrc  # Set according to your own situation
source ~/.bashrc
cd $P4_HOME # The environment variable must take effect, and subsequent scripts need to
git clone -b master # clone code from the code cloud
cd p4-env

c. Install the necessary dependency and compilation tools

sudo chmod 755 p4*.sh

d. Download source code

Method 1: download directly from Github


Method 2: replace some URL s (using Accelerated warehouse)
Since sub modules need to be built to download to grpc, it is sometimes necessary to turn on the agent. (if you don't open the agent, it's easy to get stuck in this step)


e. Compile and install


f. Start P4 experiment

cd tutorials/exercises/basic
mininet> ...
If Python reports an error of No module named protobuf.internal, execute the following instructions
cd /usr/local/lib/python2.7/dist-packages
sudo cp -rf `ls | grep protobuf`/google/* google/
sign out
mininet> exit
sudo make stop
sudo make clean

4. Install ONOS

Mainly refer to the official website tutorial:

a. Install Bazelisk and other dependencies

Official website tutorial:

Step 1: add Bazel distribution URI as package source

sudo apt install apt-transport-https curl gnupg
curl | sudo apt-key add -
echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

Step 2: install and update Bazel

sudo apt update && sudo apt install bazel
 #After installation, you can upgrade to a newer version of Bazel as part of the normal system update:
sudo apt update && sudo apt full-upgrade

In addition to the latest version, you can also install a specific version of the previous version of Bazel, such as:

sudo apt install bazel-3.0.0

Step 3: install JDK (optional)

# Ubuntu 16.04 (LTS) uses OpenJDK 8 by default:
sudo apt install openjdk-8-jdk

# Ubuntu 18.04 (LTS) uses OpenJDK 11 by default:
sudo apt install openjdk-11-jdk

Some additional dependencies are required.

sudo apt-get install git zip curl unzip python python3 bzip2

b. Download ONOS (if the download speed is too slow, try to start the agent)

git clone
cd onos
git checkout onos-2.4 #Switch onos to version 2.4. If you want the latest version, you don't need to change it.
git branch #View onos version

c. Compile onos (open agent)

Most of the problems in this step are that there is no agent.

bazel build onos

Successfully compiled graph

d. Start ONOS

bazel run onos-local -- -- clean debug
# 'clean' to delete all previous running status
# 'debug' to enable remote debugging

The above command will create a local installation from the onos.tar.gz file (rebuild it if necessary) and start the ONOS server in the background. In the foreground, it will display a continuous view of the ONOS (Apache Karaf) log file. Double dashes (–) The latter options will be passed to ONOS Apache Karaf and can be omitted. Here, the clean option forces a new installation of ONOS, and the debug option means that the default debug port 5005 will be available for attaching a remote Java debugger.

Log in to ONOS CLI (start another terminal)
tools/test/bin/onos localhost

Open the default browser on the ONOS GUI page


tools/test/bin/onos-gui localhost

Or, visit http://localhost:8181/onos/ui

Run mini network controlled by ONOS
sudo mn --controller remote,ip=<ONOS IP address> --topo torus,3,3

Tags: Linux git Ubuntu

Posted on Sun, 28 Nov 2021 22:06:35 -0500 by Sno