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

# Installation

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

## Prerequisites

First, you need to install [SR-IOV Network Operator](https://github.com/openshift/sriov-network-operator).
You may also need to install [Whereabouts CNI IPAM plugin](https://github.com/k8snetworkplumbingwg/whereabouts)
to handle uplink IP address assignment. Unless you want to use FPP-CNI as your
primary CNI (it was not tested so far in this quality), you also need to install
[Multus CNI](https://github.com/k8snetworkplumbingwg/multus-cni).

FPP requirement is to have `PCIDEVICE_` as env vars with PCI device ID, example:

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

Above variable can be set by SRIOV Network Device Plugin (which can be install
standalone or by SRIOV Operator).

FPP was tested with SRIOV Operator versions

- [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

Whereabouts as IPAM plugin was tested with `latest` release, FPP requirement is
to have IP in pod annotations:

Unless FPP is being used on a single node (e.g. in a test environment),
FPP VPPSwitch deployments need to be provided with uplink IPs in the pod
annotation in a format such as that provided by [Multus CNI](https://github.com/k8snetworkplumbingwg/multus-cni).
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 this:

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

### 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 via kernel boot options `hugepagesz=2M hugepages=2048`

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

- fpp 1.0 6Gi for FPP-manager.
- fpp 1.1 9Gi for FPP-manager.

### Uplink configuration

`vppswitch` uses DPDK-enabled uplink interfaces, it is required for dpdk driver
to use 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.

In order to enable IOMMU grouping, add 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

#### Uplink interface missing in fpp-manager
If there are no uplink interfaces present in `vppswitch`, exec to `vppswitch`
pod and execute:

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

Search for output like this:

```
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 above output is present in vpp logs, enable IOMMU grouping if node is able
to use it, or configure no-iommu mode for VFIO kernel module described below.

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

When a worker node does not support IOMMU, it is possible to run fpp-manager
by disabling IOMMU, make sure that following boot options are **not set**
in `/proc/cmdline`:

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

 For DPDK driver to pick up NIC (PF/VF) on platform that does not support
 IOMMU, enablement of unsafe no-iommu mode needs to be done:

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

Above setting needs to be applied after each restart of a node.

To check if 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

#### 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 in FPP deployment directly.
Helm based deployment uses directNICMappings, which configures PCI IDs via env
vars 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:

```console
$ lshw -c network -businfo
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:

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

After that, bind NICs to the vfio driver (e.g. using `dpdk-devbind.sh` tool from dpdk package):

```console
$ apt install dpdk # install DPDK tools on node
$ dpdk-devbind.py -s # view current driver bindings
$ dpdk-devbind.py --bind=vfio-pci 0000:8a:00.1
$ dpdk-devbind.py --bind=vfio-pci 0000:8a:00.3
```

> **Warning**
>
> This method of binding NICs to `vfio-pci` must be repeated after reboot

Following these steps, NICs should be ready to be used by FPP Manager. The following
chart configuration will enable FPP DaemonSet to use the 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:

  ```console
  $ 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

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

## Configuring the cluster

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"
```

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
  namespace: fpp
data:
  .dockerconfigjson: ...
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: vpp-switch
  namespace: fpp
imagePullSecrets:
  name: image-secret
```

Apply the deployment files (the order is important!):

```bash
kubectl apply -R -f deploy/
kubectl apply -f /tmp/pullsecret.yaml
```

For the DaemonSet to actually start, each node in the cluster that
will be using FPP must get a label according to the number of uplinks
it has, for example the following labels nodes with 2 uplinks:

```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=""
kubectl rollout status daemonset -n fpp vppswitch
```

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

In order to specify bond interface parameters, you can create a VPPConfig for VPPSwitch.
There are examples of such config for [LACP](https://docs.cennso.com/api/assets/components/fpp/1.3/assets/uplink-bond-lacp.yaml)
and [ActiveBackup](https://docs.cennso.com/api/assets/components/fpp/1.3/assets/uplink-bond-activebackup.yaml) bonding modes.

## List of environment variables used by FPPManager

The following environment variables are supported by FPPManager and
can be customized by updating k8s deployment yaml:

* `FPP_VPP_PATH` - path to the VPP binary. May make sense to be
  overridden for custom images
* `FPP_VPP_PLUGIN_PATH` - VPP plugin path. May make sense to be
  overridden for custom images
* `FPP_VPP_USE_GDB` - if set to a non-empty value, run VPP under
  GDB. This should not be used for production deployments
* `FPP_VPP_GDB_SCRIPT` - specify GDB script to use. Needs
  `FPP_VPP_USE_GDB` to be set.
* `FPP_VPP_DISPATCH_TRACE` - enable dispatch trace for VPP. This
  feature presently only properly works with e2e/integration tests.
* `FPP_HEAP_SIZE` - specify fixed VPP heap size. Note that you also need
  to adjust the resources for the pod if you change this. Defaults to 6G.
* `FPP_STAT_SEG_SIZE` - specify VPP statseg size. Note that you also need
  to adjust the resources for the pod if you change this. Defaults to 512M.
* `FPP_BUFFERS_PER_NUMA` - specify the number of buffers per NUMA node
  in VPP. Defaults to 256000
* `DEFAULT_DATA_SIZE` specifies the default VPP buffer data size in
  bytes. Note that VPP buffers also include a 128-byte header and a
  128-byte scratchpad, so full buffer size is 256+data size
  ([ref](https://lists.fd.io/g/vpp-dev/message/17325)). Defaults to
  3776.
* `FPP_PODINFO_PATH` specifies pod annotation path used by uplink
  config, which is provided via Downward API spec in the DaemonSet
  definition for VPPSwitch
* `FPP_DUMP_CONTROLLER_EVENTS` enables the verbose mode for FPP
  controllers that shows why exactly each reconciliation run is
  happening, complete with k8s object dumps / diffs
* `FPP_STOP_ON_HANG` makes FPPManager send SIGINT to the VPP process
  in case if it becomes unresponsive. When used together with
  `FPP_VPP_GDB_SCRIPT`, this makes it possible to get backtrace for
  the spot that has caused the problem
* `FPP_TRACE_API_CALLS` enables verbose tracing of VPP API calls on
  the VPPLink level (not via the VPP API tracing facility)
* `FPP_NO_HEAP_HUGEPAGES` disables hugepages for the VPP main heap
* `FPP_NO_STATSEG_HUGEPAGES` disables hugepages for the VPP statseg
* `FPP_NO_BUFFER_HUGEPAGES` disables hugepages for the VPP buffers
* `FPP_COREDUMP_DIR`, if specified, enables core dumping for VPP and
  the manager process in case of e.g. SIGSEGV
* `FPP_VPP_MULTICORE` enables multicore mode, in which VPP sets up VPP
  cores in a way compatible with
  [Kubernetes CPU Manager](https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/)
  according to cgroup information. Otherwise, only single core for VPP
  main thread is allocated
* `FPP_VPP_MAX_CORES`, when set to an integer number, limits the number of cores assigned to VPP.
  It includes 1 core to be used as the VPP main core, with remaining cores used as VPP worker cores
  that perform packet processing
* `FPP_VPP_ALLOW_HT_SIBLINGS` specifies that cores that are
  HyperThreading siblings can be used for VPP. This is not recommended
  for any production environment as it will have negative performance
  impact.
* `FPP_VPP_STATIC_CORES` provides static core list to be used by
  VPP. In this case, regardless of `FPP_VPP_MULTICORE` or
  `FPP_VPP_ALLOW_HT_SIBLINGS`, the specified cores are assigned to VPP
  ignoring cgroup information. This setting is to be used in
  conjunction with `isolcpus` kernel parameter

The following environment variables are handled by the startup script
(converted to command line flags). "Node" here refers to VPPSwitch
daemon pod mode, while "instance" means VPP-based workload pods.

* `FPP_INSTANCE_NAMESPACE` (`-namespace`) - namespace for the
  VPPInterfaces created (node) or the VPPInterfaces being processed
  (instance)
* `FPP_INSTANCE_NAME` (`-instance-name`) - the name of the instance
  for the instance mode
* `FPP_INSTANCE_UID` (`-instance-uid`) specifies pod UID for the instance mode
* `FPP_NODE_NAME` (`-node-name`) - the name of the node for the
  VPPSwitch mode
* `FPP_DISABLE_UPLINK` (`-disable-uplink`) disables FPP uplink
  detection mechanism
* `FPP_VPP_EXIT_FATAL` (`-vpp-exit-fatal`) enables manager exits when VPP is dead, default `false`
* `FPP_RUN_PATH` (`-vpp-run-path`) specifies the path for VPP
  directory that contains binary API / CLI sockets etc. Defaults to `/var/run/vpp`
* `FPP_MEMIF_SOCKET_PATH` (`-memif-socket-path`) specifies the path
  for VPP memif socket. Defaults to `/run/vppswitch/memif.sock`

The following environment variables are handled by the startup script

* `FPP_CNI_BIN_DIR` specifies the directory for deploying FPP CNI
  plugin. It defaults to `/opt/cni/bin/`
* `FPP_CNI_DEBUG` enables FPP CNI plugin debugging. If this
  environment variable is not empty, all of the CNI commands that the
  plugin is handling, along with their results are stored in
  `/tmp/cni.log`

`FPP_INSTANCE_NAME` and `FPP_NODE_NAME` should be never specified
together.

### Uplink-related env vars

Uplink DPDK device setup is done based on PCI device information
[provided by the SR-IOV Network Device plugin](https://github.com/k8snetworkplumbingwg/sriov-network-device-plugin#pod-device-information).
The names of corresponding VPP interfaces are derived from `MAPPING_*`
environment variables.

So, for example, if we have the following environment variable set by
the SR-IOV Network Device Plugin:

```
PCIDEVICE_OPENSHIFT_IO_INTELNICS=0000:04:00.1,0000:04:00.2
```

and we also set

```
MAPPING_OPENSHIFT_IO_INTELNICS=uplink
```

this will result in `uplink0` and `uplink1` DPDK interfaces created in
VPP.  These names will be used as the VPP interface names, and they
should also be used in the corresponding uplink `VPPInterface` objects
(which is done automatically when the automatic uplink setup is
enabled).

There's also a possibility to specify RX/TX queue settings in mapping
environment variables. The full format of mapping environment
variable values is this:

```
prefix[:[num-rx-queues][:[num-tx-queues][:[num-rx-desc][:[num-tx-desc]]]]]
```

For example:

```
MAPPING_OPENSHIFT_IO_INTELNICS1=extnet0n:12
MAPPING_OPENSHIFT_IO_INTELNICS2=extnet1n:12:10:1024:512
MAPPING_OPENSHIFT_IO_INTELNICS3=extnet2n:12:::512
```

Below is the description of the values:

* `prefix` specifies the interface name prefix in VPP, as described
  for the simple syntax
* `num-rx-queues` specifies the number of RX queues for the NICs.
  Defaults to the number of worker cores, or to 1 in case of a
  non-multicore setup
* `num-tx-queues` specifies the number of TX queues for the NICs.
  Defaults to the number of worker cores, or to 1 in case of a
  non-multicore setup
* `num-rx-desc` specifies the number of descriptors in each of the RX
  queues. Defaults to 2048
* `num-tx-desc` specifies the number of descriptors in each of the TX
  queues. Defaults to 2048

## FPP Helm Deployment
FPP provides Helm charts for Custom Resource Definitions (CRDs), support configuration
for Prometheus and Grafana dashboard and FPP deployment.

### FPP-CRD
`fpp-crd` helm chart installs Custom Resource Definitions like:

- FPPNetworks
- IPFixExporters
- RoutingTables
- VPPConfigs
- VPPInterfaces
- VXLANs

It does not require any configuration values. `fpp-crd` should be installed once per cluster.

### FPP-Support
`fpp-support` chart includes Prometheus Service Monitor and a Grafana dashboard with overview of FPP metrics.

By default, if no `values.yaml` is provided, nothing will be installed. To enable `ServiceMonitor` and
the Grafana dashboard, the following config should be used:

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

### FPP Manager Deployment
The main helm chart that deploys FPP is named `fpp`. Multiple instances of the `fpp` chart
can be deployed on a single cluster.

There are 2 types of deployment:

- `mode: node` is the default and uses physical interfaces (direct or VFs)
  as uplink or external network interfaces. In this case, FPP Manager is run using Kubernetes `DaemonSet` object
- `mode: instance` is used for VPP-based application deployment. The VPP-based application instance
  is configured by means of FPP Custom Resources targeting that instance via its labels. In this case,
  FPP Manager is run using Kubernetes `Deployment` object

Each FPP installation in `node` mode needs to target an exclusive set of nodes not intersecting
with other FPP installations in `node mode`, as only one FPP acting as a VPP Switch can run on a node.
FPP installation in `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, the following chart configuration
should be used:

- 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
```

- 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"
dumpControllerEvents: true
```

- 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/uplink1:
    network: sriov-network-node-policy-uplink1
    numRxQueues: 12
    numTxQueues: 12
    numRxDesc: 2048
    numTxDesc: 2048
```

For more details about the values above, please refer to [uplinks env vars](#uplink-related-env-vars)
section of this 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 # this is SriovNetwork name
```

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
```

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.

> **Warning**
>
> FPP-based CGWs should only be scheduled on the nodes with FPP version 1.2.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/1.3/assets/cgw-fpp.svg)

Full configuration of [CGW values yaml](https://docs.cennso.com/api/assets/components/fpp/1.3/assets/cgw-fpp.yaml) is included in the assets directory. Here is
an overview of particular configuration sections:

- first we configure the instance mode and add provide the CNF name:

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

This creates Kubernetes `Deployment` object (as opposed to `DaemonSet` which is used in case of
`mode: node`) and adds `cennso.net/cnf: cgw` label to all resources created by the chart.

`imageSecret` needs to be defined to be able to download FPP Manager image from a private registry:

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

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

```yaml
externalNetworks:
  ext-net:  # this name is used as interface name prefix in startup.conf
    openshift.io/extnet: extnet0 # this is SriovNetwork name

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

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
    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
with id 100 (usually this means VXLAN network with VNI 100):

```yaml
networks:
  int:
    type: memif
    vni: 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
```

# Memory usage

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

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

For earlier versions (FPP 1.0), it 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:

```console
$ 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:

```console
$ 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:

```console
$ 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.

```console
$ 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>`).
