• Stars
    star
    1,332
  • Rank 35,284 (Top 0.7 %)
  • Language P4
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

P4 language tutorials

P4 Tutorial

If you are reading this while not attending a live P4 tutorial class, see below for links to information about recently given live classes.

Introduction

Welcome to the P4 Tutorial! We've prepared a set of exercises to help you get started with P4 programming, organized into several modules:

  1. Introduction and Language Basics
  1. P4Runtime and the Control Plane
  1. Monitoring and Debugging
  1. Advanced Behavior
  1. Stateful Packet Processing

Presentation

The slides are available online and in the P4_tutorial.pdf in the tutorial directory.

A P4 Cheat Sheet is also available online which contains various examples that you can refer to.

P4 Documentation

The documentation for P4_16 and P4Runtime is available here

All excercises in this repository use the v1model architecture, the documentation for which is available at:

  1. The BMv2 Simple Switch target document accessible here talks mainly about the v1model architecture.
  2. The include file v1model.p4 has extensive comments and can be accessed here.

Obtaining required software

If you are starting this tutorial at one of the proctored tutorial events, then we've already provided you with a virtual machine that has all of the required software installed. Ask an instructor for a USB stick with the VM image.

Otherwise, to complete the exercises, you will need to either build a virtual machine or install several dependencies.

To build the virtual machine

  • Install Vagrant and VirtualBox
  • Clone the repository
  • Before proceeding, ensure that your system has at least 12 Gbytes of free disk space, otherwise the installation can fail in unpredictable ways.
  • cd vm-ubuntu-20.04
  • vagrant up - The time for this step to complete depends upon your computer and Internet access speeds, but for example with a 2015 MacBook pro and 50 Mbps download speed, it took a little less than 20 minutes. It requires a reliable Internet connection throughout the entire process.
  • When the machine reboots, you should have a graphical desktop machine with the required software pre-installed. There are two user accounts on the VM, vagrant (password vagrant) and p4 (password p4). The account p4 is the one you are expected to use.

Note: Before running the vagrant up command, make sure you have enabled virtualization in your environment; otherwise you may get a "VT-x is disabled in the BIOS for both all CPU modes" error. Check this for enabling it in virtualbox and/or BIOS for different system configurations.

You will need the script to execute to completion before you can see the p4 login on your virtual machine's GUI. In some cases, the vagrant up command brings up only the default vagrant login with the password vagrant. Dependencies may or may not have been installed for you to proceed with running P4 programs. Please refer the existing issues to help fix your problem or create a new one if your specific problem isn't addressed there.

To install P4 development tools on an existing system

There are instructions and scripts in another Github repository that can, starting from a freshly installed Ubuntu 20.04 or 22.04 Linux system with enough RAM and free disk space, install all of the necessary P4 development tools to run the exercises in this repository. You can find those instructions and scripts here (note that you must clone a copy of that entire repository in order for its install scripts to work).

Older tutorials

Multiple live tutorial classes have been given using the example code in this repository for hands-on exercises. For example, there is one each April or May at the P4 workshop at Stanford University in California, and there have been several at networking conferences such as ACM SIGCOMM.

Please create an issue for this tutorials repository if you know a public link for classroom video recordings and/or pre-built VM images that currently do not have such a link.

ACM SIGCOMM August 2019 Tutorial on Programming the Network Data Plane

https://p4.org/events/2019-08-23-p4-tutorial/

The page linked above has a link to download a pre-built VM image used for this class, as well as instructions to build one yourself from a particular branch of this repository.

P4 Developer Day, April 2019

https://p4.org/events/2019-04-30-p4-developer-day/

Both a beginner and advanced class were taught at this event. The page linked above contains instructions to download and install a pre-built Linux VM that was used during the classes.

P4 Developer Day, November 2017

  • YouTube videos
    • This link plays the first welcome video of a series of 6 videos of tutorials given at this event.

More Repositories

1

p4c

P4_16 reference compiler
C++
671
star
2

behavioral-model

The reference P4 software switch
C++
536
star
3

p4-spec

TeX
175
star
4

p4factory

Compile P4 and run the P4 behavioral simulator
C
174
star
5

p4app-switchML

Switch ML Application
C++
167
star
6

PI

An implementation framework for a P4Runtime server
C++
165
star
7

switch

Consolidated switch repo (API, SAI and Nettlink)
C
152
star
8

p4runtime

Specification documents for the P4Runtime control-plane API
Rust
146
star
9

ptf

Packet Test Framework
Python
144
star
10

p4pi

P4 on Raspberry Pi for Networking Education
JavaScript
123
star
11

p4app

Python
112
star
12

p4-applications

P4 Applications WG repo
P4
107
star
13

p4runtime-shell

An interactive Python shell for P4Runtime
Python
76
star
14

p4-dpdk-target

P4 driver SW for P4 DPDK target.
C++
56
star
15

pna

Portable NIC Architecture
P4
54
star
16

tdi

Table-Driven Interface (TDI) for a P4-programmable backend device.
C++
39
star
17

papers

Repository for papers related to P4
C
38
star
18

ntf

Network Test Framework
Python
37
star
19

education

P4 for Education
36
star
20

scapy-vxlan

A scapy clone, with support for additional packet headers
Python
36
star
21

p4-hlir

Python
32
star
22

p4ofagent

Openflow agent on a P4 dataplane
C
27
star
23

p4c-bm

Generates the JSON configuration for the behavioral-model (bmv2), as well as the C/C++ PD code
Python
24
star
24

p4lang.github.io

Deprecated P4.org website
HTML
23
star
25

p4analyzer

A Language Server Protocol (LSP) compliant analyzer for the P4 language
Rust
19
star
26

p4c-behavioral

[deprecated] P4 compiler for the behavioral model
C
18
star
27

p4app-TCP-INT

C
18
star
28

p4-constraints

Constraints on P4 objects enforced at runtime
C++
14
star
29

p4-build

Infrastructure needed to generate, build and install the PD library for a given P4 program
C++
12
star
30

gsoc

P4.org's Participation in Google Summer of Code
9
star
31

third-party

Third-party dependencies for p4lang software
Dockerfile
8
star
32

project-ideas

Ideas for P4 Projects.
6
star
33

target-utils

C
4
star
34

target-syslibs

C
3
star
35

hackathons

P4
2
star
36

governance

1
star