use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class BaseFactoriesTest method testMessageCreationApplicationIdAvp.
@Test
public void testMessageCreationApplicationIdAvp() {
// Relates to Issue #1555 (http://code.google.com/p/mobicents/issues/detail?id=1555)
List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
try {
long acctApplicationId = 23121L;
DiameterAvp avpAcctApplicationId = avpFactory.createAvp(DiameterAvpCodes.ACCT_APPLICATION_ID, acctApplicationId);
avps.add(avpAcctApplicationId);
DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
avpArray = avps.toArray(avpArray);
AccountingRequest acr = messageFactory.createAccountingRequest(avpArray);
VendorSpecificApplicationIdAvp vsaidAvp = acr.getVendorSpecificApplicationId();
assertNull("Vendor-Specific-Application-Id should not be present in message.", vsaidAvp);
long msgAppId = acr.getAcctApplicationId();
assertTrue("Acct-Application-Id should be [" + acctApplicationId + "] it is [" + msgAppId + "]", acctApplicationId == msgAppId);
} catch (Exception e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class CxDxServerSessionImpl method createServerAssignmentAnswer.
/*
* (non-Javadoc)
* @see net.java.slee.resource.diameter.cxdx.CxDxServerSession#createServerAssignmentAnswer()
*/
public ServerAssignmentAnswer createServerAssignmentAnswer() {
// Make sure we have the correct type of Request
if (!(lastRequest instanceof ServerAssignmentRequest)) {
logger.warn("Invalid type of answer for this activity.");
return null;
}
try {
// Create the answer
ServerAssignmentAnswer saa = (ServerAssignmentAnswer) this.cxdxMessageFactory.createCxDxMessage(lastRequest.getHeader(), new DiameterAvp[] {}, ServerAssignmentAnswer.COMMAND_CODE, cxdxMessageFactory.getApplicationId());
// Fill session related AVPs, if present
fillSessionAVPs(saa);
return saa;
} catch (InternalException e) {
logger.error("Failed to create Server-Assignment-Answer.", e);
}
return null;
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class CxDxServerSessionImpl method createUserAuthorizationAnswer.
/*
* (non-Javadoc)
* @see net.java.slee.resource.diameter.cxdx.CxDxServerSession#createUserAuthorizationAnswer()
*/
public UserAuthorizationAnswer createUserAuthorizationAnswer() {
// Make sure we have the correct type of Request
if (!(lastRequest instanceof UserAuthorizationRequest)) {
logger.warn("Invalid type of answer for this activity. Type: " + lastRequest);
return null;
}
try {
// Create the answer
UserAuthorizationAnswer uaa = (UserAuthorizationAnswer) this.cxdxMessageFactory.createCxDxMessage(lastRequest.getHeader(), new DiameterAvp[] {}, UserAuthorizationAnswer.COMMAND_CODE, cxdxMessageFactory.getApplicationId());
// Fill session related AVPs, if present
fillSessionAVPs(uaa);
return uaa;
} catch (InternalException e) {
logger.error("Failed to create User-Authorization-Answer.", e);
}
return null;
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class AvpFlagsTest method testCorrectFlagsBaseExample.
@Test
public void testCorrectFlagsBaseExample() throws NoSuchAvpException {
List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.SESSION_ID, "accesspoint7.acme.com;1876543210;523;mobile@200.1.1.88".getBytes()));
DiameterAvp avpVendorId = baseAvpFactory.createAvp(DiameterAvpCodes.VENDOR_ID, 193);
DiameterAvp avpAcctApplicationId = baseAvpFactory.createAvp(DiameterAvpCodes.ACCT_APPLICATION_ID, 19302);
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.VENDOR_SPECIFIC_APPLICATION_ID, new DiameterAvp[] { avpVendorId, avpAcctApplicationId }));
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.ORIGIN_HOST, "127.0.0.1".getBytes()));
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.ORIGIN_REALM, "mobicents.org".getBytes()));
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.DESTINATION_HOST, ("127.0.0.1" + ":" + "3868").getBytes()));
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.DESTINATION_REALM, "mobicents.org".getBytes()));
// Subscription ID
DiameterAvp subscriptionIdType = baseAvpFactory.createAvp(193, 555, 0);
DiameterAvp subscriptionIdData = baseAvpFactory.createAvp(193, 554, "00001000");
avps.add(baseAvpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdType, subscriptionIdData }));
// Requested Service Unit
DiameterAvp unitType = baseAvpFactory.createAvp(193, 611, 2);
DiameterAvp valueDigits = baseAvpFactory.createAvp(193, 617, 10L);
DiameterAvp unitValue = baseAvpFactory.createAvp(193, 612, new DiameterAvp[] { valueDigits });
avps.add(baseAvpFactory.createAvp(193, 606, new DiameterAvp[] { unitType, unitValue }));
// Record Number and Type
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.ACCOUNTING_RECORD_NUMBER, 0));
avps.add(baseAvpFactory.createAvp(DiameterAvpCodes.ACCOUNTING_RECORD_TYPE, 1));
// Requested action
avps.add(baseAvpFactory.createAvp(193, 615, 0));
// Service Parameter Type
DiameterAvp serviceParameterType = baseAvpFactory.createAvp(193, 608, 0);
DiameterAvp serviceParameterValue = baseAvpFactory.createAvp(193, 609, "510");
avps.add(baseAvpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType, serviceParameterValue }));
// Service Parameter Type
DiameterAvp serviceParameterType2 = baseAvpFactory.createAvp(193, 608, 14);
DiameterAvp serviceParameterValue2 = baseAvpFactory.createAvp(193, 609, "20");
avps.add(baseAvpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType2, serviceParameterValue2 }));
DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
avpArray = avps.toArray(avpArray);
AccountingRequest acr = baseMessageFactory.createAccountingRequest();
acr.setExtensionAvps(avpArray);
ArrayList<String> failures = checkAvpFlags(((DiameterMessageImpl) acr).getGenericData().getAvps());
if (failures.size() > 0) {
System.err.println("The following AVPs flags have failed to check against dictionary:");
for (String failure : failures) {
System.err.println(failure);
}
Assert.fail(failures.toString());
}
// Test going through other way for adding avp's
acr = baseMessageFactory.createAccountingRequest(avpArray);
failures = checkAvpFlags(((DiameterMessageImpl) acr).getGenericData().getAvps());
if (failures.size() > 0) {
System.err.println("The following AVPs flags have failed to check against dictionary:");
for (String failure : failures) {
System.err.println(failure);
}
Assert.fail(failures.toString());
}
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class CreditControlMessageFactoryImpl method createCreditControlRequest.
/*
* (non-Javadoc)
*
* @see net.java.slee.resource.diameter.cca.CreditControlMessageFactory#createCreditControlRequest(java.lang.String)
*/
public CreditControlRequest createCreditControlRequest(String sessionId) throws IllegalArgumentException {
try {
DiameterAvp sessionIdAvp;
sessionIdAvp = creditControlAvpFactory.getBaseFactory().createAvp(0, DiameterAvpCodes.SESSION_ID, sessionId);
CreditControlRequest req = (CreditControlRequest) createCreditControlMessage(null, new DiameterAvp[] { sessionIdAvp });
addOrigin(req);
return req;
} catch (NoSuchAvpException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations