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

# Configure routing tables and VRF

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) in the Core Cluster to create and manage routing tables. The UPGDeployment CR, applied to the Management Cluster, automatically generates RoutingTable objects based on the per-interface route definitions in the `spec.instances` section of the CR. 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 UPGDeployment CR, do so separately during deployment in the Core Cluster, outside of the UPGDeployment CR.

See the example of the `UPGDeployment` CR input to configure networking:

```yaml
spec:
  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
      (...)
```

This configuration creates the following RoutingTable CRs:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/created-for: upg-operator
    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: basic-pgw
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:
    fpp-manager.cennso.com/created-for: upg-operator
    app.kubernetes.io/instance: upg-01-upg-fpp
    app.kubernetes.io/name: upg
    cennso.net/cnf: upg
    instance: inst01
  name: upg-fpp-inst01-sgi-ipv4
  namespace: basic-pgw
spec:
  addressFamily: IPv4
  id: 200
  routes:
  - cidr: 1.2.3.4/24
    nextHopAddress: 172.22.11.1
    nextHopInterface: sgi
```

## Assign routing tables to instances

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

- Automatically assigned by the UPGDeployment CR using the `fpp-manager.cennso.com/plumbing-instance` per-instance label
- Manually defined in the UPGDeployment CR under the **spec.routingTableSelectors** section

Here’s an example of labels generated by the UPGDeployment CR:

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

You can configure **spec.routingTableSelectors** in the UPGDeployment CR 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
spec:
  routingTableSelectors:
  - matchLabels:
      crossInstance: default-routing-test-apn
```

This configuration is propagated to the VPPDeployment CR created for the UPG instance:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPDeployment
metadata:
  name: upg-fpp-inst01
  namespace: basic-pgw
spec:
  (...)
  objectSelectors:
    routingTableSelectors:
    - matchLabels:
        app.kubernetes.io/instance: upg-01-upg-fpp
        app.kubernetes.io/name: upg
        cennso.net/cnf: upg
        instance: inst01
    - matchLabels:
        crossInstance: default-routing-test-apn
```

In this case, the UPGDeployment CR 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**) in the Core Cluster outside the UPGDeployment CR:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/created-for: upg-operator
    crossInstance: default-routing-test-apn
  name: default-inet
  namespace: basic-pgw
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.

## Verification

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
(...)
```
