Skip to content

yyasuda/P4Runtime-protoswitch

Repository files navigation

P4Runtime-protoswitch

An ultimately primitive P4Runtime tutorial for beginners in P4.

see Japanese version

Introduction

The code and data in this repository were created as a tutorial to provide a simple entry point for those who want to try controlling a P4 switch using P4Runtime for the first time. It assumes that the reader has some basic understanding of P4 and P4Runtime. It is intended to serve as a good starting point for those who are trying it hands-on for the first time.

This tutorial does…

This tutorial performs the following three experiments:

  • Packet forwarding using only input port information
  • Packet forwarding based on destination MAC address
  • Packet forwarding using match-action tables

These experiments are conducted in the following environment:

  • P4Runtime Shell is used as the controller
  • A P4Runtime-enabled Mininet is used as the switch
  • The open-source p4c is used for P4 compilation

All of these are prepared to run in a Docker environment. At first, please use exactly what is described in this document.

Tools

All experiments in this tutorial are performed in a Docker environment.

P4C

P4Runtime-enabled Mininet Docker Image (modified)

The original opennetworking/p4mn also works almost the same, but since handling logs was not very convenient, a modified version was created.

P4Runtime Shell

Step by Step

The steps are shown below. It is recommended to try them in order.

Before starting the experiments, you need to compile the P4 switch program. Then, start Mininet and connect the P4Runtime Shell, which acts as the controller.

We perform a forwarding experiment using an extremely simple switch program, port2port.p4, which simply forwards packets entering port 1 to port 2, and packets entering port 2 to port 1.

Here, we parse (interpret) headers and use a switch program, macaddr.p4, that determines the forwarding destination based on the extracted destination MAC address field.

P4 has something called a Match-Action Table, which allows applying necessary processing (actions) per packet. Here, we use a switch program, tablematch.p4, where the forwarding destination is determined by a table keyed by destination MAC address.

Next Step

This tutorial focuses on providing an easy-to-understand entry point without touching the internal structure. The next step would be to use this as a starting point and dig deeper into the internals. Below are some documents that I found particularly useful.

About

An ultimately primitive P4Runtime tutorial for beginners in P4

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages