Search in sources :

Example 1 with RoCreditControlAnswer

use of net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer in project charging-server by RestComm.

the class DiameterChargingServerSbb method createCCA.

/**
 * @param ccServerActivity
 * @param request
 * @param reservations
 * @param resultCode
 * @return
 */
private RoCreditControlAnswer createCCA(RoServerSessionActivity ccServerActivity, RoCreditControlRequest request, List<CreditControlInfo> reservations, long resultCode) {
    RoCreditControlAnswer answer = ccServerActivity.createRoCreditControlAnswer();
    // <Credit-Control-Answer> ::= < Diameter Header: 272, PXY >
    // < Session-Id >
    // { Result-Code }
    answer.setResultCode(resultCode);
    // *[ AVP ]
    if (reservations != null && reservations.size() > 0) {
        MultipleServicesCreditControlAvp[] reqMSCCs = request.getMultipleServicesCreditControls();
        List<MultipleServicesCreditControlAvp> ansMSCCs = new ArrayList<MultipleServicesCreditControlAvp>();
        for (int index = 0; index < reqMSCCs.length; index++) {
            MultipleServicesCreditControlAvp reqMSCC = reqMSCCs[index];
            MultipleServicesCreditControlAvp ansMscc = avpFactory.createMultipleServicesCreditControl();
            ansMscc.setRatingGroup(reqMSCC.getRatingGroup());
            ansMscc.setServiceIdentifiers(reqMSCC.getServiceIdentifiers());
            // FIXME: Check how to handle this in case of MSCC if anything different is needed
            CreditControlInfo ccInfo = reservations.get(reservations.size() - 1);
            if (ccInfo.isSuccessful()) {
                GrantedServiceUnitAvp gsu = avpFactory.createGrantedServiceUnit();
                ArrayList<CreditControlUnit> ccUnits = ccInfo.getCcUnits();
                for (int i = 0; i < ccUnits.size(); i++) {
                    CreditControlUnit ccUnit = ccUnits.get(i);
                    if (ccUnit.getUnitType() == CcUnitType.INPUT_OCTETS) {
                        gsu.setCreditControlInputOctets(ccUnit.getReservedUnits());
                    }
                    // TODO: Add CC-Money support if not 3GPP ?
                    if (ccUnit.getUnitType() == CcUnitType.OUTPUT_OCTETS) {
                        gsu.setCreditControlOutputOctets(ccUnit.getReservedUnits());
                    }
                    if (ccUnit.getUnitType() == CcUnitType.SERVICE_SPECIFIC_UNITS) {
                        gsu.setCreditControlServiceSpecificUnits(ccUnit.getReservedUnits());
                    }
                    if (ccUnit.getUnitType() == CcUnitType.TIME) {
                        gsu.setCreditControlTime(ccUnit.getReservedUnits());
                    }
                    if (ccUnit.getUnitType() == CcUnitType.TOTAL_OCTETS) {
                        gsu.setCreditControlTotalOctets(ccUnit.getReservedUnits());
                    }
                }
                ansMscc.setGrantedServiceUnit(gsu);
                ansMscc.setResultCode(DiameterResultCode.DIAMETER_SUCCESS);
                // If we are terminating gracefully we MAY include the Final-Unit-Indication
                if (answer.getCcRequestType() == CcRequestType.TERMINATION_REQUEST) {
                    FinalUnitIndicationAvp fuiAvp = avpFactory.createFinalUnitIndication();
                    fuiAvp.setFinalUnitAction(FinalUnitActionType.TERMINATE);
                    ansMscc.setFinalUnitIndication(fuiAvp);
                }
            } else {
                // In case it's not successful we want to have Final-Unit-Indication
                FinalUnitIndicationAvp fuiAvp = avpFactory.createFinalUnitIndication();
                fuiAvp.setFinalUnitAction(FinalUnitActionType.TERMINATE);
                ansMscc.setFinalUnitIndication(fuiAvp);
                ansMscc.setResultCode(resultCode);
            }
            ansMSCCs.add(ansMscc);
            ansMscc.setValidityTime(DEFAULT_VALIDITY_TIME);
        }
        answer.setMultipleServicesCreditControls(ansMSCCs.toArray(new MultipleServicesCreditControlAvp[ansMSCCs.size()]));
    }
    if (tracer.isInfoEnabled()) {
        tracer.info("[>>] " + sidString + " Created Credit-Control-Answer with Result-Code = " + answer.getResultCode() + ".");
        if (tracer.isFineEnabled()) {
            tracer.fine(answer.toString());
        }
    }
    return answer;
}
Also used : MultipleServicesCreditControlAvp(net.java.slee.resource.diameter.cca.events.avp.MultipleServicesCreditControlAvp) CreditControlInfo(org.mobicents.charging.server.account.CreditControlInfo) FinalUnitIndicationAvp(net.java.slee.resource.diameter.cca.events.avp.FinalUnitIndicationAvp) ArrayList(java.util.ArrayList) RoCreditControlAnswer(net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer) GrantedServiceUnitAvp(net.java.slee.resource.diameter.cca.events.avp.GrantedServiceUnitAvp) CreditControlUnit(org.mobicents.charging.server.account.CreditControlUnit)

Example 2 with RoCreditControlAnswer

use of net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer in project jain-slee.diameter by RestComm.

the class RoFactoriesTest method testGettersAndSettersCCA.

@Test
public void testGettersAndSettersCCA() throws Exception {
    RoCreditControlAnswer cca = roServerSession.createRoCreditControlAnswer();
    int nFailures = RoAvpAssistant.INSTANCE.testMethods(cca, RoCreditControlAnswer.class);
    assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
}
Also used : RoCreditControlAnswer(net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 3 with RoCreditControlAnswer

use of net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer in project jain-slee.diameter by RestComm.

the class RoFactoriesTest method testServerSessionApplicationIdChangeCCA.

@Test
public void testServerSessionApplicationIdChangeCCA() throws Exception {
    long vendor = 10415L;
    ApplicationId originalAppId = ((RoMessageFactoryImpl) roMessageFactory).getApplicationId();
    boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isVendor = originalAppId.getVendorId() != 0L;
    assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
    System.out.println("Default VENDOR-ID for Ro is " + originalAppId.getVendorId());
    // let's create a message and see how it comes...
    RoCreditControlRequest ccr = roMessageFactory.createRoCreditControlRequest();
    ((RoServerSessionActivityImpl) roServerSession).fetchCurrentState(ccr);
    RoCreditControlAnswer originalCCA = roServerSession.createRoCreditControlAnswer();
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalCCA);
    // now we switch..
    originalCCA = null;
    isVendor = !isVendor;
    ((RoMessageFactoryImpl) roMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
    // create a new message and see how it comes...
    RoCreditControlAnswer changedCCA = roServerSession.createRoCreditControlAnswer();
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedCCA);
    // revert back to default
    ((RoMessageFactoryImpl) roMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
}
Also used : RoServerSessionActivityImpl(org.mobicents.slee.resource.diameter.ro.RoServerSessionActivityImpl) RoCreditControlAnswer(net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer) ApplicationId(org.jdiameter.api.ApplicationId) RoCreditControlRequest(net.java.slee.resource.diameter.ro.events.RoCreditControlRequest) RoMessageFactoryImpl(org.mobicents.slee.resource.diameter.ro.RoMessageFactoryImpl) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 4 with RoCreditControlAnswer

use of net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer in project jain-slee.diameter by RestComm.

the class RoFactoriesTest method isAnswerCCA.

@Test
public void isAnswerCCA() throws Exception {
    RoCreditControlAnswer cca = roServerSession.createRoCreditControlAnswer();
    assertFalse("Request Flag in Credit-Control-Answer is set.", cca.getHeader().isRequest());
}
Also used : RoCreditControlAnswer(net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 5 with RoCreditControlAnswer

use of net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer in project jain-slee.diameter by RestComm.

the class RoFactoriesTest method isProxiableCopiedCCA.

@Test
public void isProxiableCopiedCCA() throws Exception {
    RoCreditControlRequest ccr = roMessageFactory.createRoCreditControlRequest();
    ((RoServerSessionActivityImpl) roServerSession).fetchCurrentState(ccr);
    RoCreditControlAnswer cca = roServerSession.createRoCreditControlAnswer();
    assertEquals("The 'P' bit is not copied from request in Ro Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
    // Reverse 'P' bit ...
    ((DiameterMessageImpl) ccr).getGenericData().setProxiable(!ccr.getHeader().isProxiable());
    assertTrue("The 'P' bit was not modified in Ro Credit-Control-Request, it should.", ccr.getHeader().isProxiable() != cca.getHeader().isProxiable());
    ((RoServerSessionActivityImpl) roServerSession).fetchCurrentState(ccr);
    cca = roServerSession.createRoCreditControlAnswer();
    assertEquals("The 'P' bit is not copied from request in Ro Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
}
Also used : RoServerSessionActivityImpl(org.mobicents.slee.resource.diameter.ro.RoServerSessionActivityImpl) RoCreditControlAnswer(net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer) RoCreditControlRequest(net.java.slee.resource.diameter.ro.events.RoCreditControlRequest) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Aggregations

RoCreditControlAnswer (net.java.slee.resource.diameter.ro.events.RoCreditControlAnswer)12 Test (org.junit.Test)8 BaseFactoriesTest (org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)8 RoCreditControlRequest (net.java.slee.resource.diameter.ro.events.RoCreditControlRequest)4 IOException (java.io.IOException)3 RoServerSessionActivityImpl (org.mobicents.slee.resource.diameter.ro.RoServerSessionActivityImpl)3 ArrayList (java.util.ArrayList)2 CreateException (javax.slee.CreateException)2 SLEEException (javax.slee.SLEEException)2 MultipleServicesCreditControlAvp (net.java.slee.resource.diameter.cca.events.avp.MultipleServicesCreditControlAvp)2 RoServerSessionActivity (net.java.slee.resource.diameter.ro.RoServerSessionActivity)2 CreditControlInfo (org.mobicents.charging.server.account.CreditControlInfo)2 CreditControlUnit (org.mobicents.charging.server.account.CreditControlUnit)2 UserSessionInfo (org.mobicents.charging.server.data.UserSessionInfo)2 ActivityContextInterface (javax.slee.ActivityContextInterface)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 FinalUnitIndicationAvp (net.java.slee.resource.diameter.cca.events.avp.FinalUnitIndicationAvp)1 GrantedServiceUnitAvp (net.java.slee.resource.diameter.cca.events.avp.GrantedServiceUnitAvp)1 RequestedActionType (net.java.slee.resource.diameter.cca.events.avp.RequestedActionType)1 RequestedServiceUnitAvp (net.java.slee.resource.diameter.cca.events.avp.RequestedServiceUnitAvp)1