use of net.java.slee.resource.diameter.cca.events.avp.GrantedServiceUnitAvp 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.cca.events.avp.GrantedServiceUnitAvp in project jain-slee.diameter by RestComm.
the class CCAFactoriesTest method testAvpFactoryCreateGrantedServiceUnit.
@Test
public void testAvpFactoryCreateGrantedServiceUnit() throws Exception {
String avpName = "Granted-Service-Unit";
// Create AVP with mandatory values
GrantedServiceUnitAvp gsuAvp1 = ccaAvpFactory.createGrantedServiceUnit();
// Make sure it's not null
Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", gsuAvp1);
// Create AVP with default constructor
GrantedServiceUnitAvp gsuAvp2 = ccaAvpFactory.createGrantedServiceUnit();
// Should not contain mandatory values
// Set mandatory values
// Make sure it's equal to the one created with mandatory values constructor
Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", gsuAvp1, gsuAvp2);
// Make new copy
gsuAvp2 = ccaAvpFactory.createGrantedServiceUnit();
// And set all values using setters
CCAAvpAssistant.INSTANCE.testSetters(gsuAvp2);
// Create empty...
GrantedServiceUnitAvp gsuAvp3 = ccaAvpFactory.createGrantedServiceUnit();
// Verify that no values have been set
CCAAvpAssistant.INSTANCE.testHassers(gsuAvp3, false);
// Set all previous values
gsuAvp3.setExtensionAvps(gsuAvp2.getExtensionAvps());
// Verify if values have been set
CCAAvpAssistant.INSTANCE.testHassers(gsuAvp3, true);
// Verify if values have been correctly set
CCAAvpAssistant.INSTANCE.testGetters(gsuAvp3);
// Make sure they match!
Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", gsuAvp2, gsuAvp3);
}
Aggregations