HOME

TheInfoList



OR:

P4 is a
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming l ...
for controlling
packet Packet may refer to: * A small container or pouch ** Packet (container), a small single use container ** Cigarette packet ** Sugar packet * Network packet, a formatted unit of data carried by a packet-mode computer network * Packet radio, a form ...
forwarding plane In routing, the forwarding plane, sometimes called the data plane or user plane, defines the part of the router architecture that decides what to do with packets arriving on an inbound interface. Most commonly, it refers to a table in which the ...
s in networking devices, such as routers and switches. In contrast to a general purpose language such as C or Python, P4 is a domain-specific language with a number of constructs optimized for network data forwarding. P4 is distributed as
open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
, permissively licensed code, and is maintained by the P4 Language Consortium, a not-for-profit organization hosted by the
Open Networking Foundation The Open Networking Foundation (ONF) is a non-profit operator-led consortium. It uses an open source business model aimed at promoting networking through software-defined networking (SDN) and standardizing the OpenFlow protocol and related techn ...
.


History

P4 was originally described in a 2014 SIGCOMM ''CCR'' paper titled “Programming Protocol-Independent Packet Processors”—the alliterative name shortens to "P4". The first P4 workshop took place in June 2015 at Stanford University. An updated specification of P4, called P4-16, was released between 2016 and 2017, replacing P4-14, the original specification of P4.


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 several goals:


Target independence

P4 programs are designed to be implementation-independent: 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 In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
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: the language has no native support for even common protocols such as IP, Ethernet, TCP,
VxLAN Virtual Extensible LAN (VXLAN) is a network virtualization technology that attempts to address the scalability problems associated with large cloud computing deployments. It uses a VLAN-like encapsulation technique to encapsulate OSI layer 2 Ether ...
, or
MPLS Multiprotocol Label Switching (MPLS) is a routing technique in telecommunications networks that directs data from one node to the next based on labels rather than network addresses. Whereas network addresses identify endpoints the labels identif ...
. 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 general-purpose CPUs or
network processor A network processor is an integrated circuit which has a feature set specifically targeted at the Computer networking, networking application domain. Network processors are typically software programmable devices and would have generic characteris ...
s, rather than the fixed function 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 typically have the following components:


Parsing logic

P4 allows the specification of custom packet header parsing logic including but not limited to parsing typical headers used in the TCP/IP protocol suite and application specific headers.


Headers

Header definitions describe packet formats and provide names for the fields within the packet. The language allows customized header names and fields of arbitrary length, although many header definitions use widely known protocol names and fields widths. For example, an
802.3 IEEE 802.3 is a working group and a collection standards defining the physical layer and data link layer's media access control (MAC) of wired Ethernet. The standards are produced by the working group of Institute of Electrical and Electronics Eng ...
Ethernet header definition might be called “Ethernet” and consist of the a 48-bit field named “dest” followed by a 48-bit “src” field, followed by a 16-bit “type” field. The names in a header definition are used later in the P4 program to reference these fields.


Parsers

The P4 parser is a finite state machine that walks an incoming byte-stream and extracts headers based on the programmed parse graph. A simple example would be a parser that extracts the Ethernet source and destination and type fields, then performs a further extraction based on the value in the type field (common values might be ipv4, ipv6, or MPLS).


Stateful processing

P4 allows the programmer to maintain state in the form of registers, counters and meters.


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.


Match-action processing

Fundamental to P4 is the concept of ''match-action pipelines''. Conceptually, forwarding network packets or frames can be broken down into a series of table lookups and corresponding header manipulations. In P4 these manipulations are known as ''actions'' and generally consist of things such as copying byte fields from one location to another based on the lookup results on learned forwarding state. P4 addresses only the data plane of a packet forwarding device. It does not specify the control plane nor any exact protocol for communicating state between the control and data planes. Instead, P4 uses the concept of tables to represent forwarding plane state. An interface between the control plane and the various P4 tables must be provided to allow the control plane to inject/modify state in the program. This interface is generally referred to as the ''program API''.


Tables

P4 tables contain the state used to forward packets. Tables are composed of lookup keys and a corresponding set of actions and their parameters. A trivial example might be to store a set of destination MAC addresses as the lookup keys, and the corresponding action could set the output port on the device, and/or increment a counter. Tables and their associated actions are almost always chained together in sequence to realize the full packet forwarding logic, although in the abstract it is possible to build a single table that includes all the lookup key information and the full output action set.


Actions

''Actions'' in P4 describe packet field and metadata manipulations. In P4 context, metadata is information about a packet that is not directly derived from the parser, such as the input interface that the frame arrived on. English descriptions of an example action might be "decrement the IPv4 TTL field by one" or "copy the MAC address from the output port table into the outgoing packet header." P4 defines both standard metadata that must be provided by all targets as well as target-specific metadata, which is provided by the author of specific targets.


Control flow

The control flow in P4 determines the relative sequence of tables, and allows for
conditional execution Addressing modes are an aspect of the instruction set architecture in most central processing unit (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how the machine language instructions i ...
of tables based on if/then/else constructions.


References


External links

* {{Official website, http://p4.org Computer networking C programming language family