Welcome to the first exercise. This week, we begin learning P4 and getting proficient in P4 programming.
The P4 exercises serve two purposes:
- By programming P4, we hands-on understand specific challenges in the Internet. As an example, we will program traffic engineering and load-balancing in P4. While doing this, we will comprehend the concepts better.
- By following and practicing these exercises, we prepare for the final project.
Let's begin with an introduction to our programming environment, development framework, and toolchain. Then, we can already start coding the cornerstones of the Internet!
What we envisioned so far is as follows (please let us know if you have a better idea):
- The responsible host TA of the week presents the exercise,
- Then, general questions are discussed,
- If you have a personal question (you need to indicate that), we assign you to one of that week's TAs. You can ask your question in the Slack
#exercises
channel if you are remotely joining. - After the exercise session, you can always visit our Slack
#exercises
channel for further questions.
Before we proceed, please open the following in your browsers:
Mininet creates a realistic virtual network, running actual kernel, switch, and application code on a single machine.
In our exercises, thanks to P4-Utils, we will not directly interact with Mininet most of the time since automated scripts will build the necessary topology for us. When we need to know specific Mininet CLI commands, we will introduce them in the exercise.
In short, Mininet creates hosts using Unix namespaces and interconnects them using virtual interfaces and BMv2 switches. Linux namespaces provide a network stack for all the processes running within a specific namespace. Thus, network virtualization tools such as Mininet uses Linux network namespaces to instantiate isolated nodes in a topology (hosts, switches, routers, etc.).
Behavioral Model version 2 (BMv2) is the second version of the reference P4 software switch. Please refer to our documentation for the details.
After we build and run the BMv2 software switch, we can use the Simple Switch CLI to configure the switch and populate match-action tables.
To learn more about the Control Plane and its functions, please refer here.
Scapy is a packet manipulation library written in Python. Please check here for further information.
We will use Scapy for packet creation and capture at end hosts in our exercises.
Monitoring traffic can be a potent tool when debugging your P4 program.
To sniff the traffic that is going through an interface, we will use tcpdump
. Please refer here if you are interested in other similar tools or learning more about debugging and troubleshooting.
To capture binary-level traffic with tcpdump
run:
sudo tcpdump -XX -i <interface_name>
P4-Utils is an extension to Mininet that makes P4 networks easier to build, run, and debug. Please refer to the documentation for the details.
p4app.json
describes the topology that we want to create with the help of Mininet and the P4-Utils package.
To create the topology described in p4app.json
, you have to call p4run
, which by default will check if the file p4app.json
exists in the path:
sudo p4run
This will call a Python script that parses the configuration file, creates a virtual network of hosts and p4 switches using Mininet, compiles the P4 program, and loads it in the switch.
After running p4run
you will get the Mininet CLI prompt.
- P4 Spec: P4 Language and Related Specifications
- P4-guide: Repository that contains a lot of useful information, examples, and tests of best practices, tips, and tricks.
- P4 Tutorials: Official P4 Tutorials