Back

Gy Interface Deep Dive: The Complete Guide to Online Charging

Master the Gy online charging interface — DCCA protocol, SCUR/ECUR/IEC modes, CCR/CCA message flows, AVP definitions, quota management, and practical troubleshooting for PGW/UGW and OCS.

Gy Interface Deep Dive: The Complete Guide to Online Charging

The Gy interface is the backbone of prepaid mobile data services. It connects the PGW/UGW (Packet/User Gateway) to the OCS (Online Charging System) using the Diameter Credit Control Application (DCCA) protocol. Every time a prepaid subscriber browses the web, streams video, or sends an MMS, the Gy interface handles the real-time credit check.

This guide covers everything you need to know — from protocol fundamentals to practical troubleshooting.

What is the Gy Interface?

The Gy reference point is defined in 3GPP TS 32.291 and operates between the PGW (in EPC) or UGW (Huawei) and the OCS. It enables online charging — meaning the network verifies subscriber credit in real-time before granting service.

UE → eNodeB → SGW → PGW/UGW ←————→ OCS
                          |
                      Gy Interface
                    (Diameter DCCA)
                    TCP/SCTP:3868
                    App-ID: 4

Key Characteristics

PropertyValue
ProtocolDiameter Credit Control Application (DCCA)
RFCRFC 4006
TransportTCP or SCTP
Port3868 (IANA)
Application-ID4
Command-Code272 (Credit-Control)
3GPP SpecTS 32.291, TS 32.299

Protocol Stack

┌─────────────────────────────────┐
│     DCCA (RFC 4006)             │  ← Gy Application
├─────────────────────────────────┤
│     Diameter Base (RFC 6733)    │  ← Protocol framework
├─────────────────────────────────┤
│     TCP or SCTP                 │  ← Transport (port 3868)
├─────────────────────────────────┤
│     IP                          │  ← Network layer
└─────────────────────────────────┘

Diameter Message Header

Every Diameter message starts with a 20-byte header:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Version    |                 Message Length                |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| command flags |                  Command-Code                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Application-ID                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      Hop-by-Hop Identifier                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      End-to-End Identifier                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Command Flags:

BitNameDescription
RRequest1 = Request message, 0 = Answer
PProxiableMay be relayed or proxied
EErrorProtocol error in message
TRetransmittedPossible duplicate after failover

Online Charging Modes

The Gy interface supports four distinct charging modes, each suited for different service scenarios.

SCUR — Session Charging with Unit Reservation

The primary and most common mode. Used for volume/time-based data charging.

How SCUR Works:
═══════════════

1. User starts data session
2. UGW sends CCR-I → OCS (request quota)
3. OCS reserves quota from subscriber account
4. UGW grants service → user consumes data
5. When quota runs low → UGW sends CCR-U (request more)
6. Session ends → UGW sends CCR-T (final report)
7. OCS debits exact amount from account

When to use: Data sessions, internet browsing, video streaming, any continuous data service.

ECUR — Event Charging with Unit Reservation

Used for event-based charging where the outcome is a discrete event.

ECUR Flow:
══════════
1. Event detected → CCR-I to OCS
2. OCS grants quota for the event
3. Event completes → CCR-T reports usage
4. OCS debits or refunds accordingly

When to use: MMS send/receive, content downloads, app purchases.

eECUR — Enhanced ECUR

The older 3GPP definition with CC-Update interaction during the event. Supports quota updates for long-running events.

IEC — Immediate Event Charging

No reservation — OCS charges immediately. The most signaling-efficient mode.

When to use: SMS, USSD, any service with guaranteed outcome.

Mode Comparison

ModeSession TypeReservationTypical UseSignaling
SCURSingle DCCYes (chunks)Data, streamingHigh
ECURSeparate DCCYes (event)MMS, downloadsMedium
eECURSeparate DCCYes + UpdateLong eventsMedium-High
IECSeparate DCCNoSMS, USSDLow

CCR/CCA Message Flows

Credit-Control-Request (CCR)

Command-Code 272, Direction PGW/UGW → OCS.

<CCR> ::= <Diameter Header: 272, REQ, PXY>
  <Session-Id>                           // Unique per session
  {Origin-Host}                           // PGW/UGW hostname
  {Origin-Realm}                          // PGW/UGW realm
  {Destination-Realm}                     // OCS realm
  {Auth-Application-Id}                   // Must be 4
  {Service-Context-Id}                    // e.g., "32260@3gpp.org"
  {CC-Request-Type}                       // 1=I, 2=U, 3=T, 4=E
  {CC-Request-Number}                     // Increments per request
  [Requested-Action]                      // For EVENT_REQUEST
  [User-Name]                             // IMSI/MSISDN
  *[Subscription-Id]                      // Subscriber identity
  [Termination-Cause]                     // Reason for session end
  [Multiple-Services-Indicator]           // MSCC support flag
  *[Multiple-Services-Credit-Control]     // Per-rating-group
  [Service-Information]                   // PS-Information

CC-Request-Type Values:

ValueNameWhen Sent
1INITIAL_REQUESTFirst CCR of a new session
2UPDATE_REQUESTQuota threshold or exhaustion
3TERMINATION_REQUESTSession end
4EVENT_REQUESTEvent-based charging

Credit-Control-Answer (CCA)

Command-Code 272, Direction OCS → PGW/UGW.

<CCA> ::= <Diameter Header: 272, PXY>
  <Session-Id>
  {Result-Code}                           // 2001=SUCCESS
  {Origin-Host}                           // OCS hostname
  {Origin-Realm}
  {Auth-Application-Id}                   // 4
  {CC-Request-Type}                       // Echoes request
  {CC-Request-Number}                     // Echoes request
  [CC-Session-Failover]                   // 0=No, 1=Yes
  *[Multiple-Services-Credit-Control]     // Granted quotas
  [Credit-Control-Failure-Handling]       // 0/1/2
  [Validity-Time]                         // Quota validity

Key AVPs (Attribute-Value Pairs)

Core Session AVPs

AVP NameCodeTypeDescription
Session-Id263OctetStringUnique per-session identifier
Auth-Application-Id258Unsigned32Must be 4 for DCCA
Service-Context-Id461OctetStringCharging context identifier
CC-Request-Type416Unsigned321=I, 2=U, 3=T, 4=E
CC-Request-Number415Unsigned32Sequence per session
Result-Code268Unsigned322001=SUCCESS
Origin-Host264OctetStringSender hostname
Origin-State-Id278Unsigned32Restart detection

Quota & Credit AVPs

AVP NameCodeTypeDescription
Granted-Service-Unit431GroupedQuota granted by OCS
Used-Service-Unit446GroupedUnits consumed
CC-Time420Unsigned32Time quota (seconds)
CC-Total-Octets421Unsigned64Total volume quota
CC-Input-Octets412Unsigned64Uplink volume
CC-Output-Octets414Unsigned64Downlink volume
Rating-Group432Unsigned32Charging classification
CC-Unit-Type454Unsigned321=TIME, 2=MONEY, 4=TOTAL_OCTETS

Threshold & Timer AVPs

AVP NameCodeDescription
Time-Quota-Threshold868Trigger update when time remaining below threshold
Volume-Quota-Threshold869Trigger update when volume remaining below threshold
Quota-Consumption-Time881Idle timeout before quota stops (discontinuous traffic)
Validity-Time448How long granted quota remains valid

Failure Handling AVPs

AVP NameCodeValues
CC-Session-Failover4180=Not Supported, 1=Supported
Credit-Control-Failure-Handling4270=TERMINATE, 1=RETRY, 2=CONTINUE
Direct-Debiting-Failure-Handling4280=TERMINATE_SERVICE, 1=CONTINUE_SERVICE
Final-Unit-Action4491=TERMINATE, 2=REDIRECT, 3=RESTRICT

PS-Information AVP

The Service-Information AVP carries packet-switched charging data:

Service-Information ::= <AVP Header: 873>
  [PS-Information]
    [3GPP-Charging-Id]           // Bearer charging ID
    [3GPP-PDP-Type]              // IPv4/IPv6/IPv4v6
    *[PDP-Address]               // UE IP
    [Called-Station-Id]          // APN name
    [SGSN-Address]               // SGSN IP
    [GGSN-Address]               // GGSN/PGW IP
    [3GPP-IMSI-MCC-MNC]          // MCC+MNC
    [3GPP-RAT-Type]              // GERAN/UTRAN/E-UTRAN
    [3GPP-User-Location-Info]     // Cell ID, TAC
    [3GPP-MS-TimeZone]           // UTC offset
    [Charging-Rule-Base-Name]    // PCRF rule group
    [Serving-Node-Type]          // SGSN/MME/PGW
    [Start-Time]                 // Session start epoch
    [Stop-Time]                  // Session end epoch

Termination-Cause Values

CodeNameDescription
1DIAMETER_LOGOUTUser disconnected
2DIAMETER_SERVICE_NOT_PROVIDEDPre-auth disconnect
3DIAMETER_BAD_ANSWERMalformed auth answer
4DIAMETER_ADMINISTRATIVEAdmin disconnect (ASR)
5DIAMETER_LINK_BROKENTransport failure
6DIAMETER_AUTH_EXPIREDSession time expired
7DIAMETER_USER_MOVEDUser moved to another node
8DIAMETER_SESSION_TIMEOUTInactivity timeout

Common Result Codes

CodeNameMeaning
2001DIAMETER_SUCCESSRequest succeeded
3002DIAMETER_UNABLE_TO_DELIVERCannot reach home server
4012DIAMETER_CREDIT_LIMIT_EXCEEDEDNo credit / quota exhausted
4013DIAMETER_USER_UNKNOWNSubscriber not found
5012UNABLE_TO_COMPLYOCS processing error
5014DIAMETER_MISSING_AVPRequired AVP missing

Complete SCUR Call Flow

UE → eNodeB → SGW → UGW/PGW ←————→ OCS

Step 1: [CCR-I] UGW → OCS
  CC-Request-Type = 1 (INITIAL)
  Session-Id = "ugw.operator.com;123456;1"
  Service-Context-Id = "32260@3gpp.org"
  Subscription-Id: IMSI = 001012345678901
  Rating-Group = 1
  PS-Information: APN="internet", RAT=E-UTRAN

Step 2: [CCA-I] OCS → UGW
  Result-Code = 2001 (SUCCESS)
  Granted-Service-Unit: CC-Total-Octets = 100MB
  CC-Session-Failover = 1 (SUPPORTED)
  Volume-Quota-Threshold = 10MB

Step 3: [CCR-U] UGW → OCS  (after 90MB consumed)
  CC-Request-Type = 2 (UPDATE)
  CC-Request-Number = 1
  Used-Service-Unit: CC-Total-Octets = 90MB
  Requested-Service-Unit: CC-Total-Octets = 50MB

Step 4: [CCA-U] OCS → UGW
  Result-Code = 2001
  Granted-Service-Unit: CC-Total-Octets = 50MB

Step 5: [CCR-T] UGW → OCS  (user disconnects)
  CC-Request-Type = 3 (TERMINATION)
  CC-Request-Number = 2
  Used-Service-Unit: CC-Total-Octets = 35MB
  Termination-Cause = 1 (LOGOUT)

Step 6: [CCA-T] OCS → UGW
  Result-Code = 2001
  Total charged: 125MB

Troubleshooting Guide

Common Issues and Fixes

1. CCR-I Timeout (no CCA response)

  • Check TCP/SCTP connectivity on port 3868
  • Verify OCS is reachable and Diameter peer is up
  • Check firewall rules between UGW and OCS

2. Result-Code 4012 (CREDIT_LIMIT_EXCEEDED)

  • Subscriber has no credit or quota
  • Normal for prepaid subscribers with zero balance
  • UGW should deny service access

3. Result-Code 5012 (UNABLE_TO_COMPLY)

  • OCS cannot process the request
  • Check Service-Context-Id configuration
  • Verify rating group exists in OCS

4. Session Failover Not Working

  • Verify CC-Session-Failover = 1 in CCA
  • Check secondary OCS is configured and reachable
  • Verify Origin-State-Id increments on restart

5. Quota Exhaustion During Active Session

  • Volume-Quota-Threshold too high — lower it (e.g., 10% of quota)
  • CCR-U not being sent — check threshold configuration
  • OCS not granting sufficient quota in CCA-U

Debug Commands

# View active Gy sessions
display diameter session all

# Check Gy peer status  
display diameter peer all

# Monitor CCR/CCA messages
debugging diameter credit-control all

# View quota statistics
display charging quota statistics

# Check OCS connectivity
display diameter connection

Wireshark Filters

# All Diameter messages
diameter

# Only CCR/CCA (Gy traffic)
diameter.cmd.ccr

# Filter by Result-Code
diameter.result_code != 2001

# Filter by Application-Id (DCCA = 4)
diameter.application_id == 4

# CCR with specific IMSI
diameter and diameter.imsi == "001012345678901"

# Quota exhaustion (Result-Code 4012)
diameter.result_code == 4012

Best Practices

  1. Set appropriate quota thresholds — Request new quota at 80-90% consumption to avoid service interruption
  2. Enable session failover — Configure CC-Session-Failover = 1 for high availability
  3. Use Multiple-Services-Credit-Control — Per-rating-group charging for granular billing
  4. Monitor Quota-Consumption-Time — Set for discontinuous traffic (e.g., social media, messaging)
  5. Configure Credit-Control-Failure-Handling = 2 (CONTINUE) — Don’t drop sessions on transient OCS failures
  6. Regular DWR/DWA health checks — Ensure Diameter peer liveness monitoring is active

References

  • 3GPP TS 32.291 — Telecommunication management; Charging management; Diameter charging application
  • 3GPP TS 32.299 — Diameter charging applications
  • RFC 4006 — Diameter Credit-Control Application
  • RFC 6733 — Diameter Base Protocol
  • RFC 3588 — Diameter Base Protocol (obsoleted by 6733)