jDiameter

Legacy code prototype

Following is legacy example of Diameter client which could be used for testing. In the below code some methods are already deprecated and should be used in different way in more recent jDiameter library.

1. (OPTIONAL) Install IDE NetBeans

2. Download and install Mobicent RestComm jDiameter

git clone https://github.com/RestComm/jdiameter.git

cd jdiameter/

mvn clean install

3. (OPTIONAL) Import jDiameter and jdiameter/examples/guide1 project into NetBeans

4. Work with jdiameter/examples/guide1 and modify the ExampleClient.java and ExampleServer.java, attached bellow are modified files.

ExampleClient.java

...

private static final int commandCode = 316;

private static final long applicationID = 16777251;

...

...

public static byte[] hexStringToByteArray(String s) {

int len = s.length();

byte[] data = new byte[len / 2];

for (int i = 0; i < len; i += 2) {

data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16));

}

return data;

}


private void sendNextRequest(int enumType) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {

Request r = this.session.createRequest(commandCode, this.authAppId, realmName, serverURI);

// here we have all except our custom avps


// example how to remove AVP

AvpSet requestAvps = r.getAvps();

requestAvps.removeAvp(293);


// example how to add AVP IMSI

byte[] b = hexStringToByteArray("31313131313131313131313131313131");

requestAvps.addAvp(1, b, true, false);

// code , value , vendor, mandatory,protected,isUnsigned32

// (Enumerated)

Avp exchangeType = requestAvps.addAvp(exchangeTypeCode, (long) enumType, vendorID, true, false, true);


// code , value , vendor, mandatory,protected, isOctetString

Avp exchengeData = requestAvps.addAvp(exchangeDataCode, TO_SEND[toSendIndex++], vendorID, true, false, false);



// send

this.session.send(r, this);

dumpMessage(r,true); //dump info on console

}

...

5. Run ExampleServer and ExampleClient. Example of generated traffic is bellow.