> 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/crs.md).

# Custom Resources

The communication between FPP Manager, FPP CNI Plugin and VPP-based
workload instances happens using `VPPInterface` custom resources.
FPP Manager applies the VPPInterface state to the VPP instance
it's running and reports back the status in the `status` field of the
resource. Each `VPPInterface` can be targeted at a node (the
VPPSwitch on the node) or to a particular FPPManager instance (a
VPP-based workload). The latter is used for VPP-based workload
instances. There are also `VPPConfig` objects which can be used to
configure VPP instances, both VPPSwitch daemon pods and VPP-based
workloads.

Both `VPPConfig` and `VPPInterface` objects, as well as `IPFIXExporter` objects,
are targeted using labels.
It's possible to target a VPP workload where FPPManager is passed the specific
value of the `FPP_INSTANCE_NAME` environment variable:

```yaml
labels:
  fpp-manager.cennso.com/plumbing-instance: vpp-webserver
```

Another version of instance targeting uses `FPP_INSTANCE_UID`
environment variable value, which usually contains pod UID value in VPP-based workloads.
This method is used by FPP-CNI for VPP-based workload pods:

```yaml
labels:
  fpp-manager.cennso.com/plumbing-instance-uid: 296f1d55-bbcd-45af-872a-c3dcb906a437
```

VPPInterface is targeted via instance UID instead of instance name because otherwise,
it wouldn’t work with CNI. With CNI, the `netns` is created before
the pod is started, and it may be torn down at an arbitrary moment later, even
sometime after the pod is re-created. Targeting via instance name can run into a situation
where VPPInterface CRs remaining for a while from dead UPG pods
interfered with new UPG pods with the same instance name.

It's also possible to target specific VPPSwitch node:

```yaml
labels:
  fpp-manager.cennso.com/plumbing-node: node1
```

or all VPPSwitch nodes:
```yaml
labels:
  fpp-manager.cennso.com/plumbing-node: ""
```

`RoutingTable` objects are also subject to this label-matching mechanism
unless alternative selectors are specified using the `routingTableSelectors`
field in the `VPPConfig` spec.

## VPPConfig objects

VPPConfig objects can be used to configure VPP instances, be that
VPPSwitch daemon pods or FPP-based workload pods. `VPPConfig` lists
VPP CLI commands that must be run by FPP Manager, which can utilize many
interfaces that are configured using `VPPInterface` CRs.

When multiple VPPConfig objects match this particular FPPManager
instance, they're merged together according to their `priority` value.
The resulting config is called "effective config". When effective
config changes for an active FPPManager instance, the FPPManager
instance restarts. There's an exception from that rule, namely,
`spec.routingTableSelectors` field. When the effective value of
`spec.routingTableSelectors` changes (it being all of the
`routingTableSelectors` lists specified in all of the applicable
configs appended together, with duplicates removed), the FPP Manager
instance is not restarted but rather just continues with the new
`routingTableSelectors` being used.

```yaml
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  name: vpp-webserver
  namespace: fpp-sample
  labels:
    # target particular VPP workload
    fpp-manager.cennso.com/plumbing-instance: vpp-webserver
spec:
  # priority specifies the priority of this particular config when merging multiple
  # VPPConfig objects. The higher is priority value, the higher precedence this config
  # takes.
  priority: 100

  # beforeCommands are executed immediately when the VPPConfig is loaded
  # by FPPManager, before configuring any interfaces
  beforeCommands:
  - create loopback interface instance 42

  # 'interfaces' section specifies the interfaces that must become
  # available and up before `afterCommands` section is run
  interfaces:
  # matches "name" from 'config:' in NetworkAttachmentDefinition,
  # which is propagated to ifName of the client (slave) memifs
  # See NetworkAttachmentDefinition examples further down in this document,
  # e.g. in the "memif" section
  - srv

  # afterCommands are only run after all of the interfaces listed under 'interfaces:'
  # are ready
  afterCommands:
  - http static server www-root /srv uri tcp://{{ .Ifs.srv.IP }}/80 cache-size 2m fifo-size 60000 debug 2

  # routingTableSelectors specify the label selectors which are used
  # to select RoutingTable objects that apply to this VPP instance.
  # Separate selectors are ORed together, while labels/values within a single
  # selector are ANDed together.
  # If no routingTableSelectors are specified, the default targeting
  # mechanism is used for RoutingTable objects, too.
  routingTableSelectors:
  - label1: value1
    label2: value2
  - label3: value3

  # assumedInterfaces lists the interfaces that are assumed to exist
  # after all of beforeCommands from the effective VPPConfig are
  # executed, and are used for creation of Uplink and Extnet interfaces.
  # When any assumedInterfaces are specified, DPDK interfaces (that is,
  # interfaces specified via MAPPING_* / PCIDEVICE_* env vars) aren't
  # automatically used for uplinks or extnet unless they're explicitly
  # mentioned in assumedInterfaces.
  # assumedInterfaces: ["bond0.2001", "bond0.2002"]

  # externalNetworkConfig specifies the prefix name and settings for a physical
  # interface that can be configured as external network. This inteface can
  # join the specified bridge domain (VXLAN id) or be used (after assigning IP)
  # as routing hop for internal networks defined in FPP.
  # The corresponding DPDK settings for the physical interface
  # will be added to startup.conf
  externalNetworkConfig:
  - ifacePrefix: ext-net
    # networkName refers to an FPPNetwork object from bridgeDomain value
    # is derived
    networkName: my-network
    # or bridgeDomain can be specified directly
    # bridgeDomain: 31
    # the list of IPv4 and/or IPv6 addresses to be propagated
    # to the VPPInterface objects corresponding to the external interfaces
    ips:
    - 10.0.0.1/24
    MTU: 1500
    # routing table to get table ID from for this interface
    tableName: my-routing-table
    # table (VRF) for the external network interface,
    # can be used in place of tableName
    # table: 300
    # bond mode, one of LACP / Broadcast / XOR / ActiveBackup / RoundRobin
    bondMode: ActiveBackup
    # bond lb algorithm, one of L2 / L34 / L23 / RR / BC (Broadcast) / AB (ActiveBackup)
    bondLbAlgo: L23

    # disableBonding disables automatic bonding
    # disableBonding: true

    # memif field is used for testing, it creates a fake memif interface
    # in place of a real extnet interface
    # memif:
    #   id: 11001
    #   role: slave

    # count is used together with memif to create multiple fake
    # memif extnet interfaces. If id is specified for memif,
    # it is auto-incremented for each memif in the sequence
    # count: 3
```

This `Ifs` structure that can be used in the `afterCommands` has the following fields for each interface:

* `Name` contains the VPP interface name for the interface
* `IP` contains the IPv4 address for this interface, if any, or an empty
  string if there's no IPv4 address assigned for this interface
* `IPNet` contains CIDR (IPv4 / subnet) for this interface, if any, or
  an empty string if there's no IPv4 address assigned for this interface
* `IP6` contains the IPv6 address for this interface, if any, or an empty
  string if there's no IPv6 address assigned for this interface
* `IPNet6` contains CIDR (IPv6 / subnet) for this interface, if any, or
  an empty string if there's no IPv6 address assigned for this interface
* `Table` contains table (VRF) id for this interface (defaults to 0)

The IP address templating mechanism will not work correctly if there
are multiple IPv4 addresses or multiple IPv6 addresses specified for
the interface.

For VPPSwitch daemon pods, the config may also contain a `uplinkConfig`
section that specifies the uplink configuration:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  name: fpp-config
  namespace: fpp
  labels:
    # matches all FPP nodes
    fpp-manager.cennso.com/plumbing-node: ""
spec:
  uplinkConfig:
    # bond mode, one of LACP / Broadcast / XOR / ActiveBackup / RoundRobin
    bondMode: LACP
    # bond lb algorithm, one of L2 / L34 / L23 / RR / BC (Broadcast) / AB (ActiveBackup)
    bondLbAlgo: L23
    # IP prefix len for IPv4 subnet
    prefixLen4: 24
    # IP prefix len for IPv6 subnet
    prefixLen6: 64
    # MTU for the uplink interface
    MTU: 9000
    # table (VRF) for the uplink interface. It's not recommended to change
    # this value.
    table: 5001

    # memif field is used for testing, it creates a fake memif interface
    # in place of a real uplink interface
    # memif:
    #   id: 10001
    #   role: slave

    # count is used together with memif to create multiple fake
    # memif uplink interfaces. If id is specified for memif,
    # it is auto-incremented for each memif in the sequence
    # count: 3
```

The external network configuration code matches the name prefix specified in
`VPPConfig` against physical interface names included in a `startup``.conf`` based on
`MAPPING_` environment variables. Below is an example of a VPPConfig that matches
all of the nodes and also enables bonding for the external network:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-node: ""
    name: fpp-config
  name: fpp-config
  namespace: fpp
spec:
  uplinkConfig:
    bondMode: ActiveBackup
    prefixLen4: 24
    prefixLen6: 64
  externalNetworkConfig:
  - ifacePrefix: ext-net
    bridgeDomain: 31
```

For this to work, we need to define the `MAPPING_` environment variables for
the FPP Manager pod like this:

```
        - name: MAPPING_OPENSHIFT_IO_X540_EXTNET0
          value: ext-net0n
        - name: MAPPING_OPENSHIFT_IO_X540_EXTNET1
          value: ext-net1n
```

In the example above, 2 interfaces will be used for the ext-net external network
defined in VPPConfig. The following VPPInterface objects will be created:
`<node-name>-ext-net-0`, `<node-name>-ext-net-1`, and also a VPPInterface object for
the bond named `<node-name>-ext-net-bond`.

VPPConfigs that contain external interfaces with IP assignment must match a
single FPP node (via `fpp-manager.cennso.com/plumbing-node` label) or a single
FPP instance (via `fpp-manager.cennso.com/plumbing-instance` label) to avoid IP
conflicts:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-node: wk-4001.dev-04.ccl-01.eu.cennso.net
    name: fpp-config-wk4001
  name: fpp-config-wk4001
  namespace: fpp
spec:
  externalNetworkConfig:
  - bridgeDomain: 20
    ifacePrefix: ext-net
    ips:
    - 10.100.0.123/24
```

VPPInterfaces that are generated for uplinks and `extnet` interfaces are
continuously synced against the VPPConfigs applicable to the current
node/instance. The generated VPPInterface objects have a couple of
special labels:

 * `fpp-manager.cennso.com/plumbing-physiftype` which can be either `uplink` or `extnet`
 * `fpp-manager.cennso.com/plumbing-physifrole` which can be
   `standalone` for a non-bonded interface, `member-N` for a bond
   member, or `bond` for a bond

## VPPInterface objects

`VPPInterface` CRs can be created manually, by the FPP-CNI or by the VPPSwitch,
the latter being used for VXLAN meshing.

The name of the VPP interface is generated by VPP itself by default,
e.g. `memif1/100`.  If `spec.ifName` is set, that value is used
instead of the name of the interface.  The special case is the
`spec.ifName` beginning with a dash (`-`). In this case, `spec.ifName`
is updated using its value as a suffix for the VPP device name, so
that `-mydev` as `spec.ifName` becomes `memif1/100-mydev`, and this
name is also used as the VPP interface name. This suffix mechanism is
used by FPP-CNI on the VPPSwitch side to provide meaningful names for
the network interfaces corresponding to pods.

There are several types of VPPInterface resources supported.

## VPPInterface: uplink/bond

This corresponds to VFs or NICs that VPPSwitch owns, e.g. DPDK
interfaces. DPDK interfaces are available upon startup in VPP, so no
extra NIC details are specified there, except that `ifName` must
match the name of the interface that is created upon VPP startup based
on `MAPPING_...` environment variable value (see
[Deploying FPP](https://docs.cennso.com/components/fpp/1.3/deploy.md) document for details). When automatic uplink
creation is enabled, the uplinks should not be created manually to avoid
conflicts.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: node1
  namespace: fpp
  # target VPPSwitch on the node node1
  labels:
    fpp-manager.cennso.com/plumbing-node: node1
spec:
  # VPP interface name
  ifName: uplink0
  # IP address of the node
  ips:
  - 10.150.0.3/24
  mtu: 9000
  # VRF to use
  table: 500
status:
  # status report by VPPSwitch
  ready: true
  swIfIndex: 1
  vppName: uplink0 # same as ifName
```

It's also possible to bond the uplink interfaces. If, for example,
there are several uplinks configured like this:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  # also node1-{1..3}
  name: node1-0
  namespace: fpp
  labels:
    fpp-manager.cennso.com/plumbing-node: node1
spec:
  # also uplink{1..3}n0
  ifName: uplink0n0
  mtu: 9000
```

they can be bonded together in a single uplink like this

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: node1-bond
  namespace: fpp
  labels:
    fpp-manager.cennso.com/plumbing-node: node1
spec:
  bond:
    lb: L34
    members:
    - node1-0
    - node1-1
    - node1-2
    - node1-3
    # can also use ActiveBackup, XOR, Broadcast, RoundRobin
    mode: LACP
  ifName: bond0
  ips:
  - 10.150.0.3/24
  mtu: 9000
  table: 500
```

## VPPInterface: external network

When VPPConfig has the externalNetworkConfig section specified,
each physical interface that matches the interface name prefix will be
configured as an external network by the FPP Manager start sequence. External
interfaces are marked with VPPInterface.Spec attribute Type set to
`extnet`. The name of the VPPInterface object is constructed using the node name,
externalNetworkConfig.Name and a number: `<node-name>-<ext-net-name>-<id>`.

When the type is not set, the VPPInterface object is considered to be an uplink
interface.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: node1-ext-net-0
  namespace: fpp
  # target VPPSwitch on the node node1
  labels:
    fpp-manager.cennso.com/plumbing-node: node1
spec:
  ifName: ext-net0n0
  type: extnet
  bridgeDomain: 31
  mtu: 9000
status:
  # status report by VPPSwitch
  ready: true
  swIfIndex: 1
  memberCount:  0
  vppName: ext-net0n0
```

It's also possible to create a bond interface consisting of external interfaces.
Prefix name defined in the `externalNetworkConfig.name` needs to match
multiple physical interfaces mappings in FPP Manager `MAPPING_...` environment
variable value.

## VPPInterface: VXLAN endpoint

This corresponds to a VXLAN tunnel endpoint. The endpoints are created
internally by the VPPSwitch instances based on `VPPInterface` objects
corresponding to uplinks, and `VXLAN` objects, so, most of the time,
you don't need to create any `vxlanTunnel` type objects by hand, and
they're reserved for possible special cases.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: nv-node1-31
  namespace: fpp
  labels:
    fpp-manager.cennso.com/plumbing-node: node1
spec:
  bridgeDomain: 31
  ifName: vxlan31
  mtu: 9000
  vxlanTunnel:
    # the peer
    destIP: 10.150.0.3
    # this corresponds to the VRF in the uplink VPPInterface
    encapVRFID: 500
    instance: 31
    sourceIP: 10.150.0.1
    # VNI id
    vni: 31
status:
  # status report by VPPSwitch
  ready: true
  swIfIndex: 2
  vppName: vxlan31
```

## VPPInterface: GRE tunnel

This corresponds to a GRE tunnel endpoint. FPP supports only L3 GRE
tunnels at the moment. Another GRE tunnel endpoint is expected to be
present at the `destIP`, not necessarily provided by FPP. The
`sourceIP` must correspond to an address of an interface belonging to
this VPP instance. The traffic destined for the GRE interface will be
encapsulated and sent from `sourceIP` towards the `destIP` using GRE
datagrams. Conversely, the traffic arriving at `sourceIP` from the
`destIP` will be decapsulated. It's possible to use another table ID
for the encapsulated traffic by specifying `encapVRFID` inside the
`greTunnel` section of the spec. GRE tunnel may have a `key` configured
like it's defined in ``RFC 2890``. If present, should match similar
configuration parameters on another GRE tunnel endpoint.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: mygre31
  namespace: fpp
  labels:
    fpp-manager.cennso.com/plumbing-instance: mycgw
spec:
  bridgeDomain: 31
  ifName: mygre31
  mtu: 9000
  greTunnel:
    # the peer
    destIP: 10.150.0.3
    # source IP
    sourceIP: 10.150.0.1
    # This corresponds to the VRF used for the encapsulated packets.
    # Defaults to 0
    encapVRFID: 500
    # The VPP tunnel instance ID. Can be omitted, in which case it
    # will be generated. Doesn't affect anything, most of the time,
    # if ifName is set.
    # The instance ID is used to generate VPP interface names,
    # but FPP renames the interface according to ifName.
    instance: 31
    # Key for the tunnel may be omitted, by default Key will not
    # be used for GRE tunnels matching. If present, should be
    # configured for both GRE peers. Allowed range: 0 to (2^32) - 1
    key: 12345
    # The options may be omitted, defaults are listed below.
    # They control how the corresponding bits are copied
    # from the payload to the tunnel header during encap
    # and vice-versa during decap
    options:
      # handling of the DF bit during encap (none, copy, set)
      dfMode: none
      # copy DSCP bits during encap if true
      copyDSCP: false
      # copy the ECN bit during encap if true
      encapCopyECN: false
      # copy the ECN bit during decap if true
      decapCopyECN: false
      # compute flow hash on the inner packet for more entropy
      # during encap if true
      encapInnerHash: false
      # copy the hop-limit/TTL during encap if true
      copyHopLimit: false
      # copy the Flow Label during encap if true
      copyFlowLabel: false
status:
  # status report by VPPSwitch
  ready: true
  swIfIndex: 2
  vppName: mygre31
```

## VPPInterface: memif

Memifs are used to attach VPP-based workload instances or other tools
that use memifs, such as [Cisco TRex](https://trex-tgn.cisco.com/) to
VPPSwitch. A pair of memif `VPPInterface` objects is created by FPP-CNI
for each such network attachment.

Note that many of the `fpp-manager.cennso.com/...` labels below are
used internally by FPP CNI which has generated the VPPInterface
objects below.

Master memif:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: vpp-webserver-0-memif-1-fc2p2
  namespace: fpp-sample
  labels:
    fpp-manager.cennso.com/plumbing-container-id: f2a66d02f81ae739dffb29f8b54eb57fbe2fb32c
    fpp-manager.cennso.com/plumbing-ifname: net1
    fpp-manager.cennso.com/plumbing-instance-uid: 296f1d55-bbcd-45af-872a-c3dcb906a437
    fpp-manager.cennso.com/plumbing-memif-role: master
    fpp-manager.cennso.com/plumbing-node: fpp-cluster-control-plane
    fpp-manager.cennso.com/plumbing-pod-name: vpp-webserver-0
    fpp-manager.cennso.com/plumbing-type: memif
    fpp-manager.cennso.com/plumbing-vni: "1"
spec:
  bridgeDomain: 1
  hardwareAddress: 02:fe:09:d3:05:40
  # The name is set to '-net1` by FPP-CNI and then
  # updated by FPP Manager to avoid name collisions
  ifName: "memif1/100-net1"
  memif:
    id: 100
    role: master
    ringSize: 8192
    bufferSize: 4096
    # Queue-to-core assignment on the VPPSwitch (master) side.
    # corresponds to txPlacement in the NetworkAttachmentDefinition
    txPlacement: [2, 3]
  mtu: 9000
status:
  memberCount: 0
  ready: true
  swIfIndex: 2
  vppName: memif1/100-net1
```

Slave (client) memif. `ifName` is set to the `name` of
`NetworkAttachmentDefinition` below. It is used as the VPP interface
name in the VPP app:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-container-id: f2a66d02f81ae739dffb29f8b54eb57fbe2fb32c
    fpp-manager.cennso.com/plumbing-ifname: net1
    fpp-manager.cennso.com/plumbing-instance-uid: 296f1d55-bbcd-45af-872a-c3dcb906a437
    fpp-manager.cennso.com/plumbing-memif-role: slave
    fpp-manager.cennso.com/plumbing-pod-name: vpp-webserver-0
    fpp-manager.cennso.com/plumbing-type: memif
    fpp-manager.cennso.com/plumbing-vni: "1"
  name: vpp-webserver-0-memif-client-1-bnvd2
  namespace: fpp-sample
spec:
  hardwareAddress: 02:67:03:2d:20:be
  ifName: srv
  ips:
  - 10.0.0.1/24
  memif:
    id: 100
    role: slave
    # number of queues is only specified for master
    numRxQueues: 2
    numTxQueues: 2
    ringSize: 8192
    bufferSize: 4096
    # Queue-to-core assignment on the client (slave) side.
    # corresponds to clientTxPlacement in the NetworkAttachmentDefinition
    txPlacement: [0, 1]
  mtu: 9000
status:
  memberCount: 0
  ready: true
  swIfIndex: 1
  vppName: srv
```

Sample NetworkAttachmentDefinition with the CNI config from which
FPP-CNI has derived the above VPPInterface:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: vpp-net
  namespace: fpp-sample
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses": [
          {
            "address": "10.0.0.1/24"
          }
        ],
        "type": "static"
      },
      "mtu": 9000,
      "name": "srv",
      "type": "fpp-cni",
      "vni": 1,
      "vppIfaceType": "memif",
      "numRxQueues": 2,
      "numTxQueues": 2,
      "memifRingSize": 8192,
      "memifBufferSize": 4096,
      "txPlacement": [2, 3],
      "clientTxPlacement": [0, 1]
    }
```

The following additional tunable settings are available for memifs in the CNI config:

* `numRxQueues` (goes into `spec.memif.numRxQueues` on the slave memif
  interfaces): number of rx queues, defaults to 1
* `numTxQueues` (goes into `spec.memif.numTxQueues` on the slave memif
  interfaces): number of tx queues, defaults to 1
* `memifRingSize` (goes into `spec.memif.ringSize`) - the number of entries of RX/TX rings, defaults to 4096
* `memifBufferSize` (goes into `spec.memif.bufferSize`) - size of the buffer allocated for each ring entry, defaults to 2048
* `txPlacement` controls the core-to-tx-queue assignment on the VPPSwitch side, each entry corresponding to a tx queue on that side, so the number of items in the list must be equal to `numRxQueues` which describes the number of RX queues on the client side and thus also the number of TX queues on the VPPSwitch side
* `clientTxPlacement` controls core-to-tx-queue assignment on the client side. The number of entries must be equal to the `numTxQueues`, each entry corresponding to a tx queue on the client side.

## VPPInterface: tap

VPPInterface of type tap is used to connect pods that use Linux
networking to the VPPSwitch. Note that in the example below, the IP
address information is not included as it's handled by the CNI plugin
itself in this case.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-container-id: 92b86f0e629c10966389ee1acfd9fff6e445147c
    fpp-manager.cennso.com/plumbing-ifname: net1
    fpp-manager.cennso.com/plumbing-instance-uid: 4b879b86-3789-421e-a636-caafec73a6ba
    fpp-manager.cennso.com/plumbing-node: fpp-cluster-control-plane
    fpp-manager.cennso.com/plumbing-pod-name: linux-app-0
    fpp-manager.cennso.com/plumbing-type: tap
    fpp-manager.cennso.com/plumbing-vni: "1"
  name: linux-app-0-tap-1-b4v8g
  namespace: fpp-sample
spec:
  bridgeDomain: 1
  hardwareAddress: 02:fe:12:d9:3f:ff
  ifName: tap0-net1
  mtu: 9000
  tap:
    hostIfName: net1
    hostNS: /var/run/netns/cni-3ab3b5f8-de69-93d1-8dba-b1333ee01e32
    numRxQueues: 2
    rxRingSize: 8192
    txRingSize: 8192
status:
  memberCount: 0
  ready: true
  swIfIndex: 1
  vppName: tap0-net1
```

Below is the sample NetworkAttachmentDefinition with the CNI config from which
FPP-CNI has derived the above VPPInterface.

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: linux-net
  namespace: fpp-sample
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses": [
          {
            "address": "10.0.0.2/24"
          }
        ],
        "type": "static"
      },
      "mtu": 9000,
      "name": "tst",
      "type": "fpp-cni",
      "vni": 1,
      "vppIfaceType": "tap",
      "numRxQueues": 2,
      "tapTxRingSize": 8192,
      "tapRxRingSize": 8192
    }
```

It is also possible to specify multiple IP addresses for an interface:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: linux-net
  namespace: fpp-sample
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses": [
          {
            "address": "10.0.0.2/24"
          },
          {
            "address": "fd8a:a9f:3294:1::20/64"
          }
        ],
        "type": "static"
      },
      "mtu": 9000,
      "name": "tst",
      "type": "fpp-cni",
      "vni": 1,
      "vppIfaceType": "tap",
      "numRxQueues": 2,
      "tapTxRingSize": 8192,
      "tapRxRingSize": 8192
    }
```

The following additional tunable settings are available for taps in the CNI config:

* `numRxQueues` (goes into `spec.tap.numRxQueues`): number of rx queues, defaults to 1
* `tapRxRingSize` (goes into `spec.tap.txRingSize`) - the number of entries of TX ring, defaults to 4096
* `tapTxRingSize` (goes into `spec.tap.txRingSize`) - the number of entries of RX ring, defaults to 4096

## SPAN configuration

SPAN mapping can be configured on any VPPInterface by adding
`spanSource` field to its spec.  SPAN mappings work by applying SPAN
settings that tell VPPSwitch to copy all of the traffic targeted
towards the interface mentioned in `spanSource` towards the interface
for which that `spanSource` is set in its spec.

`spanSource` can be defined in one of two ways:

1. By specifying the name of a particular VPPInterface
1. By specifying a set of labels that match a single VPPInterface

Both ways can be used manually on the VPPInterface definition or automatically through
the FPP-CNI config in NetworkAttachmentDefinition.

Sample definition of a tap interface with a SPAN source from another
interface specified using name:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-container-id: 92b86f0e629c10966389ee1acfd9fff6e445147c
    fpp-manager.cennso.com/plumbing-ifname: net1
    fpp-manager.cennso.com/plumbing-instance-uid: 4b879b86-3789-421e-a636-caafec73a6ba
    fpp-manager.cennso.com/plumbing-node: fpp-cluster-control-plane
    fpp-manager.cennso.com/plumbing-pod-name: linux-app-0
    fpp-manager.cennso.com/plumbing-type: tap
    fpp-manager.cennso.com/plumbing-vni: "1"
  name: linux-app-0-tap-1-b4v8g
  namespace: fpp-sample
spec:
  bridgeDomain: 1
  hardwareAddress: 02:fe:12:d9:3f:ff
  ifName: tst
  mtu: 9000
  tap:
    hostIfName: net1
    hostNS: /var/run/netns/cni-3ab3b5f8-de69-93d1-8dba-b1333ee01e32
  spanSource:
    name: linux-app-1-tap-0-a298f
```

Sample definition of a tap interface with the SPAN source specified using labels:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-container-id: 92b86f0e629c10966389ee1acfd9fff6e445147c
    fpp-manager.cennso.com/plumbing-ifname: net1
    fpp-manager.cennso.com/plumbing-instance-uid: 4b879b86-3789-421e-a636-caafec73a6ba
    fpp-manager.cennso.com/plumbing-node: fpp-cluster-control-plane
    fpp-manager.cennso.com/plumbing-pod-name: linux-app-0
    fpp-manager.cennso.com/plumbing-type: tap
    fpp-manager.cennso.com/plumbing-vni: "1"
  name: linux-app-0-tap-1-b4v8g
  namespace: fpp-sample
spec:
  bridgeDomain: 1
  hardwareAddress: 02:fe:12:d9:3f:ff
  ifName: tst
  mtu: 9000
  tap:
    hostIfName: net1
    hostNS: /var/run/netns/cni-3ab3b5f8-de69-93d1-8dba-b1333ee01e32
  spanSource:
    matchingLabels:
      fpp-manager.cennso.com/plumbing-pod-name: linux-app-1
      fpp-manager.cennso.com/plumbing-vni: "1"

```

Example FPP-CNI NAD with SPAN configuration:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: linux-net
  namespace: fpp-sample
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses": [
          {
            "address": "10.0.0.2/24"
          }
        ],
        "type": "static"
      },
      "mtu": 9000,
      "name": "tst",
      "type": "fpp-cni",
      "vni": 1,
      "vppIfaceType": "tap",
      "spanSource": {
        "matchingLabels": {
          "fpp-manager.cennso.com/plumbing-pod-name": "linux-app-1",
          "fpp-manager.cennso.com/plumbing-vni": "1"
        }
      }
    }
```

## FPPNetwork Objects

FPPNetwork is **cluster-scope** (non-namespaced) object denote
separate L2 networks that are handled by this VPP
installation. Presently only a single FPPNetwork type is supported:
`vxlan`. FPP automatically creates a full VXLAN mesh across the nodes
based on FPPNetwork and VXLAN objects.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: FPPNetwork
metadata:
  name: fpp-test-network
spec:
  id: 42
  type: vxlan
```

FPPNetwork objects can be referred to via `networkName` field in a
VPPInterface spec or a `NetworkAttachmentDefinition` instead of
specifying `bridgeDomain` and `vni` values, respectively. In that
case, the value is taken from the `id` field of the `FPPNetwork`
specified in `networkName`.

## VXLAN Objects

VXLAN objects are handled by the VPPSwitch to automatically create the
full mesh between the nodes for each VNI for which VXLAN object exists.
VXLAN objects are to be eventually replaced with FPPNetwork.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VXLAN
metadata:
  name: vxlan30
  namespace: default
spec:
  vni: 30
```

## RoutingTable objects

`RoutingTable` makes it possible to specify routes to be installed in
VPP. `RoutingTable` objects are targeted to a node or a VPP-based app
instance in the same way as VPPConfigs. Each table has an `id` and
`af` (Address Family). `af` can be either `IPv4` or `IPv6`. Multiple
routing tables with the same `id` are allowed; in this case, they're
merged together.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg
    name: upg-access-routes
  name: upg-access-routes
  namespace: fpp-sample
spec:
  af: IPv4
  id: 100
  routes:
  # normal route with next hop and the target interface
  - cidr: 10.20.0.0/14
    nextHopAddress: 10.0.1.2
    nextHopInterface: access
  # blackhole route
  - cidr: 192.168.90.0/24
    nextHopAddress: blackhole
  # look up the next hop in another table
  - cidr: 192.168.90.0/24
    table: 123
```

The idea of reconciliation is mostly the same as with the VPPInterfaces:

1. Load RoutingTable objects and extract Route records from them
2. Load the current VPP FIB table state and convert it to the set of Route records
3. Diff two sets
4. Add missing Tables to VPP (the tables are never removed afterward b/c it may
  be a bit too hard to tell if it's empty)
5. Delete routes that are in VPP but not in RoutingTables
6. Add routes that aren't in VPP but are in RoutingTables.

There are multipath routes, for which only some of the paths change, the whole
route is re-created. This limitation can be fixed later, as VPP can add/remove
individual paths, too.

## IPFIXExporter objects

`IPFIXExporter` objects are used to configure IPFIX Exporters in VPP.

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: IPFIXExporter
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg
  name: sample-exporter
  namespace: fpp-sample
spec:
  # Address of the IPFIX collector
  collectorAddress: 10.0.0.2
  # Port of the IPFIX collector
  collectorPort: 4739
  # Address of the IPFIX exporter (this VPP instance)
  srcAddress: 10.0.0.10
  # Routing table ID (defaults to 0)
  tableID: 14242
  # Path MTU between exporter and collector (68..1450)
  pathMTU: 1420
  # Number of seconds after which to resend template
  templateInterval: 60
  # Enable UDP checksum calculation
  udpChecksum: false
```

If a non-zero `tableID` is specified for an IPFIXExporter, the table
with that ID must be present. For now, this is only guaranteed to
work for IPv4.

## FPP-CNI Setup diagrams

CNI Setup diagram for tap interfaces:
![Sequence diagram](https://docs.cennso.com/api/assets/components/fpp/1.3/tap.png)

CNI Setup diagram for memif interfaces:
![Sequence diagram](https://docs.cennso.com/api/assets/components/fpp/1.3/memif.png)
