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

# FPP BGP support

Border Gateway Protocol (BGP) is supported using the VPPTool Custom Resource which defines the tool (in the case of BGP, Bird application) to be deployed inside the FPP pod as a side container.

The FPP pod which supports BGP has an init container and multiple main containers. One is `fpp` main container, and the others are VPPTool containers like `tool-bird` or `tool-bird-exporter`.

FPP uses [the VPP Linux Control Plane (LCP) plugin](https://s3-docs.fd.io/vpp/24.02/developer/plugins/lcp.html). This plugin allows VPP to integrate with the Linux kernel. The general model is that Linux is the network stack, which means that it has the control plane protocols, like ARP, IPv6 ND/MLD, ping, and so on, and VPP provides a SW-based ASIC for forwarding.

## BGP as VPPTool

To use BGP support in FPP, create `VPPTool` outside of the FPP Helm chart:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPTool
metadata:
  name: bird
spec:
  image: registry.cennso.com/cennso/fpp-manager:v2.6.0
  command: ["/usr/local/bin/bird-tool.sh"]
  configFiles:
  - name: bird.conf
    canReload: true
  resources:
    requests:
      cpu: "100m"
      memory: "128Mi"
    limits:
      cpu: "100m"
      memory: "128Mi"
  volumeMounts:
  - name: bird
    mountPath: /run/bird
  volumes:
  - name: bird
    emptyDir: {}
```

## BGP metrics exporter

Bird Exporter is supported with another VPPTool:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPTool
metadata:
  name: bird-exporter
spec:
  image: openvnf/bird_exporter:1.2.5
  command:
  - /bin/sh
  - -c
  - echo $$ >/${FPP_TOOL_PID_FILE} && [ -e "/run/bird/bird.ctl" ] && ip4=true || ip4=false; [ -e "/run/bird/bird6.ctl" ] && ip6=true || ip6=false; exec /app/bird_exporter -format.new=true -bird.socket /run/bird/bird.ctl -bird.socket6 /run/bird/bird6.ctl -bird.ipv4=$ip4 -bird.ipv6=$ip6
  resources:
    requests:
      cpu: "100m"
      memory: "128Mi"
    limits:
      cpu: "100m"
      memory: "128Mi"
  volumeMounts:
  - name: bird
    mountPath: /run/bird
```

>**CAUTION:** Modifying the VPPTool objects restarts all Amberd pods that use it, which causes network downtime.

## Sample BGP IPv4 configuration

Reference the created bird tools in FPP chart values YAML:

```yaml
...
vppTools:
- name: bird
- name: bird-exporter

bird:
  metrics:
    enabled: true
...
```

The reference is based on VPPTool object name (`VPPTool.metadata.name`). Bird metrics needs to be enabled in the `values.yaml` file.

The following diagram shows an example of CGW with BGP deployment:

![CGW BGP Diagram](https://docs.cennso.com/api/assets/components/fpp/2.9/assets/cgw-bgp-setup.svg)

See the full YAML configuration for the CGW with BGP example:

```yaml
mode: instance

cnfName: cgw

image:
  repository: registry.cennso.com/cennso-dev/fpp-manager
  tag: debug

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

heapSize: 500M

enableHugepagesAllocation: false

vppTools:
- name: bird
- name: bird-exporter

bird:
  metrics:
    enabled: true

vpp:
  multicore: false
  dpdk:
    enabled: false
  traceAPICalls: true

dumpControllerEvents: true

vppConfigs:
- spec:
    toolConfigs:
    - name: bird
      configFiles:
      - name: bird.conf
        content: |
          router id 10.10.0.1;
          debug protocols all;
          protocol direct {
            interface "lo";
          }
          filter exclude_subnet {
            if net ~ [ 10.20.0.0/24 ] then reject;
            else accept;
          }
          protocol kernel {
            persist;
            scan time 20;
            import all;
            export filter exclude_subnet;
            kernel table 10;
          }
          protocol static {
            import all;
            export all;
            route 10.30.0.0/24 via 10.10.0.2;
            route 10.20.0.0/24 via 10.10.0.1;
          }
          protocol device {
            scan time 10;
          }
          protocol bgp neighbor_v4_1 {
            export all;
            import all;
            direct;
            gateway direct;
            local as 65001;
            neighbor 10.10.0.2 as 65001;
          }

vppInterfaces:
- ifName: mygre
  ips:
  - 10.10.0.1/24
  tableName: internal-rt
  greTunnel:
    sourceIf: external-nic
    destIP: 10.0.0.2
    encapTableName: external-rt
- ifName: lcp0
  lcp:
    attachTo: mygre
    hostIfName: lcp0

routingTables:
  external-rt:
    id: 50
    addressFamily: IPv4
  internal-rt:
    id: 10
    addressFamily: IPv4

networks:
  external-nic:
    type: memif
    networkName: gre-outer-network
    tableName: external-rt
    ipv4:
      addresses:
      - 10.0.0.1/24
  internalnic:
    type: memif
    networkName: net-10
    tableName: internal-rt
    ipv4:
      addresses:
      - 10.20.0.1/24
```

## BGP configuration

The BGP configuration is kept in `VPPConfig`, for example:

```yaml
vppConfigs:
- spec:
    toolConfigs:
    - name: bird
      configFiles:
      - name: bird.conf
        content: |
          router id 10.10.0.1;
          debug protocols all;
          protocol direct {
            interface "lo";
          }
          filter exclude_subnet {
            if net ~ [ 10.20.0.0/24 ] then reject;
            else accept;
          }
          protocol kernel {
            persist;
            scan time 20;
            import all;
            export filter exclude_subnet;
            kernel table 10;
          }
          protocol static {
            import all;
            export all;
            route 10.30.0.0/24 via 10.10.0.2;
            route 10.20.0.0/24 via 10.10.0.1;
          }
          protocol device {
            scan time 10;
          }
          protocol bgp neighbor_v4_1 {
            export all;
            import all;
            direct;
            gateway direct;
            local as 65001;
            neighbor 10.10.0.2 as 65001;
          }
```

`spec.toolsConfigs[].name` must match `VPPTool.metadata.name`.

## BGP monitoring

The `fpp-support` chart allows the creation of a Grafana dashboard and Prometheus ServiceMonitor to enable BGP monitoring, example values.yaml:

```yaml
dashboard:
  enabled: true

prometheus:
  servicemonitor:
    enabled: true
```

BGP-related metrics are exposed in the `Routing` row.

## BGP over GRE

In complex scenarios, BGP peering can occur over a GRE tunnel, so a GRE interface must be created. Also, the LCP interface is required to be created for the BGP daemon to populate the routes into VPP:

```yaml
vppInterfaces:
- ifName: mygre
  ips:
  - 10.10.0.1/24
  tableName: internal-rt
  greTunnel:
    sourceIf: external-nic
    destIP: 10.0.0.2
    encapTableName: gre-outer-table
- ifName: lcp0
  lcp:
    attachTo: mygre
    hostIfName: lcp0
```

In the above example, `10.10.0.1/24` is the IP address of the GRE tunnel endpoint using the `external-nic` interface to communicate to the other end of the GRE tunnel located at `10.0.0.2`. `external-nic` is created by a Helm chart in the `networks` section.

It is important to use the same name in `vppInterfaces[].ifname` and in `vppInterfaces[].lcp.attachTo`. This is the VPPInterface CR object name and will be adjusted by the Helm chart to be unique by using the chart release name as a prefix.

## Networking configuration

Use this configuration to create connected routing tables:

```yaml
routingTables:
  external-rt:
    id: 50
    addressFamily: IPv4
  internal-rt:
    id: 10
    addressFamily: IPv4
```

These are the networks used for the CGW1 example:

```yaml
networks:
  external-nic:
    type: memif
    networkName: gre-outer-network
    tableName: external-rt
    ipv4:
      addresses:
      - 10.0.0.1/24
  internal-nic:
    type: memif
    networkName: net-10
    tableName: internal-rt
    ipv4:
      addresses:
      - 10.20.0.1/24
```

See the configuration for FPPNetworks that are created outside of the FPP Helm chart:

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

## BGP IPv6 support

FPP 2.3.1 introduces the BGP IPv6 support. To enable this, you must create a new VPPTool with bird6:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPTool
metadata:
  name: bird6
spec:
  image: registry.cennso.com/cennso/fpp-manager:v2.3.1
  env:
  - name: FPP_BIRD_BINARY
    value: bird6
  command: ["/usr/local/bin/bird-tool.sh"]
  configFiles:
  - name: bird6.conf
    canReload: true
  resources:
    requests:
      cpu: "100m"
      memory: "128Mi"
    limits:
      cpu: "100m"
      memory: "128Mi"
  volumeMounts:
  - name: bird
    mountPath: /run/bird
  volumes:
  - name: bird
    emptyDir: {}
```

## BGP dual stack

FPP supports dual IPv4 and IPv6 BGP configuration using two VPPTools: one for bird (IPv4) and a second for bird6 (IPv6). The BGP metrics exporter supports dual stack configuration.

>**CAUTION:** Make sure that **bird-exporter** VPPTool is updated as provided in [BGP metrics exporter section](#bgp-metrics-exporter).

The following diagram shows an example of CGW with BGP dual stack deployment:

![CGW BGP Dual Diagram](https://docs.cennso.com/api/assets/components/fpp/2.9/assets/cgw-bgp-dual.svg)

The full BGP dual configuration is [included as an FPP Helm chart values YAML](https://docs.cennso.com/api/assets/components/fpp/2.9/assets/cgw-bgp-dual-example.yaml).

The difference between a single stack bird setup and a dual stack configuration is:

- Include `bird6` as VPPTool:

```yaml
...
vppTools:
- name: bird
- name: bird6
- name: bird-exporter
```

- Add BGP configuration:

```yaml
vppConfigs:
- spec:
    toolConfigs:
    - name: bird6
      configFiles:
      - name: bird6.conf
        content: |
          router id 10.10.0.1;
          debug protocols all;
          protocol device {
            scan time 10;
          }
          filter exclude_subnet {
            if net ~ [ 2001:db8:20::0/64 ] then reject;
            else accept;
          }
          protocol direct {
            check link yes;
            interface "lo";
          }
          protocol kernel {
            persist;
            scan time 20;
            import all;
            export filter exclude_subnet;
            kernel table 10;
          }
          protocol static {
            import all;
            export all;
            route 2001:db8:30::0/64 via 2001:db8:10::2;
            route 2001:db8:20::0/64 via 2001:db8:10::1;
          }
          protocol bgp neighbor_v6_1 {
            export all;
            import all;
            direct;
            gateway direct;
            local as 65001;
            neighbor 2001:db8:10::2 as 65001;
          }
```

- Add LCP1 interface connected to external-nic:

```yaml
vppInterfaces:
...
- ifName: lcp1
  lcp:
    attachTo: external-nic
    hostIfName: lcp1
```

- Configure the IPv6 addresses on internal and external NICs:

```yaml
networks:
  external-nic:
    type: memif
    networkName: gre-outer-network
    tableName: external-rt
    ipv4:
      addresses:
      - 10.0.0.1/24
    ipv6:
      addresses:
      - 2001:db8:10::1/24
  internalnic:
    type: memif
    networkName: net-10
    tableName: internal-rt
    ipv4:
      addresses:
      - 10.20.0.1/24
    ipv6:
      addresses:
      - 2001:db8:20::1/24
```

## Bird2 support

FPP supports **bird2** using the **registry.cennso.com/cennso/nettools:v1.13.0** image. The new version of **bird2** supports a different BGP configuration than **bird** 1.6 used in the FPP image. **bird2** enables the dual-stack configuration using a single binary (single VPPTool). A new VPPTool **bird2-exporter** is required to gather BGP metrics.

### Define bird2 VPPTool

Define the following VPPTool:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPTool
metadata:
  name: bird2
spec:
  image: registry.cennso.com/cennso/nettools:v1.13.0
  command:
  - /bin/bash
  - -c
  - while [ ! -f "${FPP_TOOL_CONFIG_FILE_0}" ]; do sleep 1; done && exec nsenter --net="${FPP_LCP_NETNS}" bird -P "${FPP_TOOL_PID_FILE}" -c "${FPP_TOOL_CONFIG_FILE_0}" -s /run/bird/bird.ctl -f -d
  configFiles:
  - name: bird.conf
    canReload: true
  resources:
    requests:
      cpu: "100m"
      memory: "128Mi"
    limits:
      cpu: "100m"
      memory: "128Mi"
  volumeMounts:
  - name: bird
    mountPath: /run/bird
  volumes:
  - name: bird
    emptyDir: {}
```

### Define bird2-exporter

Bird exporter with bird2 support:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPTool
metadata:
  name: bird2-exporter
spec:
  image: openvnf/bird_exporter:1.2.5
  command:
  - /bin/sh
  - -c
  - "echo $$ >/${FPP_TOOL_PID_FILE} && exec /app/bird_exporter -format.new=true -bird.socket /run/bird/bird.ctl -bird.v2"
  resources:
    requests:
      cpu: "100m"
      memory: "128Mi"
    limits:
      cpu: "100m"
      memory: "128Mi"
  volumeMounts:
  - name: bird
    mountPath: /run/bird
```

### Configure bird2

This diagram shows a sample CGW deployment used in the dual-stack configuration where bird2 supports the use of both IPv4 and IPv6 in a single binary (single VPPTool):

![CGW BGP Bird2 diagram](https://docs.cennso.com/api/assets/components/fpp/2.9/assets/cgw-bgp-bird2.svg)

Sample BGP configuration for bird2 dual-stack IPv4 and IPv6:

```conf
router id 10.10.0.1;
debug protocols all;
log syslog { debug, trace, info, remote, warning, error, auth, fatal, bug };
log stderr all;
protocol device {
  scan time 10;
}
protocol direct {
  interface "lo";
  ipv4;
  ipv6;
}

filter exclude_subnet4 {
  if net ~ [ 10.20.0.0/24 ] then reject;
  else accept;
}
filter exclude_local_subnet4 {
  if net ~ [ 10.10.0.0/24 ] then reject;
  else accept;
}
filter exclude_subnet6 {
  if net ~ [ 2001:db8:20::0/64 ] then reject;
  else accept;
}
filter exclude_local_subnet6 {
  if net ~ [ 2001:db8:10::0/64 ] then reject;
  else accept;
}

protocol kernel kernel4 {
  ipv4 {
    # import all;
    import none;
    export filter exclude_subnet4;
  };
  persist;
  scan time 20;
  kernel table 10;
}
protocol kernel kernel6 {
  ipv6 {
    import all;
    export filter exclude_subnet6;
  };
  persist;
  scan time 20;
  kernel table 10;
}

protocol static static4 {
  ipv4 {
    import all;
    export filter exclude_local_subnet4;
  };
  route 10.10.0.2/32 via "lcp1";
  route 10.20.0.0/24 via 10.10.0.1;
}

protocol static static6 {
  ipv6 {
    import all;
    export filter exclude_local_subnet6;
  };
  route 2001:db8:10::2/128 via "lcp1";
  route 2001:db8:20::0/64 via 2001:db8:10::1;
}

protocol bgp neighbor_1 {
  local 10.10.0.1 as 65001;
  neighbor 10.10.0.2 as 65001;
  direct;
  ipv4 {
    export all;
    import all;
  };
  ipv6 {
    export all;
    import all;
    next hop address 2001:db8:10::2;
  };
  debug all;
}
```

The full BGP bird2 configuration is included as an [FPP Helm chart values YAML](https://docs.cennso.com/api/assets/components/fpp/2.9/assets/cgw-bgp-bird2-example.yaml).

The setup uses a single GRE tunnel for both IPv4 and IPv6. A single VPPTool is used, which uses a single `bird.conf` file.

## Setup verification

### Check the number of containers

The BGP-enabled VPP pod needs to have at least three containers: one main FPP container (`fpp`), a container with a running BIRD process (`tool-bird`), and a `tool-bird-exporter` container that exposes metrics in Prometheus format. Also, the init container must be present. If IPv6 is also used, `tool-bird6` must be present as well.

### Check `tool-bird` container logs

Bird logs are visible in the `tool-bird` container logs of the FPP pod.

### Check the applied BGP configuration

To check if BGP configuration and peering is active, run this command in the Amberd pod of the `fpp` container:

```bash
vppctl show ip fib table 10
```

Table number (`10`) must match the `internal-rt` table created above.

See the output example:

```
...
10.30.0.0/24
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:39 buckets:1 uRPF:51 to:[10:840]]
    [0] [@6]: ipv4 via 0.0.0.0 mygre: mtu:9000 next:3 flags:[] 4500000000000000fe2fa8cc0a0000010a00000200000800
        stacked-on entry:25:
          [@4]: ipv4 via 10.0.0.2 external-nic: mtu:9000 next:5 flags:[] 026703d9663a026703efbec20800
...
```

To check BGP peering on the `tool-bird` container, use the `birdc` diagnostic tool to get the state:

```bash
birdc show route
```

```bash
birdc show protocol
```

```bash
birdc show protocols all neighbor_v4_1
```

See the output example:

```bash
# birdc show route
BIRD 1.6.8 ready.
10.20.0.0/24       via 10.10.0.1 on lcp0 [static1 15:10:53] * (200)
10.30.0.0/24       via 10.10.0.2 on lcp0 [static1 15:10:53] * (200)

# birdc show protocol
BIRD 1.6.8 ready.
name     proto    table    state  since       info
device1  Device   master   up     15:10:49
direct1  Direct   master   up     15:10:53
static1  Static   master   up     15:10:53
neighbor_v4_1 BGP      master   up     15:16:18    Established
kernel1  Kernel   master   up     15:10:53

# birdc show protocols all neighbor_v4_1
neighbor_v4_1 BGP      master   up     15:16:18    Established
  Preference:     100
  Input filter:   ACCEPT
  Output filter:  ACCEPT
  Routes:         0 imported, 2 exported, 0 preferred
  Route change stats:     received   rejected   filtered    ignored   accepted
    Import updates:              0          0          0          0          0
    Import withdraws:            0          0        ---          0          0
    Export updates:              2          0          0        ---          2
    Export withdraws:            0        ---        ---        ---          0
  BGP state:          Established
    Neighbor address: 10.10.0.2
    Neighbor AS:      65001
    Neighbor ID:      10.10.0.2
    Neighbor caps:    refresh enhanced-refresh restart-aware llgr-aware AS4
    Session:          internal AS4
    Source address:   10.10.0.1
    Hold timer:       199/240
    Keepalive timer:  44/80

```
