> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/fpp/2.11/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/2.11/architecture.md).

# Architecture

FPP provides a flexible VPP lifecycle management and configuration framework that follows Kubernetes Operator concept. It contains a central FPP 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 FPP Operator is called "Amberd". FPP Operator uses a GoRPC-based wrapper around VPP binary API protocol to update the VPP configuration. There are two modes in which the Amberd pod can run:

- **Node mode** - pods created from `VPPDeployment` CRs through a DaemonSet; the CRs have **spec.type** set to `node`
- **Instance mode** - pods created from `VPPDeployment` CRs through a StatefulSet; the CRs have **spec.type** set to `instance`

Node mode is used mostly to provide a common VPP-based networking "fabric" on the cluster. There's usually one node mode Amberd pod per node. Node Amberds are joined together through uplinks based on physical NICs. The Amberd nodes are designed to mimic an L2 switch with uplinks connecting it to other Amberd nodes, and with support for multiple VLANs. This is achieved by creating a VXLAN tunnel mesh between Amberd nodes, and using multiple bridge domains and VNIs. Each L2 network segment is defined by an `FPPNetwork` CR (or legacy `VXLAN` 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 Amberds 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 Amberd pod is created from the `VPPDeployment` CR. At some point, CGWs can be integrated into node Amberds 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.
Eventually, the instance mode Amberds can also be used for User Plane Gateway (UPG), by means of adding UPG VPP binary API and UPG CR support to FPP.

There are several cluster-wide CRs, namely `VPPTool`, `FPPNetwork`, and `VXLAN`. Other FPP-managed CRs target particular nodes and instances by means of labels. Multiple nodes and instances can be targeted by means of wildcard labels.

![FPP Architecture](https://docs.cennso.com/api/assets/components/fpp/2.11/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, Amberds, 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 FPP Operator processes the `VPPInterface`, it commands the node mode Amberd to create a TAP interface inside the pod's network namespace attached to the Amberd'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 FPP 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 Amberd node and one for the target (client-side) workload. The Amberd-side node VPPInterface CR lacks an IP address and is plugged into the Amberd's VPP-based L2 switch. The client-side VPPInterface CR has an IP address and is targeted at the workload.

The following applies to both methods:

If the target workload is also an Amberd, the central FPP Operator also takes care of creating the client memif interface inside that Amberd. 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 Amberd 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 vs VPP binary API

VPP has an efficient binary API mechanism which is used inside Amberds to reconcile the VPP configuration with the CRs, for example to create, update, and delete network interfaces, routes, or GRE tunnels. 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 compared to the binary APIs is that there are no mechanisms in FPP to parse the CLI output, and thus FPP can only run the commands, but not check the results, making the process of applying the CLI-based configuration non-idempotent. Consequently, if the set of CLI commands in the applicable `VPPConfig` CRs changes for an Amberd, the VPP process must be restarted to reliably apply the necessary state.

## Amberd VPP wrapper and GoRPC-based communication protocol

The VPP processes inside Amberd pods are controlled by a Go program called `vpp-wrapper`. `vpp-wrapper` functions include:

- exposing VPP binary API (and consequently CLI, which is available through a binapi call) through a protocol wrapper based on GoRPC
- monitoring VPP process, making sure that it's running
- providing endpoints for Kubernetes Readiness and Liveness probes
- exposing Prometheus metrics

To avoid the need for additional polling, the communication between Amberds and the FPP Operator is done "in reverse". Although it's the  Operator which initiates each GoRPC call, so Amberds have a server role, the actual server endpoint is provided by the Operator, and each Amberd connects to that endpoint. The protocol server is wrapped in an HTTP server, so Amberds must issue the `HTTP CONNECT` request to initiate the actual GoRPC connection. The connection is protected by means of TLS, with a possibility to manage certificates through [cert-manager](https://cert-manager.io/).

Amberds can run on their own and continue processing data plane traffic even when they can't communicate with the central FPP Operator. In such a situation, the VPP configuration cannot be updated. The Amberd pod status becomes non-ready but this does not cause traffic interruptions.

## CPU, memory, and NIC resource management

VPP should be run with static core assignment, the CPU cores required for its main thread and the worker thread are specified in the `startup.conf` file. 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/#cpu-management-policies) 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 Amberd 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 larger than 3,776 bytes (page size minus the buffer metadata overhead).

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.

## Slice support

Normally, FPP should be used with just a single central FPP Operator per cluster. Yet in some cases, such as various QA scenarios, you may want to have multiple FPP Operators controlling separate sets of Amberds. You can do it using the slice mechanism, which looks at the designated label (`fpp-manager.cennso.com/slice`) that can be applied to FPP CRs and the namespaces in which they reside. The FPP Operator configured for a slice will only consider the resources belonging to their slice. All the objects that don't have the slice label are considered to have the `default` slice.

> **CAUTION:** FPP Operators with different slices will not create FPPNetwork meshing between workload places on nodes running a different FPP slice.

To deploy FPP Operator with a non-default slice, use the following Helm values YAML file:

```yaml
# image:
#   repository: registry.cennso.com/cennso-dev/fpp-manager
#   tag: "feature-bird-exporter-v2.0.0-rc.5.7-48768751_release"

# Enable debug logging
logLevel: trace
dumpControllerEvents: true

# Here you can define the slice values
slice: "testing"

imagePullSecrets:
- name: cur-image-pull-secret
```

FPP Operator with a non-default slice will reconcile only FPP objects labelled with `fpp-manager.cennso.com/slice: testing`.

To deploy the FPP node, use the following Helm values:

```yaml
uplinkResources:
  openshift.io/uplink0_vfio: fpp/uplink0
  openshift.io/uplink1_vfio: fpp/uplink1

labels:
 fpp-manager.cennso.com/slice: testing

nodeSelector:
  fpp-manager.cennso.com/fpp: "2.0.0"

imagePullSecrets:
- name: cur-image-pull-secret
```

To deploy FPP in the instance mode, add the following configuration to the chart values:

```yaml
labels:
  fpp-manager.cennso.com/slice: testing
```

To deploy any Kubernetes workload (StatefulSet, Deployment or Daemonset) that requires the FPP interfaces, the pod should have an `fpp-manager.cennso.com/slice: testing` label. For example, you can do it in the StatefulSet manifest using `spec.template.metadata.labels`:

```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: linux-net-1
  namespace: fpp-test
spec:
  podManagementPolicy: Parallel
  replicas: 1
  selector:
    matchLabels:
      name: linux-app
  updateStrategy:
    type: RollingUpdate
  serviceName: linux-net-1
  template:
    metadata:
      annotations:
        k8s.v1.cni.cncf.io/networks: fpp-network-nic
      labels:
        fpp-manager.cennso.com/slice: testing
    spec:
      containers:
      - name: linux-app
        command:
        - /bin/sh
        - -x
        - -c
        - "ip r add 10.30.0.0/24 via 10.20.0.1 && ip a && while true; do sleep 1000; done"
        image: busybox
        imagePullPolicy: IfNotPresent
        securityContext:
          privileged: true
```
