Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

P4 Assignment

In this assignment, you will learn how to write a P4 program for programmable data planes. Using P4 you will be able to create new headers, write parser specifications and add custom match+action tables to describe how the data plane device should process packets.


This introductory video walks you through the simple router that the assignment uses as a base for the acl, it's highly recommended to watch this video before attempting the assignment:

For more information about the P4 language read the following material:

Simple Router with Access Control

In this exercise, you will be extending the simple router P4 program -- provided in the base P4 repository -- with an access control list. In order to do this, you have to update the following aspects of the simple router program:

  • Add support for reading and parsing tcp fields
  • Add a new match+action table for access control
  • Update the control flow to perform access control using tcp's source and destination ports

The following figures show the final parser and table flow graph for the simple router with acl. The boxes in RED show what needs to be added.

Update your VM to get the assignment

1- Update your local repo

$ git pull

2- Shutdown your VM

vagrant halt

3- Start your VM (it should install all the new dependencies)

$ vagrant up

4- Excecute the required provisioning scripts

$ vagrant provision

1. Copy and build the assignment

  • Copy the simple_router_acl directory to the p4facorty/targets folder
$ cd ~/p4factory/targets
$ cp -rf /vagrant/assignments/simple_router_acl/ .
  • Run make to test if the simple_router_acl builds properly. Note: that there is no acl support in the code at this time. You will be adding this support as part of this assignment.
$ cd ~/p4factory/targets/simple_router_acl
$ make

2. Update the source files to add support for access control

You need to modify the following three files:

  • p4src/includes/headers.p4: add new header type for tcp
  • p4src/includes/parser.p4: add a new parser function for tcp
  • p4src/simple_router_acl.p4: add a new table for acl and update the control flow

3. Test the assignment

  • Run make to build the assignment.
$ cd ~/p4factory/targets/simple_router_acl
$ make
  • Setup the virtual ethernet pairs.
$ sudo ~/p4factory/tools/
  • Run the behavioral-model.
$ sudo ./behavioral-model
  • In another terminal, run the test script.
$ cd ~/p4factory/targets/simple_router_acl
$ sudo python --test-dir=of-tests/tests/
  • Upon successful completion, you should see the following output.
VXLAN enabled
ERSPAN enabled
Geneve enabled device id is  0
echo.EchoTest ... ok
acl.AclTest ... ok

Ran 2 tests in 1.843s


4. Submit your code

To submit your code. Run the behavioral-model again. However, this time instead of running the script, run the script provided under the project directory in another terminal.

$ cd ~/p4factory/targets/simple_router_acl
$ sudo python

The submission script will ask for your login and password. This password is not the general account password, but an assignment-specific password that is uniquely generated for each student. You can get this from the assignments listing page.

Once finished, it will prompt the results on the terminal (either passed or failed).