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

# Installation

This document describes setting up FPP for multi-node production deployments.

Terminology used in this document:

- VPPSwitch - Amberd pod in the `node` mode, which acts as a virtual switch on each Data Plane node
- Uplink - network interface, virtual or physical, which is used by VPPSwitch to communicate inside the cluster and create a VXLAN mesh to interconnect workload CNFs between nodes

## Prerequisites

Configure the following before deploying FPP:
- [Uplink connectivity](#uplink-configuration)
- [Hugepages enabled](#hugepages)
- [Multus CNI](https://github.com/k8snetworkplumbingwg/multus-cni) installed in the Kubernetes cluster
- [Whereabouts CNI IPAM plugin](https://github.com/k8snetworkplumbingwg/whereabouts) to handle uplink IP address assignment, if SRIOV Virtual Functions as uplink are used in VPPSwitch
- CNI v1.1.1+ with the [static plugin](https://www.cni.dev/plugins/current/ipam/static/)
- [cert-manager installed](https://cert-manager.io/docs/installation/)
- NIC firmware updated to the latest version [in the case of Intel e810 cards](#intel-e810-support) for direct NIC assignment in VPPSwitch

### Hugepages

The cluster nodes that run FPP need to provide hugepages as managed allocatable
resource:

```sh
kubectl describe node <node>
...
Capacity:
  cpu:                64
  ephemeral-storage:  1950451200Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      12000Mi
  memory:             131497548Ki
  pods:               250
Allocatable:
  cpu:                63760m
  ephemeral-storage:  1787549514288
  hugepages-1Gi:      0
  hugepages-2Mi:      12000Mi
  memory:             109498956Ki
  pods:               250

```

You can enable hugepages via sysfs, which should be early in the boot process:

```sh
sysctl vm.nr_hugepages=6000
```

Hugepages may also be allocated already during the boot process through kernel boot options `hugepagesz=2M hugepages=2048`.

As a common starting point, allocate at least 12Gi of 2MB hugepages per node.

Check [the memory configuration section](#memory-configuration) for more details.

### Uplink configuration

VPPSwitch uses DPDK-enabled uplink interfaces. It is required for the DPDK driver
to use an IOMMU-enabled platform with isolation of IOMMU groups - for processor-
based (northbridge) PCI root ports and controller hub-based (southbridge) PCI
root ports. This is called Access Control Service (ACS) capabilities.

Two types of uplink interfaces are supported:

- [SRIOV Virtual Functions](#uplinks-using-sriov-vfs)
- [Direct physical NICs assignment](#uplinks-using-direct-nic-assignment)

To assign an IP address for uplinks, you can use an IPAM plugin, such as Whereabouts, or you can specify IP manually by VPPConfig `spec.uplinkConfig.ips`.

#### Enable IOMMU

In order to enable IOMMU grouping, add the following to boot options:

```
iommu=pt intel_iommu=on pci=realloc pci=assign-busses
```

To activate those options, add them to e.g. `/etc/default/grub` and run:

```bash
grub-mkconfig -o /boot/grub/grub.cfg
```

and reboot the host.

To check if the system supports IOMMU grouping, run:

```bash
find /sys/kernel/iommu_groups/ -type l
```
The proper output should look like this:

```
/sys/kernel/iommu_groups/0/devices/0000:00:00.0
/sys/kernel/iommu_groups/1/devices/0000:00:02.0
/sys/kernel/iommu_groups/2/devices/0000:00:14.0
/sys/kernel/iommu_groups/3/devices/0000:00:16.0
/sys/kernel/iommu_groups/4/devices/0000:00:19.0
/sys/kernel/iommu_groups/5/devices/0000:00:1a.0
/sys/kernel/iommu_groups/6/devices/0000:00:1b.0
/sys/kernel/iommu_groups/7/devices/0000:00:1c.0
/sys/kernel/iommu_groups/9/devices/0000:00:1c.1
/sys/kernel/iommu_groups/10/devices/0000:00:1c.2
/sys/kernel/iommu_groups/11/devices/0000:02:00.0
/sys/kernel/iommu_groups/12devices/0000:03:00.0
/sys/kernel/iommu_groups/13/devices/0000:00:1d.0
/sys/kernel/iommu_groups/14/devices/0000:00:1f.0
/sys/kernel/iommu_groups/15/devices/0000:00:1f.2
```

If the platform does not support IOMMU grouping, then above output would look
like following:

```
/sys/kernel/iommu_groups/17/devices/0000:00:1f.0
/sys/kernel/iommu_groups/17/devices/0000:00:1f.2
/sys/kernel/iommu_groups/17/devices/0000:00:1f.3
/sys/kernel/iommu_groups/18/devices/0000:02:00.0
/sys/kernel/iommu_groups/18/devices/0000:02:00.1
/sys/kernel/iommu_groups/18/devices/0000:03:01.0
/sys/kernel/iommu_groups/18/devices/0000:03:05.0
/sys/kernel/iommu_groups/18/devices/0000:03:07.0
/sys/kernel/iommu_groups/18/devices/0000:03:09.0
/sys/kernel/iommu_groups/18/devices/0000:04:00.0
/sys/kernel/iommu_groups/18/devices/0000:05:00.0
/sys/kernel/iommu_groups/18/devices/0000:06:00.0
/sys/kernel/iommu_groups/18/devices/0000:07:00.0
/sys/kernel/iommu_groups/19/devices/0000:08:00.0
/sys/kernel/iommu_groups/19/devices/0000:08:00.1
```

References:

- https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Ensuring_that_the_groups_are_valid
- https://forum.level1techs.com/t/sr-iov-all-virtual-functions-in-same-iommu-group-breaking-vms/163152/3

#### IPAM for uplinks

Unless you use FPP on a single node, for example in a test environment, you must provide uplink IPs in the pod annotation in the same format as that provided by [Multus CNI](https://github.com/k8snetworkplumbingwg/multus-cni) for VPPSwitch deployments.

For SRIOV VFs as uplinks, it's convenient to use [Whereabouts](https://github.com/k8snetworkplumbingwg/whereabouts) CNI IPAM plugin, as described in the [Configuring the cluster section](#configuring-the-cluster) of this document. The pod annotation expected by FPP is as follows:

```yaml
    k8s.v1.cni.cncf.io/networks-status: |-
      [{
        (...)
      },{
          "name": "sriov-network-operator/sriov-network-uplink0",
          "interface": "net1",
          "ips": [
              "10.30.38.3"
          ],
          "dns": {}
      },{
          (...)
      }]
```

For direct NIC attachment, you can use `spec.uplinkConfig.ips` in VPPConfig to assign the IPs to the interfaces. A sample excerpt from the values.yaml file:

```yaml
vppConfigs:
- nodeName: wk-1234.dev.cennso.net
  spec:
    uplinkConfig:
      ips:
      - 10.0.40.1/24
```

#### Uplinks using SRIOV VFs

[SR-IOV Network Operator](https://github.com/k8snetworkplumbingwg/sriov-network-operator) must be installed on the cluster.

FPP requires is to have `PCIDEVICE_` as environment variables with a PCI device ID, for example:

```
declare -x PCIDEVICE_OPENSHIFT_IO_UPLINK0="0000:06:0a.4"
declare -x PCIDEVICE_OPENSHIFT_IO_UPLINK1="0000:06:02.6"
```

The above variable is set by SRIOV Network Device Plugin, which can be installed independently or by SRIOV Operator.

FPP was tested with the following versions of SRIOV Operator:

- [origin-sriov-operator](https://quay.io/repository/openshift/origin-sriov-network-operator?tab=tags) `4.3.0`
- [openshift/sriov-network operator](https://github.com/openshift/sriov-network-operator) commit `104db73503782b16900ebc1ce14f809bde2f1086`, based on release 4.9

#### Uplinks using direct NIC assignment

FPP Manager can use Physical Functions (PFs) as uplinks. This means that no SRIOV
operator is needed and NIC PCI IDs can be passed directly in the FPP deployment.
The Helm-based deployment uses `directNICMappings`, which configures PCI IDs through environment
variables and enables direct access to the system firmware directory (`/lib/firmware`).

To use PFs of a NIC, first make sure that the machine uses the newest firmware files (see next
section for details on how to update ICE DDP package for [Intel E810](#intel-e810-support)),
then check which card should be used by FPP, for example:

```bash

Bus info          Device           Class          Description
=============================================================
pci@0000:51:00.0  eno1             network        Ethernet Controller 10G X550T
pci@0000:51:00.1  eno2             network        Ethernet Controller 10G X550T
pci@0000:8a:00.0  ens6f0           network        Ethernet Controller E810-C for SFP
pci@0000:8a:00.1  ens6f1           network        Ethernet Controller E810-C for SFP
pci@0000:8a:00.2  ens6f2           network        Ethernet Controller E810-C for SFP
pci@0000:8a:00.3  ens6f3           network        Ethernet Controller E810-C for SFP
```

In this example, `8a:00.1` and `8a:00.3` will be used. When using PFs with VPP,
`vfio-pci` driver should be used. Ensure that no VFs are created on that NICs,
in case if SRIOV Network Operator is used this means that SRIOV Custom Resources
using these NICs need to be removed (`SriovNetworkNodePolicy` objects).
Below is an example command that disables VFs on the machine:

```bash
echo 0 > /sys/class/net/ens6f1/device/sriov_numvfs
echo 0 > /sys/class/net/ens6f3/device/sriov_numvfs
```

After that, you can bind NICs to the vfio driver using an init container in the FPP node deployment. For example:

```yaml
additionalInitContainers:
- name: bind-vfio
  image: travelping/nettools:1.12.0
  command:
  - /bin/sh
  - -c
  - |
    if [ "$(basename $(readlink /sys/bus/pci/devices/0000:8a:00.1/driver))" != vfio-pci ]; then
      echo '8086 1593' >/sys/bus/pci/drivers/vfio-pci/new_id
      echo '0000:8a:00.1' > '/sys/bus/pci/devices/0000:8a:00.1/driver/unbind'
      echo '0000:8a:00.1' > /sys/bus/pci/drivers/vfio-pci/bind
      echo '0000:8a:00.3' > '/sys/bus/pci/devices/0000:8a:00.1/driver/unbind'
      echo '0000:8a:00.3' > /sys/bus/pci/drivers/vfio-pci/bind
    fi
  securityContext:
    privileged: true
  volumeMounts:
  - name: hostsys
    mountPath: /sys
  resources:
    limits:
      cpu: 100m
      memory: 100Mi
```

Every time the FPP node DaemonSet starts, the proper NIC binding is configured, so the method is reboot-safe.

The `8086 1593` is a vendor and device ID of the NIC. You can check it by running `lspci -nn -s <PCI-ID>`. Example:

```bash
# lspci -nn -s 8a:00.1
8a:00.1 Ethernet controller [0200]: Intel Corporation Ethernet Controller E810-C for SFP [8086:1593] (rev 02)
```

After performing these steps, NICs should be ready to be used by FPP Manager. The following
chart configuration enables FPP DaemonSet to use NICs and assign IPs:

```yaml
directNICMappings:
  uplink:
  - "0000:8a:00.1"
  - "0000:8a:00.3"
```

The above settings will be translated into env vars in the FPP DaemonSet:

```
- name: MAPPING_NIC
  value: uplink
- name: PCIDEVICE_NIC
  value: 0000:8a:00.1,0000:8a:00.3
```

The following DPDK interfaces will be configured in `startup.conf`:

```
dpdk {

  dev 0000:8a:00.1 {
    name uplink0
    num-rx-queues 4
    num-tx-queues 4
    num-rx-desc 2048
    num-tx-desc 2048
  }

  dev 0000:8a:00.3 {
    name uplink1
    num-rx-queues 4
    num-tx-queues 4
    num-rx-desc 2048
    num-tx-desc 2048
  }
}
```

`uplink0` and `uplink1` can be used in VPPConfig `beforeCommands` and `afterCommands` sections.
FPP Manager will create these VPPInterface objects corresponding to these NICs to be used
as uplinks or as external network interfaces if according to the external network prefixes
defined in `VPPConfig` (interfaces not matching any interface name prefixes are used as uplinks).

`spec.uplinkConfig.ips` in VPPConfig can be used to assign the IPs to the interfaces
(an example of values.yaml fragment):

```yaml
vppConfigs:
- nodeName: wk-1234.dev.cennso.net
  spec:
    uplinkConfig:
      ips:
      - 10.0.40.1/24
```

#### Intel E810 support

FPP Manager supports Intel E810 NIC cards after updating the DDP (Dynamic Device Personalization) package.
The following steps needs to be performed to update the DDP package:

1. Download DDP package from [Intel driver page](https://www.intel.com/content/www/us/en/download/19660/intel-ethernet-800-series-telecommunication-comms-dynamic-device-personalization-ddp-package.html)
, tested with `1.3.37.0` version.
2. Unpack the zip file you downloaded from the Intel site and then unpack the zip file inside it (`ice_comms-1.3.37.0.zip`)
3. Copy the DDP package file `ice_comms-1.3.37.0.pkg` to `/lib/firmware/intel/ice/ddp/`
4. In the same directory (`/lib/firmware/intel/ice/`), create symlink `/lib/firmware/intel/ice/ddp/ice.pkg`
  to point to the file you copied above:

  ```bash
  ls -ltr /lib/firmware/intel/ice/ddp/
  total 712
  -rw-r--r-- 1 root root 725428 Sep  1 17:04 ice_comms-1.3.37.0.pkg
  lrwxrwxrwx 1 root root     22 Sep  1 17:04 ice.pkg -> ice_comms-1.3.37.0.pkg
  ```

5. On the host, run `update-initramfs -c -k $(uname -r)` to update initrd.
  All the PFs need to have the same version of the DDP package
6. Reboot the node to load the updated DDP package
7. Check that the DDP package has been updated

  ```bash
  dmesg|grep DDP
  [   16.685250] ice 0000:8a:00.0: The DDP package was successfully loaded: ICE COMMS Package version 1.3.37.0
  ```

#### Uplink interface missing in fpp-manager
If there are no uplink interfaces present in the VPPSwitch pod, access the pod and execute:

```bash
vppctl -s /run/vppswtich/cli.sock show logging
```

Search for output like the following:

```
2021/11/29 10:24:43:099 notice     dpdk           EAL:   Invalid NUMA socket, default to 0
2021/11/29 10:24:43:099 notice     dpdk           EAL:   0000:03:10.6 VFIO group is not viable! Not all devices in IOMMU group bound to VFIO or unbound
2021/11/29 10:24:43:099 notice     dpdk           EAL: Requested device 0000:03:10.6 cannot be used
2021/11/29 10:24:43:099 notice     dpdk           EAL:   Invalid NUMA socket, default to 0
2021/11/29 10:24:43:099 notice     dpdk           EAL:   0000:05:10.4 VFIO group is not viable! Not all devices in IOMMU group bound to VFIO or unbound
2021/11/29 10:24:43:099 notice     dpdk           EAL: Requested device 0000:05:10.4 cannot be used
```

If the above output is present in VPP logs, enable IOMMU grouping if the node is able
to use it, or configure the no-IOMMU mode for the VFIO kernel module described below.

#### Configuration for VFIO-no-IOMMU platform

When a worker node does not support IOMMU, you can run VPPSwitch
by disabling IOMMU. Make sure that the following boot options are **not set**
in `/proc/cmdline`:

```
iommu=pt intel_iommu=on pci=realloc pci=assign-busses
```

In the case of a platform that does not support IOMMU, DPDK driver can pick up NIC (PF/VF)
only after you enable the unsafe no-IOMMU mode:

```
echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
```

You must apply the above setting after each node restart.

To check if the kernel supports no-IOMMU module, run:

```
cat /boot/config-$(uname -r) | grep NOIOMMU
CONFIG_VFIO_NOIOMMU=y
```

References:

- https://www.mail-archive.com/vpp-dev@lists.fd.io/msg14509.html
- https://dpdk-guide.gitlab.io/dpdk-guide/setup/binding.html#vfio-no-iommu
- https://doc.dpdk.org/guides/linux_gsg/linux_drivers.html#vfio-no-iommu-mode

## Configuring the cluster

Configure the following before the actual FPP deployment:

- [Configure the SRIOV Operator](#configure-the-sriov-operator) if VFs are used for uplinks
- [Enable image download](#enable-image-download)
- [Label the nodes](#label-the-nodes)

### Configure the SRIOV operator

You need then to configure `SriovNetworkNodePolicy` objects for
uplinks, that is the NICs that will be used by VPPSwitch daemon
pods. If you want to use the standard deployment YAMLs without
changing resource specifications, you need to name the uplink
resources `uplink0`, `uplink1` and so on, which together with
`RESOURCE_NAME` of `openshift.io` specified for SR-IOV Network
Operator results in Kubernetes resource names like
`openshift.io/uplink0`, `openshift.io/uplink1` and so on.

The following is an example of `SriovNetworkNodePolicy` for Intel XL710 VFs:

```yaml
---
apiVersion: sriovnetwork.openshift.io/v1
kind: SriovNetworkNodePolicy
metadata:
  name: sriov-network-node-policy-uplink0
  namespace: sriov-network-operator
spec:
  deviceType: vfio-pci
  mtu: 9000
  nicSelector:
    deviceID: "1583"
    pfNames:
    - eth0
    rootDevices:
    - "0000:04:00.3"
    vendor: "8086"
  nodeSelector:
    feature.node.kubernetes.io/network-sriov.capable: "true"
  numVfs: 4
  priority: 99
  resourceName: uplink0
```

The above example will create 4 VFs on eth0 NIC on nodes that match `nodeSelector`.
If the hardware is different across different nodes of the cluster (different
NICs or their PCI configurations), there should be multiple `SriovNetworkNodePolicy`
objects created with different `nodeSelector` values. This also requires creating
multiple fpp-manager deployments with different networks attached to it via
NetworkAttachmentDefinitions.

If multiple uplinks are used, FPPManager creates a bond that is
comprised of these uplinks.

You also need to create `SriovNetwork` objects for the uplinks. For
uplinks that are used without bonding, you need to specify IP address
in the `ipam` section.  In case of bonded interfaces, the first
interface among bonded must have an IP address. You can use
[Whereabouts CNI IPAM plugin](https://github.com/k8snetworkplumbingwg/whereabouts)
to facilitate this task. A `SriovNetwork` with an assigned IP address may look like this:

```yaml
apiVersion: sriovnetwork.openshift.io/v1
kind: SriovNetwork
metadata:
  name: sriov-network-uplink0
  namespace: sriov-network-operator
spec:
  ipam: |-
    {
      "range": "10.30.38.0/24",
      "type": "whereabouts"
    }
  resourceName: uplink0
  spoofChk: "off"
  trust: "on"
```

#### SRIOV VF MAC conflict

When using SRIOV VF as the FPP uplink, VPP inside the container sets the MAC address generated for the DPDK interface. SRIOV driver on the NIC side sets the VF MAC address after creating the VF. Overriding it inside the container by VPP results in a warning message in `dmesg`:

```
[23544.190430] i40e 0000:06:00.2: MAC addr e2:0d:d2:15:f5:78 has been set by PF, cannot delete it for VF 8, reset VF to change MAC addr
[23544.190468] i40e 0000:06:00.2: VF 8 failed opcode 11, retval: -5
```

The following kernel and driver versions are known not to work:

- kernels: `5.4.0-131-generic`, `5.4.0-148-generic`
- Intel NIC driver i40e in version `2.8.20-k`

Setting different MAC addresses on a node and in VPP may sometimes result in connectivity issues.

As a workaround, set the MAC address of a node to `00:00:00:00:00:00` on the VF that would be used for the FPP uplink. Sample bash command:

```bash
for nic in ${NIC_LIST}; do
  for vf in $(ip link show dev "${nic}" | grep 'vf ' | awk '{print $2}'); do
    ip link set "${nic}" vf "${vf}" mac 00:00:00:00:00:00
  done
done
```

Set the `$NIC_LIST` variable to the name of the network interface for which the VFs are created.

This action should be done by the cluster operator during the maintenance window, because setting the MAC address interrupts the network connectivity on the VF used in FPP. After you reset the MAC, FPP must be restarted.

MAC address can be set also in the Network Attachment Definition. This requires defining SRIOV NADs used for uplinks by hand, for example:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  annotations:
    k8s.v1.cni.cncf.io/resourceName: openshift.io/uplink0_vfio
  name: uplink0
  namespace: fpp
spec:
  config: |
  '{
      "cniVersion":"0.3.1",
      "name":"uplink0",
      "type":"sriov",
      "mac":"00:00:00:00:00:00",
      "vlan":0,
      "spoofchk":"off",
      "trust":"on",
      "vlanQoS":0,
      "capabilities":{"ips": true, "mac": true },
      "ipam":{"range":"10.35.38.0/24","type":"whereabouts"}
   }'
---
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  annotations:
    k8s.v1.cni.cncf.io/resourceName: openshift.io/uplink1_vfio
  name: uplink1
  namespace: fpp
spec:
  config: |
  '{
      "cniVersion":"0.3.1",
      "name":"uplink1",
      "type":"sriov",
      "mac":"00:00:00:00:00:00",
      "vlan":0,
      "spoofchk":"off",
      "trust":"on",
      "vlanQoS":0,
      "capabilities":{"ips": true, "mac": true },
      "ipam":{}
   }'
```

This approach enables automatic MAC reset done by SRIOV-CNI on VFs assigned by SRIOV operator to the FPP pod. It requires the FPP definition to be adjusted to use new NADs and after VPPDeployment modification, FPP pods are restarted. This approach does not affect other workloads using the VFs.

### Enable image download

In order to be able to pull FPP images from a private registry, you
may need to configure imagePullSecrets for the FPP service
account. One possibility is to create `/tmp/pullsecret.yaml` file,
adding proper base64-encoded docker auth information, so that later it
can be used to augment the FPP deployment:

```yaml
---
apiVersion: v1
kind: Secret
type: kubernetes.io/dockerconfigjson
metadata:
  name: image-secret
data:
  .dockerconfigjson: ...
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: fpp-sa
imagePullSecrets:
- name: image-secret
```

This secret should be created in `{fpp-namespace}`:

```bash
kubectl apply -n {fpp-namespace} -f /tmp/pullsecret.yaml
```

### Label the nodes

For the FPP DaemonSet to actually start, each node in the cluster that
will be using FPP must get a label, for example `fpp-manager.cennso.com/vppswitch-uplinks=2`:

```bash
kubectl label node node1 node2 node3 fpp-manager.cennso.com/vppswitch-uplinks=2
kubectl label node node1 node2 node3 fpp-manager.cennso.com/vppswitch=""
```

`fpp-manager.cennso.com/vppswitch=""` is used for workloads' nodeSelector to select the nodes where VPPSwitch is available.

## FPP Deployment

FPP is delivered as Helm charts that provide you all necessary Custom Resource Definitions (CRDs) that you can use to configure FPP. To deploy FPP using Helm charts, follow these steps:

1. Install the `fpp-crd` chart.
2. Install the `fpp-operator` chart.
3. Install the `fpp` chart.
4. Install the `fpp-support` chart if you want to have Grafana and Prometheus enabled.

### Deploy `fpp-crd`

`fpp-crd` is a cluster-wide Helm chart that installs the following Custom Resource Definitions:

- FPPNetworks
- IPFixExporters
- RoutingTables
- VPPConfigs
- VPPDeployments
- VPPInterfaces
- VPPTools
- VXLANs

This Helm chart does not require any configuration values.

### Deploy `fpp-operator`

This chart install FPP Operator - a central entity responsible for reconciling FPP CR objects and passing them to Amberd pods. Slicing mechanism is introduced to run multiple FPP Operator per cluster.

This is the sample configuration you can use to deploy and configure FPP using the `fpp-operator` chart:

  ```yaml
  # -- Define non default image
  # image:
  #   repository: registry.cennso.com/cennso-dev/fpp-manager
  #   tag: "feature-add-chart-cennso-340-v2.0.0-rc.3.8-d707c377_release"
  # -- Enable detailed logging
  # logLevel: trace
  # dumpControllerEvents: true
  # -- Enable multiple FPP Operators by specifying non default label
  # slice: "testing"
  # -- Set resources that will handle production cluster
  resources:
    cpu: 1
    memory: 512Mi
  imagePullSecrets:
  - name: cur-image-pull-secret
  ```

### Deploy `fpp`

`fpp` is the main Helm chart that deploys FPP Amberds - VPP wrapper pods. You can deploy multiple instances of the `fpp` chart on a single cluster.

There are two types of deployment:

- `node` mode is the default deployment that uses physical interfaces, either direct or VFs, as uplink or external network interfaces. In this case, FPP Operator creates VPPDeployment with `spec.mode` set to `node`, which in turn results in Kubernetes `DaemonSet` object.
- `instance` mode is used for VPP-based application deployment. The VPP-based application instance is configured by means of FPP Custom Resources targeting that instance by its labels. In this case, FPP Operator creates VPPDeployment `spec.mode` set to `instance`, which results in Kubernetes `StatefulSet` object.

Each FPP installation in the `node` mode must target an exclusive set of nodes not intersecting with other FPP installations in the `node` mode, as only one FPP acting as a VPP Switch can run on a node. FPP installation in the `instance` mode can be deployed multiple times on the same node.

#### FPP deployment using `node` mode

To run FPP in `node` mode for a production use-case, use the following chart configuration:

- Configure the number of buffers per NUMA for optimal performance

```yaml
buffersPerNuma: 512000
```

- configure image pull secret to be able to download `fpp-manager` image from a private registry

```yaml
imagePullSecrets:
- name: image-secret
```

Instead of using image pull Secret, the preconfigured service account can be used:

```yaml
serviceAccount: fpp-sa
```

- specify optional log level:

```yaml
# available values: trace, debug, info, error
logLevel: "debug"
```

To enable more verbose logging, VPP API calls (on the internal intermediate VPPLink level)
and Kubernetes controller events (Create/Update/Delete) can be logged:

```yaml
vpp:
  traceAPICalls: true
logLevel: "trace"
```

- specify the node selector for the subset of nodes where the FPP DaemonSet should be deployed:

```yaml
nodeSelector:
  fpp-manager.cennso.com/vppswitch-uplinks: "2"
```

- configure pod resources:

```yaml
resources:
  cpu: "10"
  hugepages-2Mi: 9Gi
  memory: 2Gi
```

- configure uplink and external network interfaces:

```yaml
uplinkResources:
  openshift.io/uplink0: sriov-network-node-policy-uplink0
  # openshift.io/uplink0 - this is the Kubernetes resource name, based on SriovNetworkNodePolicy.spec.resourceName
  # sriov-network-node-policy-uplink0 - this is SriovNetwork or Network Attachment Definition name, based on SriovNetwork.metadata.name
  openshift.io/uplink1:
    network: sriov-network-node-policy-uplink1
    numRxQueues: 12
    numTxQueues: 12
    numRxDesc: 2048
    numTxDesc: 2048
```

For more details about Rx/Tx configuration, refer to the [Uplinks environment variables](https://docs.cennso.com/components/fpp/2.2/devel/env-vars.md#uplink-related-env-vars) document.

To configure external network interfaces using VFs, use following chart config:

```yaml
externalNetworks:
  ext-net:  # this name is used as interface name prefix in startup.conf
    openshift.io/extnet: extnet0
    # openshift.io/extnet - this is the Kubernetes resource name, based on SriovNetworkNodePolicy.spec.resourceName
    # extnet0 - this is SriovNetwork or Network Attachment Definition name, based on SriovNetwork.metadata.name
  anotherExtNet:
    dummy.io/external-2:
      network: external-2-nad
      numRxQueues: 10
      numTxQueues: 8
      numRxDesc: 1024
      numTxDesc: 512
```

In order to configure an external network interface, VPPConfig can be used, e.g.:

```yaml
vppConfigs:
- nodeName: wk-node1.eu.cennso.net
  spec:
    externalNetworkConfig:
    - bridgeDomain: 20
      ifacePrefix: ext-net
      ips:
      - 10.100.0.123/24
      mtu: 8930
```

`vppConfigs[].spec.externalNetworkConfig.ifacePrefix` must match `externalNetworks` key name (`ext-net` or `anotherExtNet` from above example).

To define a `VPPConfig` that applies to all `fpp` pods in node mode:

```yaml
vppConfigs:
  - nodeName: ""
    spec:
      uplinkConfig:
        bondMode: ActiveBackup
        prefixLen4: 24
        prefixLen6: 64
```

#### Additional interfaces

A field named `assumedInterfaces` in `VPPConfig` is introduced to allow manual
configuration of additional VPP interfaces. The idea is to use `beforeCommands`
to configure interfaces of a type that is not directly supported by FPP but supported by VPP,
for example, subinterfaces that correspond to VLANs, and then create uplink/extnet
VPPInterface objects corresponding to these interfaces.

If `assumedInterfaces` is declared, DPDK interfaces declared in `startup.conf`
are not used, unless explicitly mentioned. Example configuration using helm chart:

```yaml
directNICMappings:
  uplink:
  - "0000:8a:00.1"
  - "0000:8a:00.3"

vppConfigs:
- nodeName: wk-1234.dev.cennso.net
  spec:
    beforeCommands:
    - set interface state uplink0 up
    - set interface state uplink1 up
    - create bond mode lacp
    - set interface name BondEthernet0 bond0
    - bond add bond0 uplink0
    - bond add bond0 uplink1
    - set interface state bond0 up
    - create sub-interface bond0 1001
    - set interface state bond0.1001 up
    - create sub-interface bond0 1002
    - set interface state bond0.1002 up
    assumedInterfaces:
    - bond0.1001
    - bond0.1002
    uplinkConfig:
      ips:
      - 10.0.40.1/24
    externalNetworkConfig:
    - ifacePrefix: bond0.1002
      bridgeDomain: 1
```

`directNICMappings` configures 2 DPDK interfaces in `startup.conf`: `uplink0` and
`uplink1`. These interfaces are used in `VPPConfig.beforeCommands` to create
a bond (`bond0`) and subinterfaces for this bond for VLANs 1001 and 1002
(`bond0.1001` and `bond0.1002` respectively). FPP creates VPPInterface objects
for `bond0.1001` and `bond0.1002`.
From these, `bond0.1001` is used as the uplink interface. `bond0.1002` is used as
an external interface, connected to bridge domain `1`.

#### FPP deployment using `instance` mode

The instance mode was introduced to enable VPP-based workloads.
This makes it possible to manage workloads using FPP Custom Resources and
configure VPP in a unified way.
The benefit of using VPP-based applications is a possibility to employ fast vector packet
processing with traffic not touching Linux kernel networking stack.

One of possible application to use the VPP as a base is Connectivity Gateway
(CGW), product of Travelping that currently uses Linux kernel to create external
connectivity to outside of the cluster endpoints, with GRE tunnels and BGP routing.
This application is called CGW-FPP in this section.

>**CAUTION:** FPP-based CGWs should only be scheduled on the nodes with FPP version 2.0.0 or later serving as VPP Switch to have VPP interfaces configured properly.

Below is a diagram with the CGW-FPP example deployment described further in this section:

![CGW-FPP Diagram](https://docs.cennso.com/api/assets/components/fpp/2.2/assets/cgw-fpp.svg)

This is the full configuration of the CGW `values.yaml` file:

```yaml
mode: instance
cnfName: cgw

imagePullSecrets:
- name: image-secret

externalNetworks:
  ext-net:  # this name is used as interface name prefix in startup.conf
    openshift.io/ext_vfio_gen3: sriov-network-operator/ext-gen3-sriov-vfio # this is SriovNetwork name

vppConfigs:
- spec:
    externalNetworkConfig:
    - ifacePrefix: ext-net
      ips:
      - 10.75.61.12/29
      mtu: 8930

# Chart will create VPPInterface with proper GRE interface configuration
vppInterfaces:
- ifName: gre1 # name of the VPP Interface
  tableName: gre-inner-table
  ips:
  - 198.19.1.3/24
  greTunnel:
    sourceIf: ext-net0n0 # chart creates interface name by concatenation of <interface-name> and <0n0>
    destIP: 10.75.61.11
    # encapTableName: gre-outer-table
    # key: 1234 # optional support

# Chart will generate NAD with `int` interface for CGW-FPP
networks:
  int: # int is a name of the interface
    type: memif
    vni: 1830 # VNI of FPPNetwork that traffic be routed into
    tableName: gre-inner-table
    ipv4:
      addresses:
      - 198.18.1.10/24

# For testing purpose only!
routingTables:
  # gre-outer-table:
  #   id: 42
  #   addressFamily: IPv4
  #   routes:
  #   - cidr: 192.168.10.0/24
  #     nextHopAddress: 10.0.0.10
  gre-inner-table: # example of routing table that forwards traffic from remote GRE endpoint to internal FPP network
    id: 4242
    addressFamily: IPv4
    routes:
    - cidr: 198.19.65.0/24
      nextHopAddress: 198.19.1.4
      nextHopInterface: gre1
    - cidr: 198.18.65.0/24
      nextHopAddress: 198.18.1.2
      nextHopInterface: int

# Minimal resource configuration that enables CGW to run:
resources:
  cpu: "2"
  memory: 2Gi
  hugepages-2Mi: 2Gi

heapSize: 1900M
enableHugepagesAllocation: false

# optional log level extension to more verbose mode:
# vpp:
#   traceAPICalls: true
# logLevel: "trace"
```

To start configuring the `instance` mode based on the CGW example above, first provide the CNF name:

```yaml
mode: instance
cnfName: cgw
```

For FPP 2.0, the configuration above creates the VPPDeployment object with mode set to `instance`, which in turn creates Kubernetes `StatefulSet` object (as opposed to `DaemonSet` which is used for the `node` mode), and adds the `cennso.net/cnf: cgw` label to all resources created by the chart.

**imageSecret** must be defined to download FPP Manager image from a private registry:

```yaml
imagePullSecrets:
- name: image-secret
```

To enable external connectivity, you can use an external network interface based on VF with `SriovNetwork` configuration which provides a VF for use by CGW-VPP. Also, you can assign the IP address of the external network using VPPConfig, for example:

```yaml
externalNetworks:
  ext-net:  # this name is used as interface name prefix in startup.conf
    openshift.io/extnet: extnet0
    # openshift.io/extnet - this is the kubernetes resource name, based on SriovNetworkNodePolicy.spec.resourceName
    # extnet0 - this is SriovNetwork and Network Attachment Definition name, based on SrioVNetwork.metadata.name

vppConfigs:
- spec:
    externalNetworkConfig:
    - ifacePrefix: ext-net
      ips:
      - 10.75.0.12/29
      mtu: 9000
```

`vppConfigs[].spec.externalNetworkConfig.ifacePrefix` must match `externalNetworks` key name (`ext-net`).

Next thing is to configure the GRE interface, which can also be created using the chart:

```yaml
vppInterfaces:
- ifName: gre1
  tableName: inner-table
  ips:
  - 198.19.1.1/24
  greTunnel:
    sourceIf: ext-net0n0 # FPP creates interface name by concatenation of <interface-name> and <0n0>
    destIP: 10.75.0.11
    encapTableName: outer-table
    # key: 123 # optional to specify the GRE key
```

The above configuration will create a tunnel from the external IP of the interface named `ext-net0n0`
(`10.75.0.10/29`) to the destination IP somewhere in the external network, that is
where the other endpoint of the GRE tunnel resides (`10.75.0.11/29`). The VPP interface
for the local GRE tunnel endpoint will be named `gre1` and will be assigned the IP address `198.19.1.1`.

It is possible to specify inner and outer routing tables for VPP GRE interfaces.
These tables (`inner-table` and `outer-table`) can also be defined outside the FPP chart.

Example of `inner-table` RoutingTable definition:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  name: inner-table
...
spec:
  addressFamily: IPv4
  id: 4242
  routes:
  - cidr: 198.19.65.0/24
    nextHopAddress: 198.19.1.4
    nextHopInterface: gre1
  - cidr: 198.18.65.0/24
    nextHopAddress: 198.18.1.2
    nextHopInterface: int
```

A Network Attachment Definition can be used to provide routing between the GRE tunnel and
the internal FPP network. Here we create a `memif` interface connected to the internal FPP network
called `net-100`, the network must be created outside of a Helm chart:

```yaml
networks:
  int:
    type: memif
    networkName: net-100
    tableName: inner-table
    ipv4:
      addresses:
      - 198.18.1.1/24
```

In this example, CGW-FPP serves as a gateway to the FPP VXLAN network,
connecting it to an external network via the GRE tunnel.

Minimal resource configuration for test run of VPP-based application is:

```yaml
resources:
  cpu: "2"
  memory: 2Gi
  hugepages-2Mi: 1Gi

heapSize: 1900M
enableHugepagesAllocation: false
```

### Deploy `fpp-support`

`fpp-support` chart provides you with the Prometheus ServiceMonitors and Grafana dashboards that contain FPP metrics. This chart provides two dashboards and two ServiceMonitors, one for FPP `node` mode and second dedicated to CGW deployment in `instance` mode.

You install `fpp-support` only once per cluster.

  ```yaml
  prometheus:
    servicemonitor:
      enabled: true
  dashboard:
    enabled: true
  ```

## Memory configuration

It is advised to have the following resources allocated for VPPSwitch pods for the most common cases:

```yaml
resources:
  cpu: "10"
  hugepages-2Mi: 9Gi
  memory: 2Gi
```

The FPP 1.0 version is recommended to have the following settings:

```yaml
resources:
  cpu: "10"
  hugepages-2Mi: 6Gi
  memory: 6Gi
```

## CPU Pinning

By default, FPP relies on [Kubernetes CPU Manager](https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/)
running in `static` mode. FPP Manager pods use Guaranteed QoS in this
case (requests being same as the limits), and resulting cpuset cgroup
configuration is used to assign cores to the VPP process via`startup.conf`.
The cores assigned to the VPP processes in VPP Switch pods
can be checked using the following command:

```bash
cat /var/run/vppswitch/startup.conf
...
cpu {
  main-core 27
  corelist-workers 28,29,30,31
}
...
```

### Static CPU cores

In some cases, it may be desirable to preallocate dedicated cores to VPP
processes, excluding them from being used by any other process on node.
In this case, a subset of cores first need to be specified in the `isolcpus`
kernel parameter, e.g. in `/etc/default/grub`

```
export GRUB_CMDLINE_LINUX='(...) isolcpus=27,28,29,30,31,59,60,61,62,63 (...)'
```

After adjusting the grub settings, run `grub-mkconfig -o /boot/grub/grub.cfg`
and reboot the host. To check if the setting is configured on node, run:

```bash
cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-5.15.0-48-generic root=UUID=689e2902-f6d3-494b-a81f-aa1e0df5d0d6 ro isolcpus=27,28,29,30,31,59,60,61,62,63 iommu=pt intel_iommu=on pci=realloc pci=assign-busses
```

The cores must be specified together with their HyperThreading siblings in case
if HyperThreading is enabled on the system. The HT siblings can be checked using:

```bash
lstopo-no-graphics --no-io --no-legend --of txt
```

(`hwloc` package) or by looking at `/sys/devices/system/cpu/cpu*/topology/thread_siblings_list`
for each of the CPU cores to be used.

After configuration done on node level, the cores can be specified via `vpp.staticCPUCores` in
`values.yaml`, but note that from each HT sibling pair, just one core can be specified:

```yaml
vpp:
  staticCPUCores: 27,28,29,30,31
```

It's possible to verify whether the desired cores are actually assigned to the VPP process
by checking `startup.conf` inside FPP pod and also e.g. by adding `PROCESSOR` column in `htop` on node.

### Max CPU cores

Another approach to VPP CPU allocation is to use `vpp.maxCPUCores` without `isolcpus` kernel parameter.
In this case, like in normal FPP deployment, Guaranteed QoS class is used for FPP pods so that Kubernetes
CPU Manager provides it with a dedicated cpuset. In this case FPP pod needs to be assigned more CPU
than used for VPP itself, for example 14:

```yaml
resources:
  cpu: "14"
  hugepages-2Mi: 9Gi
  memory: 2Gi
vpp:
  maxCPUCores: "5"
```

In this case, FPP pod will have 7 physical cores assigned, but only 5 of them will be
used for VPP.

```bash
cat /sys/fs/cgroup/cpuset/cpuset.cpus                                            │
1-7,49-55
```

Resulting `startup.conf`:

```
cpu {
  main-core 1
  corelist-workers 2,3,4,5
}
```

Cores 6 and 7 will be used by the Linux scheduler to run other processes than VPP,
most importantly, kernel threads that are created to serve TAP interfaces (`vhost-<PID>`).
