> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/fpp/3.2/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/fpp/3.2/architecture.md).

# Architecture

FPP provides a flexible VPP lifecycle management and configuration framework that follows Kubernetes Operator concept. It contains a central VPP Operator that uses `VPPDeployment` Custom Resources (CRs) to create VPP workloads (DaemonSets and StatefulSets) and applies VPP configurations defined in the set of other CRs, such as `VPPInterface`, `VPPConfig`, `RoutingTable`, and `FPPNetwork`.

Additionally, FPP provides CNI (Container Network Implementation) that makes it possible to attach pods that use Linux networking to the fast datapath using TAP interfaces. FPP CNI is also used to configure VPP networking aspects, providing benefits such as possibility to use external CNI IP Address Management (IPAM) plugins such as Whereabouts. FPP CNI creates the necessary `VPPInterface` CRs when a pod using FPP CNI starts, and deletes them when the pod network namespace is torn down.

The VPP pod managed by the VPP Operator is called "FPP pod". VPP Operator uses a GoRPC-based wrapper around VPP binary API protocol to update the VPP configuration. There are two modes in which the FPP pod can run:

- **Node mode** - pods created from `FPPDeployment` CRs through a DaemonSet
- **Instance mode** - pods created from `CGWDeployment` CRs through a StatefulSet

Node mode is used mostly to provide a common VPP-based networking "fabric" on the cluster. There's usually one node mode FPP pod per node. Node FPP pods are joined together through uplinks based on physical NICs. The FPP nodes are designed to mimic an L2 switch with uplinks connecting it to other FPP nodes, and with support for multiple VLANs. This is achieved by creating a VXLAN tunnel mesh between FPP nodes, and using multiple bridge domains and VNIs. Each L2 network segment is defined by an `FPPNetwork` CR. Eventually, support for other protocols like GENEVE might be added in addition to VXLAN, bringing in support for technologies like iOAM. In case of the node mode, multiple FPP pods are created from a single description in the `VPPDeployment` CR.

Instance mode is used primarily to implement Connectivity Gateways (CGWs). In case of the instance mode, a single FPP pod is created from the `VPPDeployment` CR. At some point, CGWs can be integrated into node FPP pods as subsections of their configuration, but at this moment, having them as separate pods is easier implementation-wise. CGWs are used for the following purposes:

- GRE tunnels
- BGP peering
- VRRP
- Policy-based routing
- Firewall setup

Effectively, CGWs provide external connectivity for the workloads connected to the FPP network.

Another example of an FPP pod running in instance mode is the User Plane Gateway (UPG). The VPP Operator manages UPG instances by interacting with the UPG-VPP binary API and by reconciling the configuration defined in the UPG Custom Resources.

Several Custom Resources are defined at the cluster scope, including `VPPTool` and `FPPNetwork`. Other FPP-managed Custom Resources are scoped to specific nodes or instances using labels. You can use wildcard labels to target multiple nodes or instances at once.

![FPP Architecture](https://docs.cennso.com/api/assets/components/fpp/3.2/assets/fpp-architecture.svg)

## Container Network Interface (CNI) support

Although the primary interface of FPP is a Kubernetes API based on CRs, there's also a possibility to use CNI to connect Linux network based workloads, FPP pods, and other applications using fast shared memory based memif interfaces to the FPP network.

FPP is not intended to be used as the cluster's primary CNI implementation, so it cannot replace Calico, Weave, Flannel, and other well-known CNI implementations. At the same time, by default, Kubernetes supports just a single CNI implementation per cluster. In order to deal with this problem,
[Multus CNI](https://github.com/k8snetworkplumbingwg/multus-cni) is used so that FPP CNI can be used alongside a more conventional CNI implementation.

For Linux networking pod, FPP CNI creates a single `VPPInterface` CR of type TAP targeted at the node on which the pod runs. The path to the pod's network namespace is specified as the target namespace path in the `VPPInterface` object. Also, IP address information obtained from the used CNI IPAM (IP Address Management) plugin is added to the `VPPInterface`. When VPP Operator processes the `VPPInterface`, it commands the FPP node pod to create a TAP interface inside the pod's network namespace attached to the FPP pod's VPP process. This effectively connects the Linux networking pod to the FPP network. Thanks to Multus, each pod can have multiple such interfaces if they use different L2 networks (VNI / FPPNetwork).

Another mode of FPP CNI is memif. Memif is a fast shared memory based networking interface which can be used to transfer data between two VPP processes, or a VPP process and another process supporting memif protocol, for examples Cisco TRex and TPLoad traffic generators. Unlike TAP, memifs require very little Linux kernel processing, which is only needed for basic things such as TX/RX ring setup through the control socket.

There are two ways to connect memif workloads:

- New, where the user creates one VPPInterface CR of the memif type with `attachToNetwork` parameter. Then, the VPP Operator creates a matching ephemeral VPPInterface CR plugged into the VPP-based L2 switch. Ephemeral means that the VPPInterface CR is not actually stored in the Kubernetes API Server.

- Legacy, where FPP CNI creates two VPPInterface CRs of the memif type, one for the FPP node pod and one for the target (client-side) workload. The FPP node's VPPInterface CR lacks an IP address and is plugged into the FPP node's VPP-based L2 switch. The client-side VPPInterface CR has an IP address and is targeted at the VPP workload pod.

The following applies to both methods:

If the target workload is also an FPP pod, the central VPP Operator also takes care of creating the client memif interface inside that FPP pod. Otherwise, it is the responsibility of the client to load and parse the VPPInterface CR accordingly, connect to the memif control socket, and set up the TX/RX rings.

## Linux Control Plane, BGP, and VPP Tool support

VPP by itself doesn't support BGP (Border Gateway Protocol) which is important for CGWs and external connectivity. In order to overcome this problem,
[Linux Control Plane](https://s3-docs.fd.io/vpp/22.10/developer/plugins/lcp.html) (LCP) mechanism of VPP is used. LCP creates a TAP or a TUN interface which is attached to a VPP interface inside a Linux network namespace. All the packets with their destination IP matching the IP address of the VPP interface are "punted" (VPP term) towards the Linux interface. All of the packets sent from the Linux interface are sent through the VPP interface by means of the internal VPP "xconnect" mechanism. Also, LCP synchronizes the routes in a Linux network namespace with the VPP FIB (Forwarding Information Base) table, which makes it possible to use tools like [BIRD](https://bird.network.cz/) routing daemon with VPP.

In addition to LCP, FPP has a mechanism called "VPP tool support". There's a CR type called `VPPTool` which defines additional containers to be added to the FPP pods. There are standard `VPPTool` definitions for BIRD and also [bird_exporter](https://github.com/czerwonk/bird_exporter) which takes care of providing metrics for the routing daemon.

BIRD VPPTool uses a Linux interface paired with a FPP CGW VPP interface to establish BGP peering. The routes that BIRD creates in a dedicated Linux network interface are then propagated to the VPP FIB table.

## VPP CLI

Some of the aspects of VPP configuration may not be available in the CRs. In this case, you can use VPP CLI commands, which can be embedded in `VPPConfig` CRs in their **beforeCommands** and **afterCommands** sections. The downside of using the CLIs is that the process is non-idempotent. Consequently, if the set of CLI commands in the applicable `VPPConfig` CRs changes for an FPP pod, the VPP process must be restarted to reliably apply the necessary state.

## CPU, memory, and NIC resource management

VPP should be run with static core assignment. This doesn't work well with the usual Kubernetes resource allocation scheme. To deal with the issue, normally [Kubernetes CPU Manager static policy](https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/#changing-the-cpu-manager-policy) is used, and `vpp-wrapper` reads the cpuset cgroup information to propagate the allocated set of CPU cores to the `startup.conf` file which VPP uses. There's also still a possibility to remove CPU resource requirements for an FPP pod and use the static CPU core allocation scheme, should that be needed.

Concerning the memory use, VPP documentation specifies that hugepages must be used for VPP heap, buffers, and the stat segment. In practice, FPP makes it possible to reduce the hugepage requirements. One caveat is that the hugepages should still be preferably used for the buffers, as otherwise VPP may not be able to handle the packets with MTU larger than 3,776 bytes.

One issue with the VPP memory allocation is that it is NUMA (Non-Uniform Memory Access) aware, which Kubernetes used to be not. VPP allocates memory for each NUMA node on which its threads execute. With the naive approach to cgroup memory allocation, this may sometimes lead to unexpected OOM (out of memory) errors, for example, b/c all of the memory corresponding to a NUMA node happens to be allocated by processes from various pods running on the host. Since Kubernetes 1.22, there's a possibility to use Kubernetes [Memory Manager](https://kubernetes.io/docs/tasks/administer-cluster/memory-manager/) to deal with this problem.

Using [SRIOV Network Operator](https://github.com/openshift/sriov-network-operator), you can provide access to the VFs (Virtual Functions) of physical NICs supporting SRI-OV (Single Root I/O Virtualization) with the Kubernetes container resource specification. In such a case, `vpp-wrapper` retrieves the PCI IDs of the VFs and passes them to VPP through the `startup.conf` DPDK section.
