p4 language specification


The configuration of the data plane according to the code takes place during the initialization of the device.

Then we configure the interface IP address and default routes on host1 and host2. you want to read about. The PSA model specifies six programmable blocks and two fixed-function blocks, as depicted in the figure below (see Figure 3). * @param type of headers; defined by user The matching can be handled using a combination of protocol header fields and user-defined metadata.

The programmable block has to be marked as a parser or control function. Actions are code fragments that describe the rules for handling the packet header fields and metadata. It is defined in the P4 program. For each table, one or more actions can be assigned to be executed at runtime (see action examples). Protocol independence and the abstract language model allow for reconfigurabilityP4 targets should be able to change the way they process packets (perhaps multiple times) after they are deployed. * VSS deparser. The term runtime refers to operations that take place after initial configuration of the target.

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. Another quasi-standard architecture is v1.0 switch model, also known as V1Model. HlTn0+tH.E@mLKlh 8A3:|!g6}%M"x4IB$uK+ hbbd```b`` d"Y`R,&'H.eDZLf@QK?

The Portable Switch Architecture (PSA) is addressed for multi-port Ethernet targets (like a switch with multiple Ethernet interfaces).

It is worth mentioning that we cannot adjust the internal behaviour of external objects. 68 0 obj <> endobj 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). Thus, the computational complexity of the P4 program is linear in the total size of all headers. Originally, P4 served for programming of the sending the data plane packets of network switches, but eventually, it covered other network devices like routers, software & hardware switches, network interface cards. The compiler generates a data plane configuration that implements forwarding logic and an API to control the state of data plane objects from the control plane. The idea is to employ a P4-defined dataplane in the process of creating service chains between virtual or physical service appliances (or mixed). The current version of SONiC-P4 was a simple docker image. that can be used by P4 programmers according to their needs.

The chip is the heart of the system and in practice determines how device OS is realized and what functionality it can offer. */, /** Fundamental to P4 is the concept of match-action pipelines.

* @param outCtrl information for architecture, accompanying output packet It can be composed of one or multiple tables where matching against parsed header fields takes place (see Figure 2). The control flow in P4 determines the relative sequence of tables, and allows for conditional execution of tables based on if/then/else constructions. Let's go! It can still have a number of fixed-function blocks inside, but it must also contain programmable blocks (see Figure 1). * @param headers headers received from the parser and sent to the deparser

A deep dive into deep dev. * @param parsedHeaders headers constructed by parser P414 programs are not supported nativelytranslation into P416 must be done beforehand. There are several differences between the two and it is worth noting that P416 introduces some backwards-incompatible changes to P414 in terms of both syntax and semantics. We launch a series of articles on the relatively new programming language P4 and what it is all about. at the same time. Of course, to enable this, you need to use a special type of chip. Although P4 itself appears to be a relatively simple language next to more popular programming languages, the entire P4 environment may seem complex at first glance. PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.

/*******************************************, ********** H E A D E R S ******************, *******************************************/, /****************************************, ********** P A R S E R******************, *****************************************/, inout standard_metadata_t standard_metadata) {, transition select(hdr.ethernet.etherType) {, action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {. Your P4 code must be in line with the architecture, i.e. 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 is because a chip redesign is usually required. P4 describes packet processing only in the context of the data plane, and more specifically, defines the functionality of the device's data plane.

Instead, P4 uses the concept of tables to represent forwarding plane state. -v $ PWD / switch1: / sonic mounts the configuration folder to the switch containers. configures specialized objects, such as registers; The functionality of the data plane is not initially defined, i.e. The first P4 workshop took place in June 2015 at Stanford University. endstream endobj 69 0 obj <> endobj 70 0 obj <> endobj 71 0 obj <>stream The six remaining blocks are fully programmable using P4. Below you may see the header, parser, and table for the Very Simple Switch model. The architecture file must contain at least one declaration for a package.

A deep dive into deep dev. The control plane and data plane interact through the same channels as in the standard switch, but the set of tables and other objects in the data plane is no longer fixed. Since that time, tables and other objects defined in your P4 code are present in the dataplane. 0 P4 language or Programming Protocol-Independent Packet Processors is an open-source, domain-specific network programming language for specifying the processing of packets by data plane devices like routers, switches, NICs, etc.

The ability of a developer to make a custom description of headers with the field names and choose any desired protocol makes the language protocol independent.

The user defines a program in P4 for a specific architecture. Let us show this with a simple example: The diagram shows the difference between a standard switch and a P4-defined switch.

engineering and R&D teams. It never depends on the size of the state that has accumulated during data processing, such as the number of threads or the total number of packets processed. It defines a set of standard data types, externs, counters, meters, etc.

For example, an 802.3 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 idea of INT is to gather telemetry metadata for each packet such as packet routing paths, ingress and egress timestamps, latency the packet has experienced, queue occupancy in a given node, egress port link utilization etc. 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. In contrast to the bottom-up paradigm, here the programmer defines the network feature set. Network devices like switches or routers are most commonly designed bottom-up. The switch vendors that offer products to their clients usually rely on external chips from 3rd party silicon vendors.

Another method is to embed them into packets at every node the packet visits on its routing path and finally remove them in designated nodes that will send them aggregated to the monitoring system. P4 treats all match action tables as generic, leaving the user to add their match-action rules via the control plane.[4]. '- 1tWa`i6a*S8B{Y Z. The control plane controls the data plane, viz: Now let's take a look at the two main differences between the P4-defined switch: We move on to the P4 abstractions and their brief description: Headers describe the format or set of fields and their sizes for each header in a packet. * @param b output packet

d<6!OePKf}}A9pv"pR,d^]vIal%p*{L5:z.a dJ=`C Language for controlling network data forwarding, Learn how and when to remove these template messages, Learn how and when to remove this template message, reliable, independent, third-party sources, "P4: Programming Protocol-Independent Packet Processors", https://en.wikipedia.org/w/index.php?title=P4_(programming_language)&oldid=1092023459, Short description is different from Wikidata, Articles lacking in-text citations from May 2015, Articles lacking reliable references from July 2019, Articles with multiple maintenance issues, Creative Commons Attribution-ShareAlike License 3.0, This page was last edited on 7 June 2022, at 19:25. 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. "-H`q9)xHNb`6%Ct1@ Then we create three links. So, that's all for now.

Tables are composed of lookup keys and a corresponding set of actions and their parameters.

The programming language P4 is gaining in popularity in the network industry and is considered the next step in the SDN evolution.

The only thing that limits the number of tables is the programmer's needs. melayu arif budiman intelek This action connects the eth1 interface to port 1 of the P4 software switch, eth2 to port 2, and so on. As stated in the PSA specification document, the PSA is to the P416 language as the C standard library is to the C programming language. These are designed for the SONiC control plane and do NOT carry data plane packets. The current language specification goes byP416. Xilinx devices with P4 support are FPGA-based smart cards out of the Alveo product portfolio. As mentioned above, the header types, their structures as well as parsers behaviour must be defined in the P4 program (this responsibility falls to the P4 program developer, not the architecture model provider). P4 represents a completely different approach, similar to how the Central Processing Unit (CPU), Graphics Processing Unit (GPU) or Digital Signal Processor (DSP) work. Let's take a look at P4 through some real-life cases.

At the same time, a large number of native P414 language features have been moved into libraries of fundamental constructs needed for writing effective P4 programs. Header definitions describe packet formats and provide names for the fields within the packet. This is a top-down approach. The /sonic/etc/config_db/vlan_config.json configures the interfaces of the VLAN switch we use in this experiment through the ConfigDB interface (see the SONiC Configuration Database manual): The /sonic/etc/quagga/bgpd.conf configures the BGP session on the switch. Earlier versions of Alveo cards feature Xilinx Zynq UltraScale + FPGA circuits, while brand-new versions include the dedicated Xilinx UltraScale+ FPGA, which is only found in the Alveo line.

This interface is generally referred to as the program API. 64 bytes from 192.168.2.2: icmp_seq=1 ttl=62 time=9.81 ms 64 bytes from 192.168.2.2: icmp_seq=2 ttl=62 time=14.9 ms 64 bytes from 192.168.2.2: icmp_seq=3 ttl=62 time=8.42 ms 64 bytes from 192.168.2.2: icmp_seq=4 ttl=62 time=14.7 ms, lgh@acs-p4:~/sonic$ docker exec -it switch1 bash, root@switch1:/# vtysh -c "show ip bgp sum", BGP router identifier 192.168.1.1, local AS number 10001. These ethX interfaces are commonly referred to as front panel interfaces and are used by P4 switches to transmit data plane packets. As an example, take the link between switch1 and switch2. access-list all permit any. The behaviour of the fixed-function blocks is determined by the target manufacturer, leaving it out of P4 programmers control. However, in many scenarios this may be not the optimal way to execute some network functions. Moreover, not only can packet header fields be processed in the tables, but so can standard or user-defined metadata assigned to packets. Programming Protocol-Independent Packet Processors., put the explicit reference to the architecture definition file in the P4 program source code (by #include directive), instantiate the package from the architectural model, provide custom implementations of function blocks existing in the model. Entries in tables are sequential unless there is no abstract table that consists of several custom tables. This includes match-action table chain execution, checksum verification and recalculation, deparsing etc.

Thanks to the high flexibility P4 offers, sophisticated forwarding rules can be defined and executed for the traffic flows. They generalize traditional switching tables and help implement routing tables, access control lists, and the creation of complex custom tables. In the first part, we will find out its general description and purpose.

A clear and concise guide, prepared for you. */, /** */. In such a case, protocol-specific headers like PPPoE and GTP, respectively are processed by the P4 fabric switch while the control plane part is still deployed as a virtual appliance on the server. This is a gRPC/protobuf-based API, which allows for automatic generation of client/server code for many languages. Three of them are designated to provide an implementation of ingress packet processing (with parser, match-action treatment and deparser blocks). ), called externs. The following snippet of code (source: official P416 Language Specification v.1.2.0) presents declaration of programmable function blocks and package declarations for an example architecture. In /sonic/scripts/startup.sh we launch all the SONiC services and the P4 switch via the following code line: simple_switch --log-console -i 1@eth1 -i 2@eth2 . You can either build it on your own or use software (like an SDN controller) by extending it with a set of functions enabling effective communication with your newly created dataplane. endstream endobj 72 0 obj <>stream Some people believe this use case is the P4 killer-app. Barefoot Tofino 2 + Tofino products comparison. [4], The primary component of a P4 program is a set of user-defined match action tables. However, the SONiC works with a different type of interface, the so-called EthernetX host interfaces. In general, both fixed-function blocks and programmable blocks can exist for a given target.

This makes P4 a powerful solution.

Finally, we call the startup script for switch1 and switch2: sudo docker exec -d switch1 sh /sonic/scripts/startup.sh, sudo docker exec -d switch2 sh /sonic/scripts/startup.sh. The most important configurations are in /sonic/scripts/startup.sh, /sonic/etc/config_db/vlan_config.json and /sonic/etc/quagga/bgpd.conf. Searching in the table to match the created key to the desired action. 91 0 obj <>/Filter/FlateDecode/ID[<49A7751007913BA246DD00654A1C48DB><72130086F48AAD4E81C13B1E3D018A02>]/Index[68 55]/Info 67 0 R/Length 116/Prev 729648/Root 69 0 R/Size 123/Type/XRef/W[1 3 1]>>stream 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. There are interesting use cases for both datacenter networks, enterprise networks and telco networks. The compiler may be embedded in the target device, an externally running software, or even a cloud service. We have marked this with the red arrow. P4 is distributed as open-source, permissively licensed code, and is maintained by the P4 Language Consortium, a not-for-profit organization hosted by the Open Networking Foundation. The key motivation for transformation from P414 to P416 was to reduce the complexity of the language (from more than 70 keywords to less than 40) and provide a stable core of the language in order to ensure that current P416 programs will be syntactically correct also in future, when examined against subsequent versions of the language. The Buffer Queuing Engine (BQE) and the Packet buffer and Replication Engine (PRE) are target dependent blocks.

Only declarations of programmable blocks are included in the architecture definition model since, on principle, no single fixed-function block (if they are present in the target processing pipeline) can be manipulated by any P4 program. Actions define what to do with the packet: modify the values of selected header fields, drop the packet, forward the packet to the chosen physical port, etc. All the aspects related to tables and their internal structure (like number of tables, match fields and actions for each table, actions behaviour, etc.) Creation of a search key from package fields or calculated metadata. Fm^*^X]Y;E5U^e\TUzpfUJaB"": URh An example might be a vBNG or vSPGW. This capability is traditionally associated with forwarding planes built on general-purpose CPUs or network processors, rather than the fixed function ASICs.

The language is designed to meet several goals: 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. This includes target-specific implementations of some functions (e.g. Xilinx has its target FPGA platform for defining packet processing in the data plane SDNet. They don't have a default feature set available. An example target that supports V1model is a software switch called BMv2, a popular tool for testing P4 programs, e.g. P4 is a programming language for controlling packet forwarding planes in networking devices, such as routers and switches.

Given the fixed cost of table lookup operations and interactions with external objects, both parsers and control elements perform a constant number of procedures for each byte of the incoming packet.

In the first part, we got acquainted with the P4 language, suitable hardware platforms, and configured the SONiC-P4 switch.

Parsers describe the allowed header sequences in received packets, header identification rules and fields for extraction from packets. Stay tuned! hdr.ethernet.srcAddr = hdr.ethernet.dstAddr; Once we have enjoyed the headers and parsers, let's try to understand why P4 is so good and whether it is good at all. In this case, it seems that fast packet processing is guaranteed, but this is not enough.

Match-Action modules are components of tables for performing the following: A control flow is an imperative program that describes how packets are processed on the device, including the sequence of calls to the Match-Action modules. This is because P4 allows you to program dataplane to gather much more information about the network state than what we can determine today using traditional tools, with the simplest of those being the well-known ping and traceroute. 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. In start.sh weve installed the configuration folder in the switch container in /sonic. Actions in P4 describe packet field and metadata manipulations.

These architectures include XilinxSwitch, XilinxStreamSwitch, and XilinxEngineOnly. * The arguments to the package indicate blocks that It is also the programmers responsibility to design a so-called match-action pipeline within the given dataplane block. These products are not just switches or NICs. The P4 program determines it. Here are several examples: checksum, counters, registers, etc. P4 is a relatively new programming language, so hardware support is not robust enough yet.

Probably not, but if properly used it will increase the efficiency of your network resources to better handle service workloads. For instance, the key section of the my_table table in the example below includes two match fields: hdr.ipv4.dstAddr and hdr.tcp.dstPort, corresponding to destination IP address and destination TCP port, respectively. Switch1 and switch2 are two SONiC-P4 switches in two different BGP AS that communicate with each other. This has never been possible to such an extent.

The names in a header definition are used later in the P4 program to reference these fields.

$)vV4[3X#||\2{,>==wd*=. endstream endobj startxref The first P4 language release was called P414. It could be based on white box switches, for instance, and thanks to using a P4-programmable dataplane, the fabric would be easily reconfigured when needed.

This use case can be relevant for a wide variety of targets like physical switches, NIC, software switches, etc. The language allows customized header names and fields of arbitrary length, although many header definitions use widely known protocol names and fields widths.

In the second part, we'll go over the network architecture and do some experiments. * @param type of input and output headers Those metrics can be generated by each network node and sent to the monitoring system in the form of a report. We also believe that practice makes perfect, so we'll look at coding examples and hardware with P4 support. This is where the most high-level functional declaration of the architectural model takes place, since all references to previously declared function blocks are grouped together here. There are some minor issues. * Programmable parser. The code is then compiled and the configuration is injected into the network device. Intel's Tofino 2 architecture also gives more resources to handle heavy workloads in distributed applications, virtual machine scaling, AI, and serverless deployments. For each packet, the parser produces a parsed representation of all relevant headers, which is then passed to the first control block.

Fig 2. it can be described by the programmer. Let's demonstrate the use of the SONiC-P4 software switch: Test bench topology for the SONiC-P4 switch. The commonly used term in P4 is a target, which represents a variety of devicesswitch, router, Network Interface Card (NIC) inserted into the server, a software switchwhich in general can be programmed using P4. However, it is worth noting that P4Runtime can work only with P416 or a later version. P4 is based on the same principle, but for network devices. However, programs created for the same architecture should be portable across all targets that conform to the considered model. Internal metadata is defined by the architecture. The other three blocks represent egress processing based on the same principle. It is worth noting that P4 programs are not expected to be portable across different architecture models.

122 0 obj <>stream In order to construct a valid P4 program for the given architecture, the user has to: An architecture model description must be provided by a target manufacturer in order to indicate all the capabilities and architectural bounds for the P4 programs which are supposed to operate on a given target. * Top-level package declaration - must be instantiated by user. Together with the simple_switch command in /sonic/scripts/startup.sh we configured the following mapping: Ethernet0 -> lane 1 -> eth1. User metadata are data structures that are associated with each package.

Deploying VNFs on x86 servers follows general NFV principles and as such can provide a lot of benefits. counters, meters, checksum calculation, etc. Such a fabric can serve various workloads related to web-scale, enterprise or telco applications whilst allowing for effective processing of different traffic patterns like flat IP/Ethernet, VLAN-tagged flows (including QinQ), MPLS flows, tunnelled traffic (VXLAN, GRE) etc.

Most network devices implement both the control plane and the data plane.

However, standard architecture specifications also exist.

A starter pack containing the impactful networking and cloud technologies you want to read about. Current trends tracked and packaged in a series of articles to give you the necessary insights to help your business grow. *n3X)7dqV!@^=F An example of such a runtime specification is P4Runtime, which provides a standard runtime control API for P4-defined dataplane. The mapping between host interfaces and switch ports is specified in /port_config.ini: # alias lanes Ethernet0 1 Ethernet1 2 . SONiC-P4 runs wherever the docker does on bare metal Linux / Windows machines, inside a virtual machine or in a cloud environment. We specify --net = none so that the Docker engine does not add its docker0 interface, which could interfere with the topology under test. * @param user-defined type of the headers processed. In that context, V1Model facilitates the translation of P4 programs originally written in P414 to the P416 version. Real-life challenges and research cases solved and presented by CodiLimes engineering and R&D teams. like traditional switches or routers normally do, but also fully custom ones, as presented in the example P4 code below: All header types (both well-known and custom), as well as the way they are parsed, must be explicitly defined in the P4 program. An example of such functions would be a firewall, a NAT or a load balancer. P4 outperforms today's packet processing systems in the following points: Flexibility, simplicity, efficiency sounds good, but do we have enough hardware that supports P4? V1Model was introduced to propose a kind of interim architecture until the PSA standard is ready and properly defined. The domain-specific P4 language can be implemented on various devices, including programmable network interface cards, FPGAs, software switches and hardware ASICs. %PDF-1.5 % // control block implementation, tables, actions definition etc. These include populating tables for further packet processing, updating a forwarding elements configuration, etc. So in what areas can P4 really help?

The target manufacturer provides the compiler, which takes your P4 program code as an input and generates a target-specific configuration binary, which is then loaded into the target. Engineers at Barefoot Networks created a P4 language and ASIC type chipset that does not use a proprietary SDK such as Broadcom or Cavium. The P4 compiler generates an API that uses the control plane to communicate with the data plane.

From a P4 perspective, the SDNet environment offers several basic architecture models that P4 programmers can use.

CUPS decomposes a given network function into control and user plane parts. Ethernet, IP, TCP, etc.) necessary insights to help your business grow. */, /**

* @param inCtrl information from architecture, accompanying input packet