Your Network Datapath Will Be P4 Scripted


Jamal Hadi Salim
Victor Nogueira
Pedro Tammela
Anjali Singhai Jain
Deb Chatterjee
Evangelos Haleplidis



Session Type




P4 has gained industry-wide acceptance as a datapath language. NIC consumers are now requesting NIC vendors to allow prescription of a P4 program to define required xPU datapaths, example MS[11].

Running P4 on top of TC has been a subject of many many discussions in the community over the last few years, initially in physical and electronic hallways and eventually in physical formal meetings, see[1],[2],[3],[4],[5],[6].

The call-to-arms was made by at the Netdev 0x14 conference by Nick Mckeown in a keynote titled: “Creating an End-to-End Programming Model for Packet Forwarding” [7]

Due to the industry takeoff of P4 we are (finally in 2022) putting resources to make it real for the Linux kernel. We hope to make the first code release at the conference.

In this talk we will discuss:

  • The overview of the P4TC Motivation and Goals and Requirements
  • Design And Architecture Overview with a focus on “scriptability”
  • The different P4TC objects and interaction between P4 and TC/kernel infra
  • User space integration into iproute2::tc
  • Integration into drivers
  • And finally describe the P4TC Workflow for devs and ops as well as runtime control.

P4TC goals are: 1) Offloading entirely to P4-capable hardware with tc skip_sw flag.

2) Running entirely in software infrastructures (VMs, baremetal, containers) with skip_hw flag. Think this mode as the digital twin of #1.

3) Split setup - where some of the P4 program control and pipeline is in software and some is in hardware (using a mix of skip_sw and skip_hw).

4) Running multiple independent P4 programs across multiple independent hardware and/or software (using tc filter infrastructure).

5) Post P4TC upstreaming, independence from changing or compiling any kernel or user space code for any P4 program (achieved via “scriptability”). IOW, no loading of any binary blob into the kernel or user space. Imagine the developer and ops productivity boost for not having to play acrobatics with various versions of a library, a compiler or kernel just because they want to introduce some new datapath foo with bar header processing in the kernel with hardware offload. Imagine not having to change any iproute2 code either…

“Scriptability” as a concept has precedence in the kernel TC architecture in the u32 classifier[8], the pedit action[9], skbedit, etc. A P4 program when compiled using the P4C compiler[10] generates tc scripts, which when executed, manifests into the functionally equivalent P4 program in the kernel. Alternatively, for simple programs, one could hand code the tc scripts to instantiate a P4 program.

P4TC takes advantage of the modularity of the TC architecture and makes very minimal changes to the TC core code while providing all the necessary objects to sufficiently abstract a P4 program.

A secondary goal for P4TC is to go beyond what P4 prescribes today where appropriate; IOW, while we strive to meet P4 spec we will also be pragmatic in marrying ideas from the kernel, and TC in particular, that we can feed back to the P4 community and general network programming world.


[1] Matty Kadosh, “P4 Offload”, TC Workshop, Netdev conference 2.2, 2017

[2] Prem Jonnalagadda, “Mapping tc to P4”, TC Workshop, Netdev conference 2.2, 2017

[3] Jamal Hadi Salim, “What P4 Can Learn From Linux Traffic Control”, proceedings of ONF 5th P4 Workshop, 2018

[4] Many speakers, TC P4 workshop, Intel, Santa Clara, 2018

[5] Antonin Bas and R. Krishnamoorthy. “Instrumenting P4 in the Kernel”, TC Workshop, Netdev conference 0x12, 2018

[6] Marian Pritsak and Matty Kadosh, “P4 Compiler Backend for TC”, Netdev conference 0x13, 2019

[7] Nick Mckeown Netdev conference 0x14, 2020 “Creating an End-to-End Programming Model for Packet Forwarding”

[8] Jamal Hadi Salim et al “Demystifying The TC Ugly (or Universal) 32bit Key Packet Classifier”, Netdev conference 0x13, 2019

[9] Pedit source and man pages:

[10] P4C compiler

[11] MS Azure DASH