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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations