Getting Started

You will use the P4 language to implement the data plane of your internet router. Note that there are two versions of the language, P4_14 and P4_16. For this course we will use P4_16. You should familiarize yourself with the P4_16 specification. You should implement the control plane with Python, and use P4Runtime to communicate with the switch.


  • P4C is the reference compiler for the P4 language.
  • BMV2 is a software switch that runs P4 programs compiled with P4C.
  • Mininet creates a virtual network running software switches and real user-space applications.
  • Scapy is a Python library for crafting and decoding raw packets. It also has utilities for sniffing and sending packets.
  • p4app is a tool for running P4 programs on a Mininet topology. It includes all the dependencies for compiling, running and testing your programs: P4C, BMV2, Mininet and Scapy.

How to run p4app on Mac OSX:

  • Install homebrew & cask:
xcode-select --install
ruby -e "$(curl -fsSL"
brew install caskroom/cask/brew-cask
  • Install docker-toolbox:
brew cask install docker-toolbox
  • Install git:
brew install git
  • Clone p4app github repo:
git clone --branch rc-2.0.0
  • Make p4app command available:
ln -s <PATH_TO_P4APP_REPO>/p4app/p4app /usr/local/bin/p4app
  • Launch docker quickstart terminal:
open -a Docker\ Quickstart\ Terminal -j
  • Run program through p4app:
p4app run <PROG_NAME>.p4app/
  • For example, run wire.p4app:
p4app run <PATH_TO_P4APP_REPO>/p4app/examples/wire.p4app

Writing P4 Programs

We use Vim to edit .p4 files, but you can use any text editor. Here are some syntax highlighters for popular editors: