> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cdf/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/cdf/latest/troubleshooting/gtp-prime.md).

# GTP Prime errors

GTP Prime (GTP') is the protocol used by CDF Sender to transfer Charging Data Records (CDRs) to the Charging Gateway Function (CGF) over the Ga reference point. Each GTP Prime Data Request message contains a sequence number that uniquely identifies the request and allows matching it with the corresponding response.

The GTP Prime sequence number is a 16-bit unsigned integer (`0`-`65535`) that wraps around after reaching its maximum value. CDF Sender maintains a separate sequence number counter for each CGF connection. When sending a CDR, CDF Sender assigns the next available sequence number, increments the counter, and waits for a GTP Prime Data Response with the matching sequence number.

CDF Sender behavior during CDR delivery is controlled by these parameters:

- **spec.config.retries** - number of times to retry sending a CDR if no response is received (default: `1`). For Helm chart configuration: `sender.retries`
- **spec.config.responseTimeout** - time in milliseconds to wait for a GTP Prime Data Response before timing out (default: `1000`). For Helm chart configuration: `sender.response_timeout`
- **spec.config.echo** - interval in milliseconds between GTP Prime Echo Requests to check CGF availability (minimum: `60000`, default: `60000`). For Helm chart configuration: `sender.echo`

CDF Sender consumes CDRs from a Cennso Data Mesh (CDM) work queue service with `workqueue` retention policy. This policy keeps messages in the stream until they are explicitly acknowledged:

- **ack** (acknowledge) - CDF Sender confirms successful CDR delivery to CGF. CDM removes the message from the stream permanently.
- **nack** (negative acknowledge) - CDF Sender indicates delivery failure. CDM makes the message available for redelivery to the same or another consumer.

When CDF Sender nacks a message, CDM redelivers it after the configured **ackWait** timeout (default: `30` seconds). This ensures CDRs are not lost even when CGF is temporarily unavailable.

## Error scenarios

The following diagrams show various error scenarios and their consequences. For brevity, CDF Sender is referred to as CDF.

### No connection available

When no CGF connection is available (all CGFs are marked unavailable due to failed echo requests), CDF Sender immediately nacks the CDR without consuming a sequence number:

```mermaid
sequenceDiagram
Work Queue ->> CDF : CDR1
Note right of CDF : No connection available
CDF ->> Work Queue : CDR1 nack
```

As a result, the CDR is returned to the work queue for redelivery. No sequence number is consumed. This protects CDF Sender from exhausting sequence numbers when CGF is unreachable.

### No response case

When CDF Sender sends a CDR but receives no response within the configured timeout, it retries using the same sequence number. After exhausting all retries, it nacks the CDR.

```mermaid
sequenceDiagram
Work Queue ->> CDF : CDR1
CDF ->> CGF : GTP1 (for CDR1)
CDF ->> CGF : GTP1 (for CDR1), retry
Note right of CDF : Configured number of retries later
CDF ->> Work Queue : CDR1 nack
```

As a result, the CDR is returned to the work queue. Sequence number `1` is consumed but can be reused after the sequence counter wraps around (after `65535` other CDRs). The CDR will be redelivered by CDM after the **ackWait** timeout.

With default settings (`1` retry, `1000`ms timeout), CDF Sender waits `2` seconds total before nacking (initial attempt + 1 retry).

### Response timeout too short for CGF

When the configured **responseTimeout** is shorter than the actual CGF processing time, CDF Sender times out prematurely, retries with the same sequence number, and eventually nacks the CDR. If the CGF response arrives later while CDF Sender has moved to processing another CDR, the late response is matched to the wrong CDR (now reusing that sequence number).

```mermaid
sequenceDiagram
Work Queue ->> CDF : CDR1
CDF ->> CGF : GTP1 (for CDR1)
CDF ->> CGF : GTP1 (for CDR1), retry
Note right of CDF : Configured number of retries later
CDF ->> Work Queue : CDR1 nack
Work Queue ->> CDF : CDR2
CDF ->> CGF : GTP2 (for CDR2)
CGF ->> CDF : GTP1 (for CDR1)
CDF ->> Work Queue : CDR2 nack
```

As a result, CDR2 is incorrectly nacked even though it was never acknowledged by CGF. CDR1 was actually delivered to CGF but CDF Sender doesn't know this. Both CDRs will be redelivered by CDM, potentially causing duplicate CDR1 in CGF.

To avoid this, set **responseTimeout** to at least twice the expected CGF processing time plus network round-trip time. Monitor the **ercdf_cdr_response_lost_total** metric to detect timeout issues.

### Sequence number wraparound collision

This is a rare scenario that occurs when CGF response time is extremely long and the sequence number counter wraps around (after 65535 CDRs) before the original response arrives.

```mermaid
sequenceDiagram
Work Queue ->> CDF : CDR1
CDF ->> CGF : GTP1 (for CDR1)
CDF ->> CGF : GTP1 (for CDR1), retry
CDF ->> Work Queue : CDR1 nack
Work Queue ->> CDF : CDR2
CDF ->> CGF : GTP2 (for CDR2)
CDF ->> CGF : GTP2 (for CDR2), retry
CDF ->> Work Queue : CDR2 nack
Note right of Work Queue : Many CDRs later...
Work Queue ->> CDF : CDR65535
CDF ->> CGF : GTP65535 (for CDR65535)
CDF ->> CGF : GTP65535 (for CDR65535), retry
CDF ->> Work Queue : CDR65535 nack
Work Queue ->> CDF : CDR65536
Note right of CDF : Sequence wraps to 1
CDF ->> CGF : GTP1 (for CDR65536)
CGF ->> CDF : GTP1 (for CDR1)
Note right of CDF : Late response from original CDR1
CDF ->> Work Queue : CDR65536 ack
```

As a result, CDR65536 is incorrectly acknowledged to CDM and permanently removed from the queue without being delivered to CGF. The actual response was for CDR1 (sent `65536` CDRs earlier). CDR65536 is lost.

With default configuration (`retries=1`, `responseTimeout=1000`ms), this requires CGF to take more than `36` hours to respond:

- Time per CDR cycle = (`1000`ms initial + `1000`ms retry) = `2000`ms
- CDRs before wraparound = `65536`
- Total time = `65536` × `2000`ms = `131,072,000`ms ≈ `36.4` hours

To avoid this:

- Ensure CGF responds within reasonable time (seconds, not hours)
- Set **responseTimeout** longer than maximum expected CGF processing time
- Monitor CGF health using the **ercdf_gtp_prime_total{name="echo_response"}** metric
- If CGF consistently takes hours to respond, increase **echo** interval and **responseTimeout**, but investigate CGF performance issues
