JBoss.orgCommunity Documentation

Chapter 2. Mobicents Diameter Stack

2.1. Mobicents Diameter Stack Design
2.1.1. Mobicents Diameter Stack Extensibility
2.1.2. Mobicents Diameter Stack Model
2.1.3. Application session factories
2.1.4. Session Replication
2.2. Mobicents Diameter Stack Setup
2.2.1. Pre-Install Requirements and Prerequisites
2.2.2. Source Code
2.3. Mobicents Diameter Stack Configuration
2.3.1. Cluster configuration
2.4. Mobicents Diameter Stack Source overview
2.4.1. Session Factory
2.4.2. Sessions
2.4.3. Application Session Factories
2.5. Mobicents Diameter Stack Validator
2.5.1. Validator Configuration
2.5.2. Validator Source Overview

The Mobicents Diameter Stack is the core component of the presented Diameter solution. It performs all necessary tasks to allow user interact with Diameter network. It manages state of diameter peers and allows to route messages between them. For details please refer to RFC 3588.

Currently the Mobicents Diameter Stack supports the following application sessions:

Mobicents Diameter Stack has been designed to be extensible. In order to achieve that, two set of API are defined by the stack: one which defines basic contracts between user application and stack, second which defines contracts allowing for instance to inject custom objects into stack to perform certain tasks( SessionFactory for instance). ISessionFactory declares additional methods which allow developer to declare custom behaviour (custom application sessions, please refer to Section 2.4.1, “Session Factory” for more detailed information).

Figure 2.1. Mobicents Diameter Stack Extensibility Visualization


General pattern for interface declaration can be understood as follows: Interface ComponentInterface declares minimal set of methods for component to perform its task, and Interface IComponentInterface provides additional behavior methods. Please refer to java doc for list of interfaces and description of method contracts.

Mobicents Diameter Stack supports replication of session data and state. Clustered stack instances can perform operations on session regardless of physical location. Logicaly clustered stack can be imagined as follows:

Figure 2.4. Mobicents Diameter Cluster


Stack replicates only non simple sessions. Thats because simple session do not hold state and can be simply recreated by application. Simple sessions include:

  • RawSession

  • Session

Mobicents Diameter Cluster replicates full state of sessions, however it does not replicated resources which are entirely local to stack instance, like session listeners. Local resources references are recreated once session is being preparepared to be uses in stack instance. Listeners(state and events) are fetched from respective session factory instance. See Section 2.1.3, “Application session factories” for more details.

This section provides instructions on how to obtain and build the Mobicents Diameter Stack from source code.

  1. Downloading the source code

    Use SVN to checkout a specific release source, the base URL is http://mobicents.googlecode.com/svn/tags/servers/diameter/core/jdiameter, then add the specific release version, lets consider 1.3.0.FINAL.

    [usr]$ svn co http://mobicents.googlecode.com/svn/tags/servers/diameter/core/jdiameter/1.3.0.FINAL jdiameter-1.3.0.FINAL
  2. Building the source code

    Important

    Maven 2.0.9 (or higher) is used to build the release. Instructions for using Maven2, including install, can be found at http://maven.apache.org

    Use Maven to build the deployable unit binary.

    						[usr]$ cd jdiameter-1.3.0.FINAL
    						[usr]$ mvn install
    					

    Once the process finishes you should have the JAR files deployed in maven archive.

Similar process as for Section 2.2.2.1, “Release Source Code Building”, the only change is the SVN source code URL, which is http://mobicents.googlecode.com/svn/trunk/servers/diameter/core/jdiameter.

The stack is initially configured by parsing an XML file. The top level structure of the file is described below. Further explanation of each child element, and the applicable attributes is provided later in this section.


<Configuration xmlns="http://www.jdiameter.org/jdiameter-server">

    <LocalPeer></LocalPeer>
    <Parameters></Parameters>
    <Network></Network>
    <Extensions></Extensions>

</Configuration>

<LocalPeer>
    <URI value="aaa://localhost:1812"/>
    <IPAddresses>
        <IPAddress value="127.0.0.1"/>
    </IPAddresses>

    <Realm value="mobicents.org"/>
    <VendorID value="193"/>
    <ProductName value="jDiameter"/>
    <FirmwareRevision value="1"/>

    <OverloadMonitor>
        <Entry index="1" lowThreshold="0.5" highThreshold="0.6">
            <ApplicationID>
                <VendorId value="193"/>
                <AuthApplId value="0"/>
                <AcctApplId value="19302"/>
            </ApplicationID>
        </Entry>
    </OverloadMonitor>
    <Applications>
        <ApplicationID>
            <VendorId value="193"/>
            <AuthApplId value="0"/>
            <AcctApplId value="19302"/>
        </ApplicationID>
    </Applications>
</LocalPeer>

The <LocalPeer> element contains parameters which affect the local Diameter peer. The available elements and attributes are listed for reference.

<LocalPeer> Elements and Attributes

<URI>

Specifies the URI for the local peer. URI has following format: "aaa://FQDN:port".

<IPAddresses>

Contains one or more child <IPAddress> elements which contain a single, valid IP address for the local peer, stored in the value attribute of IPAddress.

<Realm>

Specifies the realm of the local peer, using the value attribute.

<VendorID>

Specifies a numeric identifier that corresponds to the vendor ID allocated by IANA.

<ProductName>

Specifies the name of the local peer product name.

<FirmwareRevision>

Specifies the version of the firmware.

<OverloadMonitor>

Optional parent element containing child elements which specify settings relating to the Overload Monitor.

<Entry>

Supports child elements of type <ApplicationID>, which specify the id of the tracked application(s). It also supports following properties:

<ApplicationID>

Parent element containing child elements which specify information about the application. Child elements are: VendorId, AuthAppId and AcctAppId. Together they create an unique application identifier.

<VendorId>

Specifies vendor id for application definition. It supports a single property: "value"

<AuthAppId>

The Authentication Application ID for application definition. It supports a single property: "value"

<AcctAplId>

The Account Application ID for application defitniion. It supports a single property: "value"

<Applications>

Contains a child element <ApplicationID>, which defines the list of default supported applications. It is used for server side. When stack is configured to accept incoming calls and there is empty list of preconfigured peers (server is configured to accept any connection).


<Parameters>

    <AcceptUndefinedPeer value="true"/>
    <DuplicateProtection value="true"/>
    <DuplicateTimer value="240000"/>
    <UseUriAsFqdn value="true"/> <!-- Needed for Ericsson SDK Emulator -->
    <QueueSize value="10000"/>
    <MessageTimeOut value="60000"/>
    <StopTimeOut value="10000"/>
    <CeaTimeOut value="10000"/>
    <IacTimeOut value="30000"/>
    <DwaTimeOut value="10000"/>
    <DpaTimeOut value="5000"/>
    <RecTimeOut value="10000"/>

    <Concurrent>
        <Entity name="ThreadGroup" size="64"/>
        <Entity name="ProcessingMessageTimer" size="1"/>
        <Entity name="DuplicationMessageTimer" size="1"/>
        <Entity name="RedirectMessageTimer" size="1"/>
        <Entity name="PeerOverloadTimer" size="1"/>
        <Entity name="ConnectionTimer" size="1"/>
        <Entity name="StatisticTimer" size="1"/>
        <Entity name="ApplicationSession" size="16"/>
    </Concurrent>

</Parameters>

The <Parameters> element contains elements which specify parameters for the Diameter stack. The available elements and attributes are listed for reference. If not specified otherwise each tag supports a single property "value" which indicates value of tag.

<Parameters> Elements and Attributes

<AcceptUndefinedPeer>

Specifies whether the stack will accept connections from unidentified peers. The default value is false.

<DuplicateProtection>

Specifies whether duplicate message protection is enabled. The default value is false.

<DuplicateTimer>

Specifies the time each duplicate message is valid for. The default, minimum value is 240000 (4 minutes in milliseconds)

<UseUriAsFqdn>

Determines as URI should be used as FQDN, if set to true stack expects destination/origin host in format of "aaa://isdn.domain.com:3868" instead of proper "isdn.domain.com". Default value is false.

<QueueSize>

Determines how many tasks peer state machine can have before rejecting next task. This queue contains FSM event and messaging.

<MessageTimeOut>

Determines timeout for other than protocol FSM messages. Delay is in milliseconds.

<StopTimeOut>

Determines how long stack waits for all resources to stop gracefully. Delays is in milliseconds.

<CeaTimeOut>

Determines how long it takes for CER/CEA exchange to timeout if there is no response. Delay is in milliseconds.

<IacTimeOut>

Determines how long to retry communication with a peer that stopped answering DWR messages. The delay is in milliseconds

<DwaTimeOut>

Determines how long it takes for DWR/DWA exchange to timeout if there is no response. Delay is in milliseconds.

<DpaTimeOut>

Determines how long it takes for DPR/DPA exchange to timeout if there is no response. Delay is in milliseconds.

<RecTimeOut>

Determines how long it takes for reconnection procedure to timeout. Delay is in milliseconds.

<Concurrent />

Controls thread pool sizes for different aspects of stack. Supports multiple Entity child elements. Entity elements configure thread groups

Entity element supports following properties:

Default supported entities are as follows:


<Network>

    <Peers>
        <!-- This peer is a server, if it's a client attempt_connect should be set to false -->
        <Peer name="aaa://127.0.0.1:3868" attempt_connect="true" rating="1"/>
    </Peers>

    <Realms>
        <Realm name="mobicents.org" peers="127.0.0.1" local_action="LOCAL" dynamic="false" exp_time="1">
            <ApplicationID>
                <VendorId value="193"/>
                <AuthApplId value="0"/>
                <AcctApplId value="19302"/>
            </ApplicationID>
        </Realm>
    </Realms>

</Network>

The <Network> element contains elements which specify parameters for external peers. The available elements and attributes are listed for reference.

An example configuration file for a server supporting the CCA, Sh and Ro Applications:


<?xml version="1.0"?>
<Configuration xmlns="http://www.jdiameter.org/jdiameter-server">

    <LocalPeer>
        <URI value="aaa://127.0.0.1:3868" />
        <Realm value="mobicents.org" />
        <VendorID value="193" />
        <ProductName value="jDiameter" />
        <FirmwareRevision value="1" />
        <OverloadMonitor>
            <Entry index="1" lowThreshold="0.5" highThreshold="0.6">
                <ApplicationID>
                    <VendorId value="193" />
                    <AuthApplId value="0" />
                    <AcctApplId value="19302" />
                </ApplicationID>
            </Entry>
        </OverloadMonitor>
    </LocalPeer>

    <Parameters>
        <AcceptUndefinedPeer value="true" />
        <DuplicateProtection value="true" />
        <DuplicateTimer value="240000" />
        <UseUriAsFqdn value="false" /> <!-- Needed for Ericsson Emulator (set to true) -->
        <QueueSize value="10000" />
        <MessageTimeOut value="60000" />
        <StopTimeOut value="10000" />
        <CeaTimeOut value="10000" />
        <IacTimeOut value="30000" />
        <DwaTimeOut value="10000" />
        <DpaTimeOut value="5000" />
        <RecTimeOut value="10000" />
        <Concurrent>
             <Entity name="ThreadGroup" size="64"/>
             <Entity name="ProcessingMessageTimer" size="1"/>
             <Entity name="DuplicationMessageTimer" size="1"/>
             <Entity name="RedirectMessageTimer" size="1"/>
             <Entity name="PeerOverloadTimer" size="1"/>
             <Entity name="ConnectionTimer" size="1"/>
             <Entity name="StatisticTimer" size="1"/>
             <Entity name="ApplicationSession" size="16"/>
        </Concurrent>
    </Parameters>

    <Network>
        <Peers>
            <Peer name="aaa://127.0.0.1:1218" attempt_connect="false" rating="1" />
        </Peers>
        <Realms>
            <!-- CCA -->
            <Realm name="mobicents.org" peers="127.0.0.1" local_action="LOCAL" 
                dynamic="false" exp_time="1">
                <ApplicationID>
                    <VendorId value="0" />
                    <AuthApplId value="4" />
                    <AcctApplId value="0" />
                </ApplicationID>
            </Realm>
            
            <!-- Sh -->
            <Realm name="mobicents.org" peers="127.0.0.1" local_action="LOCAL" 
                dynamic="false" exp_time="1">
                <ApplicationID>
                    <VendorId value="10415" />
                    <AuthApplId value="16777217" />
                    <AcctApplId value="0" />
                </ApplicationID>
            </Realm>

            <!-- Ro -->
            <Realm name="mobicents.org" peers="127.0.0.1" local_action="LOCAL" 
                dynamic="false" exp_time="1">
                <ApplicationID>
                    <VendorId value="10415" />
                    <AuthApplId value="4" />
                    <AcctApplId value="0" />
                </ApplicationID>
            </Realm>
        </Realms>
    </Network>

    <Extensions />

</Configuration>

To enable stack clsuter mode you need following:

Mobicents Diameter stack is built with the following basic components:

SessionFactory provides stack user access to session objects. It manages registered application session factories, in order to allow creation of specific application sessions. An Session Factory instance can be obtained from stack with use of getSessionFactory() method. Base SessionFactory interface is defined as follows:

package org.jdiameter.api;


import org.jdiameter.api.app.AppSession;
public interface SessionFactory {
    RawSession getNewRawSession() throws InternalException;
    Session getNewSession() throws InternalException;
    Session getNewSession(String sessionId) throws InternalException;
    <extends AppSession> T getNewAppSession(ApplicationId applicationId, 
        Class<? extends AppSession> userSession) throws InternalException;
    <extends AppSession> T getNewAppSession(String sessionId, ApplicationId
        applicationId, Class<? extends AppSession> userSession) throws InternalException;
}

However, since stack is extensible, it is safe to cast SessionFactory object to this interface:

package org.jdiameter.client.api;



public interface ISessionFactory extends SessionFactory {
    <extends AppSession> T getNewAppSession(String sessionId, 
        ApplicationId applicationId, java.lang.Class<? extends AppSession> 
        aClass, Object... args) throws InternalException;
    void registerAppFacory(Class<? extends AppSession> sessionClass, 
        IAppSessionFactory factory);
    void unRegisterAppFacory(Class<? extends AppSession> sessionClass);
    IConcurrentFactory getConcurrentFactory();
}
RawSession getNewRawSession() throws InternalException;

This method creates RawSession. Raw sessions are meant as handles for code performing part of routing decision on stacks behalf, such as rely agents for instance.

Session getNewSession() throws InternalException;

This method creates session which acts as endpoint for peer communication(for given session ID). It declares method which work with Request and Answer objects. Session created with this method has autogenerated ID. It should be considered as client session.

Session getNewSession(String sessionId) throws InternalException;

As above, however created session has Id equal to passsed as argument. Created session should be considered as server session.

<T extends AppSession> T getNewAppSession(ApplicationId applicationId, Class<? extends AppSession> userSession) throws InternalException;

This method creates new specific application session, identified by application Id and class of session passed. Session Id is generated by implementation. New application session should be considered as client session. It is safe to type cast return value to class passed as argument. This method delegates call to specific application session factory.

<T extends AppSession> T getNewAppSession(String sessionId, ApplicationId applicationId, Class<? extends AppSession> userSession) throws InternalException;

As above, however session Id is equal to argument passed. New session should be considered as server session.

<T extends AppSession> T getNewAppSession(String sessionId, ApplicationId applicationId, java.lang.Class<? extends AppSession> aClass, Object... args) throws InternalException;

As above, however it allows to pass some additional argument. Passed values are implementation specifc.

void registerAppFacory(Class<? extends AppSession> sessionClass, IAppSessionFactory factory);

registers factory for certain sessionClass. This factory will receive delegated call when ever getNewAppSession method is called with application class matching one from register method.

void unRegisterAppFacory(Class<? extends AppSession> sessionClass);

removes application session factory registered for sessionClass.



RawSession, Session and ApplicationSession provide means of disspatching and receiving messages. Specific implementation of ApplicationSession may provide non standard methods.

RawSession and Session life span is controlled entirelly by application. However ApplicationSession life time depends on implemented state machine.

RawSession is defined as follows:

public interface BaseSession extends Wrapper, Serializable {

 
    long getCreationTime();
    long getLastAccessedTime();
    boolean isValid();
    Future<Message> send(Message message) throws InternalException, 
        IllegalDiameterStateException, RouteException, OverloadException;
    Future<Message> send(Message message, long timeOut, TimeUnit timeUnit) 
        throws InternalException, IllegalDiameterStateException, RouteException, OverloadException;
    void release();
}
public interface RawSession extends BaseSession {
    Message createMessage(int commandCode, ApplicationId applicationId, Avp... avp);
    Message createMessage(int commandCode, ApplicationId applicationId, 
        long hopByHopIdentifier, long endToEndIdentifier, Avp... avp);
    Message createMessage(Message message, boolean copyAvps);
    void send(Message message, EventListener<Message, Message> listener) 
        throws InternalException, IllegalDiameterStateException, RouteException, OverloadException;
    void send(Message message, EventListener<Message, Message> listener,
        long timeOut, TimeUnit timeUnit) throws InternalException, 
        IllegalDiameterStateException, RouteException, OverloadException;
}
long getCreationTime();

Returns time stamp of this session creation

long getLastAccessedTime();

Returns last time stamp indicating send or receive operation

boolean isValid();

Returns true when this session is still valid (ie, release() has not been called)

void release();

Application calls this method to inform that session should free any associated resource - it shall not be used anymore

Future<Message> send(Message message)

Sends message in async mode. Provided Future reference provides means of accessing answer once its received

void send(Message message, EventListener<Message, Message> listener, long timeOut, TimeUnit timeUnit)

As above. Allows to specif time out value for send operation

Message createMessage(int commandCode, ApplicationId applicationId, Avp... avp);

Creates a Diameter message. It should be explicitly set either as request or answer. Passed parameters are used to build message

Message createMessage(int commandCode, ApplicationId applicationId, long hopByHopIdentifier, long endToEndIdentifier, Avp... avp);

Same as above, however it allow to also set Hop-by-Hop and End-to-End Identifiers in message header. This method should be used to create answers

Message createMessage(Message message, boolean copyAvps);

Clones message and returns created object

void send(Message message, EventListener<Message, Message> listener)

Sends message, answer will be delivered to the specified listener

void send(Message message, EventListener<Message, Message> listener, long timeOut, TimeUnit timeUnit)

As above, it allows to pass answer wait timeout

Session defines similar methods, with exactly the same purpose:

public interface Session extends BaseSession {

    String getSessionId();
    void setRequestListener(NetworkReqListener listener);
    Request createRequest(int commandCode, ApplicationId appId, String destRealm);
    Request createRequest(int commandCode, ApplicationId appId, String destRealm, String destHost);
    Request createRequest(Request prevRequest);
    void send(Message message, EventListener<Request, Answer> listener) 
        throws InternalException, IllegalDiameterStateException, RouteException, OverloadException;
    void send(Message message, EventListener<Request, Answer> listener, long timeOut,
        TimeUnit timeUnit) throws InternalException, IllegalDiameterStateException, 
        RouteException, OverloadException;
}

Validator is one of the Stack features. The primary purpose of the Validator is to detect malformed messages, such as an Answer message containing a Destination-Host Attribute Value Pair (AVP).

The Validator is capable of validating multi-leveled, grouped AVPs, excluding the following content types:

That is, it is capable of checking structural integrity, not content.

Validator performs the following checks:

Validator is called by stack implementation. It is invoked after message is received and before it is dispatched to remote peer. Note that latter means that if peer does not exist in local peer table validator is not called, as stack fails before calling it.

Validator is configured with a single XML file. This file contains the structure definition for messages and AVPs.

Upon creation of Diameter Stack, the validator is initialized. It performs initialization by looking up dictionary.xml file in classpath.

Configuration file structure is the following:



<dictonary>
    <validator enabled="true|false" sendLevel="OFF|MESSAGE|ALL" receiveLevel="OFF|MESSAGE|ALL" />
    <vendor name="" vendor-id="" code=""/>
    <typedefn type-name="" type-parent=""/>
    <application id="" name="">
        <avp ...>
            <type type-name=""/>
            <enum name="" code=""/>
            <grouped>
                <gavp name=""/>
            <grouped/>
        <avp/>
        <command name="" code="" request="true|false"/>
        <avp ...>
            <type type-name=""/>
            <enum name="" code=""/>
            <grouped>
                <gavp name=""/>
            <grouped/>
        <avp/>
    <application>
<dictionary/>
<dictionary>

The root element, which contains the child elements comprising the validator and dictionary components. This element does not support any attributes.

<validator>

Specifies whether message validation is activated for sent and received stack messages. The element supports the following optional attributes:

<vendor>

Optional element, which specifies the mapping between the vendor name, vendor ID, and vendor code. The element supports the following required attributes:


<typedefn>

Defines the simple Attribute Value Pair (AVP) types. The element supports the following required attributes:

type-name

Specifies a type name in accordance with the acceptable base types defined in RFC 3588. For example; "Enumerated", "OctetString", "Integer32".

type-parent

Specifies the parent type name used to define the base characteristics of the type. The values are restricted to defined <typedefn> elements. For example; "OctetString", "UTF8String", "IPAddress".


<application>

Defines the specific applications used within the dictionary. Two child elements are supported by <application>: <avp> and <command>. The <application> element supports the following attributes:

id

Specifies the unique ID allocated to the application. The attribute is used in all messages and forms part of the message header.

name

Optional attribute, which specifies the logical name of the application.

uri

Optional attribute, which specifies a link to additional application information.


<avp>

Element containing information necessary to configure the Attribute Value Pairs. Table 2.2, “<avp> Attributes” contains the complete list of supported attributes, and their available values (if applicable).

The <avp> element supports a number of child elements, which are used to set finer parameters for the individual AVP. The supported elements are <type>, <enum>, and <grouped>.

Note

Different sets of elements are supported by <avp> depending on its position in the dictionary.xml file.


<type>

Child element of <avp>, which is used to match the AVP with the AVP type as defined in the <typedefn> element. The element supports the following mandatory attribute:

type-name

Specifies the type name, which is used to match to the type-name value specified in the <typedefn> element.

Note

<type> is ignored if the <avp> element contains the <grouped> element.

<enum>

Child element of <avp>, which specifies the enumeration value for the specified AVP. <enum> is used only when the type-name attribute of <type> is specified. The element supports the following mandatory attributes:

name

Specifies the name of a constant value that applies to the AVP.

code

Specifies the integer value associated with the name of the constant. The value is passed as a value of the AVP, and maps to the name attribute.

Note

<enum> is ignored if the <avp> element contains the <grouped> element.

<grouped>

Child element of <avp>, which specifies the AVP is a grouped type. A grouped AVP is one that has no <typedefn> element present. The element does not support any attributes, however the <gavp> element is allowed as a child element.

<gavp>

Child element of <grouped>, which specifies a reference to a grouped AVP. The element supports one mandatory attribute:

name

Specifies the name of the grouped AVP member. The value must match the defined AVP name.



<command>

Specifies the command for the application. The element supports the <avp> element, which specifies the structure of the command. The element supports the following attributes:

name

Optional parameter, which specifies the message name for descriptive purposes.

code

Mandatory parameter, which specifies the integer code of the message.

request

Mandatory parameter, which specifies whether the declared command is a request or answer. The available values are "true" (request) or "false" (answer).

Note

If the <avp> element is specified in <command> it does not support any child elements. The <avp> element only refers to defined AVPs when used in this context.


Validator API defines methods to access its data base of AVP and check if AVP and message has proper structure.

Currently Validator is message oriented, that is it declared methods which center on message consitency checks. Class containing all validation logic is org.jdiameter.common.impl.validation.DiameterMessageValidator. It exposes the following methods:

Current implementation provides more methods, however those are out of scope for this documentation.

Simple example of validator use case look as follows: