> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/fpp/2.2/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/fpp/2.2/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 three main containers. One is `fpp` main container, and two others are `tool-bird` and `tool-bird-exporter`.

## 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.0.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: {}
```

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} && exec /app/bird_exporter -format.new=true -bird.socket /run/bird/bird.ctl -bird.ipv6=false"
  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.

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.2/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:
  exitFatal: false
  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
```

## Setup verification

### Check the number of containers

The BGP-enabled Amberd 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.

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

```
