Skip to content

Building an Internet Router with P4Pi

noaz edited this page Dec 12, 2021 · 4 revisions

Introduction

This page describes Building an Internet Router with P4Pi, which is a semester-long, hands-on exercise.

This page is still being updated, and we appreciate contributions by the community.

Overview

In the Build an Internet Router project, students are required to develop a Router, implementing both the control plane and the data plane. The data plane is written in P4, and the control plane in Python. Students receive a starter code with a minimal P4 program for the data plane, and a minimal Python program for the control plane.

An important part of the project is its testing and evaluation. Students can test their design as stand alone (using P4Pi and 1-2 laptops) and running interoperability test, connecting to routers designed by their colleagues.

Before you start

  1. Students are expected to know P4 and Python. To learn more about how to run P4 and P4Runtime you can follow the P4 tutorials.

  2. You will need a working P4Pi platform for every student / team. Step-by-step instructions are provided on the Getting Started page. We recommend to always use the latest P4Pi release.

Data plane development

Data plane development starter code is available in the P4Pi repository.

  1. The P4Pi-based router is implemented using simple_switch_grpc, and can run over bmv2. It is possible to first develop and test it in an emulation environment (e.g., Mininet).

  2. The logic needs to be implemented in the ingress pipeline of the data plane.

  3. The implementation must support multiple protocols:

    • Ethernet
    • ARP
    • IP (lecturer choice between IPv4, IPv6 or both)
    • ICMP (lecturer choice if to support in the data plane or just the control plane)
  4. All incoming ARP packets need to be sent to the CPU port, and all packets arriving from the CPU with a valid destination port need to be sent to the designated destination port.

  5. TTL of IP packets needs to be decremented and packets should be dropped if TTL=0.

  6. Packets with Local IP addresses should be forwarded to the CPU.

  7. For outgoing packets, the next hop MAC address should be updated in the Ethernet header.

  8. A header with metadata should be appended to packets sent to the CPU. Incoming packets from the CPU need to be decapsulated, and information from the header should be saved to the metadata bus.

  9. It is recommended to included several counters in the design (e.g., number of incoming packets), to assist with debug.

Control plane development

Control plane development starter code is available in the P4Pi repository.

All the routing functionality needs to be implemented in the control plane. The control plane needs to be implemented in Python using P4Runtime API and Scapy. Using P4Runtime, the controller can send/receive messages to/from the switch over a gRPC connection. P4Runtime allows the controller to access the entities defined in a P4 program, such as tables and counters. Scapy is used to send/receive packets over the CPU port.

In the first stage, the students are required to develop the control plane to support static routing, including:

  1. Handling ARP messages, e.g.,:

    • Updating the ARP table in the data plane.
    • Sending ARP requests.
    • Removing entries in the ARP table that have timed out.
    • Queueing packets that are pending ARP replies.
  2. Handling ICMP messages, e.g.,:

    • Responding to ICMP echo requests.
    • Generating ICMP host unreachable packets.
  3. Handling corrupted or otherwise incorrect IP packets, and any other packets sent directly to the router.

After the first stage, it is recommended to run a basic functionality test, and a first interoperability test between teams.

In the second stage, students are required to implement PW-OSPF (link to wiki page) , a simplified version of OSPFv2. This includes, but is not limited to (read the protocol!):

  1. Broadcasting periodic HELLO packets.

  2. Populating the routing table with information received in HELLO packets.

  3. Generating and processing link state update messages (LSU).

  4. Calculating the shortest path to every other router, using Djikstra's algorithm.

  5. Updating the data plane's forwarding table with next hops.

Evaluation

Students can test their router in two modes: standalone or connected to a group of routers.

Standalone mode

In standalone mode, the router is connected to one or more laptops.

In this mode, it is possible to test that some functions are acting correctly:

  • ARP
  • ICMP (e.g., using ping)
  • IPv4/IPv6.

In addition, the following method may be used to test a router. First, create virtual Ethernet (veth) interface pairs, moving one end of each pair to another network namespace. Then, attach the interface that is visible in the root namespace to the switch and send traffic to it.

One can test that entries are added and deleted from the routing table using the P4Runtime Shell.

A basic performance test can be done by running iperf between two laptops with P4Pi in the middle. By comparing the throughput using a direct connection or with P4Pi in the middle, it is possible to assess the limitations of the implementation.

Interoperability

One of the fun parts of the project is interoperability tests between multiple projects.

To perform tests with multiple P4Pi devices, you can construct a network topology such as the one illustrated in the figure below.

To connect to more than one P4Pi, using both the 1GbE RJ-45 (Ethernet) port and USB-to-Ethernet adapters. Each Ethernet interface should be configured with a static IP address.

An example topology used to test the operation of multiple P4Pi Routers

Reference

Please use the following reference to cite Building an Internet Router using P4Pi:

"Building an Internet Router with P4Pi". Radostin Stoyanov, Adam Wolnikowski, Robert Soulé, Sándor Laki, and Noa Zilberman. 4th P4 Workshop in Europe (EuroP4) 2021, December 2021.

Credit

The content of this page was developed based on the courses CPSC 435/535 Building an Internet Router(bmv2) at Yale and CS344 Build an Internet Router(bmv2 / NetFPGA) at Stanford.

Clone this wiki locally