jDiameter – Open Source Diameter Protocol Implementation

5 minutes Tutorial


5 minutes Tutorial
version 1.5.x


special or consequential damages. by or with respect to anything in this document. and shall not be liable for any implied warranties of merchantability or fitness for a particular purpose or for any indirect. 2 . either expressed or implied.jDiameter – Open Source Diameter Protocol Implementation 5 minutes Tutorial Disclaimer of warranty jDiameter team makes no representations or warranties.

forName("org. Secondly you need be configured created stack instance: XMLConfiguration configuration = null.impl.x JDiameter Default Implemetation 1.getClass().client. StackManager. Example of a client configuration files : <?xml version="1. The following prerequisites are required for this tutorial: · · · · JDiameter API 1.x JDK 1. Stack diameter or we create a stack shared instance: Class diameterClass = Class.registerStack(diameter).5.. // Server version Class diameterClass = Class. Compilation commands and steps to execute the program have been removed for brevity.forName("org.StackImpl").StackImpl"). .init(configuration).jdiameter.5 or greater Pico Container: binary & sources If you have any problems getting this program to work..0"?> <Configuration xmlns="http://www..server.client.jdiameter..xml") ). StackManager.impl.StackImpl").. configuration = new XMLConfiguration( this. SessionFactory factory = stack. Stack diameter = (Stack)diameterClass. If you need help learning how to either compile of execute java programs.newInstance(). . Stack diameter = (Stack)diameterClass.5.. .jDiameter – Open Source Diameter Protocol Implementation 5 minutes Tutorial Installation The JDiameter Tutorials are practical guides for programmers who want to use the JDiameter implementation to work with diameter network.newInstance().getResourceAsStream("/configuration.org/jdiameter-client"> 3 .unregisterStack(diameter). please consult the Java tutorial Client part The JDiameter Tutorials are practical guides for programmers who want to use the JDiameter implementation to work with diameter network. please do not hesitate to use the Mailing Lists in order to talk to the JDiameter developers.forName("org.jdiameter. First you need to create a stack instance: // Client version Class diameterClass = Class.jdiameter.impl.

jdiameter. Assembler.helpers.defValue()). public ClientTestsConfiguration() { super().server.*. import static org.jdiameter. add(Assembler.jDiameter – Open Source Diameter Protocol Implementation <LocalPeer> <URI value="aaa://localhost:1812"/> <IPAddress value="127.jdiameter.helpers.0.server.1"/> <Realm value="home"/> <VendorID value="193"/> <ProductName value="jDiameter"/> <FirmwareRevision value="1"/> <Applications> <ApplicationID> <VendorId value="193"/> <AuthApplId value="0"/> <AcctApplId value="19302"/> </ApplicationID> <ApplicationID> <VendorId value="193"/> <AuthApplId value="19301"/> <AcctApplId value="0"/> </ApplicationID> </Applications> </LocalPeer> <Parameters> <QueueSize value="10000"/> <MessageTimeOut value="60000"/> <StopTimeOut value="10000"/> <CeaTimeOut value="10000"/> <IacTimeOut value="30000"/> <DwaTimeOut value="10000"/> <DpaTimeOut value="5000"/> <RecTimeOut value="10000"/> </Parameters> <Network> <Peers> <Peer name="aaa://localhost:1813" rating="1"/> </Peers> <Realms> <Realm name="home" peers="localhost"/> </Realms> </Network> <Extensions/> </Configuration> 5 minutes Tutorial Also you can create configuration file in runtime by helper class EmptyConfiguration : package org.EmptyConfiguration.0.Parameters.impl.impl. 4 .server. public static final String peerTwo = "terra". public class ClientTestsConfiguration extends EmptyConfiguration { public static final String peerOne = "localhost". import org.

add(VendorId.add(InternalTransportFactory. add(VendorId. List of supported extensions and extension parameters: · · StackLayer: InternalMetaData. false). "LOCAL"). InternalRouterEngine 5 . 193).TransportLayerFactoryImpl").ordinal())[ TransportLayer. InternalMessageParser. add(RealmName. getInstance(). add(PeerAttemptConnection. "home"). add(AuthApplId. "aaa://"+ peerOne +":1812"). "aaa://"+ peerTwo +":1814") ). "aaa://"+ peerOne +":1813"). add(RealmHosts. add(PeerName. // Set realm table add( RealmTable. // AppId 1 getInstance(). "home"). true). 2). InternalElementParser ControllerLayer: InternalPeerFsmFactory. true). true). // Peer 2 getInstance(). // Set Applications add(ApplicationId. peerOne + ". // Realm 1 getInstance(). add(RealmLocalAction. // Peer 1 getInstance(). add(OwnRealm. add(AuthApplId. InternalSessionFactory. "org.jdiameter. getInstance(). 19302) ). 3) ). add(PeerRating. add(ApplicationId.id() ]. add(OwnVendorID. add(RealmEntryIsDynamic. 1).plugins. add(PeerName. add(AcctApplId. 1000L) ) ). 193).mina. false). 19302).add( RealmEntry.jDiameter – Open Source Diameter Protocol Implementation 5 minutes Tutorial add(OwnDiameterURI. add(DuplicateProtection. extTransport. add(AcctApplId. add(PeerRating. 1). add(AcceptUndefinedPeer. } } Application can use external plugins ( MINA FrameWork for transport layer): // Set extension external transport layer MutableConfiguration extTransport = (MutableConfiguration) getChildren(Extensions." + peerTwo). // Set peer table add(PeerTable. add(PeerAttemptConnection. add(RealmEntryExpTime. 1).

logger. Session session = factory.setLevel(Level.SECONDS).getMetaData().ANY_PEER.logger().println("Warning:"+record).. Blocking start . } } public void flush() { } public void close() throws SecurityException { } } )..FSM.SEVERE) { System.getNewSession().stack..) method to begin a stack work Not blocking start .println("Severe:"+record).addHandler( new Handler() { public void publish(LogRecord record) { if (record. It's necessary to call a start (.start(Mode. 10.getLogger(). stack.jDiameter – Open Source Diameter Protocol Implementation · 5 minutes Tutorial TransportLayer: InternalTransportFactory After configuration it is possible to read the meta-information on a stack: MetaData metaData = stack. } else if (record. TimeUnit.start().getLogger(). ConsoleHandler fh = new ConsoleHandler()..setLevel(Level.ALL).addHandler(fh). // Set logger levels Loggers. 6 .out. The thread is blocked till time will not expire or the condition defined by the first parameter will not be satisfied (Any/All peers pass to condition "OKAY") Using factory we create diameter session and establish listener that will process requests from a s erver.out. SessionFactory factory = stack.setUseParentHandlers(false). fh.stack.getLevel() == Level.getSessionFactory(). stack.ALL). Logger management: .WARNING) { System.getLogger(). . Logger logger = stack.getLevel() == Level..

EventListener answerListener listener = new EventListener() { public void receivedSuccessMessage(Request r.createByAccAppId(19302).getFQDN()). ApplicationId. "localhost").getUri().toArray(new Peer[0])[0].jDiameter – Open Source Diameter Protocol Implementation session. 100). For a stop of a stack it's necessary to cause blocking command stop(.getStatistic( mw.getRecords()) { logger. and send to a server: session.stop(10.class). on callback one of methods signalling that the answer is recei ved will be caused.). } Configuration 7 . fill its with necessary data: msg. Server part Statistics Statistics allows control of the stack instance. TimeUnit.SECONDS). it is necessary to release resources bor rowed by session: session. Examples MutablePeerTable mw = stack.unwrap(MutablePeerTable.destroy(). then e xception is generated.getAvps(). stack. Statistic stat = mw. Answer a) { … } public void timeoutExpired(Message r) { … } } After work with session is finished.getPeerTable . After work it's necessary to release all resources which were used with a sta ck: stack.DOWN). setRequestListener(listener). "network". After a while. Further we create diameter message 5 minutes Tutorial Message msg = session. for (StatisticRecord sr : stat.createRequest(1.send(msg. whi ch stops network activity of a stack (expects when all peers will pass to condition PeerState .getValueAsInt()). answerListener)..addAvp(100..getDescription() + sr. If during specified time the stack doesn't pass in a condition "stop".info( sr.release().

0.jDiameter – Open Source Diameter Protocol Implementation 5 minutes Tutorial Example of configuration file: <?xml version="1.1"/> <IPAddress value="127.0.org/jdiameter-server"> <LocalPeer> <URI value="aaa://localhost:1812"/> <IPAddresses> <IPAddress value="127.2"/> </IPAddresses> <Realm value="home"/> <VendorID value="193"/> <ProductName value="jDiameter"/> <FirmwareRevision value="1"/> <OverloadMonitor> <Entry index="1" lowThreshold="0.0.0"?> <Configuration xmlns="http://www.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"/> <QueueSize value="10000"/> <MessageTimeOut value="60000"/> <StopTimeOut value="10000"/> <CeaTimeOut value="10000"/> <IacTimeOut value="30000"/> <DwaTimeOut value="10000"/> <DpaTimeOut value="5000"/> <RecTimeOut value="10000"/> </Parameters> <Network> <Peers> <Peer name="aaa://localhost:1813" attempt_connect="true" rating=" 1"/> </Peers> <Realms> <Realm name ="abc" peers="localhost" local_action="LOCAL" dynamic ="false" exp_time="1"> <ApplicationID> <VendorId value="193"/> <AuthApplId value="0"/> <AcctApplId value="19302"/> </ApplicationID> </Realm> </Realms> </Network> <Extensions/> 8 .5" highThreshold="0.0.jdiameter.

Realm. Levels Runtime Parameters name DuplicateTimer AcceptUndefinedPeer MessageTimeOut StopTimeOut CeaTimeOut IacTimeOut DwaTimeOut DpaTimeOut RecTimeOut PeerTable. AcctApplId OverloadMonitor. configuration1. RealmLocalAction. configuration1. OverloadMonitorEntry. RealmEntryIsDynamic. RealmHosts. RealmEntry RealmName. PeerAttemptConnection ( by NetWork interface) RealmTable.ordinal()). PeerName. AcceptUndefinedPeer.ordinal()). configuration1. OverloadEntrylowThreshold DuplicateProtection QueueSize Restart stack Not changable Examples MutableConfiguration configuration1 = (MutableConfiguration) serverStack. OverloadMonitorData. 9 .ordinal(). OwnIPAddress OwnRealm OwnVendorID OwnProductName OwnFirmwareRevision ApplicationId. false). Peer. ConfigurationListener cf = new ConfigurationListener() { public boolean elementChanged(int i. VendorId.getConfiguration().addChangeListener(cf.removeChangeListener(cf. RealmEntryExpTime ( by NetWork interface) OwnDiameterURI OwnIPAddresses.setBooleanValue(AcceptUndefinedPeer. OverloadEntryIndex OverloadEntryhighThreshold.jDiameter – Open Source Diameter Protocol Implementation </Configuration> 5 minutes Tutorial Mutable Configuration allows changes parameters of stack. PeerRating. Object o) { return false. AuthApplId. AcceptUndefinedPeer. // rollback changes } }.

.class).. 0.. } }.jDiameter – Open Source Diameter Protocol Implementation 5 minutes Tutorial Overload Manager Overload manager allows an application to manage app/stack behaviour if we has CPU. 10 .parentAppOverloadCeased( ApplicationId. 1D ). 0. double v) { . we can reduce the application load skipping new network requests to application OverloadManager manager = serverStack. OverloadListener lsr = new OverloadListener() { public void overloadDetected(URI uri. 0).unwrap(OverloadManager.createByAccAppId(193. 1.. Network overloads.class)... Using overload manager.0D. Using listener. 19302). 0). } public void overloadCeased(URI uri) { . manager. …. we can reduce the load on the network level : OverloadManager manager = serverStack1.addOverloadListener( lsr.parentAppOverloadDetected(ApplicationId. manager. manager.5D.createByAccAppId(193..unwrap(OverloadManager. 19302)..

Sign up to vote on this title
UsefulNot useful