API Class Documentation
3.1 Core Classes
3.1.1 DiameterStack
DiameterStack is a core interface that defines the structure and functionality of a Diameter protocol stack. It provides methods for managing Diameter sessions, sending and receiving messages, handling providers, and managing the state of the Diameter network and protocol layers. This interface allows for modular and extensible integration with Diameter-based network services.
Key Functions
Session Management: The DiameterStack manages Diameter sessions through DiameterSessionStorage, ensuring sessions are created, stored, and retrieved as needed during the lifecycle of message exchanges. It supports both stateful and stateless modes.
Message Routing: The stack is responsible for routing messages between the network and the Diameter providers. It uses the NetworkManager to send and receive messages, and dynamically selects the appropriate provider based on the message’s ApplicationID and command type.
Provider Management: The stack registers and manages different Diameter providers based on the specific Diameter application (e.g., Credit Control, Gx, Sh). Each provider handles specific Diameter requests and responses related to its application.
Network Communication: Through the NetworkManager, the stack interfaces with the network layer (via Netty) to send and receive Diameter messages. It also handles callbacks to process message responses asynchronously.
Session and Message Metrics: The stack tracks various metrics, such as the number of messages sent and received, errors encountered, and sessions created and terminated, categorized by ApplicationID, CommandCode, and session state.
Error Handling: The stack is responsible for detecting and handling Diameter protocol errors. This includes tracking errors by type and responding appropriately based on the Diameter message content and session state.
Periodic Tasks: The DiameterStackImpl (implementation of the DIameterStack) maintains a task queue for handling recurring tasks, such as managing idle session timeouts, duplicate message checking, and session expiration.
Methods
Name |
Description |
Provider Management |
|
getProvider(Class<?> providerClass) / getProvider(Long applicationID, Package parentPackage) |
Retrieve a provider based on either class or Application ID and parent package. |
registerCustomProvider(DiameterProvider<?,?,?,?,?> provider, Package parentPackage) / registerGlobalApplication(Package providerPackageName, Package packageName) |
Register a custom or global provider with the stack, associating it with a package. |
Session Management |
|
generateNewSessionID() |
Generate a new unique session ID. |
newIncomingSession(ApplicationID applicationID) / newOutgoingSession(ApplicationID applicationID) |
Register a new incoming or outgoing session for the specified application. |
sessionEnded(Long resultCode, ApplicationID applicationID) |
Handle session-ending events, categorized by result code and application. |
isSessionLess() |
Check if the stack is operating in a session-less mode. |
Timeouts & Duplicates Management |
|
getResponseTimeout() |
Get the default response timeout for Diameter messages. |
getIdleTimeout() / setIdleTimeout(Long value): |
Retrieve or set the idle timeout for Diameter sessions. |
getDuplicatesTimeout() / getDuplicatesCheckPeriod() |
Get the duplicates detection timeout or check period for duplicate messages. |
Message Handling |
|
sendRequest(DiameterRequest message, AsyncCallback callback) |
Send a DiameterRequest with an asynchronous callback. |
sendAnswer(DiameterAnswer message, String destinationHost, String destinationRealm, AsyncCallback callback) |
Send a DiameterAnswer to a specific host and realm with an asynchronous callback. |
messageReceived(DiameterMessage message, String linkID) / messageSent(DiameterMessage message, String linkID) |
Handle or log received and sent Diameter messages associated with a given link ID. |
Link & Network Management |
|
getLinkMessagesSentByTypeAndApplication(String linkID, ApplicationID applicationID) / getLinkMessagesReceivedByTypeAndApplication(String linkID, ApplicationID applicationID) |
Get messages sent or received by link and application. |
ID & Identifier Management |
|
getIDGenerator() / generateID() |
Retrieve the ID generator or generate a ClusteredID for distributed environments. |
getNextHopByHopIdentifier() |
Retrieve the next available Hop-by-Hop identifier for message tracking. |
Task & Queue Management |
|
getQueue() / getPeriodicQueue() |
Get the task queue or the periodic task queue for handling tasks. |
Message Statistics |
|
getMessagesSentByType() / getMessagesReceivedByType() |
Retrieve sent or received messages categorized by type. |
getErrorsSentByType() / getErrorsReceivedByType() |
Retrieve sent or received errors categorized by type. |
getOutgoingSessionByApplication() / getIncomingSessionsByApplication() |
Retrieve outgoing or incoming sessions categorized by application. |
getSessionEndedByResultCode() |
Retrieve ended sessions categorized by result code. |
getMessagesSentByTypeAndApplication(ApplicationID applicationID) / getMessagesReceivedByTypeAndApplication(ApplicationID applicationID) |
Retrieve sent or received messages categorized by type and application. |
getErrorsSentByTypeAndApplication(ApplicationID applicationID) / getErrorsReceivedByTypeAndApplication(ApplicationID applicationID) |
Retrieve sent or received errors categorized by type and application. |
System & Stack Management |
|
stop() |
Stop the Diameter stack and gracefully terminate all sessions and network connections. |
getSessionStorage() / getRequestsStorage() |
Retrieve the session storage or the incoming requests storage used by the stack. |
Miscellaneous |
|
getClassLoader() |
Get the class loader used by the stack. |
getProductName() / getVendorID() / getFirmwareRevision() |
Retrieve the product name, vendor ID, or firmware revision of the stack. |
getGlobalParser() |
Retrieve the global DiameterParser responsible for parsing messages across the stack. |
3.1.2 DiameterProvider
The DiameterProvider interface in the Mobius Diameter Stack defines a blueprint for handling Diameter protocol message processing and session management. It serves as a key component that interacts with both client-side and server-side listeners and provides access to factories for AVP (Attribute-Value Pair), message, and session management. It also integrates closely with the DiameterStack to facilitate the creation of new Diameter sessions.
The DiameterProvider interface is highly extensible, using generic type parameters to support various types of listeners (L1 and L2), AVP factories, message factories, and session factories. It also acts as a NetworkListener for network-related events.
Type Parameters:
L1: The type of the client-side SessionListener.
L2: The type of the server-side SessionListener.
A: The type of the AVP factory used by the provider.
M: The type of the message factory used by the provider.
F: The type of the session factory used by the provider.
Methods
Name |
Description |
Factory Access |
|
getAvpFactory() |
Returns the AVP factory (A) responsible for creating AVPs, which represent data elements in Diameter messages. |
getMessageFactory() |
Returns the message factory (M), responsible for creating new Diameter messages such as requests and responses. |
getSessionFactory() |
Returns the session factory (F) that manages the lifecycle of Diameter sessions, including creating and managing sessions. |
Listener Management |
|
setClientListener(ClusteredID<?> listenerID, L1 listener) / removeClientListener(ClusteredID<?> listenerID) |
Registers or removes a client-side listener (L1) for a given ClusteredID, handling client-side session events. |
setServerListener(ClusteredID<?> listenerID, L2 listener) / removeServerListener(ClusteredID<?> listenerID) |
Registers or removes a server-side listener (L2) for a given ClusteredID, handling server-side session events. |
getClientListeners() / getServerListeners() |
Returns a map of all registered client-side or server-side listeners, keyed by their ClusteredID. Each entry represents a listener that handles session events on either the client or server side. |
Session Management |
|
getNewSession(DiameterRequest message) |
Creates and returns a new DiameterSession based on an incoming DiameterRequest. This method is used to initialize a session when a new request is received. |
Stack and Package Management |
|
getStack() |
Returns the associated DiameterStack, which manages network connections and session handling for the Diameter protocol. |
getPackageName() |
Returns the name of the package associated with the provider, used for identifying and organizing providers within the Mobius Diameter Stack. |
3.1.3 DiameterSessionStorage
The DiameterSessionStorage interface is responsible for managing and maintaining Diameter sessions within the Mobius Diameter Stack. It defines methods for storing, retrieving, and removing sessions, as well as controlling idle and send timers associated with each session. This interface is crucial for ensuring that sessions are properly tracked and managed, including timeout mechanisms and session lifecycle control.
For example, when a new session is initiated upon receiving a Diameter request, the session is stored using storeSession(). During the session's lifetime, idle and send timers are managed using the corresponding methods (startIdleTimer(), startSendTimer()), ensuring the session is tracked for both inactivity and message transmission. Once the session is completed or terminated, it is removed using removeSession().
Methods
Name |
Description |
Session Management |
|
removeSession(String sessionId) / storeSession(DiameterSession session) |
Removes or stores a DiameterSession in the session storage. Use removeSession() when a session ends, and storeSession() when a new session needs to be tracked. |
getSession(String sessionId, DiameterProvider<?, ?, ?, ?, ?> provider) |
Retrieves a DiameterSession based on the session ID and provider. Returns the session if found, or null if not. |
Idle Timer Management |
|
startIdleTimer(DiameterSession session, Long idleTime) / restartIdleTimer(DiameterSession session, Long newTime) |
Starts or restarts the idle timer for a session with a specified timeout, ensuring the session is monitored for inactivity. |
stopIdleTimer(ClusteredID<?> timerID) |
Stops the idle timer for the session associated with the provided ClusteredID, typically used when a session is ending or no longer needs idle tracking. |
Send Timer Management |
|
startSendTimer(DiameterSession session) / restartSendTimer(DiameterSession session) |
Starts or restarts the send timer for a session, tracking message transmission deadlines. |
stopSendTimer(ClusteredID<?> timerID) |
Stops the send timer for the session associated with the provided ClusteredID, useful when no further messages are expected to be sent in the session. |
Session Monitoring |
|
getSessionsCount() |
Returns the number of active sessions currently stored in the DiameterSessionStorage, useful for monitoring session load. |
3.1.4 DiameterLink
The DiameterLink interface represents a communication link between two peers in the Diameter protocol. It is responsible for managing the connection state, sending and receiving messages, and handling connection events such as capabilities exchange, device watchdog requests, and disconnect operations. This interface provides methods for checking the status of the link, interacting with the remote peer, and managing the lifecycle of the connection. It also supports both SCTP (Stream Control Transmission Protocol) and TCP-based connections, making it versatile for different network setups.
For example, it handles message exchange, capabilities negotiation, and connection monitoring. When a Diameter connection is established, the link sends a Capabilities Exchange Request (CER), checks the connection with Device Watchdog Requests (DWR), and gracefully handles disconnect operations through Disconnect Peer Requests (DPR). The state of the link can be monitored and managed using peer state checks and timers.
Methods
Name |
Description |
Basic Information & Status |
|
getID() |
Returns the unique identifier for the Diameter link. |
isStarted() / isConnected() / isUp() |
These methods return true or false based on the link’s status—whether it has started, is connected to a peer, and is fully operational. |
isServer() / isSctp() |
Returns true if the link is configured as a server or uses SCTP for communication, otherwise false. |
Address and Host Information |
|
getRemoteAddress() / getRemotePort() |
Returns the remote address (IP) and port of the peer connected to this link. |
getLocalAddress() / getLocalPort() |
Returns the local address (IP) and port used by this link for communication. |
getLocalHost() / getLocalRealm() |
Returns the local Diameter hostname and realm used by this link. |
getDestinationHost() / getDestinationRealm() |
Returns the destination Diameter hostname and realm for this link. |
Application Registration & IDs |
|
registerApplication(List<VendorSpecificApplicationId>, List<Long>, List<Long>, Package, Package) |
Registers Diameter applications for the link, using vendor-specific, authentication, and accounting application IDs. |
getAuthApplicationIds() / getAcctApplicationIds() / getVendorSpecificApplicationIds() |
Returns lists of supported authentication, accounting, and vendor-specific application IDs. |
getPackage(Long applicationID, Boolean isAuth) |
Retrieves the package associated with a specific application ID, used for authentication or other purposes. |
Message Handling |
|
canSendMessage(DiameterMessage) / sendMessage(DiameterMessage, AsyncCallback) |
Determines if the link can send a specific message, and sends the message if possible with an asynchronous callback for the response. |
sendEncodedMessage(ByteBuf, AsyncCallback) |
Sends a pre-encoded Diameter message using a ByteBuf and an AsyncCallback to handle the response. |
messageReceived(DiameterMessage, String linkID) / messageSent(DiameterMessage, String linkID) |
Handles received or sent Diameter messages, associating them with the given link ID. |
Capabilities and Watchdog |
|
sendCER() / sendCEA(CapabilitiesExchangeRequest) |
Sends a Capabilities Exchange Request (CER) or Answer (CEA) to negotiate supported capabilities. |
sendDWR() / sendDWA(DeviceWatchdogRequest, long resultCode) |
Sends a Device Watchdog Request (DWR) to check if the connection is operational, or a Device Watchdog Answer (DWA) in response to a DWR. |
Disconnect Operations |
|
sendDPR(DisconnectCauseEnum, AsyncCallback) / sendDPA(DisconnectPeerRequest, long resultCode) |
Sends a Disconnect Peer Request (DPR) or Answer (DPA) in response to a disconnect operation. |
disconnectOperationCompleted() |
Notifies the link that a disconnect operation has been successfully completed. |
Peer State Management |
|
getPeerState() / setPeerState(PeerStateEnum) |
Gets or sets the current state of the peer associated with this link (e.g., OPEN, IDLE). |
Timers |
|
resetInactivityTimer() / resetReconnectTimer() |
Resets the inactivity or reconnect timers for the link, ensuring that the connection is active or that reconnections are attempted. |
Error Handling |
|
sendError(DiameterException) |
Sends an error message to the peer, handling any DiameterExceptions, such as missing or unsupported AVPs. |
Lifecycle Management |
|
start() / stop(Boolean remove) |
Starts or stops the Diameter link, with the option to remove it from storage on stop. Throws DiameterException in case of failure. |
3.1.5 DiameterParser
The DiameterParser class is a critical component in the Mobius Diameter stack, responsible for encoding and decoding Diameter protocol messages. It translates Diameter messages from their wire format (byte stream) into Java objects (DiameterMessage), and vice versa, while ensuring validation and error handling as per Diameter protocol specifications.
This parser is designed to handle Diameter requests and responses by processing AVPs (Attribute-Value Pairs), which are the building blocks of Diameter messages. The DiameterParser operates on various Diameter applications and supports both global and application-specific command registrations.
Encoding Process
The parser begins by encoding the message header, including the version, length, and command-specific flags.
It retrieves and encodes each AVP recursively, ensuring that grouped AVPs and optional AVPs are handled properly.
The encode method writes the message into a ByteBuf, ready for transmission over a network.
Decoding Process
The parser reads the header, verifies the version and message length, and looks up the command by its command code and application ID.
It reconstructs the DiameterMessage object and recursively decodes each AVP.
Optional AVPs are handled depending on the configuration, and unknown mandatory AVPs result in a DiameterException.
Fields
Name |
Description |
logger: |
A Logger instance from Apache Log4j used to log parser-related events and errors. |
avpDefsMap: |
A ConcurrentHashMap that stores AVP definitions (annotations) mapped by class type. |
commandDefsMap: |
A ConcurrentHashMap that stores command definitions (annotations) mapped by class type. |
folderFilter: |
An instance of FolderFilter, used for filtering file system objects. |
globalInterfacesMapping: |
A ConcurrentHashMap that stores globally registered Diameter commands by package name. |
interfacesMapping: |
A ConcurrentHashMap that stores Diameter commands mapped to specific application IDs. |
avpImplementationsMap: |
A ConcurrentHashMap that stores AVP class implementations mapped by the interface type. |
avpsMap: |
A ConcurrentHashMap that stores AvpData instances, which contain information about AVP structure and handling. |
commandsMap: |
A ConcurrentHashMap that stores command data (metadata about Diameter commands) mapped by class type. |
Constructor:
DiameterParser(ClassLoader classLoader, List<Class<?>> errorClasses, Package avpPackage):
Initializes the DiameterParser by registering AVPs using the provided class loader and package, and processes error classes to build command data for Diameter commands that may generate errors.
Methods
Name |
Description |
Encoding Methods |
|
ByteBuf encode(DiameterMessage message) / void encode(ByteBuf result, DiameterAvp avp, Boolean isError) |
Encodes a DiameterMessage or an individual DiameterAvp into a ByteBuf. Validates the message or AVP, adds necessary headers, and handles encoding errors. |
Decoding Methods |
|
DiameterMessage decode(ByteBuf message, Boolean rejectUnmandatoryAvps) / DiameterMessage decode(ByteBuf message, Boolean rejectUnmandatoryAvps, Boolean isGlobal, String packageName) |
Decodes a DiameterMessage from a ByteBuf, validating headers and AVPs. The second method supports globally registered applications and package-specific command mappings. |
void decode(ByteBuf message, DiameterAvp parent, Boolean isError, ConcurrentHashMap<DiameterAvpKey, AvpData> childAvps, Integer length, Boolean rejectUnmandatoryAvps) |
Decodes individual AVPs within a Diameter message, handling mandatory, optional, and grouped AVPs. |
Length Calculation |
|
Integer getLength(DiameterAvp parent, List<AvpData> childAvps) / Integer getLength(DiameterAvp parent) |
Calculates the length of an AVP, either with child AVPs or the inner length excluding headers. |
Application and AVP Registration |
|
void registerGlobalApplication(ClassLoader classLoader, Package mappingName, Package packageName) / void registerApplication(ClassLoader classLoader, Package packageName) |
Registers global or specific Diameter applications, loading necessary classes and setting up parsing logic for the commands and AVPs. |
void registerAvps(ClassLoader classLoader, Package parentPackageName) |
Registers AVPs found in the specified package, mapping AVP definitions to implementations. |
AVP List Building |
|
void buildAvpList(ChildData parentStorage, Long applicationID, Boolean isRequest, Integer commandCode, Class<?> parentType) |
Builds the list of AVPs for a message using reflection to gather AVP field information. |
Class Loading |
|
List<Class<?>> loadClasses(ClassLoader classLoader, Package packageName) / List<Class<?>> loadAllClasses(ClassLoader classLoader, Package rootPackage) |
Loads classes from a specified package, with the second method recursively loading all classes from the package and its sub-packages. |
AVP and Command Definitions |
|
DiameterAvpDefinition getAvpDefinition(Class<?> clazz) / Class<?> getAvpDefinitionClass(Class<?> clazz) |
Retrieves the DiameterAvpDefinition annotation or the class that contains the annotation for a given class. |
DiameterCommandDefinition getCommandDefinition(Class<?> clazz) |
Retrieves the DiameterCommandDefinition annotation for a class. |
Class and Interface Retrieval |
|
List<Class<?>> getAllInterfaces(Class<?> clazz) / List<Class<?>> getAllClasses(Class<?> clazz) |
Returns lists of all interfaces or classes in the hierarchy of the specified class, including superclasses. |
3.1.6 NetworkListener
The NetworkListener interface defines a listener for handling network events related to Diameter protocol messages. It is a key component in the Diameter communication stack, responsible for receiving messages from the network and triggering appropriate callbacks. Implementations of this interface will process incoming Diameter messages and ensure that network communication between Diameter peers is properly managed.
Method
Name |
Description |
void onMessage(DiameterMessage message, String linkID, AsyncCallback callback): |
This method is invoked whenever a new DiameterMessage is received from the network. The parameters provide the details needed to handle the message: |
message: |
The DiameterMessage object representing the incoming Diameter message that needs to be processed. |
linkID: |
A String representing the ID of the link over which the message was received. This helps identify the source of the message in multi-link scenarios. |
callback: |
An AsyncCallback object, which is used to handle the asynchronous response or result of processing the incoming message. |
3.1.7 SessionListener
The SessionListener interface defines a listener for handling events related to Diameter sessions. It focuses on session-specific events such as timeouts and idle session handling. Implementations of this interface can be used to monitor the status of Diameter sessions, providing callbacks when certain session-related events occur, such as when a session times out or becomes idle.
Methods
Name |
Description |
void onTimeout(DiameterRequest lastRequest, DiameterSession session): |
Triggered when a session times out after the last request was sent. This method provides details about the session and the last DiameterRequest message sent before the timeout occurred. |
lastRequest: |
The DiameterRequest object representing the last message that was sent before the timeout. |
session: |
The DiameterSession object representing the Diameter session that has timed out. |
void onIdleTimeout(DiameterSession session): |
Triggered when a session becomes idle for a specified period of time without activity. This method provides the session details, allowing for appropriate actions to be taken (such as closing the session or keeping it alive). |
3.1.8 NetworkManager
The NetworkManager interface is responsible for managing network links and handling the transmission of Diameter messages in the Diameter protocol stack. It provides methods to manage links between peers, register applications, and send messages across these links. The NetworkManager is a central component that orchestrates communication between Diameter nodes, ensuring that links are established, maintained, and utilized correctly for message exchange.
Methods
Name |
Description |
Parameters |
void addLink(String linkId, InetAddress remoteAddress, Integer remotePort, InetAddress localAddress, Integer localPort, Boolean isServer, Boolean isSctp, String localHost, String localRealm, String destinationHost, String destinationRealm, Boolean rejectUnmandatoryAvps) throws DiameterException: |
Adds a new link between the local node and a remote Diameter node. The method specifies the remote and local addresses, ports, hostnames, realms, and whether the connection should reject non mandatory AVPs. |
linkId: Unique identifier for the link. remoteAddress: IP address of the remote peer. remotePort: Port number of the remote peer. localAddress: Local IP address of the link. localPort: Local port number of the link. isServer: Whether this link is a server-side link. isSctp: Whether this link uses SCTP (Stream Control Transmission Protocol). localHost: Local Diameter host name. localRealm: Local Diameter realm. destinationHost: Destination Diameter host name. destinationRealm: Destination Diameter realm. rejectUnmandatoryAvps: If true, the link will reject messages with unmandatory AVPs. |
Name |
Description |
Link Management |
|
void removeLink(String linkId) throws DiameterException / void startLink(String linkId) throws DiameterException / void stopLink(String linkId, AsyncCallback callback) throws DiameterException: |
Manages the lifecycle of a link—removing, starting, or stopping it based on the linkId. An AsyncCallback is used for stopLink to handle asynchronous tasks. |
Link Retrieval |
|
DiameterLink getLink(String linkId) / List<DiameterLink> getAllLinks() |
Retrieves a specific DiameterLink by linkId or returns a list of all active links managed by the NetworkManager. |
Application Registration |
|
void registerApplication(String linkId, List<VendorSpecificApplicationId> vendorApplicationIds, List<Long> authApplicationIds, List<Long> acctApplicationIds, Package providerPackageName, Package packageName) throws DiameterException |
Registers vendor-specific applications, authentication, and accounting services for a specific link. |
Network Control |
|
void stop() |
Stops all active links and gracefully shuts down the NetworkManager. |
Network Listener Management |
|
void addNetworkListener(String listenerId, NetworkListener listener) / void removeNetworkListener(String listenerId) |
Adds or removes a NetworkListener to monitor network events or incoming messages for the specified listenerId. |
Message Sending |
|
void sendMessage(String linkId, DiameterMessage message, AsyncCallback callback) / void sendRequest(DiameterRequest message, AsyncCallback callback) / void sendAnswer(DiameterAnswer message, String destinationHost, String destinationRealm, AsyncCallback callback) |
Sends a DiameterMessage, DiameterRequest, or DiameterAnswer over a specified link or to a destination. AsyncCallback is used to handle the result of sending the message asynchronously. |
3.2 Factories
3.2.1 SessionFactory
The SessionFactory interface is responsible for managing Diameter sessions by creating client and server sessions for different Diameter applications (e.g., Credit Control, S9, Gq, Gy, etc.). Each Diameter application has a corresponding session factory that allows for the instantiation of new sessions based on incoming requests. These sessions are integral for managing the communication lifecycle between Diameter peers, ensuring that messages are exchanged within the context of a properly established session.
Each SessionFactory instance supports both client-side and server-side session creation, allowing the factory to cater to both ends of a Diameter communication link.
Key Methods
The SessionFactory interface typically provides methods to create new client and server sessions, with each method corresponding to a specific type of request that initiates a session. Below are the most commonly used methods:
Name |
Description |
Parameters |
createClientSession(Request request): |
This method creates a new client-side session based on the specified request type. The request can vary depending on the Diameter application (e.g., CreditControlRequest, LocationInfoRequest, etc.). A ClientSession object is returned, representing the client-side session that can send requests and process responses. |
request: The specific request that initiates the session, which could be different for each Diameter application. Throws: DiameterException or AvpNotSupportedException (depending on the session type and protocol). Returns: ClientSession: A session instance for managing client-side communication. |
createServerSession(Request request): |
This method creates a new server-side session based on the specified request type. Similar to the client session creation, the request type varies depending on the application, and the returned ServerSession is used to handle incoming requests and send responses. |
request: The specific request that initiates the session. Throws: DiameterException or AvpNotSupportedException. Returns: ServerSession: A session instance for managing server-side communication. |
Application-Specific Implementations:
The SessionFactory interface is implemented differently for each Diameter application, with each implementation tailored to the specific needs of that application. Below are some common applications and their corresponding session creation methods:
Cx/Dx Application:
Client: createClientSession(UserAuthorizationRequest request)
Server: createServerSession(UserAuthorizationRequest request)
Gq Application:
Client: createClientSession(AARequest request)
Server: createServerSession(AARequest request)
S9 Application:
Client: createClientSession(CreditControlRequest request)
Server: createServerSession(CreditControlRequest request)
Each application implements the SessionFactory to provide session management that is specific to the types of requests and responses handled by that application.
3.2.2 AvpFactory
The AVPFactory provides factory methods for creating various Attribute-Value Pairs (AVPs) used in the Diameter protocol. These AVPs represent different pieces of information that can be exchanged in Diameter messages. The AVPFactory interface has been implemented in various packages, each catering to a specific Diameter application or function.
For specific rules and cases on AVP structure, formats and logic please refer to: [RFC6733]
While AVPs can be simple (e.g., an integer, string, or octet string), in the context of AVPFactories, only grouped AVPs are generated and handled.
Grouped AVPs are structured containers that encapsulate multiple AVPs, either simple or grouped themselves. They are used when there is a need to represent complex, related data in a structured format. For instance, grouped AVPs might encapsulate user subscription details, charging information, or policy rules—each consisting of several sub-AVPs.
Grouped AVPs are typically more complex and structured, containing a collection of related AVPs that together define a specific logical entity, such as RequestedServiceUnit, GrantedServiceUnit, or SubscriptionId.
AVPFactories simplify the creation of these complex structures by providing factory methods to create them with all necessary and optional sub-AVPs.
Grouped AVPs represent modular units of data that are reused across various Diameter applications. AVPFactories encapsulate the logic for creating these reusable AVPs, allowing for consistent use throughout different applications and interfaces.
When constructing grouped AVPs, there are specific rules regarding mandatory and optional sub-AVPs, as well as their order and occurrence limits. AVPFactories ensure that these rules are followed, reducing the risk of protocol violations during message construction.
Methods Examples
Name |
Description |
getProxyInfo(String proxyHost, ByteBuf proxyState): |
Creates a ProxyInfo AVP, containing proxy host information and proxy state. Applicable for Diameter scenarios where intermediaries (proxies) handle communication. |
getVendorSpecificApplicationId(Long vendorId, Long authApplicationId, Long acctApplicationId): |
Generates a VendorSpecificApplicationId AVP that identifies a vendor-specific Diameter application. Throws AvpOccursTooManyTimesException or MissingAvpException if validation fails. |
getUserEquipmentInfo(UserEquipmentInfoTypeEnum userEquipmentInfoType, ByteBuf userEquipmentInfoValue): |
Creates an AVP for user equipment information in applications like Credit Control or Gi. Example of user equipment data includes IMEI, MAC addresses, etc. |
getRestrictionFilterRule(String rule): |
Generates a RestrictionFilterRule AVP for defining filters that restrict network traffic. Useful for applications like Gi, where network access policies are enforced. |
getFlows(Long mediaComponentNumber): |
Creates a Flows AVP, which represents media flow information used in applications like Gq or Rx. Required in scenarios dealing with multimedia streaming or real-time communication. |
getSMDeliveryOutcome(): |
Generates an AVP for SMS delivery outcome, which is critical in S6c-based applications related to SMS messaging delivery status. |
3.2.3 MessageFactory
The MessageFactory serves as a fundamental interface for generating Diameter protocol messages in various Diameter applications (such as Credit-Control, NAS, Gx, etc). The main objective of the factory is to encapsulate the creation logic for different types of request and answer messages, ensuring consistency, maintainability, and flexibility. By centralizing the creation logic, MessageFactory enables the developers to maintain a uniform approach to generating messages for different Diameter applications.
In Mobius Diameter, the MessageFactory interface is implemented separately for each application, based on the specific Diameter commands required for the application. However, the core principles and approach to using MessageFactory remain consistent across different applications.
Session Management:
Session IDs: Every Diameter request created by a MessageFactory generates a unique session identifier using the underlying DiameterStack. This ensures that requests and responses can be properly correlated within the scope of a session.
Session State: Each message respects the session state, which is typically set to NO_STATE_MAINTAINED unless specified otherwise. This is relevant for applications where stateful session management is not required, such as in stateless services.
Application and Vendor IDs:
Application IDs: Each MessageFactory is linked to a specific Diameter application through the ApplicationID defined during initialization. This ensures that messages are always created for the correct application and conform to its specifications.
Vendor-Specific Application IDs: For certain applications (e.g., S6a, NP), a VendorSpecificApplicationId is required to ensure proper handling of vendor-specific Diameter applications (such as 3GPP). This is handled internally by the MessageFactory when creating requests or answers.
Message Structure:
Request and Answer Objects: Each MessageFactory provides methods to create both request and answer objects. Requests are typically created first and sent to a remote Diameter peer, which then responds with an answer.
AVP Handling: MessageFactory handles the construction of messages with mandatory AVPs (e.g., OriginHost, DestinationRealm, SessionID).
Exception Handling: During the creation of messages, various exceptions may be thrown to handle missing AVPs, unsupported AVPs, or incorrect message structures. These exceptions help ensure the message is properly formed before it is sent over the network.
Hop-by-Hop and End-to-End Identifiers: Every Diameter message created includes Hop-by-Hop and End-to-End identifiers, which are used for tracking and correlating messages. These are automatically set when creating answers in response to requests, ensuring proper linkage between related messages.
Customization per Application:
While the core logic for message creation is shared, each MessageFactory implementation is tailored to the specific needs of the application it supports. For example, the Credit-Control factory may include specific request types such as CreditControlRequest, while the S6a factory includes requests like AuthenticationInformationRequest and UpdateLocationRequest.
Each factory is responsible for ensuring that its messages conform to the appropriate Diameter standards (RFC, 3GPP specifications).
Key Use Cases
Name |
Description |
Request Creation |
Each MessageFactory offers methods for creating various request messages such as CreditControlRequest, AARequest, SessionTerminationRequest, or MIP6Request. Developers provide the necessary parameters (e.g., originHost, destinationRealm, sessionID), and the factory constructs the message with all required AVPs. |
Answer Creation |
The factory also provides methods for creating answer messages such as CreditControlAnswer, AAAnswer, or ReAuthAnswer. These methods take in the corresponding request, identifiers, and result codes to construct a proper Diameter answer. |
Start innovating with Mobius
What's next? Let's talk!