## 2 Background
### P4 and Data Plane Programmability  
P4 [17] is an open-source programming language that controls data plane packet processing. As depicted in Figure 1, a P4-enabled switch differs from traditional ones in two aspects: (i) the switch functions are not hardwired but specified by a P4 program, and (ii) control and data plane communication take place through a fixed-function device channel, but the data plane APIs are established by the P4 program. The Southbound Interface APIs that expose the particular features and protocols supported by the data plane are built using the specifications provided by P4 Runtime [18] for abstracting the hardware interfaces. P4's primary goals are as follows:  
* Reconfigurability: The packet parsing logic and processing rules can be dynamically installed and updated by the controller.
* Protocol independence: By giving rule names, key types, and typed match+action tables in the header fields, the controller can determine how to process header fields, freeing the switch from fixed actions taken on standard packet formats.
* Target independence: The P4 code is completely portable for every target. The P4 compiler is tasked with translating program features that make use of target-specific capabilities.  
P4 is designed around an abstract model that explains the traffic forwarding of the switch through match+action steps that are organized in series, parallel, or both. The parser, which extracts header information and serves as a programmable interpreter of supported protocols, first handles inbound packets. The match+action tables, which choose the egress port and queue for the packet, obtain the extracted header data next. The packet may be sent, replicated, dropped, or cause flow control depending on the ingress processing. A P4 program defines the following elements to express the behavior of the data plane:  
1. Header types: packet header definitions, i.e., the set of fields and their sizes.
2. Parsers: finite-state machines that map packets into headers and metadata.
3. Tables: data structures defining matching fields and actions applied to them.
4. Actions: code fragments that describe packet manipulation and can consider external data supplied by the control plane at runtime.  
5. Match-action units: elements that construct lookup keys from packet fields' metadata and use them to find the right action and execute it.
6. Control flows: imperative blocks that describe packet processing on a target using the data-dependent sequence of match-action unit invocations.  
Thus, P4 enhances traditional SDNs (heavily reliant on the OpenFlow protocol [19]) by addressing two well-known shortcomings [20]: (i) a significant communication overhead is generated between the data plane and the control plane and (ii) significant processing capabilities are needed at the controller.  
P4's unrivaled expressiveness provided a revolutionary new perspective on network programmability and monitoring: with P4-programmable switches, it is instead possible for network operators to partially overcome such drawbacks. Programmable switches can execute a portion of network monitoring and security operations directly in their data plane pipeline and provide partially or fully processed information to the control plane. On the other hand, data plane programming has some intrinsic entry barriers, such as the need for enabled hardware and the effort needed for network architects to become proficient in the art of creating efficient and portable code [21].  
The expressiveness limitations of OpenFlow-based SDNs do not allow coding algorithms on the data plane, such as network entropy calculation, which is presented in the next section. In fact, OpenFlow only allows for a fixed set of configurations, while P4 can be used to code custom packet processing algorithms.