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

# Traffic Detection Function

Traffic Detection Function (TDF) is responsible for inspecting and classifying data traffic within a network to optimise network performance and enforce policies. Session Management Controller (SMC) configured as TDF-C serves the following purposes:

- Traffic management: It helps prioritise and manage network traffic based on the type of application, ensuring optimal use of network resources.
- Policy enforcement: TDF-C works with the Policy and Charging Rules Function (PCRF) to enforce policies related to data usage, such as bandwidth allocation and access restrictions.
- Usage monitoring: TDF-C monitors data usage, which can be used for analytics, billing, and providing insights into network performance and user behaviour.

In more technical terms, TDF-C controls a PGW-U using PFCP (Packet Forwarding Control Protocol) to provide data tunnels to end users on a target data network. TDF operates directly in response to events detected by the User Plane Gateway (UPG) component without the involvement of SGSN (Serving GPRS Support Node) or SGW (Serving Gateway). Whenever an IP packet from an unknown IP address is detected, it triggers a process similar to session creation from a GTP (GPRS Tunneling Protocol) interface. Tunnel details can be controlled from a AAA (Authentication, Authorization, and Accounting) server through the Gx interface, which manages policy instructions. Data usage and time quotas can be charged and controlled through SMC based on events detected in UPG, both for online and offline charging. See the diagram that shows the architecture of SMC acting as TDF:

![TDF use case](https://docs.cennso.com/api/assets/components/smc/3.15/assets/tdf.svg)

The key features of SMC configured as TDF include:

- PFCP for connectivity with the User Plane Function (UPF).
- HTTP OAM API that allows operations and management tasks such as checking node status, draining GTP contexts, and managing GTP sessions.
- Limited Npcf connectivity that facilitates per-IMSI (International Mobile Subscriber Identity) forwarding policies.
- Diameter connections to Online Charging System (OCS), Charging Data Function (CDF), and PCRF nodes for policy and charging functions.
- Preconfigured policy and charging rules that ensure efficient handling of data services.
- AVP filters for Diameter Ro and RADIUS interfaces, allowing control over specific attributes.
- Preconfigured answers for offline OCS nodes, ensuring continued service when the OCS is not available.
- Rate limitation for managing the incoming GTP and outgoing Diameter traffic.

> [!NOTE]
> In this use case, SMC implements a 4G TDF-C as described in 3GPP TS 23.214 and 3GPP TS 23.203.

## Configuration

This section presents the minimal configuration that allows you to set up a minimal TDF-C instance that is connected to TDF-U through the Sx interface, and to PCRF node through the Diameter NASREQ interface.

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

### Define Access Point Name (APN) and TDF configuration

TDF detects user flows from the mobile core to the data network, which is specified by an APN. The APN details listed in the **apn** property include only the APN's name. When **nat.enabled** is set to `true`, flows are reported for authentication to a Diameter NASREQ server, which may provide more information on handling the flow. You can use the **trafficDetectionFilter** property to set the overall filter for detecting new flows.

```yaml
type: tdf
nodeID: test.tdf.location.de
trafficDetectionFilter:
  - permit out ip from 10.0.0.0/8 to any
apn:
  name: test.apn.name
nat:
  enabled: true
  type: cgnat
```

### Configure networking

> [!NOTE]
> The terms **nasreq**, **sx0**, 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 TDF allows you to configure multiple network interfaces. You must configure а dedicated network interface to communicate with UPG and PCRF. The **sx** network interface is used for communication between SMC and UPG. The **nasreq** network interface is used to carry Diameter NASREQ traffic. The **networking.interfaces** property specifies the settings to apply to the 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/3.15/config/networking.md#access-network).

Interfaces for the 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 **nasreq** interface contains connection details for the Diameter NASREQ connection. The **sx0** interface contains connection details for UPF.

```yaml
networking:
  interfaces:
    nasreq:
      endpoints:
        nasreq:
          ipv4:
            addr: "198.51.100.10/24"
    sx0:
      vrf: cp
      endpoints:
        sx:
          ipv4:
            addr: "198.51.100.138/28"
  services:
    nasreq:
      endpoint: "nasreq.nasreq"
      type: nasreq
    sx:
      endpoint: sx0.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 TDF use case.

### Specify AAA details

TDF often needs to contact an authorisation server to get information on handling a specific flow. In such cases, follow the guidelines for [Diameter configuration](https://docs.cennso.com/components/smc/3.15/config/aaa/diameter-concepts.md) to establish a dedicated connection to a NASREQ server. Use the **transportOpts** property to increase the send and receive buffers. See the configuration example:

```yaml
aaa:
  nasreq:
    enabled: true
    standalone: true
    destinations:
      - nasreq.dest
    destinationRealm: tposs.location.de
    originFqdn: scg6.testapn.com
    originRealm: the.realm.off.e.g.tposs
    transportOpts:
      recbuf: 1048576
      sndbuf: 1048576
```

### 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. You must set the IP pools for each network interface card (NIC) in UPGs. See the configuration example:

```yaml
upg:
  instances:
    inst01:
      networking:
        sx:
          ipv4:
            addr: "192.168.1.1/24"
      nat:
        pools:
          pool-us:
            nic: sgi-us
          pool-ca:
            nic: sgi-ca
```

### 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
```
