use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.
the class DiameterTestsSbb method sendAccountingRequest.
private void sendAccountingRequest() {
try {
List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
avps.add(avpFactory.createAvp(Avp.SESSION_ID, "12345".getBytes()));
DiameterAvp avpVendorId = avpFactory.createAvp(Avp.VENDOR_ID, 193);
DiameterAvp avpAcctApplicationId = avpFactory.createAvp(Avp.ACCT_APPLICATION_ID, 193);
avps.add(avpFactory.createAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, new DiameterAvp[] { avpVendorId, avpAcctApplicationId }));
avps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, "aaa://127.0.0.1:3868".getBytes()));
avps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, "mobicents.org".getBytes()));
avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "aaa://127.0.0.1:13868".getBytes()));
avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes()));
// Subscription ID
DiameterAvp subscriptionIdType = avpFactory.createAvp(193, 555, 0);
DiameterAvp subscriptionIdData = avpFactory.createAvp(193, 554, "00001000");
avps.add(avpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdType, subscriptionIdData }));
// Requested Service Unit
DiameterAvp unitType = avpFactory.createAvp(193, 611, 2);
DiameterAvp valueDigits = avpFactory.createAvp(193, 617, 10L);
DiameterAvp unitValue = avpFactory.createAvp(193, 612, new DiameterAvp[] { valueDigits });
avps.add(avpFactory.createAvp(193, 606, new DiameterAvp[] { unitType, unitValue }));
// Record Number and Type
avps.add(avpFactory.createAvp(Avp.ACC_RECORD_NUMBER, 0));
avps.add(avpFactory.createAvp(Avp.ACC_RECORD_TYPE, 1));
// Requested action
avps.add(avpFactory.createAvp(193, 615, 0));
// Service Parameter Type
DiameterAvp serviceParameterType = avpFactory.createAvp(193, 608, 0);
DiameterAvp serviceParameterValue = avpFactory.createAvp(193, 609, "510");
avps.add(avpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType, serviceParameterValue }));
// Service Parameter Type
DiameterAvp serviceParameterType2 = avpFactory.createAvp(193, 608, 14);
DiameterAvp serviceParameterValue2 = avpFactory.createAvp(193, 609, "20");
avps.add(avpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType2, serviceParameterValue2 }));
DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
avpArray = avps.toArray(avpArray);
logger.info("Creating Custom Message...");
DiameterMessage ms = messageFactory.createAccountingRequest(avpArray);
logger.info("Created Custom Message[" + ms + "]");
logger.info("Sending Custom Message...");
provider.createActivity().sendMessage(ms);
logger.info("Sent Custom Message[" + ms + "]");
} catch (Exception e) {
logger.error("", e);
}
}
use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.
the class RoSessionActivityImpl method sendSyncMessage.
@Override
public DiameterMessage sendSyncMessage(DiameterMessage message) {
DiameterMessage answer = null;
Message receivedMessage = doSendMessage(message);
if (receivedMessage != null) {
if (!receivedMessage.isRequest()) {
if (receivedMessage.isError()) {
answer = new ErrorAnswerImpl(receivedMessage);
} else {
switch(receivedMessage.getCommandCode()) {
case RoCreditControlRequest.commandCode:
answer = new RoCreditControlAnswerImpl(receivedMessage);
break;
default:
logger.error("Received an unknown type of Message for Ro Activity: " + receivedMessage);
break;
}
}
} else {
logger.error("Received a REQUEST message when expecting an ANSWER.");
}
} else {
logger.debug("No answer received. Returning null.");
}
return answer;
}
use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.
the class RxMessageFactoryImpl method createDiameterMessage.
protected DiameterMessage createDiameterMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws IllegalArgumentException {
boolean creatingRequest = diameterHeader == null;
Message msg = null;
if (!creatingRequest) {
Message raw = createMessage(diameterHeader, avps, 0, appId);
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
msg = raw;
} else {
Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
raw.setRequest(true);
msg = raw;
}
int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
DiameterMessage diamMessage = null;
switch(commandCode) {
case AARequest.commandCode:
diamMessage = creatingRequest ? new AARequestImpl(msg) : new AAAnswerImpl(msg);
break;
case Message.ABORT_SESSION_REQUEST:
diamMessage = creatingRequest ? new AbortSessionRequestImpl(msg) : new AbortSessionAnswerImpl(msg);
break;
case Message.RE_AUTH_REQUEST:
diamMessage = creatingRequest ? new ReAuthRequestImpl(msg) : new ReAuthAnswerImpl(msg);
break;
case Message.SESSION_TERMINATION_REQUEST:
diamMessage = creatingRequest ? new SessionTerminationRequestImpl(msg) : new SessionTerminationAnswerImpl(msg);
break;
default:
throw new IllegalArgumentException();
}
// Finally, add Origin-Host and Origin-Realm, if not present.
addOriginHostAndRealm(diamMessage);
return diamMessage;
}
use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.
the class RxSessionActivityImpl method sendSyncMessage.
public DiameterMessage sendSyncMessage(DiameterMessage message) {
DiameterMessage answer = null;
Message receivedMessage = doSendMessage(message);
if (receivedMessage != null) {
if (!receivedMessage.isRequest()) {
if (receivedMessage.isError()) {
answer = new ErrorAnswerImpl(receivedMessage);
} else {
switch(receivedMessage.getCommandCode()) {
case 274:
answer = new AbortSessionAnswerImpl(receivedMessage);
break;
case 258:
answer = new ReAuthAnswerImpl(receivedMessage);
break;
case 275:
answer = new SessionTerminationAnswerImpl(receivedMessage);
break;
case AARequest.commandCode:
answer = new AAAnswerImpl(receivedMessage);
default:
logger.error((new StringBuilder()).append("Received an unknown type of Message for Base Activity: ").append(receivedMessage).toString());
break;
}
}
} else {
logger.error("Received a REQUEST message when expecting an ANSWER.");
}
} else {
logger.debug("No answer received. Returning null.");
}
return answer;
}
use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.
the class S13MessageFactoryImpl method createS13Message.
/**
* Creates a S13 Message with specified command-code and avps filled. If a header is present an answer will be created, if not
* it will generate a request.
*
* @param diameterHeader
* @param avps
* @param _commandCode
* @param appId
* @return
* @throws InternalException
*/
DiameterMessage createS13Message(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws InternalException {
boolean creatingRequest = diameterHeader == null;
Message msg = null;
if (!creatingRequest) {
Message raw = createMessage(diameterHeader, avps, 0, appId);
raw.setProxiable(diameterHeader.isProxiable());
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
// FIXME ? raw.getAvps().removeAvp(Avp.AUTH_APPLICATION_ID);
msg = raw;
} else {
Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
raw.setProxiable(true);
raw.setRequest(true);
msg = raw;
}
int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
DiameterMessage diamMessage = null;
switch(commandCode) {
case MEIdentityCheckRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new MEIdentityCheckRequestImpl(msg) : new MEIdentityCheckAnswerImpl(msg);
break;
default:
diamMessage = new ExtensionDiameterMessageImpl(msg);
}
if (!diamMessage.hasSessionId() && session != null) {
diamMessage.setSessionId(session.getSessionId());
}
return diamMessage;
}
Aggregations