Search in sources :

Example 41 with DiameterAvp

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());
    }
}
Also used : VendorSpecificApplicationIdAvp(net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp) AccountingRequest(net.java.slee.resource.diameter.base.events.AccountingRequest) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 42 with DiameterAvp

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;
}
Also used : ServerAssignmentRequest(net.java.slee.resource.diameter.cxdx.events.ServerAssignmentRequest) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ServerAssignmentAnswer(net.java.slee.resource.diameter.cxdx.events.ServerAssignmentAnswer) InternalException(org.jdiameter.api.InternalException)

Example 43 with DiameterAvp

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;
}
Also used : UserAuthorizationRequest(net.java.slee.resource.diameter.cxdx.events.UserAuthorizationRequest) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) UserAuthorizationAnswer(net.java.slee.resource.diameter.cxdx.events.UserAuthorizationAnswer) InternalException(org.jdiameter.api.InternalException)

Example 44 with DiameterAvp

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());
    }
}
Also used : AccountingRequest(net.java.slee.resource.diameter.base.events.AccountingRequest) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) Test(org.junit.Test)

Example 45 with DiameterAvp

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);
    }
}
Also used : DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) CreditControlRequest(net.java.slee.resource.diameter.cca.events.CreditControlRequest) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Aggregations

DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)65 Message (org.jdiameter.api.Message)22 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)21 InternalException (org.jdiameter.api.InternalException)21 AvpSet (org.jdiameter.api.AvpSet)18 ArrayList (java.util.ArrayList)15 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)15 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)12 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)9 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)6 AccountingRequest (net.java.slee.resource.diameter.base.events.AccountingRequest)3 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)3 GxCreditControlMessage (net.java.slee.resource.diameter.gx.events.GxCreditControlMessage)3 GxReAuthMessage (net.java.slee.resource.diameter.gx.events.GxReAuthMessage)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 DiameterIdentity (net.java.slee.resource.diameter.base.events.avp.DiameterIdentity)2 CreditControlRequest (net.java.slee.resource.diameter.cca.events.CreditControlRequest)2 RoCreditControlMessage (net.java.slee.resource.diameter.ro.events.RoCreditControlMessage)2 ApplicationId (org.jdiameter.api.ApplicationId)2