# P4-KBR: A Key-Based Routing System for P4-Programmable Networks
## 3 P4 Ecosystem  
Programming Protocol-independent Packet Processor (P4) [5] is a representative data plane programming language that provides packet processing abstractions in networking elements in a target-independent way. The P4 language is used to program how packets are going to be processed by the data plane of programmable forwarding elements (e.g., hardware or software switches, network interface cards, routers, or network appliances), which are commonly known as P4 targets. The P4 language offers end-users the ability to create custom protocols and algorithms in an agile and generic way. It allows the user to specify the format of packets (protocol's headers) to be recognised by network devices and the actions to be performed on incoming packets (e.g., forwarding, headers modification, adding protocol header). In addition, P4 offers stateful programming [6] based on the use of memory registers that can be accessed when processing a packet. Thus, forwarding procedures can be defined based on the network state, variations, and history of flow statistics at node level, without requiring the intervention of a controller. The definition of a memory register that stores the switch vid and the possibility of defining new actions to be applied during processing of a packet through the pipeline are the key aspects that have made possible the implementation of the solution described in Section 4.3. The P4 source code is not directly consumed by the network elements. A P4 program must be compiled for a particular platform. These platforms can be hardware-based (e.g., Barefoot Tofino, FPGA) or software-based (e.g., bmv2, eBPF/XDF, PISCES or P4 rt-OVS). P4c [16] is a reference P4 compiler, that supports both P4 language versions P4-14 [17] and P4-16 [18]. A survey of P4 compilers can be found in [19]. Figure 1 depicts a typical workflow when programming a P4 target, showing the different elements involved in the P4 ecosystem. Target manufacturers provide a model of a specific hardware or software implementation, an architecture definition (that is, the P4 programmable blocks and an API to program the target) and a P4 compiler for the target. The P4 compiler maps the P4 source code into the target model, and it then produces a data plane configuration that implements the forwarding logic and an API to manage the state of the data plane objects from the control plane. Another important and useful component of the P4 ecosystem is P4 Runtime [6]. P4 Runtime is a standard, open and silicon-independent protocol that enables us to control the P4 forwarding plane at runtime. Once a P4 program is deployed, it does not offer functions to interact with the P4 switch, for example, to add or remove entries in tables or to read counters. P4 Runtime API has been developed for this aim. It follows a client-server model. A client integrated within the control plane interacts with the server to load the P4 program, write and read pipeline information (e.g., table entries and meters) and send and receive packets. P4 Runtime uses a gRPCprotobuf-based language to define the API called p4 runtime.proto. As specified in the figure labeled in red, we have used ONOS (Open Network Operating System) [7], an open source SDN controller that includes support for P4 Runtime, offering useful featured such as: device discovery, P4 pipeline provisioning, match-action table operations (via exiting ONOS APIs such as FlowRule, FlowObjective or Intent), controller packet-in and packet out, and counter reads. Our proposal has been validated using the P4 reference software switch bmv2 [20] and Stratum [21], a open-source silicon-independent switch OS that exposes a set of next-generation SDN interfaces including P4 Runtime. Bmv2 switches can also be controlled and programmed using a Thrift-based interface with a Command Line Interface (CLI). Packet processing in bmv2 switches using P4 has the following phases. The input packets are first handled by the P4 programmable _Parser Stage_ defined as a state machine.