P4 (programming language): Difference between revisions

Content deleted Content added
No edit summary
Line 22:
The language was originally described in a SIGCOMM CCR paper in 2014 titled “Programming Protocol-Independent Packet Processors”<ref>{{cite web|url=http://www.sigcomm.org/node/3503|title=P4: Programming Protocol-Independent Packet Processors|date=July 2014|accessdate=7 April 2015}}</ref> – the alliterative name shortens to “P4”. The first P4 workshop took place in June, 2015 <ref>{{cite web |url=https://p4.org/events/2015-06-04-p4-workshop/ |website=P4 Official Website |accessdate=1 August 2019}}</ref> at [[Stanford University | Stanford University]]. An updated specification of P4, called P4-16, was released between 2016 and 2017 <ref>{{cite web |title=P4-16 Specification |url=https://p4.org/p4-spec/p4-14/v1.0.4/tex/p4.pdf |website=P4 Official Website}}</ref> replacing original specification of P4, called P4-14.
 
== Language overview and design considerations ==
 
=== Design ===
As the language is specifically targeted at packet forwarding applications, the list of requirements or design choices is somewhat unusual to those use cases. The language is designed to meet a number of these goals:
 
====Target independence====
 
P4 programs are designed to be '''implementation-independent''', meaning they can be compiled against many different types of execution machines such as general-purpose CPUs, FPGAs, system(s)-on-chip, network processors, and ASICs. These different types of machines are known as P4 '''targets''', and each target must be provided along with a [[compiler]] that maps the P4 source code into a target switch model. The compiler may be embedded in the target device, an externally running software, or even a cloud service. As many of the initial targets for P4 programs were used for simple packet switching it is very common to hear the term “P4 switch” used, even though “P4 target” is more formally correct.
 
====Protocol independence====
P4 is designed to be '''protocol-independent''', meaning that the language has no native support even for common protocols such as IP, Ethernet, TCP, VxLAN, or MPLS. Instead, the P4 programmer describes the header formats and field names of the required protocols in the program, which are in turn interpreted and processed by the compiled program and target device.
 
====Reconfigurability====
 
Protocol independence and the abstract language model allow for '''reconfigurability''' – P4 targets should be able to change the way they process packets (perhaps multiple times) after they are deployed. This capability is traditionally associated with forwarding planes built on [[History of general-purpose CPUs|general-purpose CPUs]] or [[network processor]]s, rather than the fixed function [[Application-specific integrated circuit|ASICs]]. Although within the language there is nothing to prevent a given target from optimizing around a certain set of protocols, these optimizations are invisible to the language author and may ultimately reduce the system’s flexibility and reconfigurability goals.
 
=== Components ===
P4 programs are typically have the following components
 
==== Parsing Logic ====
P4 allows the specification of custom packet header parsing logic <ref>{{cite web |title=P4-16 Specification |url=https://p4.org/p4-spec/p4-14/v1.0.4/tex/p4.pdf |website=P4 Official Website}}</ref> including but not limited to parsing typical headers used in the TCP/IP protocol suite and application specific headers.
 
==== Stateful Processing ====
P4 allows the programmer to maintain state in the form of registers, counters and meters <ref>{{cite web |title=P4-16 Specification |url=https://p4.org/p4-spec/p4-14/v1.0.4/tex/p4.pdf |website=P4 Official Website}}</ref>.
 
==== Generic Match Action Tables ====
The primary component of a P4 program is a set of user-defined match action tables. P4 treats all match action tables as generic, leaving the user to add their match-action rules via the control plane. <ref>{{cite web |title=P4-16 Specification |url=https://p4.org/p4-spec/p4-14/v1.0.4/tex/p4.pdf |website=P4 Official Website}}</ref>
 
==Match-Action processing==