> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/upg/2.8/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.8/installation/deploy.md).

# UPG deployment guide

## UPG Deployment

`upg-manager` image uses `fpp-manager` as base image. This includes Golang
based controller for `VPPInterface`, `VPPConfig`, `IPFIXExporter` and
`RoutingTable` Custom Resources (CRs). UPG registers to watch for this resources
on Kubernetes API. Besides that, UPG does reconciliation for `UPGConfig` CR.

This mechanism uses Kubernetes Custom Resources to configure interfaces, routing
tables, PFCP Server parameters and NWIs (network instances) in VPP instance.
Any CLI commands referring to this resources will be revoked and align with k8s
API state.

UPG is installed as a regular Helm chart. For more information about configurable parameters, read the [User Plane Gateway chart configuration](https://docs.cennso.com/components/upg/2.8/installation/chart-configuration.generated.md) document.

Steps to deploy UPG:

1. Deploy `fpp-crd` chart

1. Deploy `upg-crd` chart

1. Deploy `upg-support` chart

1. Deploy `upg` chart

### Deploy `fpp-crd`
`fpp-crd` chart deployment is needed because UPG uses `VPPInterface` and other FPP Custom Resources for configuration. This chart does not require any additional configuration and should be deployed once per cluster.

### Deploy `upg-crd`
`upg-crd` helm chart provides UPG-specific Custom Resources, which must be
installed for proper `upg-manager` functioning. This chart does not require
any additional configuration and should be deployed once per cluster.

This mean that UPG CRDs are shared between all UPG deployments in the cluster.

### Deploy `upg-support`
`upg-support` chart provides Prometheus `ServiceMonitor` and `UPG Overview`
Grafana dashboard.

A current limitation is that the `UPG Overview` dashboard should be installed once
in the cluster - it gathers metrics from multiple `upg` instances. Installing
it twice may influence the Grafana Operator to flip the ownership and location
of the dashboard.

Example of chart configuration:

```yaml
dashboard:
  enabled: true
  prometheusDatasourceName: "Prometheus"

prometheus:
  servicemonitor:
    enabled: true
    namespaceSelector:
      any: false
```

To deploy `upg-support` without the `UPG Overview` dashboard, include `dashboard.enabled: false` in chart's `values.yaml`.

For more details, see [UPG Support chart documentation](https://docs.cennso.com/components/upg/2.8/installation/support-chart-configuration.generated.md).

### Deploy `upg`
`upg` chart deploys `upg-manager` with proper configuration. This chart can be
installed multiple times in the same cluster.

Example configuration values:

- [PGW example values.yaml](https://docs.cennso.com/api/assets/components/upg/2.8/example-config/pb-routing-values.yaml)
- [TDF example values.yaml](https://docs.cennso.com/api/assets/components/upg/2.8/example-config/tdf-values.yaml)

For more details, see [UPG chart documentation](https://docs.cennso.com/components/upg/2.8/installation/chart-configuration.generated.md).

## General UPG configuration

Based on the chart configuration, the below settings are included in the UPG deployment.

UPG manager acts like VPP manager - generates `startup.conf` and starts `vpp` as
a child process. To start `upg-manager`, define the following environment variables:

- `FPP_DISABLE_UPLINK` - set to any value, instructs the manager not
to use DPDK-based physical interfaces, for upg `memifs` are used

- `FPP_INSTANCE_NAME` - sets UPG name, used for watching resources labelled with
`fpp-manager.cennso.com/plumbing-instance`, both values must match

- `FPP_VPP_RUN_PATH` - defines VPP runtime directory, by default set to
`/run/vppswitch`, which is used in `fpp-manager`. Must be set not to use
the same directory as `fpp-manager`

- `FPP_INSTANCE_NAMESPACE` - sets namespace where `upg-manager` watches for CRs

- `FPP_INSTANCE_UID` - contains pod UID value, distinguishes between pod
generations and is used in label `fpp-manager.cennso.com/plumbing-instance-uid`

- `FPP_HEAP_SIZE` - declares heap size for UPG instance, by default set to 6G
by manager

- `FPP_STATS_SIZE` - declares stats segment size for metrics, default 512M

UPG handles configuration based on VPP CLI commands with
the UPF plugin extension. The UPF plugin consists of the following:

- definition of 3GPP TS 29.244 standard implementation
(CLI: `upf specification release 16`)

- Node name, used in control plane communication:
(CLI: `upf node-id fqdn <node-name>`)

- PFCP server configuration:
  - CLI: `upf pfcp endpoint ip <ip-sx-interface> vrf <control-plane-table-id>`
  - CLI: `upf pfcp server set fifo-size 512`

- Define tunnel endpoint id:
  - CLI: `upf gtpu endpoint ip <ip-sx-interface> nwi <cp-nwi-name> teid 0x80000000/2`
  - if running in PGW mode, CLI: `upf gtpu endpoint ip <ip-grx-interface> nwi epc teid 0x80000000/2`

There are also general VPP commands used to configure UPG:

- Setting up expiration time for ip neighbors per address family:
  - CLI: `set ip neighbor-config ip4 age 10`
  - CLI: `set ip neighbor-config ip6 age 10`

Execute the above CLI commands using the `afterCommands` field in `VPPConfig.spec` CR:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
(...)
spec:
  afterCommands:
  - set ip neighbor-config ip4 age 10
  - set ip neighbor-config ip6 age 10
  - upf specification release 16
  - upf node-id fqdn upg-fpp-inst01
  - upf pfcp server set fifo-size 512
  - upf pfcp endpoint ip 172.20.0.20 vrf 0
  - upf gtpu endpoint ip 172.20.0.20 nwi cp teid 0x80000000/2
  - upf gtpu endpoint ip 198.18.0.20 nwi epc teid 0x80000000/2
```

### Additional config

If specific, non-standard CLI commands must be executed per UPG instance, they can be defined in the `additionalConfig` field in `values.yaml`:

```yaml
instances:
  inst01:
  (...)
    additionalConfig:
      - ip table add 201
      - ip table add 202
      - upf policy add id defaultInet via ip4-lookup-in-table 201
      - upf policy add id defaultVpn via ip4-lookup-in-table 202
```

## Interface creation

UPG uses `VPPInterface` CR to handle interface creation. For VPP-based
workloads, most suitable interface type is `memif` - in memory interface,
that connects underlying VPP switch with UPG.

`VPPInterface` can be created manually, by higher level UPG operator or
by NetworkAttachmentDefinition (NAD) with `fpp-cni` as an interface type.
NADs are created by helm chart provided with UPG Manager for interfaces:

- `grx` - for access network interface
- `sx` - for control plane communication
- `sgi` - for data network connectivity

As an example of `grx` interface, Helm chart configuration:

```yaml
instances:
  inst01:
    networking:
      grx:
        type: memif
        vni: 90
        mtu: 9000
        interface: grx
        ipv4:
          addresses:
           - 198.18.0.20/24
          routes:
            - to: 0.0.0.0/0
              via: 198.18.0.1
```

Resulting NAD:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: upg-inst01-grx
  namespace: upg-fpp
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses":
        [
          {
            "address": "198.18.0.20/24"
          }
        ],
        "type": "static"
      },
      "mtu": 9000,
      "name": "grx",
      "table": 100,
      "type": "fpp-cni",
      "vni": 90,
      "vppIfaceType": "memif"
    }
```

Static IP address assignment is used here, and the resulting `VPPInterface`:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  finalizers:
  - fpp-manager.cennso.com/vpp-interface-finalizer
  labels:
    fpp-manager.cennso.com/plumbing-container-id: a65e91ee578185d4e822fcb8be3c8ccc31b775b5
    fpp-manager.cennso.com/plumbing-ifname: grx
    fpp-manager.cennso.com/plumbing-instance-uid: 64f8b1a1-2373-4dcd-8801-539cdec505d2
    fpp-manager.cennso.com/plumbing-memif-role: slave
    fpp-manager.cennso.com/plumbing-pod-name: upg-inst01-7fc97c76bb-s5vq5
    fpp-manager.cennso.com/plumbing-type: memif
    fpp-manager.cennso.com/plumbing-vni: "90"
  name: upg-inst01-7fc97c76bb-s5vq5-memif-client-90-j4fbw
  namespace: upg-fpp
spec:
  hardwareAddress: 02:67:03:0f:84:bf
  ifName: grx
  ips:
  - 198.18.0.20/24
  memif:
    id: 103
    role: slave
  mtu: 9000
  table: 100
status:
  memberCount: 0
  ready: true
  swIfIndex: 4
  vppName: grx
```

The interface name in VPP CLI and in UPG metrics is set to `grx`.

Network Attachment definitions for grx/sx/sgi are added to UPG deployment by chart.

```yaml
apiVersion: apps/v1
kind: Deployment
...
spec:
  template:
    metadata:
      annotations:
        k8s.v1.cni.cncf.io/networks: upg-fpp-upg-inst01-grx@grx,upg-fpp-upg-inst01-sxb@sxb,upg-fpp-upg-inst01-sgi@sgi
```

`VPPInterface` is targeted against UPG deployment by label:
`fpp-manager.cennso.com/plumbing-instance-uid`.

### CNI-less interface creation

You can create memifs directly with VPPInterface (without invoking FPP-CNI) by setting **useCNILessMemifs** to `true` and adding **networkName** with a valid FPPNetwork name in the UPG chart configuration. The rest of the configuration stays the same.

> **NOTE:** The CNI-less feature requires the deployment of FPP 2.2.0 (both Operator and VPPSwitch on Data Plane nodes) on the cluster.

The benefits of using the direct creation of VPPInterface:
- The UPG pod starts immediately without waiting for CNI to finish. This is useful when UPG has more than 40 connected interfaces.
- The user can change the interface parameters (like IP, MAC, MTU, FPP Network) in the runtime. The following table lists the consequences of such action.

Possible aftermath if the VPPInterface parameter is changed:

| Parameter | UPG reaction |
|---|---|
| IP | Change of an IP is updated in VPP instantly, but VPPConfig **afterCommands** can be regenerated, if an interface is used (for example Control/SX or Access/GRX IPs are used in VPPConfig). This means that UPG is restarted. |
| MAC | Change of MAC is done in the runtime, no reactions. |
| attachedNework | Changing FPPNetwork recreates the affected interface, which results in connectivity downtime. |
| MTU | Change of MTU is done in the runtime, no reactions. |
| interface name | When the VPP interface name changes, memif is deleted in the background. All interface names (`ifName`) are used in VPPConfig, so UPG is restarted. |

> **CAUTION:** See the [Known issues](https://docs.cennso.com/components/upg/2.8/releases/2.6.0.md#known-issues) before modifying the number of Rx/Tx queues and buffer/queue size.

To use CNI-less memif creation, set **useCNILessMemifs** to `true` (by default `false`). Also, add **networkName** with a valid FPPNetwork name to all interfaces, for example:

```yaml
instances:
  inst01:
    networking:
      grx:
        ipv4: (...)
        interface: an0
        type: memif
        networkName: access-net
      sx:
        type: memif
        networkName: sx-net
        ipv4: (...)
        interface: sx
    nat:
      pools:
        pool-1:
          networking:
            type: memif
            networkName: pool-1
            interface: pool-1
            mtu: 1500
            ipv4: (...)
...

useCNILessMemifs: true
```

### Additional interfaces

Any additional interfaces than grx/sgi/sx can be connected to UPG by creating
NAD and attaching its name in networks annotations. Chart configuration enables
to define extra NAD names in `additionalNetworks` value (per upg deployment)
or `instances.<instance-name>.networking.` (per UPG instance). NADs itself
should be provisioned outside of the chart.

```yaml
additionalNetworks:
  - upg-inst01-vpn@vpn
(...)
instances:
  inst01:
    networking:
      (...)
      additionalNetworks:
        - test-network-1-inst01
        - test-network-2-inst01
```

## VRF - Routing Table creation

UPG uses `RoutingTable` CR to handle routing table creation. VPP CLI commands
are not supported, as the routing state is synced against CR objects, and additional
routes are removed from the VPP.

For UPG deployment, chart configuration will create appropriate `RoutingTable`
objects, for per interface route definition in `values.yaml`. Chart supports
routes for access network (grx), data network (sgi) and NAT pools (default gw).
Any additional routes should be defined during deployment, outside of UPG chart.

`RoutingTable` is targeted against UPG deployment by per instance label
`fpp-manager.cennso.com/plumbing-instance`, or by set of labels defined in
`VPPConfig` `spec.routingTableSelectors`. UPG charts generate list of label
based on chart name, release name and UPG instance name:

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

More info on `RoutingTable` targeting is included in next paragraph.

Example of input of networking configuration:

```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 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 check routes applied on the UPG instance, run VPP CLI:

```
vpp# sh ip fib
(...)
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
(...)
```

### Targeting routing tables based on labels

You can define the `routingTableSelectors` value in the `values.yaml` chart for a routing table that matches the UPG instance. It allows you to apply one Routing table to multiple UPG instances.

By definition of multiple label sets, one UPG instance can apply multiple
routing tables matching different labels, for example configuration in chart
`values.yaml`:

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

This is propagated to `VPPConfig` 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
```

UPG chart will generate the basic routing tables matching
`app.kubernetes.io/instance`, `app.kubernetes.io/name`, `cennso.net/cnf`
and `instance` labels. There can be created additional routing table objects,
that match only additional label (`crossInstance` in example) outside of 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 that case, all UPG instance that have VPPConfig with `crossInstance` label
defined will fetch and apply above routing table.

## NWI creation
In PGW mode, 3 NWIs should be created: `epc`, `cp` and `sgi`. For TDF mode,
NWIs: `access`, `cp` and multiple `sgi`s (one per destination, nat pool) should
be created.

UPG chart takes care of proper NWI creation, based on `values.yaml` `type` value:
`pgw` or `tdf`. One `sgi` per nat pool is added after declaration `nat.enabled: true`
and `nat.type` set to `cgnat`.

Instead of using the `type` value, the name and type of NWI can be configured using the `nwis` section:

```yaml
nwis:
  access:
    name: epc     # name of access NWI, `epc` for PGW and `access` for TDF mode
    type: gtpu    # or `tdf`, `gtpu` for PGW and `tdf` for TDF mode
  control:
    name: cp      # all modes use the `cp` name for the control network
    type: gtpu    # all modes use the `gtpu` type for the control network
  data:
    name: sgi     # `sgi` for PGW mode, not used for TDF
    type: ip      # or `gtpu`, `ip` for PGW, not used for the TDF mode
```

Do not set `type: tdf` and per NWI configuration together.

The default configuration provided above serves for the PGW-U use-case.

Example of a configuration for TDF-U:

```yaml
nwis:
  access:
    name: access
    type: tdf
```

Data Networks are configured one per NAT pool, based on `instances.nat.pools`

Sample configuration for GTP-proxy use case, when Access and Data networks are using only GTP endpoints:

```yaml
nwis:
  access:
    name: access
    type: gtpu
  data:
    name: core
    type: gtpu
```

### NWI CR config
UPG uses `UPGConfig` CR to create NWIs. Old way of CLI NWI creation is not
supported, as the only source of truth is Kubernetes API CRs.

For the PGW-U UPG case, the following NWIs will be created by the chart using default values:

```yaml
apiVersion: upg-manager.cennso.com/v1alpha1
kind: UPGConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-fpp-inst01
  name: upg-fpp-inst01
  namespace: upg-fpp
spec:
  nwis:
  - ipv4TableID: 0
    ipv6TableID: 0
    name: cp
  - ipv4TableID: 100
    ipv6TableID: 100
    name: epc
  - ipv4TableID: 200
    ipv6TableID: 200
    name: sgi
```

The TDF-U use-case using the following `values.yaml`:

```yaml
nwis:
  access:
    name: access
    type: tdf

nat:
  enabled: true
  type: cgnat
  maxNatFlows: 500000
instances:
  inst01:
    networking:
      (...)
    nat:
      pools:
        pool-de:
          networking:
            interface: de1
        (...)
        pool-at:
          networking:
            interface: at1
        (...)
```

And resulting `UPGConfig`:

```yaml
apiVersion: upg-manager.cennso.com/v1alpha1
kind: UPGConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-fpp-inst01
  name: upg-fpp-inst01
  namespace: upg-fpp
spec:
  nwis:
  - ipv4TableID: 0
    ipv6TableID: 0
    name: cp
  - ipv4TableID: 100
    ipv6TableID: 100
    name: access
  - ipv4TableID: 200
    ipv6TableID: 200
    name: at1
  - ipv4TableID: 300
    ipv6TableID: 300
    name: de1
```

The GTP-Proxy use case NWI configuration:

```yaml
nwis:
  access:
    name: access
    type: gtpu
  data:
    name: core
    type: gtpu
```

It results in the following UPGConfig:

```yaml
apiVersion: upg-manager.cennso.com/v1alpha1
kind: UPGConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-fpp-inst01
  name: upg-fpp-inst01
  namespace: upg-fpp
spec:
  pfcp:
    heartbeat:
      timeout: 10
      retries: 3
  nwis:
  - ipv4TableID: 0
    ipv6TableID: 0
    name: cp
  - ipv4TableID: 100
    ipv6TableID: 100
    name: access
  - ipv4TableID: 200
    ipv6TableID: 200
    name: core
```

To check the NWI configuration on running UPG instance, use VPP CLI:

```
vpp# sh upf nwi
epc, ip4-table-id 100, ip6-table-id 100, ipfix-policy none, ipfix-collector-ip 0.0.0.0
sgi, ip4-table-id 200, ip6-table-id 200, ipfix-policy none, ipfix-collector-ip 0.0.0.0
cp, ip4-table-id 0, ip6-table-id 0, ipfix-policy none, ipfix-collector-ip 0.0.0.0
```

## Features

### Policy-based routing configuration

Policy-based routing, or traffic steering feature, provides possibility to
apply routing rules per session and forward traffic to different data networks
like Internet or VPN. This feature assumes SMC support in PFCP Session Creation
Request using 3GPP TS 29.244 V16.9.1 8.2.23 Forwarding Policy IE.

During session establishment, SMC assigns a policy by adding the Forwarding
Policy IE to the FAR(s) with Destination Interface SGi-LAN/N6-LAN.
For each session, one of the policies is applied, causing a lookup in one of
the respective tables. UPG and SMC configuration should be in sync, SMC should
send already configured policy IDs in UPG config. Policy ID is a regular string
with max 63 characters. For example `defaultInet` or `defaultVpn`.

Example topology overview:

![policy based routing topology](https://docs.cennso.com/api/assets/components/upg/2.8/images/policy-based-topology.png)

Steps needed to configure policy based routing:
1. Regular SGI interface (called `inet` in above picture) can be used for
Internet connectivity, chart will create NAD for `inet`
1. Ensure that VXLANs for SGI and VPN interface are created (outside of UPG
chart), to enable connectivity to Internet and VPN CGWs - both gateways need
to have FPP-CNI `tap` interfaces deployed
1. Create NAD for VPN interface (outside of UPG chart)
1. Define additional interface in UPG deployment for VPN connectivity -
`additionalNetworks` in `instances.<name>.networking`
1. Define policy names in UPG config using `additionalConfig` section in
`instances.<name>`
1. Define routing tables attached to policy created, outside of UPG chart
1. For multi UPG instances, define `routingTableSelectors` so that one routing
table object will be used on each UPG.

Please refer to [policy based routing values.yaml](https://docs.cennso.com/api/assets/components/upg/2.8/example-config/pb-routing-values.yaml)
and example of [NAD and RoutingTable](https://docs.cennso.com/api/assets/components/upg/2.8/example-config/pb-additional-config.yaml)
definitions for full configuration needed.

Policy based routing feature should be used in `pgw` mode of UPG. To define
forwarding policy, CLI commands in `instances.<name>.additionalConfig` should
be used, example:

```yaml
instances:
  inst01:
    (...)
    additionalConfig:
      - ip table add 201
      - ip table add 202
      - ip6 table add 201
      - ip6 table add 202
      - upf policy add id defaultInet via ip4-lookup-in-table 201 via ip6-lookup-in-table 201
      - upf policy add id defaultVpn via ip4-lookup-in-table 202 via ip6-lookup-in-table 202
      - upf policy add id defaultInetIPFix via ip4-lookup-in-table 201 via ip6-lookup-in-table 201
      - upf policy add id defaultVpnIPFix via ip4-lookup-in-table 202 via ip6-lookup-in-table 202
```

Current requirement is to create tables first before `upf policy add id <name>`
command is used. Table creation in `additionalConfig` should be removed after
implementing conditional wait for RoutingTable CR to be added before executing
`additionalConfig` commands.

`upf policy add id <policy-name> via ip4-lookup-in-table <table-id> via ip6-lookup-in-table <table-id>`
defines `<policy-name>` to be used for traffic forwarding, with connected IPv4
and IPv6 routing table look ups. Routing table must exist before referencing
them in policy creation command. If routing table is deleted during runtime,
policy is working, but no traffic is forwarded outside of UPG. After routing
table is available again, traffic is passing normally.

Above example of policy creation shows how to configure policy based routing
together with IPFIX activation per session. Two policies needs to be created,
for example `defaultInet` and `defaultInetIPFix`, and proper configuration at
SMC side will send PFCP IEs for routing (FAR - forwarding policy name) and
ipfix template (TP IPFIX Policy IE - `FlowUsage` as prepared for PGW mode).

IPFIX configuration includes exporter config:

```yaml
ipfixExporters:
  - collectorAddress: 172.18.0.196
    collectorPort: 4739
    pathMTU: 1420
    srcNetwork: sx
    templateInterval: 5
    udpChecksum: false
    exporterID: "pool1"
```

And SGI IPFIX configuration:

```yaml
instances:
  inst01:
    networking:
      (...)
      sgi:
        interface: inet
        type: memif
        vni: 2130
        mtu: 8930
        ipv4:
          addresses:
          - 172.20.0.16/24
        ipv6:
          addresses:
          - fd71:357a:a82e:1::16/64
        ipfixCollector: 172.18.0.196
        observationDomainID: 21
        observationDomainName: pgw.upg-01
        observationPointID: 1
        ipfixReportInterval: 10
```

For VPN interface, separate NAD needs to be created outside of UPG chart.
Example:

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: vpn21-memif-inst01
  namespace: proxy-load-cennso-net
spec:
  config: |-
    {
      "cniVersion": "0.3.1",
      "ipam": {
        "addresses": [
          {
            "address": "172.21.0.16/24"
          },
          {
            "address": "fd71:357a:a831:1::16/64"
          }
        ],
        "type": "static"
      },
      "mtu": 8930,
      "name": "vpn21",
      "table": 200,
      "type": "fpp-cni",
      "vni": 2150,
      "vppIfaceType": "memif"
    }
```

This NAD `vpn21-memif-inst01` can be added in `additionalNetworks` in per
instance network configuration:

```yaml
instances:
  inst01:
    networking:
      grx: (...)
      sx: (...)
      sgi: (...)
      additionalNetworks:
        - vpn21-memif-inst01@vpn21
```

Last step is to configure routing tables connected to policy tables. This needs
to be done outside of UPG chart. Policy based routing enables pointing default
route to Internet and specific IP network addresses to VPN data network. Also
blocking of IP range is allowed. Example:

```yaml
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: pcg-proxy-load-cennso-net-upg
  name: default-inet
  namespace: proxy-load-cennso-net
spec:
  addressFamily: IPv4
  id: 201
  routes:
  - cidr: 0.0.0.0/0
    nextHopAddress: 172.20.0.96
    nextHopInterface: inet
  - cidr: 172.21.0.128/32
    nextHopAddress: 172.21.0.128
    nextHopInterface: vpn21
  - cidr: 9.9.9.9/32
    nextHopAddress: blackhole
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: pcg-proxy-load-cennso-net-upg
  name: default-vpn
  namespace: proxy-load-cennso-net
spec:
  addressFamily: IPv4
  id: 202
  routes:
  - cidr: 0.0.0.0/0
    nextHopAddress: 172.21.0.128
    nextHopInterface: vpn21
  - cidr: 198.19.1.0/24
    nextHopAddress: 172.20.0.96
    nextHopInterface: inet
  - cidr: 8.8.8.8/32
    nextHopAddress: 172.20.0.96
    nextHopInterface: inet
  - cidr: 8.8.4.4/32
    nextHopAddress: 172.20.0.96
    nextHopInterface: inet
  - cidr: 9.9.9.9/32
    nextHopAddress: blackhole
```

Above example shows different routes configuration for tables 201 and 202,
where 201 table pass default traffic to Internet, and specific address to VPN
data network. Table 202 does opposite routing, by default passing traffic to
VPN data network, and only specific routes are forwarded to SGI (Internet)
network. IP `9.9.9.9/32` is blocked.

Common label across all RoutingTable CRs is configured in UPG chart by:

```yaml
routingTableSelectors:
- fpp-manager.cennso.com/plumbing-instance: pcg-proxy-load-cennso-net-upg
```

### IPFIX configuration

UPG enables IPFIX to be exported. This is built in feature and to properly
use it, IPFIX exporter and per NWI IPFIX settings should be configured. IPFIX
exporter configures the IPFIX collector, these are current assumptions for
IPFIX exporter configuration:
- UPG supports sending IPFIX data over VPP interface, so current configuration
does not support to use Kubernetes default network (like Calico)
- Collector IP address should use FPP-CNI, and recommended is control network
(`sx`), as it was tested and reported to be working
- IPFIX collectors are distinguish by IP address, so only one collector per
IP is supported currently (this is VPP internal limitation)
- Collector IP defined in `ipfixExportes` should match per NWI `ipfixCollector`
settings, otherwise IPFIX feature will not work

Example:

```yaml
ipfixExporters:
  - exporterID: data-net-exporter
    collectorAddress: 172.18.1.100
    collectorPort: 4739
    pathMTU: 1420
    srcNetwork: sx
    templateInterval: 15
    udpChecksum: false
```

UPG supports two IPFIX templates:
- `NatEvent` - mainly created for TDF use-case, with NAT information
- `FlowUsage` - used in PGW mode

Second part of IPFIX configuration is per uplink NWI ipfix config, supported in `sgi` or per NAT pool configuration in `values.yaml`. Example for PGW mode:

```yaml
instances:
  inst01:
    networking:
      grx: (...)
      sx: (...)
      sgi:
        interface: sgi21
        type: memif
        vni: 2130
        mtu: 8930
        ipv4:
          addresses:
          - 172.20.0.16/24
        ipv6:
          addresses:
          - fd71:357a:a82e:1::16/64
        ipfixCollector: 172.18.1.100
        ipfixPolicy: FlowUsage
        observationDomainID: 21
        observationDomainName: pgw.sgi-example
        observationPointID: 1
        ipfixReportInterval: 10

```

`ipfixExporters.collectorAddress` and `instances.<name>.networking.sgi.ipfixCollector` needs to match, otherwise IPFIX will not be sent. For PGW mode, `ipfixPolicy` can be set in NWI configuration, or if policy is omitted, PFCP Session Establishment Request should include PFCP TP IPFIX Policy IE with a valid name of the policy (`FlowUsage`/`NatEvent`). PGW mode can use `FlowUsage` as `ipfixPolicy`. In case where `ipfixPolicy` is empty, no ipfix is sent by default and IPFIX is activated per session.

For TDF mode, per NAT pool ipfix configuration is supported, and should be
included in NAT config section, example:

```yaml
instances:
  inst01:
    networking: (...)
    nat:
      pools:
        pool-de:
          networking:
            ipfixCollector: 172.18.1.100
            ipfixPolicy: NatEvent
            observationDomainID: 21
            observationDomainName: tdf.de-inst01
            observationPointID: 1
            ipfixReportInterval: 10
            interface: de1
            type: memif
            vni: 4302
            mtu: 1500
            ipv4:
              gw: 198.19.2.1
              addresses:
                - 198.19.2.21/24
          start: 198.19.8.1
          end: 198.19.8.254
          blocksize: 512
```

To check IPFIX configuration, VPP CLI on UPG can be executed:

```
vpp# sh upf nwi
cp, ip4-table-id 0, ip6-table-id 0, ipfix-policy none, ipfix-collector-ip 0.0.0.0
access, ip4-table-id 100, ip6-table-id 100, ipfix-policy none, ipfix-collector-ip 0.0.0.0
at1, ip4-table-id 200, ip6-table-id 200, ipfix-policy default, ipfix-collector-ip 172.18.1.101
de1, ip4-table-id 300, ip6-table-id 300, ipfix-policy default, ipfix-collector-ip 172.18.1.100
```

### TDF with CG-NAT
To configure UPG in TDF mode, the following settings need to be defined in
`values.yaml`.

First of all, we need to define the `type` to `tdf`.

As UPG requires an FPP-enabled node to run on, `nodeAffinity` needs to be defined.
For example, if all nodes with fpp enabled are labeled with
`fpp-manager.cennso.com/vppswitch: ""`, then the chart config should include:

```yaml
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: fpp-manager.cennso.com/vppswitch
          operator: Exists
```

If UPG deployment should be pinned to a specific node, then affinity can look
like this (assuming the node name is `worker-node1.test.cluster.net`):

```yaml
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - worker-node1.test.cluster.net
            - key: fpp-manager.cennso.com/vppswitch
              operator: Exists
```

`labels` need to be defined because there are used in the `upg-support` Grafana dashboard:

```yaml
labels:
  apn: test.apn.cennso
```

If the UPG Manager image is hosted on a private registry, `imagePullSecrets` should be
set in `values.yaml`, example:

```yaml
imagePullSecrets:
  - name: image-secret
```

This will set the service account to use that secret, as well as it will be
set in UPG deployment. The secret needs to be created outside UPG deployment.

Based on the load test (250k sessions), a recommendation for resource allocation is:

```yaml
resources:
  cpu: 2
  memory: 8Gi
heapsize: "7G"
enableHugepagesAllocation: false
```

The **enableHugepagesAllocation** parameter specifies if UPG uses hugepages for heap, stats segment, and buffer. If set to `true`, UPG uses a hugepages memory system instead of the standard memory allocation mechanisms. When hugepages are enabled, the **resources.memory** parameter must be set to at least `1Gi` and **resources.hugepages-2Mi** must be set to at lease `4Gi`. If **enableHugepagesAllocation** is set to `false`, hugepages are disabled and the **resources.memory** must be set to at least the value of `heapsize + 1G`. Enabling and disabling hugepages allocation for heap, stats, and buffer does not influence the performance or stability of UPG.

Networking configuration for UPG instance includes regular `grx` and `sx`
interface configuration. `sgi` configuration is omitted, as a per pool `sgi` will be added.
Example config:

```yaml
instances:
  inst01:
    networking:
      # access network
      grx:
        interface: an1
        type: memif
        vni: 4201
        ipv4:
          addresses:
            - 198.18.1.21/24
          routes:
            # 10.0.0.0/10 is the UE address range
            - to: 10.0.0.0/10
            # via is a IP of access network gateway
              via: 198.18.1.100
      # control network
      sx:
        interface: sx1
        type: memif
        vni: 4101
        mtu: 8930
        ipv4:
          addresses:
            -  172.18.1.21/24
```

Above will result in the UPG chart to define NADs with memif interfaces for GRX (named
`an1`) and SX (named `sx1`). Proper VXLANs should be created (i.e. 4201 and
4101) using the Custom Resource of `vxlan.fpp-manager.cennso.com`. UPG chart does
not create those VXLAN objects. This will enable cross-node communication.
Example:

```yaml
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VXLAN
metadata:
  name: an1
  namespace: tdf-example
spec:
  vni: 4201
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VXLAN
metadata:
  name: sx1
  namespace: tdf-example
spec:
  vni: 4101

```

TDF setup requires NAT. UPG enables 2 types of NAT: basic and carrier-grade NAT (CG-NAT).
In the TDF case, `cg-nat` will be used. To enable `cg-nat` `values.conf` should include:

```yaml
nat:
...
  enabled: true
  type: cgnat
  maxNatFlows: 500000
```

Where `500000` is the number of connections for all users, and this number was
verified by load test to be sufficient (250k sessions run).

The `maxNatFlows` represent the maximum of NAT flows that can be processed per UPG instance. This influences total memory consumption.
1 NAT flow was measured to take 246 bytes, and 1M of sessions took 246 MB of memory.

It is advised to configure `maxNatFlows` to a high number, to prepare the system for many connections.
The `maxNatFlows` entries are pre-allocated on UPG startup.

If `maxNatFlows` will be reached, no new connection will be NATed, and the UE will not be able to reach the Data Network.

NAT flow has its idle timeout to free up the resources, it depends on the protocol, and it can be configurable
using UPG chart values:

```yaml
nat:
...
  timeouts:
    icmp: 60 # in seconds, by default 1 minute
    tcpEstablished: 7440 # in seconds, by default 2 hours 4 minutes
    tcpTransitory: 240 # in seconds, by default 4 minutes
    udp: 300 # in seconds, by default 5 minutes
```

NAT flows are not removed after reaching the timeout, they are removed in the Least Recently Used (LRU) style.
So the flow table can be filled up, but when a new flow should be created - an invalid flow will be removed and replaced
with the new one.

To further estimate UPG CG-NAT capacity, NAT pool configuration is introduced:

- `start` - start external IP range, example: `198.19.8.1`
- `end` - end external IP range, example: `198.19.8.254`
- `blocksize` - range of port assigned to NAT binding

```yaml
instances:
  {UPG_INSTANCE_NAME}:
  ...
    nat:
      pools:
        {NAT_POOL_NAME}:
          ...
          start: 198.19.8.1
          end: 198.19.8.2
          blocksize: 512
```

The capacity of the NAT pool in terms of total NAT flows is calculated as follows:

- External_IPs * (MAX_PORT - MIN_PORT) <br>
  where `MIN_PORT` is by default 1024 and `MAX_PORT` is by default 65535.

`MIN_PORT` and `MAX_PORT` are configurable by:

```yaml
nat:
  minNatPort: 1024
  maxNatPort: 65535
```

Example calculation for 2 external IPs and default port ranges:

- 2 * (65535 - 1024) = 2 * 64511 = 129022

The maximum number of NAT flows is fragmented into `blocksize` ranges. In conjunction with external IP,
the port block creates NAT binding, for example:

```
  FRAMED: 100.71.3.248
  EXTERNAL: 198.19.8.1
  port start 1024 port end 1536
```

After the UPF session is deleted, NAT binding is released and a port block is returned to be used by other sessions.
This NAT binding might be used immediately, but the algorithm that assigns NAT bindings to new UPF sessions tries
to pick up less used external IP first.

NAT binding is reused immediately after the previous session is deleted.

UPG exposes `vpp_nat_pool_capacity` metric per NAT Pool, which helps to see what is the total capacity of
NAT bindings per NAT pool, calculated as `External_IPs * (MAX_PORT - MIN_PORT)/BLOCK_SIZE`.

`vpp_nat_pool_utilization` metric shows how many NAT bindings are allocated to UEs.

When UE uses all ports assigned in NAT Binding, new connections will not be NATed, and traffic will be blocked
until some port will be freed up.

NAT pools are configured in `instances.<name>.nat` section of chart `values.yaml`.
Example NAT pool configuration:

```yaml
instances:
  inst01:
  (...)
    nat:
      pools:
        pool-de:
          networking:
            ipfixCollector: 172.18.1.100
            ipfixPolicy: NatEvent
            observationDomainID: 21
            observationDomainName: tdf.de-inst01
            observationPointID: 1
            ipfixReportInterval: 10
            interface: de1
            type: memif
            vni: 4302
            mtu: 1500
            ipv4:
              gw: 198.19.2.1
              addresses:
                - 198.19.2.21/24
          start: 198.19.8.1
          end: 198.19.8.254
          blocksize: 512
        pool-at:
          networking:
            ipfixCollector: 172.18.1.101
            ipfixPolicy: NatEvent
            observationDomainID: 21
            observationDomainName: tdf.at-inst01
            observationPointID: 1
            ipfixReportInterval: 10
            interface: at1
            type: memif
            vni: 4303
            mtu: 1500
            ipv4:
              gw: 198.19.3.1
              addresses:
                - 198.19.3.21/24
          start: 198.19.16.1
          end: 198.19.16.254
          blocksize: 512
```

In per pool configuration, ipfix capabilities are defined, interface details
(name, type, mtu, IP address and pool gateway address). `vni` refers to FPP
VXLAN network id. This vxlan needs to be created with with
`vxlan.fpp-manager.cennso.com` CRs outside of UPG chart. Above configuration
will generate NADs for NAT pool interfaces, with `fpp-cni` and `memif` type.

```yaml
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: upg-01-tdf-example-inst01-pool-at-at1
  namespace: tdf-example
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses":
        [
          {
            "address": "198.19.3.21/24"
          }
        ],
        "type": "static"
      },
      "mtu": 1500,
      "name": "at1",
      "table": 200,
      "type": "fpp-cni",
      "vni": 4303,
      "vppIfaceType": "memif"
    }
---
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: upg-01-tdf-example-inst01-pool-de-de1
  namespace: tdf-example
spec:
  config: |-
    {
      "cniVersion": "0.3.0",
      "ipam": {
        "addresses":
        [
          {
            "address": "198.19.2.21/24"
          }
        ],
        "type": "static"
      },
      "mtu": 1500,
      "name": "de1",
      "table": 300,
      "type": "fpp-cni",
      "vni": 4302,
      "vppIfaceType": "memif"
    }
```

Based on NAT pool definitions, NWI per NAT pool will be defined using
`UPGConfig` CR. Also IPFIX configuration per NWI will be included.
IPFIX template `default` should be used for TDF use-case:

```yaml
apiVersion: upg-manager.cennso.com/v1alpha1
kind: UPGConfig
metadata:
  name: upg-01-tdf-example-inst01
  namespace: tdf-example
spec:
  nwis:
  - ipv4TableID: 0
    ipv6TableID: 0
    name: cp
  - ipv4TableID: 100
    ipv6TableID: 100
    name: access
  - ipfixCollectorAddress: 172.18.1.101
    ipfixPolicy: NatEvent
    observationDomainID: 21
    observationDomainName: tdf.at-inst01
    observationPointID: 1
    ipfixReportInterval: 10
    ipv4TableID: 200
    ipv6TableID: 200
    name: at1
  - ipfixCollectorAddress: 172.18.1.100
    ipfixPolicy: NatEvent
    observationDomainID: 21
    observationDomainName: tdf.de-inst01
    observationPointID: 1
    ipfixReportInterval: 10
    ipv4TableID: 300
    ipv6TableID: 300
    name: de1
```

NAT pools configuration will be included in VPPConfig with per UPG target:

```yaml
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-01-tdf-example-inst01
  name: upg-01-tdf-example-inst01
  namespace: tdf-example
spec:
  afterCommands:
  - set ip neighbor-config ip4 age 10
  - set ip neighbor-config ip6 age 10
  - upf gtpu endpoint ip 172.18.1.21 nwi cp teid 0x80000000/2
  - upf tdf ul table vrf {{ (index .Ifs "an1").Table }} ip4 table-id 1001
  - upf tdf ul enable ip4 {{ (index .Ifs "an1").Name }}
  - nat44 plugin enable sessions 500000
  - upf nat pool 198.19.16.1 - 198.19.16.254 block_size 512 nwi at1 name pool-at
  - set interface nat44 out {{ (index .Ifs "at1").Name }} output-feature
  - upf ueip pool nwi at1 id pool-at
  - upf nat pool 198.19.8.1 - 198.19.8.254 block_size 512 nwi de1 name pool-de
  - set interface nat44 out {{ (index .Ifs "de1").Name }} output-feature
  - upf ueip pool nwi de1 id pool-de
  - nat44 controlled enable
  - upf specification release 16
  - upf node-id fqdn upg-01-tisp-ref-inst01
  - upf pfcp server set fifo-size 512
  - upf pfcp endpoint ip 172.18.1.21 vrf 0
  - upf pfcp policer set cir-pps 150 cb-ms 1000
  interfaces:
  - an1
  - sx1
  - at1
  - de1
```

This is example exporters configuration:

```yaml
ipfixExporters:
  - exporterID: pool-de
    collectorAddress: 172.18.1.100
    collectorPort: 4739
    pathMTU: 1420
    srcNetwork: sx
    templateInterval: 5
    udpChecksum: false
  - exporterID: pool-at
    collectorAddress: 172.18.1.101
    collectorPort: 9374
    pathMTU: 9000
    srcNetwork: sx
    templateInterval: 10
    udpChecksum: true
```

### Rate limiter

For TDF case, there is possibility to throttle the session creation rate, which
is important to not overwhelm SMF. Rate limiter will be applied to PFCP Session
Report Request, sent from UPG to SMF. `rateLimiterPPS` included in `values.yaml`
will set how many messages per second can be sent.

```yaml
rateLimiterPPS: 150
```

## PFCP Server Configuration

`UPGConfig` CR can be used to configure UPG PFCP Server parameters.

### PFCP Heartbeat Configuration

PFCP Heartbeat mechanism is used to identify connectivity problems between UPG and
CP-Function. The number of retries for unanswered PFCP Heartbeat Request and the
timeout between retries in seconds can be configured within `pfcp` section of
`UPGConfig`.

```yaml
apiVersion: upg-manager.cennso.com/v1alpha1
kind: UPGConfig
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-fpp-inst01
  name: upg-fpp-inst01
  namespace: upg-fpp
spec:
  pfcp:
    heartbeat:
      retries: 10
      timeout: 3
  nwis:
...
```

`UPGConfig` CR is populated with dedicated values by setting appropriate parameters
in `values.yaml`. Note, that number of retires should not be greater than `30`, and
timeout should be positive number in seconds not greater than `120`.

```yaml
pfcpHeartbeatTimeout: 10
pfcpHeartbeatRetries: 5
```

PFCP Heartbeat configuration can be verified from VPP CLI:

```
vppctl# show upf heartbeat-config
Timeout: 10 Retries: 5
```

## UPG runtime reconfiguration

The following actions can happen when you change the UPG configuration and apply it on a running instance:

1. UPG can be restarted - the UPG pod restarts but no lifecycle action, such as deleting the pod and creating a new one, is triggered
1. UPG can be recreated - the UPG pod is deleted and a new copy is created

UPG restart does not trigger CNI to be executed. This impacts the application of the changed IP address from Network Attachment Definition (NAD) to a running UPG pod. To apply the IP changes, you must recreate the UPG pod.

Changes to the UPG configuration that do not trigger the UPG restart or recreation:

| Action | Effect | Comment |
| :--- | :--- | :--- |
| Modify labels| No restart | Changes applied using chart's `label` section |
| Reconfigure PFCP HeartBeat | No restart | Configuration using chart parameters: `pfcpHeartbeatRetries` and `pfcpHeartbeatTimeout` |
| Change Routing table selectors | No restart | Chart parameter `routingTableSelectors` can decide which RoutingTable CRs are applied per UPG deployment |
| Change routing for Access and Data networks | No restart | `instances.{name}.networking.grx.routes.ipv4` and `instances.{name}.networking.sgi.routes.ipv4` can be changed in the runtime |
| Change default routing for NAT pool network | No restart | `instances.{name}.nat.pools.{name}.networking.ipv4.gw` are applied in the runtime |

Other changes that affect UPG:

| Action | Effect | Comment |
| :--- | :--- | :--- |
| Add IPFix configuration | UPG restart | New values from the chart are configured in UPGConfig CR in the NWI section |
| IP address changes for Access, Control, or Data interfaces (including the NAT Pool IPs) | UPG restart | UPG pod is restarted but not recreated because changes are applied in VPPConfig but modification in NAD requires manual UPG deletion to apply changes |
| Add NAT Pool | UPG recreation | New NAT pool is added as new NWI and changing the UPG deployment network annotation. This triggers the UPG pod to be deleted and started with new interfaces. |
| Modify `applicationDetection` | UPG restart | Changes are applied in VPPConfig's `afterCommands` so UPG is restarted |
| Modify `rateLimiterPPS` | UPG restart | VPPConfig's `afterCommands` are changed |
| Modify `additionalNetworks` | UPG recreation | Network annotation in the UPG deployment is changed so UPG is recreated |
| Performance tuning (TX placement, Tx/Rx Queues, buffer size) | No effect | NAD is changed but to apply it, UPG pod must be manually deleted.
