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

# Packet Gateway

To deploy UPG as a [Packet Gateway (PGW)](https://docs.cennso.com/components/upg/latest/use-cases/pgw.md), you must deploy two Custom Resources (CRs) to your Management Cluster:
1. [Deploy `FPPNetworks`](#deploy-fppnetworks)
2. [Deploy `UPGDeployment`](#deploy-upgdeployment)

Read the sections below to learn how to configure these CRs.

## Deploy FPPNetworks

In the Core Cluster, create the necessary [FPPNetwork](https://docs.cennso.com/cennso/fpp/main/concepts/fppnetwork.md) resources for your access, control, and data networks. A data network is required since [CG-NAT is not used](https://docs.cennso.com/components/upg/latest/concepts/upgdeployment.md#network-configuration) in this snippet. For example:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: FPPNetwork
metadata:
  name: grx40
spec:
  id: 40
  type: vxlan
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: FPPNetwork
metadata:
  name: sgi41
spec:
  id: 41
  type: vxlan
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: FPPNetwork
metadata:
  name: sx39
spec:
  id: 39
  type: vxlan
```

## Deploy UPGDeployment

Create a [UPGDeployment](https://docs.cennso.com/components/upg/latest/concepts/upgdeployment.md) Custom Resource (CR) in the Management Cluster. For example:

```yaml
apiVersion: fpp.cennso.com/v1alpha1
kind: UPGDeployment
metadata:
  name: basic-pgw
  namespace: cennso-infra
spec:
  version: <version>
  connectionSecretRef:
    name: example-core-cluster
    namespace: cennso-infra

  labels:
    apn: basic.load.cennso.net

  imagePullSecrets:
    - name: cennso-pull-secret

  operatorName: fpp-operator

  instances:
    inst01:
      networking:
        grx:
          interface: grx
          networkName: grx40
          mtu: 8930
          ipv4:
            addresses:
              - 198.18.0.16/24
            routes:
              - to: 0.0.0.0/0
                via: 198.18.0.1

        sx:
          interface: sxb
          networkName: sxb39
          mtu: 8930
          ipv4:
            addresses:
              - 172.18.0.16/24

        sgi:
          interface: sgi
          networkName: sgi41
          mtu: 8930
          ipv4:
            addresses:
              - 198.19.0.16/24
```

To deploy UPG with multiple IPs for GRX/SX/SGI, [follow the guide](#deploy-upg-with-multiple-ips-per-grx-interface).

To deploy UPG with multiple Access Network Instances, see [this section](#deploy-upg-with-multiple-access-network-instances).

### Verification

To check if the UPGDeployment is installed and ready, run:

```bash
kubectl get upgdeployments.fpp.cennso.com -n cennso-infra basic-pgw
```

Sample output:

```bash
NAME                       SYNCED   READY   CONNECTION-SECRET   AGE
basic-pgw                  True     True                        3m
```

You can also check the status of the VppDeployment resource that the UPGDeployment CR created in the Core Cluster:

```bash
kubectl get vppdeployment -n basic-pgw
```

Sample output:

```bash
NAME                       READY   IMAGE                                                AGE
basic-pgw-inst01           True    registry.cennso.com/cennso/upg/vpp-operator:v3.0.0   3m
```

## Deploy UPG with multiple IPs per GRX interface

If you need to assign more IP addresses per GRX interface, you can do it in UPGDeployment's **spec.instances.{name}.networking.grx.ipv4.addresses**. When multiple IPs are configured, only one can be used as a GTP-u endpoint per NWI. This is the current UPG limitation.

The GTP-u endpoint is selected in one of two ways:
1. Use the first IP address from **ipv4.addresses** list. This is the default behaviour.
2. Set **spec.instances.{name}.networking.grx.ipv4.gtpuEndpoints** list with IP address (without a netmask). Only the first element from the list will be used.

### Default GTP-U endpoint

The first entry from UPGDeployment's **spec.instances.{name}.networking.grx.ipv4.addresses** list is selected as the GTP-u endpoint:

```yaml
apiVersion: fpp.cennso.com/v1alpha1
kind: UPGDeployment
metadata:
  name: basic-pgw
  namespace: cennso-infra
spec:
  ...
  instances:
    inst01:
      networking:
        grx:
          networkName: grx40
          mtu: 8930
          interface: grx
          ipv4:
            addresses:
              - 198.18.50.22/24
              - 198.18.0.22/24
```

In the above example, `198.18.50.22` will be used as a GTP-u endpoint.

### Use **gtpuEndpoints**

You can explicitly define an IP address that should be used as a GTP-u endpoint in **spec.instances.{name}.networking.grx.ipv4.gtpuEndpoints**. Only the first address from the list is used. See the configuration example:

```yaml
apiVersion: fpp.cennso.com/v1alpha1
kind: UPGDeployment
metadata:
  name: basic-pgw
  namespace: cennso-infra
spec:
  ...
  instances:
    inst01:
      networking:
        grx:
          networkName: grx40
          mtu: 8930
          interface: grx
          ipv4:
            addresses:
              - 198.18.50.22/24
              - 198.18.0.22/24
            gptuEndpoints:
              - 198.18.0.22
```

Here, `198.18.0.22` is explicitly used as a GTP-u endpoint.

## Deploy UPG with multiple Access Network Instances

This section describes how to deploy UPG with multiple Access Network Instances (NWIs) using a [`UPGDeployment` CR](https://docs.cennso.com/components/upg/latest/concepts/upgdeployment.md) on the Management Cluster, along with additional configuration. In this tutorial, you will apply the following resources to the Core Cluster:
- [`UPGDeployment` CR](https://docs.cennso.com/api/assets/components/upg/latest/assets/example-config/multi-grx-ip-values.yaml) configured for the basic Packet Gateway (PGW)
- [VPPInterfaces with additional UPGConfig custom resources (CRs)](https://docs.cennso.com/api/assets/components/upg/latest/assets/example-config/multi-grx-ip-config.yaml)

To deploy UPG with multiple Access Network Instances, you must:
1. [Define NWIs using `UPGConfig` CR](#define-nwis)
2. ```
   ```2. [Create VPPInterfaces](#create-vppinterfaces)
2. [Create `VPPInterfaces`](#create-vppinterfaces)
3. [Configure `UPGDeployment`](#configure-upgdeployment)

Read the sections below to learn how to configure these resources.

### Define NWIs

1. Define three Access Network NWIs:
  
  - `epc` - NWI created by default by `UPGDeployment` CR
  - `epc2` - second NWI created by an additional `UPGConfig` CR
  - `epc3` - third NWI also created by `UPGConfig` CR

  Create `epc2` and `epc3` in the Core Cluster using the following `UPGConfig` CR:
  
  ```yaml
  kind: UPGConfig
  apiVersion: upg-manager.cennso.com/v1alpha1
  metadata:
    name: pgw-u-nwis
    labels:
      fpp-manager.cennso.com/plumbing-instance: upg-inst01 # {UPGDEPLOYMENT_NAME}-{INSTANCE_NAME}
      fpp-manager.cennso.com/created-for: upg-operator
  spec:
    priority: 110 # Priority to merge the additional config with the default one generated by the CR
    nwis:
    - name: epc2
      ipv4TableID: 100
      ipv6TableID: 100
    - name: epc3
      ipv4TableID: 100
      ipv6TableID: 100
  ```

2. Then, apply the YAML file with the `UPGConfig` CR to the Core Cluster using this command:

  ```bash
  kubectl apply -f {FILENAME}.yaml
  ```

### Create VPPInterfaces

To configure NWI IPs, create additional VPPInterface objects outside of the `UPGDeployment` CR and apply them to the Core Cluster:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: pgw-u-epc2-inst01
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-inst01 # {UPGDEPLOYMENT_NAME}-{INSTANCE_NAME}
    fpp-manager.cennso.com/created-for: upg-operator
spec:
  ifName: grx2
  attachToNetwork: net-grx2
  table: 100
  memif:
    role: slave
  ips:
  - 198.51.100.1/24
  mtu: 8930
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPInterface
metadata:
  name: pgw-u-epc3-inst01
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg-inst01 # {UPGDEPLOYMENT_NAME}-{INSTANCE_NAME}
    fpp-manager.cennso.com/created-for: upg-operator
spec:
  ifName: grx3
  attachToNetwork: net-grx3
  table: 100
  memif:
    role: slave
  ips:
  - 203.0.113.1/24
  mtu: 8930
```

The additional interfaces `grx2` and `grx3` will be created on UPG instance `upg-inst01`.

### Configure UPGDeployment

Add the configuration created in the previous steps to the [`UPGDeployment` CR configuration](#deploy-upgdeployment):

```yaml
spec:
  instances:
    inst01:
      additionalConfig:
      - upf gtpu endpoint ip 198.51.100.1 nwi epc2 teid 0x80000000/2
      - upf gtpu endpoint ip 203.0.113.1 nwi epc3 teid 0x80000000/2
      networking:
        grx: (...)
        sx: (...)
        sgi: (...)
```

NWIs created in UPGConfig are used to create the GTP-U endpoint in the UPF CLI `upf gtpu endpoint ...` in `spec.instances.{NAME}.additionalConfig`.

The `metadata.name` of the `UPGDeployment` CR must match the UPGConfig label `fpp-manager.cennso.com/plumbing-instance: upg-inst01`, so that the additional configuration is applied on UPG. In this example, `metadata.name` is equal to `upg`.

> [!NOTE]
> If you are modifying an existing UPGDeployment, you must recreate the UPG pod to apply the updated VPP CLI configuration. See [Reconfiguration at runtime](https://docs.cennso.com/components/upg/latest/troubleshooting/reconfig.md) for details.

> [!NOTE]
> For basic Packet Gateway deployment instructions, see the [Packet Gateway](https://docs.cennso.com/components/upg/latest/deployment-guides/pgw.md) deployment guide.

### Verification

You can check if the requested changes are applied on UPG using the `vppctl` command in the UPG pod on the Core Cluster:

```bash
vppctl show interface address
```

See the output example:

```bash
grx1 (up):
  L3 198.18.0.20/24 ip4 table-id 100 fib-idx 1
grx2 (up):
  L3 198.51.100.1/24 ip4 table-id 100 fib-idx 1
grx3 (up):
  L3 203.0.113.1/24 ip4 table-id 100 fib-idx 1
local0 (dn):
sgi (up):
  L3 198.19.0.20/24 ip4 table-id 200 fib-idx 2
sxb (up):
  L3 172.20.0.20/24
upf-nwi-cp (up):
upf-nwi-epc2 (up):
upf-nwi-epc3 (up):
upf-nwi-epc (up):
upf-nwi-sgi (up)
```

To see the NWIs configuration, use the following `vppctl` command in the UPG pod:

```bash
vppctl show upf nwi
```

This is the output example:

```bash
cp, ip4-table-id 0, ip6-table-id 0, ipfix-policy none, ipfix-collector-ip 0.0.0.0
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
epc2, ip4-table-id 100, ip6-table-id 100, ipfix-policy none, ipfix-collector-ip 0.0.0.0
epc3, ip4-table-id 100, ip6-table-id 100, ipfix-policy none, ipfix-collector-ip 0.0.0.0
```

To check the GTP-U endpoints, use the following `vppctl` command in the UPG pod:

```bash
vppctl show upf gtpu endpoint
```

This is the output example:

```txt
[0]:  ip4: 172.20.0.20, nwi: cp
[1]:  ip4: 198.18.0.20, nwi: epc
[2]:  ip4: 198.51.100.1, nwi: epc2
[3]:  ip4: 203.0.113.1, nwi: epc3
```
