Version

Core Components

Diameter Stack

The DiameterStackImpl class is responsible for managing the core Diameter protocol operations, including session management, message processing, network communication, and interaction with various Diameter application providers. It acts as the central entity within the Diameter protocol stack, coordinating the flow of messages, routing, and session lifecycle.
This class is maintaining communication between different Diameter applications and network entities, handling the reception and transmission of Diameter messages, and managing session-based interactions.

Fields

Name

Description

responseTimeout

Defines the timeout period for awaiting a response

idleTimeout

Defines the timeout for idle sessions

duplicateTimeout

Defines the timeout for checking duplicate messages

duplicatesCheckPeriod

Interval for periodically checking duplicate messages

sessionStorage

Responsible for storing and managing Diameter sessions

incomingRequestsStorage

Manages incoming Diameter requests

networkManager

Manages network communication and message transmission

globalParser

The parser responsible for interpreting Diameter messages and commands

sessionCounter

Tracks the total number of sessions created by the stack

hopByHopCounter

Used to generate unique hop-by-hop identifiers for messages

classLoader

Class loader for loading and managing Diameter classes dynamically

stackID

Unique identifier for the Diameter stack, useful for identifying instances in a clustered environment.

messagesSentByType, messagesReceivedByType, errorsSentByType, errorsReceivedByType

Various maps that track metrics about sent, received, and erroneous messages by type and application

queue

Task queue used to handle periodic tasks and timers

periodicQueue

Manages periodic tasks such as checking for idle sessions and duplicates

 

Network Communication

The DiameterStackImpl interacts with the network using the NetworkManager. This entity is responsible for sending and receiving messages over the network. The stack ensures that all messages are routed correctly, sessions are created as necessary, and any errors encountered during communication are handled appropriately. It also supports both synchronous and asynchronous message handling using callbacks.

Session Lifecycle and Management

The DiameterStackImpl is responsible for managing the entire lifecycle of a Diameter session. This includes creating new sessions for incoming requests, storing session state, tracking session metrics, and terminating sessions when necessary. Each session is uniquely identified by a session ID, which is generated by the stack. The session storage ensures that sessions can be retrieved efficiently and that their state is preserved throughout the message exchange.

Constructor

The constructor initializes the stack with various configurations, including timeouts, network parameters, and session management. It sets up the NetworkManager, DiameterParser, session storages, and various factories that handle message creation and processing.

public DiameterStackImpl(ClassLoader classLoader, IDGenerator<?> idGenerator, CountableQueue<Task> queue, PeriodicQueuedTasks<Timer> periodicQueue, int workerThreads, String localHost, String productName, Long vendorId, Long firmwareRevision, Long idleTimeout, Long responseTimeout, Long reconnectTimeout, Long duplicateTimeout, Long duplicatesCheckPeriod) throws Exception

Key Methods

Name

Description

Parameters

sendRequest(DiameterRequest message, AsyncCallback callback)

Sends a Diameter request message through the NetworkManager.

message: The DiameterRequest to be sent.

callback: The AsyncCallback to handle the response asynchronously.

sendAnswer(DiameterAnswer message, String destinationHost, String destinationRealm, AsyncCallback callback)

Sends a Diameter answer message, specifying the destination host and realm.

message: The DiameterAnswer to be sent.

destinationHost: The target host for the message.

destinationRealm: The target realm for the message.

callback: The AsyncCallback to handle the response asynchronously.

registerCustomProvider(DiameterProvider<?, ?, ?, ?, ?> provider, Package parentPackage)

Registers a custom provider for handling Diameter messages related to a specific application or package.

provider: The DiameterProvider to register.

parentPackage: The parent package of the provider.

messageReceived(DiameterMessage message, String linkID)

Processes an incoming DiameterMessage. Based on the message type, it updates relevant metrics and routes the message to the appropriate DiameterProvider or session.

message: The incoming DiameterMessage (request or answer).

linkID: The network link associated with the message.

messageSent(DiameterMessage message, String linkID)

Tracks the sending of a DiameterMessage, updating relevant metrics and routing information for the message.

message: The sent DiameterMessage.

linkID: The network link associated with the message.

getProvider(Class<?> providerClass)

Returns the registered DiameterProvider associated with the specified class.

providerClass: The class of the provider to retrieve.

generateNewSessionID()

Generates a new unique session ID for use in a Diameter session. The session ID is created using the local host name, a counter, and the stack ID.

Returns: a String representing the new session ID.

 

getNextHopByHopIdentifier()

Generates the next hop-by-hop identifier for a message. This identifier is unique within the Diameter stack and is used to correlate requests and responses.

Returns: a Long representing the next hop-by-hop identifier.

 

newIncomingSession(ApplicationID applicationID)

Registers a new incoming session based on the given ApplicationID.

applicationID: The ApplicationID of the incoming session.

newOutgoingSession(ApplicationID applicationID)

Registers a new outgoing session based on the given ApplicationID.

applicationID: The ApplicationID of the outgoing session.

sessionEnded(Long resultCode, ApplicationID applicationID)

Tracks the termination of a session by logging the result code and ApplicationID.

resultCode: The result code associated with the session termination.

applicationID: The ApplicationID of the terminated session.

stop()

Stops the Diameter stack, shutting down the NetworkManager and releasing any associated resources.


 


Diameter Provider

The DiameterProviderImpl class is an abstract implementation of the DiameterProvider interface. It plays a central role in managing Diameter sessions, message handling, and client-server communication in the Diameter protocol stack. The provider is responsible for receiving, routing, and processing Diameter messages while managing session lifecycles for both clients and servers.
This class supports the creation of Diameter-related objects through various factories, manages listeners for session events, and integrates with the DiameterStack to maintain a cohesive protocol workflow.

Key Functions

Session Management: The provider manages both client and server session listeners, storing and removing them as necessary. These listeners handle important session events such as requests and responses.
Message Processing: The DiameterProviderImpl class is responsible for processing both incoming and outgoing Diameter messages, ensuring that they are routed to the correct session, or in case of a new request, initiating a new session.
Integration with DiameterStack: The provider interacts with the DiameterStack to retrieve and store sessions, send messages, and track message metrics. It uses the stack’s session storage and callback mechanisms to asynchronously handle message processing.

The class uses several factories:
AVP Factory (A): For creating AVP objects.
Message Factory (M): For creating Diameter requests and answers.
Session Factory (F): For managing session creation and lifecycle.

Session Handling

The DiameterProviderImpl is responsible for managing Diameter sessions and their respective listeners. It ensures that when a message is received, it is routed to the correct session based on the session ID. If no session exists for a request message, a new session is created and stored in the DiameterStack.
For both client and server-side operations, the provider maintains separate listener maps (clientListenersMap and serverListenersMap), which are updated dynamically as sessions are created or terminated.

Message Routing

The onMessage() method is the core of message routing. It ensures that incoming messages are directed to the correct session or that a new session is created if necessary. The provider leverages DiameterSessionStorage to retrieve or store sessions and relies on the AsyncCallback mechanism to handle asynchronous message processing.

Constructor

Initializes a DiameterProviderImpl instance, responsible for managing Diameter sessions, message handling, and communication with the Diameter stack.

public DiameterProviderImpl(DiameterStack stack, A avpFactory, M messageFactory, String packageName)

Parameters:
stack: The DiameterStack instance used for routing and message processing.
avpFactory: Factory to generate AVPs required for Diameter messages.
messageFactory: Factory to create Diameter messages (requests and answers).
packageName: The package name associated with the provider.

Diameter Session

The DiameterSessionImpl class serves as the foundation for managing Diameter sessions, encapsulating the key logic for processing requests, handling timers, and maintaining session states. This class is primarily responsible for managing the lifecycle of Diameter protocol sessions, ensuring they operate correctly within the Diameter protocol's stateful communication framework. By abstracting these operations, this class serves as a reusable component for various Diameter applications (Credit Control, Authentication, etc.) to manage sessions consistently and reliably.

Key Functions

Session State Management: Keeps track of the session state, including session initialization, sending and receiving Diameter messages, and session termination.
Timers Management: Manages idle and send timers to track the session’s activity and ensure that resources are efficiently managed.
Handling Incoming and Outgoing Messages: Processes incoming Diameter requests and responses, validates them, and interacts with other components of the Diameter protocol stack.
Retry Mechanism: Includes a mechanism to retry sending requests if necessary.

Constructors

Name

Description

DiameterSessionImpl(Long applicationID)

This constructor initializes the session with the provided applicationID. It is particularly useful in scenarios where the session needs to be deserialized or initialized with minimal state (e.g., in a clustered environment or after a crash recovery).

DiameterSessionImpl(String sessionID, Long applicationID, String remoteHost, String remoteRealm, DiameterProvider<?, ?, ?, ?, ?> provider)

This is the primary constructor that initializes a session with full context, including the session ID, application ID, remote host/realm, and the associated provider.

Fields

Name

Description

provider

The provider associated with this session, responsible for message handling and protocol operations.

sessionID

A unique identifier for this Diameter session. It is used to track and manage the session lifecycle across the network.

applicationID:

The application ID identifies the specific Diameter application that this session is part of (e.g., Credit-Control, NASREQ, etc.).

idleTimerID and sendTimerID

Unique IDs for idle and send timers, which are used to track timeouts and trigger appropriate session events (e.g., termination or retries).

state

The current state of the session (e.g., OPEN, CLOSED). This field is used to track session progress and control its lifecycle.

remoteHost and remoteRealm

The remote host and realm represent the remote peer participating in this session.

lastSentRequest

The last Diameter request sent from this session, which is used for validation when a response is received.

isRetry

A flag indicating whether this session is in a retry state, typically used when re-sending a failed request.

Methods

Name

Description

Session Management

getID()

Returns the session ID, which is the unique identifier for this Diameter session.

getApplicationID()

Returns the application ID, indicating which Diameter application (e.g., Credit Control, Authentication) this session belongs to.

terminate(Long resultCode)

Terminates the session and removes it from the session storage. It also stops all associated timers (idle and send). The result code (such as DIAMETER_SUCCESS or DIAMETER_SESSION_TIMEOUT) indicates the reason for termination.

getSessionState() and setSessionState(SessionStateEnum state)

Get and set the current state of the session, helping to manage its lifecycle.

Timer Management

restartIdleTimer(Long time)

Restarts the idle timer, which tracks how long the session remains inactive. If the session is idle for too long, it may be terminated.

stopIdleTimer() and startIdleTimer()

Stop or start the idle timer. These methods are crucial for tracking whether the session is active or not.

restartSendTimer()

Restarts the send timer, which tracks the time between sending requests and receiving responses. This ensures that requests are not left hanging indefinitely.

stopSendTimer() and startSendTimer()

Start or stop the send timer, managing the waiting period after sending a request.

Message Handling

requestReceived(DiameterRequest request, String linkID, AsyncCallback callback)

This method is invoked when a Diameter request is received. It restarts the idle timer and ensures the session is updated in the storage.

answerReceived(DiameterAnswer answer, Long idleTime, Boolean stopSendTimer, String linkID, AsyncCallback callback)

This method processes incoming Diameter answers, restarting timers and updating the session storage.

requestSent(Boolean newSession, DiameterRequest request, AsyncCallback callback)

Called when a request is sent. It restarts both the idle and send timers, and if it's a new session, updates the outgoing session counters.

answerSent(DiameterAnswer answer, Long idleTime, AsyncCallback callback)

Invoked when a Diameter answer is sent. It restarts the idle timer and updates the session storage.

getLastSendRequest() and setLastSentRequest(DiameterRequest request)

These methods manage the tracking of the last sent request, which is important for validating responses.

validateAnswer(DiameterAnswer answer)

Validates the incoming answer by checking the HopByHopIdentifier and EndToEndIdentifier fields against the last sent request. This ensures the response matches the original request.

Timeout Handling

onTimeout()

Called when the session times out. It triggers the appropriate listener methods and ensures the session is updated in storage.

onIdleTimeout()

This method is invoked when the session remains idle for too long. It terminates the session with a DIAMETER_SESSION_TIMEOUT result code.

Retry Handling

isRetry() and setIsRetry(Boolean isRetry)

These methods manage the retry state of the session. If a request fails or needs to be resent, the session may enter a retry state.

Serialization Helpers

load(String sessionID, SessionStateEnum sessionState, byte otherFields)

This method loads the session’s state (e.g., session ID, session state) from serialized data, typically used in clustered or failover scenarios.

getOtherFieldsByte()

Returns a byte value representing various session flags, which can be serialized for more compact storage.

Diameter Link

DiameterLinkImpl is providing the functionality required to establish, manage, and communicate over a Diameter link between two peers. It handles peer state transitions, message transmission, and processing, as well as network association management. The class also serves as a listener for network association events, making it a key component for managing SCTP/TCP connections in the Diameter protocol stack.

public class DiameterLinkImpl implements DiameterLink, AssociationListener

Key Functions

Network Association Management: Establishes, starts, and stops network associations (TCP/SCTP connections) between Diameter peers.
Peer State Management: Tracks and controls the state of the peer connection using PeerStateEnum (e.g., OPEN, IDLE, DPR_SENT).
Message Transmission: Encodes and sends Diameter messages such as Capabilities-Exchange, Device-Watchdog, and Disconnect-Peer messages.
Message Reception: Receives and decodes Diameter messages, passing them for processing while ensuring message integrity.
Error Handling: Detects and sends error messages (e.g., malformed or unsupported messages) in response to invalid Diameter messages.

Constructor

public DiameterLinkImpl(DiameterStack stack, Management management, ConcurrentHashMap<String, NetworkListener> genericListeners, String linkId, InetAddress remoteAddress, ...)

Purpose

  • Initializes key fields, including the DiameterParser, timers, and network association.
  • Sets up the communication channel (SCTP or TCP) based on the isSctp parameter.
  • Registers Diameter application IDs and prepares the link for message transmission.

Parameters

Name

Description

stack

The Diameter protocol stack, responsible for managing message processing and overall communication.

management

Handles network associations, such as establishing and tearing down connections.

genericListeners

A map of network listeners that respond to Diameter network events.

linkId

Unique identifier for the Diameter link.

remoteAddress, localAddress

The IP addresses of the remote peer and local node.

localHost, localRealm, destinationHost, destinationRealm

Identifiers representing the hostnames and realms for Diameter communication.

inactivityTimeout, reconnectTimeout

Configurable timeouts for detecting inactivity and managing reconnection after failure.

Network Manager

The NetworkManagerImpl class is a component of the Mobius Diameter Stack, responsible for managing Diameter links and providing functionalities for message routing, network listener management, and link lifecycle control. This class handles the underlying networking details such as SCTP/TCP management, link creation, message sending, and event callbacks for network events.

Constructor

NetworkManagerImpl(DiameterStack stack, Integer workerThreads, Long idleTimeout, Long responseTimeout, Long reconnectTimeout)

Initializes a new instance of NetworkManagerImpl, setting up the SCTP/TCP transport layer and configuring timeouts for idle links, response handling, and reconnect attempts.

 Parameters

Name

Description

stack

The DiameterStack instance that this manager operates within.

workerThreads

The number of threads used for handling network operations.

idleTimeout

The maximum allowed idle time for a link before it is considered inactive.

responseTimeout

The maximum time to wait for a response from a peer.

reconnectTimeout

The timeout period before attempting to reconnect a link. 

Start innovating with Mobius

What's next? Let's talk!

Mobius Software

As a company you'll get:

  • Get started quickly

  • Support any business model

  • Join millions of businesses

Questions? websupport@mobius.com