use of net.java.slee.resource.diameter.cca.events.avp.FinalUnitIndicationAvp 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.FinalUnitIndicationAvp in project jain-slee.diameter by RestComm.
the class CCAFactoriesTest method testAvpFactoryCreateFinalUnitIndication.
@Test
public void testAvpFactoryCreateFinalUnitIndication() throws Exception {
String avpName = "Final-Unit-Indication";
// Create AVP with mandatory values
FinalUnitIndicationAvp fuiAvp1 = ccaAvpFactory.createFinalUnitIndication(FinalUnitActionType.RESTRICT_ACCESS);
// Make sure it's not null
Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", fuiAvp1);
// Create AVP with default constructor
FinalUnitIndicationAvp fuiAvp2 = ccaAvpFactory.createFinalUnitIndication();
// Should not contain mandatory values
Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Final-Unit-Action AVP.", fuiAvp2.hasFinalUnitAction());
// Set mandatory values
fuiAvp2.setFinalUnitAction(FinalUnitActionType.RESTRICT_ACCESS);
// 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.", fuiAvp1, fuiAvp2);
// Make new copy
fuiAvp2 = ccaAvpFactory.createFinalUnitIndication();
// And set all values using setters
CCAAvpAssistant.INSTANCE.testSetters(fuiAvp2);
// Create empty...
FinalUnitIndicationAvp fuiAvp3 = ccaAvpFactory.createFinalUnitIndication();
// Verify that no values have been set
CCAAvpAssistant.INSTANCE.testHassers(fuiAvp3, false);
// Set all previous values
fuiAvp3.setExtensionAvps(fuiAvp2.getExtensionAvps());
// Verify if values have been set
CCAAvpAssistant.INSTANCE.testHassers(fuiAvp3, true);
// Verify if values have been correctly set
CCAAvpAssistant.INSTANCE.testGetters(fuiAvp3);
// Make sure they match!
Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", fuiAvp2, fuiAvp3);
}
use of net.java.slee.resource.diameter.cca.events.avp.FinalUnitIndicationAvp in project jain-slee.diameter by RestComm.
the class CreditControlAVPFactoryImpl method createFinalUnitIndication.
/* (non-Javadoc)
* @see net.java.slee.resource.diameter.cca.CreditControlAVPFactory#createFinalUnitIndication(net.java.slee.resource.diameter.cca.events.avp.FinalUnitActionType)
*/
public FinalUnitIndicationAvp createFinalUnitIndication(FinalUnitActionType finalUnitAction) {
// Create the empty AVP
FinalUnitIndicationAvp avp = createFinalUnitIndication();
// Set the provided AVP values
avp.setFinalUnitAction(finalUnitAction);
return avp;
}
Aggregations