Following provides instructions on how to setup virtual machines for the PISCES simulation environment along with some example P4 programs.
The Vagrant box was last modified over a year ago at the time of writing and versions of VirtualBox, Guest Additions, and Vagrant conflict with the preconfiguration in this repository. The major modification was for the Vagrantfile, where the provisioning command was updated for shell scripts as written here. In addition, steps can be
There are three virtual machines: Switch, Generator, and Receiver. The Generator
sends traffic to the switch on its eth1
interface, the switch then processes the packet
based on the configured P4 program and sends it out to the receiver on its eth2
interface.
The receiver receives the traffic and displays stats on the screen.
Add the vagrant
box.
$ vagrant box add pisces-ubuntu-trusty64 http://www.cs.princeton.edu/~mshahbaz/projects/pisces/vagrant/ubuntu-trusty64.box
Clone the vagrant
repository.
$ git clone https://github.com/P4-vSwitch/vagrant.git
$ cd vagrant
Bring up virtual machines.
$ vagrant up
Note: Make sure that you have enough memory on the host to run the setup (switch ~ 4G, generator/receiver ~ 2G each). Also, VMs are only compatible with VirtualBox, so please make sure this provider is available to vagrant.
It can take vagrant 10-15 mins to start up the VMs. So sit back, relax, and wait for the setup to complete. :-)
We show how to build a simple layer-2 switch using PISCES. We use the
l2_switch.p4
program provided with the
p4lang/p4factory repository.
Log into the switch VM.
$ vagrant ssh switch
First, make sure that DPDK environment variables are populated in the switch VM.
$ export RTE_SDK=/home/vagrant/ovs/deps/dpdk
$ export RTE_TARGET=x86_64-native-linuxapp-gcc
$ export DPDK_DIR=$RTE_SDK
$ export DPDK_BUILD=$DPDK_DIR/$RTE_TARGET/
Compile the l2_switch.p4
program. Specify /vagrant/examples/l2_switch/l2_switch.p4
for the p4inputfile
flag.
$ cd ~/ovs
$ sudo ./configure --with-dpdk=$DPDK_BUILD CFLAGS="-g -O2 -Wno-cast-align" \
p4inputfile=/vagrant/examples/l2_switch/l2_switch.p4 \
p4outputdir=./include/p4/src
$ sudo make clean
$ sudo make -j 2
Open a new terminal, log into the switch VM and run ovsdb-server
.
$ cd ~/ovs/ovsdb
$ sudo ./ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile
In another terminal, log into the switch VM and run ovs-vswitchd
.
$ cd ~/ovs/vswitchd
$ sudo ./ovs-vswitchd --dpdk -c 0x1 -n 4 -- unix:/usr/local/var/run/openvswitch/db.sock --pidfile
Open a third terminal, log into the switch VM and run the following commands to create a new OVS bridge.
$ cd ~/ovs/utilities
$ sudo ./ovs-vsctl --no-wait init
$ sudo ./ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev
$ sudo ./ovs-vsctl set bridge br0 protocols=OpenFlow15
$ sudo ./ovs-vsctl add-port br0 dpdk0 -- set Interface dpdk0 type=dpdk
$ sudo ./ovs-vsctl add-port br0 dpdk1 -- set Interface dpdk1 type=dpdk
Note:
This needs to be done only once. These changes persist across reboots.Also, to delete the bridge run:
$ sudo ./ovs-vsctl del-br br0And to display bridge settings run:
$ sudo ./ovs-vsctl show
$ cd /vagrant/examples/l2_switch/
$ sudo ./l2_switch.sh
Open a new terminal and log into the generator VM.
$ vagrant ssh generator
Go to the pktgen
directory.
$ cd ~/pktgen
Run pktgen
as follows:
$ sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -c 0x3 -n 4 -- -P -m "1.0" -f /vagrant/examples/l2_switch/generator.pkt
Similarly, in another terminal log into the receiver VM.
$ vagrant ssh receiver
Run pktgen
as follows:
$ cd ~/pktgen
$ sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -c 0x3 -n 4 -- -P -m "1.0" -f /vagrant/examples/l2_switch/receiver.pkt
Now go back to the pktgen
interface, running on the generator VM, and start sending traffic.
$ start 0
To stop sending traffic, type:
$ stop 0
On the receiver side, you will start seeing stats (e.g., packet RX counts) on the pktgen
interface.
You can also verify if the switch is forwarding traffic by dumping flows on the switch VM. Open a new terminal and log into the switch VM.
$ vagrant ssh switchNow run the following commands:
$ cd ~/ovs/utilities $ sudo ./ovs-ofctl --protocols=OpenFlow15 dump-flows br0
You should see non-zero byte and packet counts in the dumped flow rules.
To build a simple router, follow the same steps as above with following changes.
/vagrant/examples/simple_router/simple_router.p4
When compiling the switch, make sure to run
sudo make clean
before runningsudo make -j 2
.
/vagrant/examples/simple_router/simple_router.sh
Use the following commands on the generator VM.
$ cd ~/pktgen
$ sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -c 0x3 -n 4 -- -P -m "1.0" -f /vagrant/examples/simple_router/generator.pkt
And the following on the receiver VM.
$ cd ~/pktgen
$ sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -c 0x3 -n 4 -- -P -m "1.0" -f /vagrant/examples/simple_router/receiver.pkt
Enjoy!
For more information please visit:
pisces.cs.princeton.edu