> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/upg/2.16/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.16/features/ipfix.md).

# IP Flow Information Export (IPFIX)

User Plane Gateway (UPG) supports exporting per-flow data using the IPFIX protocol, as defined in RFC5470 (architecture), RFC7011 (protocol), and RFC8158 (NAT extension).

## Terminology

- Flow - set of packets sent from one endpoint to another (UE to outside or outside to UE), Packets share the same **src**, **dst**, **proto**, **src_port**, and **dst_port** fields. UPG works with biflows and IPFIX reports contain information for both directions of the bidirectional flow.
- Uplink direction - traffic direction from UE
- Downlink direction - traffic direction to UE

## Reporting

Three conditions can trigger IPFIX flow reporting:

1. Flow creation
1. Intermediate reports, if the reporting interval is configured
1. Flow termination

The source address of the IPFIX report always points to UE, even if UE is not the initiator of this flow. It is not always guaranteed to detect the initiator of the biflow but the `biflowDirection` field provides a good estimation, which can be used for statistic purposes.

The side of PFCP session directed towards UE is determined by "Source Interface" IE in PDRs or "Destination Interface" IE in FARs. One of them should have the value "Access" providing UE flow direction.

Multiple reports can be batched in a single UDP packet depending on the network load.

Because of the unreliability of UDP messaging and multiple unpredictable reliability requirements, you should always assume that a fraction of reports can be missing.

### Reporting on creation

The flow creation report is triggered by sending any packet which is not a part of the existing flow. The report is sent as soon as it determines all the required information for the corresponding flow, such as PDRs and FARs.

It is not guaranteed to send the creation report when the flow was destroyed before the determination of PDRs and FARs as this flow was finished.

### Reporting on flow termination

Flow termination happens when:

- Session is removed by a Control Plane event, such as session deletion request or association loss, or when a flow timeout occurs.
- Flow timeout happens when there is no traffic received for this flow for the duration of the flow timeout. The timeout is configurable per protocol.

There is no difference in IPFIX reporting, no matter if the report was triggered by a flow timeout or a session deletion.

### Reporting on intermediate report timer

The reporting interval of zero means that no intermediate reports are sent.

A configured reporting interval is the minimal time duration between the reporting intervals. The real value varies depending on the flow traffic presence.

## Available Information Elements

Information Elements provided in the report depend on the configured IPFIX policy and the flow IP version. The provided elements used in the report do not depend on the reporting trigger. IE reference information can be obtained in "IP Flow Information Export (IPFIX) Entities" IANA-IPFIX registry assignments.

### IPFIX policy `NatEvent`

| IPFIX IE Name | Proto | Description |
|---|---|---|
| sourceIPv4Address | IPv4 | UE address |
| sourceIPv6Address | IPv6 | UE address |
| destinationIPv4Address | IPv4 | Uplink endpoint address |
| destinationIPv6Address | IPv6 | Uplink endpoint address |
| postNATSourceIPv4Address | IPv4 | External NAT allocated address of the flow if NAT is used |
| postNAPTSourceTransportPort | IPv4 | External NAT allocated port of the flow if NAT is used |
| natEvent | IPv4 | Change of the state of NAT allocation. Details in the additional section below |
| protocolIdentifier | any | Protocol number of the IP packet |
| mobileIMSI | any | UE IMSI |
| initiatorOctets | any | Bytes seen in the uplink direction |
| responderOctets | any | Bytes seen in the downlink direction |
| initiatorPackets | any | Packets seen in the uplink direction |
| responderPackets | any | Packets seen in the downlink direction |
| flowStartMilliseconds | any | Time of the first seen packet of the flow |
| flowEndMilliseconds | any | Time of the last seen packet of the flow |
| sourceTransportPort | any | Uplink source port |
| destinationTransportPort | any | Uplink endpoint port |
| biflowDirection | any | Direction in which the flow was created. Details in the additional section below |

### IPFIX policy `FlowUsage`

| IPFIX IE Name | Proto | Description |
|---|---|---|
| sourceIPv4Address | IPv4 | UE address |
| sourceIPv6Address | IPv6 | UE address |
| destinationIPv4Address | IPv4 | Uplink endpoint address |
| destinationIPv6Address | IPv6 | Uplink endpoint address |
| protocolIdentifier | any | Protocol number of the IP packet |
| initiatorOctets | any | Bytes seen in the uplink direction |
| responderOctets | any | Bytes seen in the downlink direction |
| initiatorPackets | any | Packets seen in the uplink direction |
| responderPackets | any | Packets seen in the downlink direction |
| flowStartMilliseconds | any | Time of the first seen packet of the flow |
| flowEndMilliseconds | any | Time of the last seen packet of the flow |
| VRFname | any | If forwarding policy is defined - name of forwarding policy, otherwise - egress VRF name |
| interfaceName | any | Interface name in the direction to uplink |
| observationDomainName | any | Configured observation domain name |
| observationPointId | any | Configured observation point id |
| biflowDirection | any | Direction in which the flow was created. Details in the additional section below |

### NAT event field

The **natEvent** field can have values `create(4)`, `delete(5)`, and `reserved(0)` in the case that there is no event to report.

In the case of UPG, this field is not NAT-specific and if NAT is not configured, it relates to the flow creation or removal.

The **natEvent** field populated with values in the corresponding conditions:

- `create(4)` - in the first IPFIX report for the flow
- `delete(5)` - in the last IPFIX report for the flow
- `reserved(0)` - in intermediate IPFIX reports for the flow

If the flow haven't finished the initialisation (no downlink packets in the case of connection failure), it may be that the `delete(5)` event is sent as the first and the last report for the flow without the `create(4)` report.

### biflowDirection field

The **biflowDirection** field can have the following values:

- `initiator(1)` if the flow was created by traffic from the UE side
- `reverseInitiator(2)` if the flow was created by traffic in the direction to UE

This value should not be considered reliable, since it's not always possible to determine the correct direction of the flow.

### IPFIX reporting policy configuration priority

You can configure the IPFIX reporting policy per NWI or for a session in the PFCP Forwarding Action Rule (FAR) through a vendored IE. The policy set in FAR applies only to flows using that FAR. If both NWI and FAR have reporting policies, the FAR policy takes priority. To disable IPFIX reporting for a specific FAR enabled on the NWI, use the special policy name `none` to override the NWI policy.

## Configuration

UPG supports exporting IPFIX data, but for proper setup, you must configure IPFIX exporter and IPFIX setting for each NWI (Network Instance). Follow these steps to configure IPFIX and ensure it works correctly:

1. Configure IPFIX exporter in the **ipfixExporters** section which includes the IPFIX collector setup:

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

   UPG can send IPFIX data over a VPP interface, but the current configuration does not support Kubernetes default networks (such as Calico). The **collectorAddress** must be specified in FPPNetwork. The recommended network is Control Network Sx which is tested and works reliably. Since IPFIX collectors are identified by their IP addresses, each IP can only be associated with one collector (a VPP internal limitation). Additionally, **collectorAddress** must match the **ipfixCollector** setting in the **instance.<name>.networking.sgi**. If they do not match, IPFIX does not work.

2. Configure IPFIX for each uplink NWI in the **instances.{NAME}.networking** section. To set up **ipfixPolicy**, choose one of the preconfigured template:

   - `FlowUsage` - for the Packet Gateway (PGW) use case
   - `NatEvent` - for the Traffic Detection Function (TDF) use case, with NAT information

   If **ipfixPolicy** is not set, IPFIX data is not sent by default, but it can be activated per session.

   - See the configuration example for the PGW use case:

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

      In the PGW use case, you can set the **ipfixPolicy** in the NWI configuration. If you don’t set it, the PFCP Session Establishment Request should include the IPFIX Policy Information Element (IE), with a valid policy name (`FlowUsage`).

   - See the example for the TDF use case. For TDF, define IPFIX settings in the NAT pool configuration:

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

3. To check the IPFIX configuration, run this VPP CLI command:

   ```bash
   vppctl sh upf nwi
   ```

   See the output example:

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