Diameter Protocol Explained: Header, AVPs, Messages and Agents
A complete guide to the Diameter protocol (RFC 6733): message header fields and flags, AVP format, base messages CER, DWR and DPR, sessions, routing, and DRA / DEA agents.
Browse all articles
Diameter is the signalling protocol that holds the 4G and IMS core together. Every time an MME authenticates a subscriber, a P-CSCF asks for a voice bearer, an S-CSCF downloads a user profile or a PGW asks the OCS for credit, the request is a Diameter message. If you work on EPC, IMS or VoLTE, reading Diameter fluently is not optional.
This is the first of three Solex Network Solutions articles on Diameter. Here we cover the protocol itself: what it is, the message header field by field, AVPs, the base messages every peer exchanges, and the agents (DRA and DEA) that route it. Part 2 covers result codes and troubleshooting, and part 3 walks through the Cx, Sh and Rx call flows.
What Diameter is
Diameter is an AAA protocol - Authentication, Authorization and Accounting - defined by the IETF in RFC 6733 (which replaced RFC 3588). It was designed as the successor to RADIUS, fixing the things RADIUS does badly in a carrier network:
- Reliable transport. Diameter runs over TCP or SCTP (port 3868, or 5658 for TLS/DTLS) instead of UDP, so retransmission and failover are part of the protocol.
- Peer-to-peer, not client-server. Either side can send a request. A PCRF can push a policy to a PGW (RAR) as easily as the PGW can ask for one (CCR).
- Capability negotiation. Peers tell each other which applications they support before any traffic flows.
- Agents. Relays, proxies and redirect agents are part of the standard, which is what makes a Diameter Routing Agent (DRA) possible.
- Large attribute space. 32-bit AVP codes and vendor IDs let 3GPP define hundreds of its own attributes without collisions.
3GPP builds its interfaces as Diameter applications on top of the base protocol. Each application has its own Application-ID and its own set of commands:
Interface Between Application-ID Typical commands
S6a / S6d MME/SGSN - HSS 16777251 ULR/ULA, AIR/AIA, CLR, IDR, DSR, PUR, NOR
Cx / Dx I/S-CSCF - HSS (SLF) 16777216 UAR, SAR, LIR, MAR, RTR, PPR
Sh AS (TAS) - HSS 16777217 UDR, PUR, SNR, PNR
Rx P-CSCF (AF) - PCRF 16777236 AAR, RAR, STR, ASR
Gx PCEF (PGW) - PCRF 16777238 CCR/CCA (I/U/T), RAR/RAA
Gy / Ro PGW / CSCF - OCS 4 (DCCA) CCR/CCA
S13 MME - EIR 16777252 ECR/ECA
SWx 3GPP AAA - HSS 16777265 MAR, SAR, RTR, PPR
The Diameter message header
Every Diameter message starts with a fixed 20-byte header, followed by any number of AVPs.
Field by field:
- Version (8 bits) - always 1.
- Message Length (24 bits) - length of the whole message in bytes, header included. A mismatch between this value and the bytes actually received gives result code 5015 DIAMETER_INVALID_MESSAGE_LENGTH.
- Command Flags (8 bits):
- R (Request) - 1 for a request, 0 for an answer. Request and answer share the same command code; the R bit is what tells them apart.
- P (Proxiable) - 1 means the message may be relayed, proxied or redirected. If it is 0 the message must be processed by the node that receives it.
- E (Error) - set only in answers that carry a protocol error (the 3xxx class). An answer with E set uses a reduced, generic set of AVPs.
- T (Potentially retransmitted) - set when a request is resent after a transport failover, so the receiver can look for duplicates.
- Reserved (4 bits) - must be zero. Any of them set gives 3008 DIAMETER_INVALID_HDR_BITS.
- Command Code (24 bits) - identifies the command, for example 316 for Update-Location or 272 for Credit-Control.
- Application-ID (32 bits) - identifies the application the message belongs to (16777251 for S6a, 0 for the base protocol). It must match the Auth-Application-Id or Vendor-Specific-Application-Id AVP in the body.
- Hop-by-Hop Identifier (32 bits) - matches an answer to its request on a single hop. Each agent replaces it when forwarding a request and restores the original value on the answer.
- End-to-End Identifier (32 bits) - unique per request for at least four minutes, never changed by agents. Together with Origin-Host it is how duplicates are detected.
AVPs: where the information lives
Everything apart from the header is an AVP (Attribute-Value Pair). Session-Id, Origin-Host, the IMSI in User-Name, the QoS in a Charging-Rule-Install - all AVPs.
- AVP Code (32 bits) - codes up to 255 are shared with RADIUS; 3GPP AVPs use larger codes with Vendor-ID 10415.
- Flags:
- V (Vendor-specific) - the optional Vendor-ID field is present. Every 3GPP-defined AVP has V=1 and Vendor-ID 10415.
- M (Mandatory) - the receiver must understand this AVP. If it does not, it must reject the message with 5001 DIAMETER_AVP_UNSUPPORTED and return the AVP in Failed-AVP.
- P - reserved in RFC 6733 (it used to mean end-to-end encryption).
- AVP Length - header plus data, without padding. Data is padded to a 32-bit boundary.
- Data - typed: OctetString, Integer32/64, Unsigned32/64, Float32/64 or Grouped, plus derived types such as Address, Time, UTF8String, DiameterIdentity (an FQDN), DiameterURI and Enumerated.
A Grouped AVP contains other AVPs. Subscription-Data in an S6a ULA is a grouped AVP several levels deep; Media-Component-Description in an Rx AAR is another.
Base AVPs you will see in almost every message
Code AVP Notes
263 Session-Id first AVP of every session-based message
264 Origin-Host FQDN of the sending node (DiameterIdentity)
296 Origin-Realm realm of the sending node
283 Destination-Realm where the request should go - used for routing
293 Destination-Host specific server, if known
258 Auth-Application-Id application being used
260 Vendor-Specific-Application-Id grouped: Vendor-Id + Auth/Acct-Application-Id
277 Auth-Session-State STATE_MAINTAINED (0) / NO_STATE_MAINTAINED (1)
268 Result-Code base / IETF result
297 Experimental-Result grouped: Vendor-Id + Experimental-Result-Code (3GPP results)
282 Route-Record added by every relay/proxy - loop detection
279 Failed-AVP which AVP caused a 5xxx error
294 Error-Reporting-Host which agent produced a protocol error
278 Origin-State-Id increases on restart - peers learn you rebooted
1 User-Name IMSI on S6a, IMPI on Cx
Reading the message format (ABNF)
Every 3GPP spec defines its messages in the same notation. This is the Cx User-Authorization-Request from TS 29.229:
<UAR> ::= < Diameter Header: 300, REQ, PXY, 16777216 >
< Session-Id >
{ Vendor-Specific-Application-Id }
{ Auth-Session-State }
{ Origin-Host }
{ Origin-Realm }
[ Destination-Host ]
{ Destination-Realm }
{ User-Name }
*[ Supported-Features ]
{ Public-Identity }
{ Visited-Network-Identifier }
[ User-Authorization-Type ]
[ UAR-Flags ]
*[ AVP ]
< >fixed position (Session-Id must come first),{ }required,[ ]optional,*may repeat.REQmeans R bit set,PXYmeans P bit set.- A missing
{ }AVP is answered with 5005 DIAMETER_MISSING_AVP.
The base messages every peer uses
Before any application message flows, two peers must open a connection, exchange capabilities and keep the link alive.
Command Code Purpose
Capabilities-Exchange 257 CER/CEA - identity and supported applications
Device-Watchdog 280 DWR/DWA - keep-alive when the link is idle
Disconnect-Peer 282 DPR/DPA - clean shutdown, with Disconnect-Cause
Re-Auth 258 RAR/RAA - server asks client to re-authorise (Gx, Rx)
Session-Termination 275 STR/STA - client ends a session (Rx)
Abort-Session 274 ASR/ASA - server ends a session (Rx)
Accounting 271 ACR/ACA - offline charging (Rf)
Credit-Control 272 CCR/CCA - Gx and Gy/Ro (RFC 4006)
AA (NASREQ) 265 AAR/AAA - used by Rx
CER and CEA
The CER carries Origin-Host, Origin-Realm, one or more Host-IP-Address, Vendor-Id and Product-Name, and lists the applications the peer supports (Auth-Application-Id, Acct-Application-Id, Vendor-Specific-Application-Id). The CEA answers with Result-Code 2001 and its own list.
Three CEA results matter in practice:
- 2001 DIAMETER_SUCCESS - the connection moves to the Open state and application messages can flow.
- 5010 DIAMETER_NO_COMMON_APPLICATION - the two sides have no application in common. Typically one side has S6a configured as a vendor-specific application and the other expects a plain Auth-Application-Id.
- 3010 DIAMETER_UNKNOWN_PEER - the receiver does not know the Origin-Host and refuses the connection. Check peer configuration and any whitelist on the DRA.
DWR and DWA
When a connection carries no traffic for the watchdog interval (Tw, 30 seconds by default), a peer sends a DWR. A missing DWA marks the connection as suspect, and the client fails over to an alternative peer, setting the T bit on any requests it resends. Origin-State-Id in the DWR tells the other side whether the peer has restarted.
DPR and DPA
A peer that wants to close a connection sends a DPR with Disconnect-Cause: REBOOTING (0), BUSY (1) or DO_NOT_WANT_TO_TALK_TO_YOU (2). The cause tells the other side whether, and when, to reconnect.
Sessions
Most 3GPP applications are session based. A session is identified by the Session-Id, created by the client and kept for the life of the session, for example:
pgw01.epc.mnc010.mcc404.3gppnetwork.org;1700000000;12345
On Gx the session lives from CCR-I to CCR-T. On Rx it lives from the first AAR to the STR. A DRA that load-balances sessions has to keep every message of a session on the same server - session binding - which is why Rx and Gx sessions for the same subscriber must end up at the same PCRF.
Routing: realms, hosts and agents
A Diameter request is routed on Destination-Realm and, when present, Destination-Host, together with the Application-ID. Each node keeps a routing table of realm + application pointing to peers.
- If the Destination-Host is a directly connected peer, the message goes straight to it.
- Otherwise the realm routing table chooses the next hop.
- Every relay and proxy adds a Route-Record with its own identity. Seeing your own identity in Route-Record means a loop: 3005 DIAMETER_LOOP_DETECTED.
RFC 6733 defines four kinds of agent:
- Relay agent - forwards messages based on routing AVPs only. It does not look at or change application AVPs, so one relay can serve every application.
- Proxy agent - routes like a relay but can read and change the message: add or remove AVPs, rewrite realms, enforce policy, reject requests.
- Redirect agent - does not forward at all. It answers with 3006 DIAMETER_REDIRECT_INDICATION and a Redirect-Host, and the client resends the request to that host.
- Translation agent - converts between Diameter and another AAA protocol, typically RADIUS, during migrations.
In an operator network these functions are packaged as:
- DRA (Diameter Routing Agent) - the central router of the core. Instead of a full mesh between every MME, PGW, CSCF, HSS, PCRF and OCS, each node connects to a pair of DRAs. The DRA does realm and host routing, load balancing over server pools, SLF lookups (which HSS holds this subscriber), session binding for Gx/Rx, throttling and overload protection.
- DEA (Diameter Edge Agent) - the DRA at the border, facing roaming partners over IPX. It hides the internal topology (Origin-Host and Origin-Realm rewriting), filters what partners may send, and is the only Diameter node partners can reach. S6a for inbound roamers and S9 for policy both pass through it.
Transport: TCP or SCTP
Most 3GPP deployments use SCTP for Diameter because of multi-homing: one association can use two IP paths, so a single link failure does not drop the connection. TCP is common between DRAs and on smaller networks. Both use port 3868. Whatever the transport, a peer is only usable when the CER/CEA has completed and the connection is in the Open state - a TCP or SCTP connection on its own is not enough.
What to learn next
- Part 2: Diameter result codes and troubleshooting - 3002 DIAMETER_UNABLE_TO_DELIVER, header and AVP errors, and how to read them in a trace.
- Part 3: Cx, Sh and Rx call flows - every message of IMS registration, application server data access and VoLTE QoS.
At Solex Network Solutions we teach Diameter on a live core, decoding S6a, Gx, Cx, Sh and Rx traces message by message in our 4G LTE and EPC and IMS, VoLTE and VoNR courses.
Learn this hands-on
IMS, VoLTE and VoNR
The IMS core from registration to release: P-CSCF, I-CSCF, S-CSCF, TAS and the SIP and Diameter that binds them, plus VoLTE and VoNR end to end.



Discussion
No comments yet. Start the discussion - questions are welcome.
Leave a comment