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

# VPPConfig CR

`VPPConfig` Custom Resource (CR) is applied on the Core Cluster and is used to configure VPP instances. It can configure VPP switch daemon pods (node-mode FPP pods) or instance mode FPP pods. `VPPConfig` lists VPP CLI commands that must be run by VPP Operator, which can use many interfaces that are configured using `VPPInterface` CRs.

When multiple VPPConfig objects match the same VPP instance, they're merged based on their `priority` values. The resulting config is called "effective config". When an effective config is changed, the VPP instance needs to be restarted.

VPP CLI commands are defined in the `VPPConfig` Custom Resource under **spec.afterCommands**. Because these commands are provided as a list of strings, they cannot be modified at runtime. When the VPP CLI configuration changes, the VPP Operator marks the corresponding FPP pod as requiring a restart. You must restart (recreate) the FPP pod to apply the updated VPP CLI configuration.

```yaml
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  name: vpp-webserver
  namespace: fpp-sample
  labels:
    fpp-manager.cennso.com/created-for: node-op
    # target particular instance-mode FPP pod
    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

  # 'routingTables' is equivalent to `vppctl ip table add`, which guarantees that
  # empty routing tables are created before the `afterCommands` section is run
  routingTables:
  - 10
  - 20

  # 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 is deprecated, use objectSelectors.routingTableSelectors in VPPDeployment
  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 interface 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 can be a prefix matching a physical DPDK interface (see `spec.assumedInterfaces`) or a VPPInterface object generated from uplink configurartion (e.g., `uplink-bond`).
  - 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
    # Create VLAN subinterface
    vlanId: 1001

    # 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

  # config files for the VPPTools in the FPP pod
  toolConfigs:
  - name: bird # the name of the VPPTool
    configFiles:
    - name: bird.conf # corresponds to the config file name in the VPP tool spec
      content: |
        router id 10.10.0.1;
        debug protocols all;
        protocol direct {
          interface "lo";
        }
        # ...

  # VPP configuration included in VPPConfig AfterCommands, that should not be overriden by
  # VPP Operator. For example, IPs are strictly managed by VPPInterface object.
  # manualConfig.ips can define IPs, which will not be removed by VPP Operator during reconcile loop.
  manualConfig:
    ips:
    - 10.10.0.2/24
```

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:
    fpp-manager.cennso.com/created-for: node-op
    # 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
    # Create VLAN subinterface
    vlanId: 1000

    # 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/created-for: node-op
    fpp-manager.cennso.com/plumbing-node: ""
  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 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/created-for: node-op
    fpp-manager.cennso.com/plumbing-node: wk-4001.dev-04.ccl-01.eu.cennso.net
  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`: indicates `uplink` or `extnet`
 * `fpp-manager.cennso.com/plumbing-physifrole`: specifies `standalone` (for a non-bonded interface), `member-N` (for a bond member), `bond` (for a bond), or `vlan` (for a subinterface).
