Skip to main content

5.6. Peer State Machine

This section contains a finite state machine that MUST be observed by all Diameter implementations. Each Diameter node MUST follow the state machine described below when communicating with each peer. Multiple actions are separated by commas, and may continue on succeeding lines, as space requires. Similarly, state and next state may also span multiple lines, as space requires.

This state machine is closely coupled with the state machine described in [RFC3539], which is used to open, close, failover, probe, and reopen transport connections. In particular, note that [RFC3539] requires the use of watchdog messages to probe connections. For Diameter, DWR and DWA messages are to be used.

The I- prefix is used to represent the initiator (connecting) connection, while the R- prefix is used to represent the responder (listening) connection. The lack of a prefix indicates that the event or action is the same regardless of the connection on which the event occurred.

The stable states that a state machine may be in are Closed, I-Open, and R-Open; all other states are intermediate. Note that I-Open and R-Open are equivalent except for whether the initiator or responder transport connection is used for communication.

A CER message is always sent on the initiating connection immediately after the connection request is successfully completed. In the case of an election, one of the two connections will shut down. The responder connection will survive if the Origin-Host of the local Diameter entity is higher than that of the peer; the initiator connection will survive if the peer's Origin-Host is higher. All subsequent messages are sent on the surviving connection. Note that the results of an election on one peer are guaranteed to be the inverse of the results on the other.

For TLS/TCP and DTLS/SCTP usage, a TLS/TCP and DTLS/SCTP handshake SHOULD begin when both ends are in the closed state prior to any Diameter message exchanges. The TLS/TCP and DTLS/SCTP connection SHOULD be established before sending any CER or CEA message to secure and protect the capabilities information of both peers. The TLS/TCP and DTLS/SCTP connection SHOULD be disconnected when the state machine moves to the closed state. When connecting to responders that do not conform to this document (i.e., older Diameter implementations that are not prepared to received TLS/TCP and DTLS/SCTP connections in the closed state), the initial TLS/TCP and DTLS/SCTP connection attempt will fail. The initiator MAY then attempt to connect via TCP or SCTP and initiate the TLS/TCP and DTLS/SCTP handshake when both ends are in the open state. If the handshake is successful, all further messages will be sent via TLS/TCP and DTLS/SCTP. If the handshake fails, both ends move to the closed state.

The state machine constrains only the behavior of a Diameter implementation as seen by Diameter peers through events on the wire.

Any implementation that produces equivalent results is considered compliant.

State transition table​

state           event           action                  next state
-----------------------------------------------------------------
Closed          Start           I-Snd-Conn-Req          Wait-Conn-Ack
                R-Conn-CER      R-Accept,               R-Open
                                Process-CER,
                                R-Snd-CEA

Wait-Conn-Ack   I-Rcv-Conn-Ack  I-Snd-CER               Wait-I-CEA
                I-Rcv-Conn-Nack Cleanup                 Closed
                R-Conn-CER      R-Accept,               Wait-Conn-Ack/Elect
                                Process-CER,
                                Elect
                Timeout         Error                   Closed

Wait-I-CEA      I-Rcv-CEA       Process-CEA             I-Open
                R-Conn-CER      R-Accept,               Wait-Returns
                                Process-CER,
                                Elect
                I-Peer-Disc     I-Disc                  Closed
                I-Rcv-Non-CEA   Error                   Closed
                Timeout         Error                   Closed

Wait-Conn-Ack/  I-Rcv-Conn-Ack  I-Snd-CER,Elect         Wait-Returns
Elect           I-Rcv-Conn-Nack R-Snd-CEA               R-Open
                R-Peer-Disc     R-Disc                  Wait-Conn-Ack
                R-Conn-CER      R-Reject                Wait-Conn-Ack/Elect
                Timeout         Error                   Closed

Wait-Returns    Win-Election    I-Disc,R-Snd-CEA        R-Open
                I-Peer-Disc     I-Disc, R-Snd-CEA       R-Open
                I-Rcv-CEA       R-Disc                  I-Open
                R-Peer-Disc     R-Disc                  Wait-I-CEA
                R-Conn-CER      R-Reject                Wait-Returns
                Timeout         Error                   Closed

R-Open          Send-Message    R-Snd-Message           R-Open
                R-Rcv-Message   Process                 R-Open
                R-Rcv-DWR       Process-DWR,            R-Open
                                R-Snd-DWA
                R-Rcv-DWA       Process-DWA             R-Open
                R-Conn-CER      R-Reject                R-Open
                Stop            R-Snd-DPR               Closing
                R-Rcv-DPR       R-Snd-DPA               Closing
                R-Peer-Disc     R-Disc                  Closed

I-Open          Send-Message    I-Snd-Message           I-Open
                I-Rcv-Message   Process                 I-Open
                I-Rcv-DWR       Process-DWR,            I-Open
                                I-Snd-DWA
                I-Rcv-DWA       Process-DWA             I-Open
                R-Conn-CER      R-Reject                I-Open
                Stop            I-Snd-DPR               Closing
                I-Rcv-DPR       I-Snd-DPA               Closing
                I-Peer-Disc     I-Disc                  Closed

Closing         I-Rcv-DPA       I-Disc                  Closed
                R-Rcv-DPA       R-Disc                  Closed
                Timeout         Error                   Closed
                I-Peer-Disc     I-Disc                  Closed
                R-Peer-Disc     R-Disc                  Closed