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

# Packet Gateway

Following the Control and User Plane Separation (CUPS) architecture, Travelping offers a Packet Gateway (PGW) implementation split into two components:

- **Control Plane (PGW-C)** – implemented by Session Management Controller (SMC), responsible for session management and signalling
- **User Plane (PGW-U)** – implemented by User Plane Gateway (UPG), responsible for forwarding user data traffic

Session Management Controller configured as PGW-C serves the following purposes:

- Session establishment and modification – PGW-C is responsible for establishing and modifying data sessions for user equipment (UE). It handles the signalling messages to set up the data path, negotiates the QoS (Quality of Service) parameters, and provisions them to the PGW-U (UPG).
- IP address allocation – PGW-C assigns IP addresses to the user equipment. It ensures each device receives a unique IP address for its data sessions. This is crucial for routing data packets to and from the UE.
- Policy control – PGW-C interacts with the Policy and Charging Rules Function (PCRF) to apply policies that determine how data services are managed and which charging rules apply.
- Charging – PGW-C is involved in collecting and reporting usage data for charging purposes. It ensures that the user’s data usage is monitored, that traffic and time quotas or limits are applied, and that offline charging data is generated. This function involves interaction with the Online Charging System (OCS), Offline Charging System (OFCS), and AAA servers:
   - For OCS, PGW-C requests data traffic and time quotas/limits from the OCS, applies the resulting rules to the PGW-U (UPG), and reports the consumed data and time volumes back to the OCS.
   - For OFCS, PGW-C reports the consumed data and time volumes to the OFCS.
   - For AAA (either Diameter or RADIUS over (S)Gi), PGW-C provisions traffic monitoring rules to the PGW-U (UPG), and reports the consumed data and time volumes to the AAA server.
- Mobility management – PGW-C supports mobility by handling the changes in the data path as the user equipment moves from one location to another. It ensures seamless data session continuity during handovers.

## Architecture

See the diagram that shows the architecture and workflow of SMC acting as PGW-C that connects to a AAA server:

![PGW use case](https://docs.cennso.com/api/assets/components/smc/latest/assets/pgw.svg)

1. Serving Gateway (SGW) initiates session creation by sending GTP-C messages to SMC. These messages define bearer contexts and establish initial data tunnels.
2. SMC can interact with a AAA server (through the Diameter Gx interface) to apply policy and charging rules. This ensures proper authentication, authorisation, and quota enforcement for the subscriber.
3. Using the Sxb interface and PFCP (Packet Forwarding Control Protocol), SMC configures and manages User Plane Gateway, which implements PGW-U.
4. SMC monitors data usage and event triggers reported by UPG for both online and offline charging. Quotas and policy enforcement can dynamically adjust during the session based on these reports.

## Configuration

This section presents the minimal chart configuration that allows you to create a PGW-C connected to UPG with the ability to create a data tunnel to Packet Data Network.

> [!TIP]
> You can find the full list of configurable parameters in the SMC [chart configuration](https://docs.cennso.com/components/smc/latest/reference/chart-configuration.generated.md) document.

### Define Access Point Name (APN)

First, define an APN under the **apn** section. APN defines how a mobile device connects to external data networks and how the data traffic is managed, controlled, and billed. It includes the name of the APN, the MCC and MNC of the mobile core, and an IP pool to assign IP addresses to a user. To accept any APN name without per-APN configuration, see [Wildcard APN](https://docs.cennso.com/components/smc/latest/guides/wildcard-apn.md). The following code snippet shows the APN configuration example:

```yaml
apn:
  name: apn.example.com
  mcc: "001"
  mnc: "001"
  ue_ip_pools:
    - name: sgi
      ranges:
        - from: 10.32.0.2
          to: 10.32.255.254
          type: IPv4
      dns_v4:
        MS-Primary-DNS-Server: 4.2.2.4
        MS-Secondary-DNS-Server: 74.82.42.42
        MS-Primary-NBNS-Server: 127.0.0.1
        MS-Secondary-NBNS-Server: 127.0.0.1
```

### Configure networking

> [!NOTE]
> The terms **grx0**, **sx2**, **grx**, and **sx** in network interface and endpoint names are just examples. They have no special meaning and any sensible identifier can be used. Endpoint names don't need to match or relate to interface names.

SMC acting as PGW allows you to configure multiple network interfaces to forward GTP traffic. To do so, configure one or more dedicated interfaces to handle GTP-C traffic from the GRX access side on the Gn/Gp interface (when acting as a GGSN) and the S5/S8 reference interface. The **networking.interfaces** property specifies the settings of a given network interface, such as interface name, IPv4 or IPv6 address, mask, and routes with which this interface is configured. The physical network interfaces are created based on the [Network Attachment Definition](https://docs.cennso.com/components/smc/latest/guides/networking.md#access-network).

Interfaces for GTP or Sx traffic should have individual VRF settings. This means the underlying Linux network interface is encapsulated in a Linux [VRF-Lite](https://docs.kernel.org/networking/vrf.html) instance, preventing traffic on the underlying interfaces from accidentally or intentionally reaching other VRFs or the pod network.

The example below defines two network interfaces. The **grx0** interface contains connection details for the GRX access side. The **sx2** interface contains connection details for UPF.

```yaml
networking:
  interfaces:
    grx0:
      vrf: epc
      endpoints:
        grx:
          ipv4:
            addr: "192.0.2.0/24"
            routes:
              - to: 192.0.2.65
    sx2:
      vrf: cp
      endpoints:
        sx:
          ipv4:
            addr: "198.51.100.128/28"
  services:
    grx:
      endpoint: grx0.grx
      networkInstance: epc
      type: grx
      direction: access
    sx:
      endpoint: sx2.sx
      networkInstance: cp
      type: sx
```

The **services** section is used to bind specific services to the endpoints. Multiple services can use the same endpoint.
The **services.{SERVICE_NAME}** section creates a new named binding between a service and an endpoint. It contains the following configuration options for the newly created service:
- **services.{SERVICE_NAME}.endpoint** - references the endpoint to which the service is attached. The value of this property has the format of `{INTERFACE_NAME}.{ENDPOINT_NAME}`. `{INTERFACE_NAME}` must refer to the network interface defined in the **networking.interfaces.{INTERFACE_NAME}**. `{ENDPOINT_NAME}` refers to the endpoint referenced by the given interface. 
- **services.{SERVICE_NAME}.networkInstance** - must be set and match the **networkInstance** configured for UPG for interfaces of the `sx` or `grx` type.
- **services.{SERVICE_NAME}.type** - defines the type of a service. The possible values are `grx`, `sx`, `rf`, `ro`, and `gx`. 
- **services.{SERVICE_NAME}.direction** - must be set to `access` for GTP services in the PGW use case.

### Configure UPF nodes connection

Configure a connection to the UPF nodes under the **upg** property. This section must contain details about the interfaces related to UPF, including the address and mask. A reference to the previously defined IP pool (**ip_pool**) is also necessary. See the configuration example:

```yaml
upg:
  instances:
    prox01:
      networking:
        sx:
          ipv4:
            addr: 172.21.15.205/28
      ip_pool: sgi
```

### Add Kubernetes labels and annotations

Optionally, you can also add Kubernetes labels and annotations. If you are using SMC Grafana dashboard, setting the **labels.apn** property is mandatory.

```yaml
labels:
  apn: apn.example.com
```
