PISCES Simulation Environment
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


PISCES Simulation Environment

Following provides instructions on how to setup virtual machines for the PISCES simulation environment along with some example P4 programs.

Setup Virtual Machines (VMs)

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


1. Simple Layer-2 Switch

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
a. Compiling l2_switch.p4

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

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 \
$ sudo make clean
$ sudo make -j 2
b. Running l2_switch.p4
Run ovsdb-server

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
Run ovs-vswitchd

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
Create an OVS bridge

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

This needs to be done only once. These changes persist across reboots.

Also, to delete the bridge run:

$ sudo ./ovs-vsctl del-br br0

And to display bridge settings run:

$ sudo ./ovs-vsctl show
Install flow rules
$ cd /vagrant/examples/l2_switch/
$ sudo ./l2_switch.sh
Send and receive test traffic

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 switch

Now 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.

2. Simple Router

To build a simple router, follow the same steps as above with following changes.

a. P4 program:


When compiling the switch, make sure to run sudo make clean before running sudo make -j 2.

b. Flow rules:


c. Send and test traffic

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


For more information please visit: