> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/upg/2.17/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/upg/2.17/configuration/routing-table.md).

# Routing tables and VRF configuration

Routing tables specify the paths that data packets take to reach their destinations. Each entry in a routing table defines a network destination, the next hop to reach it, and the interface used for transmission. Routing tables can be tied to VRFs (Virtual Routing and Forwarding instances), which separate traffic into logical routing domains for different network contexts, such as separating Access, Data, and Control Networks.

User Plane Gateway (UPG) uses the **RoutingTable** Custom Resource (CR) to create and manage routing tables. The UPG Helm chart automatically generates RoutingTable objects based on the per-interface route definitions in `values.yaml`. It supports routing for the following networks:

- Access Network (GRX)
- Data Network (SGI)
- NAT pools (default gateway)

To define additional routes not covered by the Helm chart, do so separately during deployment, outside of the UPG chart.

See the example of the `values.yaml` input to configure networking:

```yaml
instances:
  inst01:
    networking:
      grx:
        (...)
        interface: grx
        ipv4:
          addresses:
           - 198.18.0.20/24
          routes:
            - to: 0.0.0.0/0
              via: 198.18.0.1
      sgi:
        (...)
        interface: sgi
        ipv4:
          addresses:
            - 172.22.11.5/24
          routes:
            - to: 1.2.3.4/24
              via: 172.22.11.1
    (...)
    nat:
      pools:
        pool-one:
          networking:
            (...)
            interface: one1
            ipv4:
              gw: 198.19.2.1
              addresses:
                - 198.19.2.21/24
```

This configuration creates the following RoutingTable CRs:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
  name: upg-fpp-inst01-grx
  namespace: upg-fpp
spec:
  addressFamily: IPv4
  id: 100
  routes:
  - cidr: 0.0.0.0/0
    nextHopAddress: 198.18.0.1
    nextHopInterface: grx
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
  name: upg-fpp-inst01-sgi
  namespace: upg-fpp
spec:
  addressFamily: IPv4
  id: 200
  routes:
  - cidr: 1.2.3.4/24
    nextHopAddress: 172.22.11.1
    nextHopInterface: sgi
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
  name: upg-fpp-inst01-one1
  namespace: upg-fpp
spec:
  addressFamily: IPv4
  id: 300
  routes:
  - cidr: 0.0.0.0/0
    nextHopAddress: 198.19.2.1
    nextHopInterface: one1
```

To verify the applied routes on a UPG instance, use this VPP CLI command:

```bash
vppctl sh ip fib
```

See the output example:

```bash
(...)
ipv4-VRF:100, fib_index:1, flow hash:[src dst sport dport proto flowlabel ] epoch:0 flags:none locks:[interface:2, API:1, adjacency:1, ]
0.0.0.0/0
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:9 buckets:1 uRPF:32 to:[0:0]]
    [0] [@3]: arp-ipv4: via 198.18.0.1 grx
(...)
198.18.0.0/24
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:16 buckets:1 uRPF:29 to:[0:0]]
    [0] [@4]: ipv4-glean: [src:198.18.0.0/24] grx: mtu:9000 next:1 flags:[] ffffffffffff0267037082450806
198.18.0.20/32
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:19 buckets:1 uRPF:22 to:[11:1320]]
    [0] [@12]: dpo-receive: 198.18.0.20 on grx
198.18.0.30/32
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:49 buckets:1 uRPF:72 to:[0:0]]
    [0] [@5]: ipv4 via 198.18.0.30 grx: mtu:9000 next:5 flags:[] 02fef38b03d60267037082450800
198.18.0.31/32
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:37 buckets:1 uRPF:52 to:[0:0] via:[11:1320]]
    [0] [@5]: ipv4 via 198.18.0.31 grx: mtu:9000 next:5 flags:[] 02fef38b03d60267037082450800
198.18.0.255/32
  unicast-ip4-chain
  [@0]: dpo-load-balance: [proto:ip4 index:18 buckets:1 uRPF:20 to:[0:0]]
    [0] [@0]: dpo-drop ip4
(...)
```

## Assign routing tables to instances

RoutingTable CRs are assigned to UPG instances using labels. These labels are either:

- Automatically assigned by the UPG chart using the `fpp-manager.cennso.com/plumbing-instance` per-instance label based on the chart name, release name, and UPG instance name
- Manually defined in the VPPConfig CR under the **spec.routingTableSelectors** section

Here’s an example of labels generated by the UPG chart:

```yaml
  routingTableSelectors:
  - app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
```

You can configure **routingTableSelectors** in `values.yaml` to apply the same routing table to multiple UPG instances. You can also define multiple label sets for a UPG instance to apply multiple routing tables based on different labels, for example:

```yaml
routingTableSelectors:
- crossInstance: default-routing-test-apn
```

This configuration is propagated to the VPPConfig CR that matches the UPG instance:

```yaml
piVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-fpp-inst01
  name: upg-fpp-inst01
  namespace: upg-fpp
spec:
  (...)
  routingTableSelectors:
  - app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
  - crossInstance: default-routing-test-apn
```

In this case, the UPG chart generates the basic routing tables that match these labels:

- `app.kubernetes.io/instance: upg-01-upg-fpp`
- `app.kubernetes.io/name: upg`
- `cennso.net/cnf: upg`
- `instance: inst01`

You can create additional RoutingTable objects with custom labels (like **crossInstance**) outside the UPG chart:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    crossInstance: default-routing-test-apn
  name: default-inet
  namespace: upg-fpp
spec:
  addressFamily: IPv4
  id: 201
  routes:
  - cidr: 0.0.0.0/0
    nextHopAddress: 172.20.1.1
    nextHopInterface: sgi
```

In this case, all UPG instances with a matching VPPConfig label (`crossInstance: default-routing-test-apn`) will apply the specified routing table.
