Search in sources :

Example 1 with ServiceInformation

use of net.java.slee.resource.diameter.ro.events.avp.ServiceInformation in project smscgateway by RestComm.

the class ChargingSbb method setupChargingRequestInterface.

// public void onActivityEndEvent(ActivityEndEvent event, ActivityContextInterface aci) {
// logger.info(" Activity Ended[" + aci.getActivity() + "]");
// }
// Setup charging request
public void setupChargingRequestInterface(ChargingMedium chargingType, Sms sms) {
    if (logger.isFineEnabled()) {
        logger.fine("ChargingSbb: received message for process charging process: chargingType=" + chargingType + ", message=[" + sms + "]");
    }
    ChargingData chargingData = new ChargingData();
    chargingData.setSms(sms);
    chargingData.setChargingType(chargingType);
    this.setChargingData(chargingData);
    String sourceAddress = sms.getSourceAddr();
    int sourceTon = sms.getSourceAddrTon();
    String originatorSccpAddress = sms.getOriginatorSccpAddress();
    String origMoServiceCentreAddressDA = sms.getOrigMoServiceCentreAddressDA();
    if (origMoServiceCentreAddressDA == null) {
        origMoServiceCentreAddressDA = smscPropertiesManagement.getServiceCenterGt(sms.getSmsSet().getNetworkId());
    }
    String recipientAddress = sms.getSmsSet().getDestAddr();
    int destTon = sms.getSmsSet().getDestAddrTon();
    int dataCodingScheme = sms.getDataCoding();
    String interfaceId = Integer.toString(sms.getSmsSet().getNetworkId());
    String interfaceText = sms.getOrigEsmeName();
    try {
        DiameterIdentity destHost = null;
        if (smscPropertiesManagement.getDiameterDestHost() != null && !smscPropertiesManagement.getDiameterDestHost().equals("")) {
            // destHost = new DiameterIdentity("aaa://" +
            // smscPropertiesManagement.getDiameterDestHost() + ":" +
            // smscPropertiesManagement.getDiameterDestPort());
            destHost = new DiameterIdentity(smscPropertiesManagement.getDiameterDestHost());
        }
        DiameterIdentity destRealm = new DiameterIdentity(smscPropertiesManagement.getDiameterDestRealm());
        RoClientSessionActivity activity = this.roProvider.createRoClientSessionActivity(destHost, destRealm);
        ActivityContextInterface roACI = acif.getActivityContextInterface(activity);
        roACI.attach(getSbbContext().getSbbLocalObject());
        RoCreditControlRequest ccr = activity.createRoCreditControlRequest(CcRequestType.EVENT_REQUEST);
        // ccr.setDestinationRealm(destRealm);
        // ccr.setAuthApplicationId(APPLICATION_ID_OF_THE_DIAMETER_CREDIT_CONTROL_APPLICATION);
        ccr.setServiceContextId(SERVICE_CONTEXT_ID_SMSC);
        ccr.setCcRequestNumber(0);
        // ((SipUri)fromHeader.getAddress().getURI()).getUser();
        if (smscPropertiesManagement.getDiameterUserName() != null && !smscPropertiesManagement.getDiameterUserName().equals("")) {
            ccr.setUserName(smscPropertiesManagement.getDiameterUserName());
        }
        // This field contains the state associated to the CTF
        // do not know how to use it
        // a monotonically increasing value that is advanced whenever a
        // Diameter
        // entity restarts with loss of previous state, for example upon
        // reboot
        // ccr.setOriginStateId(smscRebootStep);
        // do not know if we need it
        ccr.setEventTimestamp(Calendar.getInstance().getTime());
        SubscriptionIdAvp subId = avpFactory.createSubscriptionId(SubscriptionIdType.END_USER_E164, sourceAddress);
        ccr.setSubscriptionId(subId);
        ccr.setRequestedAction(RequestedActionType.DIRECT_DEBITING);
        // ccr.setMultipleServicesIndicator(MultipleServicesIndicatorType.MULTIPLE_SERVICES_NOT_SUPPORTED);
        // requested units
        int messageCount = 1;
        int serviceIdentifier = 1;
        MultipleServicesCreditControlAvp multipleServicesCreditControl = avpFactory.createMultipleServicesCreditControl();
        RequestedServiceUnitAvp requestedServiceUnit = avpFactory.createRequestedServiceUnit();
        requestedServiceUnit.setCreditControlServiceSpecificUnits(messageCount);
        multipleServicesCreditControl.setRequestedServiceUnit(requestedServiceUnit);
        multipleServicesCreditControl.setServiceIdentifier(serviceIdentifier);
        ccr.setMultipleServicesCreditControl(multipleServicesCreditControl);
        // RequestedServiceUnitAvp RSU =
        // avpFactory.createRequestedServiceUnit();
        // RSU.setCreditControlTime(_FIRST_CHARGE_TIME);
        // ccr.setRequestedServiceUnit(RSU);
        // ServiceInformation - SMS info 2000
        ArrayList<DiameterAvp> smsInfoAvpLst = new ArrayList<DiameterAvp>();
        int vendorID = 10415;
        // Originator-SCCP-Address 2008
        if (originatorSccpAddress != null) {
            byte[] originatorSccpAddressAddrPartByteArr = originatorSccpAddress.getBytes(utf8Charset);
            byte[] originatorSccpAddressByteArr = new byte[2 + originatorSccpAddressAddrPartByteArr.length];
            originatorSccpAddressByteArr[1] = 8;
            System.arraycopy(originatorSccpAddressAddrPartByteArr, 0, originatorSccpAddressByteArr, 2, originatorSccpAddressAddrPartByteArr.length);
            DiameterAvp avpOriginatorSccpAddress = avpFactory.getBaseFactory().createAvp(vendorID, 2008, originatorSccpAddressByteArr);
            smsInfoAvpLst.add(avpOriginatorSccpAddress);
        }
        // SMSC-Address 2017
        if (origMoServiceCentreAddressDA != null) {
            byte[] origMoServiceCentreAddressDAPartByteArr = origMoServiceCentreAddressDA.getBytes(utf8Charset);
            byte[] origMoServiceCentreAddressDAByteArr = new byte[2 + origMoServiceCentreAddressDAPartByteArr.length];
            origMoServiceCentreAddressDAByteArr[1] = 8;
            System.arraycopy(origMoServiceCentreAddressDAPartByteArr, 0, origMoServiceCentreAddressDAByteArr, 2, origMoServiceCentreAddressDAPartByteArr.length);
            DiameterAvp avpOrigMoServiceCentreAddressDA = avpFactory.getBaseFactory().createAvp(vendorID, 2017, origMoServiceCentreAddressDAByteArr);
            smsInfoAvpLst.add(avpOrigMoServiceCentreAddressDA);
        }
        // Data-Coding-Scheme 2001
        DiameterAvp avpDataCodingScheme = avpFactory.getBaseFactory().createAvp(vendorID, 2001, dataCodingScheme);
        smsInfoAvpLst.add(avpDataCodingScheme);
        // SM-Message-Type 2007
        DiameterAvp avpSmMessageType = avpFactory.getBaseFactory().createAvp(vendorID, 2007, SmMessageTypeEnum.SUBMISSION.getValue());
        smsInfoAvpLst.add(avpSmMessageType);
        // Originator-Interface 2009
        ArrayList<DiameterAvp> originatorInterfaceAvpLst = new ArrayList<DiameterAvp>();
        DiameterAvp avpInterfaceId = avpFactory.getBaseFactory().createAvp(vendorID, 2003, interfaceId);
        originatorInterfaceAvpLst.add(avpInterfaceId);
        if (interfaceText != null) {
            DiameterAvp avpInterfaceText = avpFactory.getBaseFactory().createAvp(vendorID, 2005, interfaceText);
            originatorInterfaceAvpLst.add(avpInterfaceText);
        }
        DiameterAvp[] originatorInterfaceAvpArr = new DiameterAvp[originatorInterfaceAvpLst.size()];
        originatorInterfaceAvpLst.toArray(originatorInterfaceAvpArr);
        DiameterAvp avpOriginatorInterface = avpFactory.getBaseFactory().createAvp(vendorID, 2009, originatorInterfaceAvpArr);
        smsInfoAvpLst.add(avpOriginatorInterface);
        // Recipient-Address 1201
        ArrayList<DiameterAvp> recipientAddressAvpLst = new ArrayList<DiameterAvp>();
        DiameterAvp avpAddressType;
        if (destTon == 1)
            avpAddressType = avpFactory.getBaseFactory().createAvp(vendorID, 899, AddressTypeEnum.Msisdn.getValue());
        else
            avpAddressType = avpFactory.getBaseFactory().createAvp(vendorID, 899, AddressTypeEnum.Others.getValue());
        recipientAddressAvpLst.add(avpAddressType);
        DiameterAvp avpAddressData = avpFactory.getBaseFactory().createAvp(vendorID, 897, recipientAddress);
        recipientAddressAvpLst.add(avpAddressData);
        DiameterAvp[] recipientAddressAvpArr = new DiameterAvp[recipientAddressAvpLst.size()];
        recipientAddressAvpLst.toArray(recipientAddressAvpArr);
        DiameterAvp avpRecipientAddress = avpFactory.getBaseFactory().createAvp(vendorID, 1201, recipientAddressAvpArr);
        // Recipient-Info 2026
        ArrayList<DiameterAvp> recipientInfoAvpLst = new ArrayList<DiameterAvp>();
        recipientInfoAvpLst.add(avpRecipientAddress);
        DiameterAvp[] recipientInfoAvpArr = new DiameterAvp[recipientInfoAvpLst.size()];
        recipientInfoAvpLst.toArray(recipientInfoAvpArr);
        DiameterAvp avpRecipientInfo = avpFactory.getBaseFactory().createAvp(vendorID, 2026, recipientInfoAvpArr);
        smsInfoAvpLst.add(avpRecipientInfo);
        // Originator-Received-Address 2027
        ArrayList<DiameterAvp> originatorReceivedAddressAvpLst = new ArrayList<DiameterAvp>();
        if (sourceTon == 1)
            avpAddressType = avpFactory.getBaseFactory().createAvp(vendorID, 899, AddressTypeEnum.Msisdn.getValue());
        else
            avpAddressType = avpFactory.getBaseFactory().createAvp(vendorID, 899, AddressTypeEnum.Others.getValue());
        originatorReceivedAddressAvpLst.add(avpAddressType);
        avpAddressData = avpFactory.getBaseFactory().createAvp(vendorID, 897, sourceAddress);
        originatorReceivedAddressAvpLst.add(avpAddressData);
        DiameterAvp[] originatorReceivedAddressAvpArr = new DiameterAvp[originatorReceivedAddressAvpLst.size()];
        originatorReceivedAddressAvpLst.toArray(originatorReceivedAddressAvpArr);
        DiameterAvp avpOriginatorReceivedAddress = avpFactory.getBaseFactory().createAvp(vendorID, 2027, originatorReceivedAddressAvpArr);
        smsInfoAvpLst.add(avpOriginatorReceivedAddress);
        // final assembling
        DiameterAvp[] smsInfoAvpArr = new DiameterAvp[smsInfoAvpLst.size()];
        smsInfoAvpLst.toArray(smsInfoAvpArr);
        DiameterAvp[] smsInfo = new DiameterAvp[1];
        smsInfo[0] = avpFactory.getBaseFactory().createAvp(vendorID, 2000, smsInfoAvpArr);
        ServiceInformation si = avpFactory.createServiceInformation();
        si.setExtensionAvps(smsInfo);
        ccr.setServiceInformation(si);
        activity.sendEventRoCreditControlRequest(ccr);
        if (logger.isFineEnabled()) {
            logger.fine("Sent INITIAL CCR: " + ccr);
        }
        // set new timer for the case we will not get CCA in time
        timerFacility.setTimer(roACI, null, System.currentTimeMillis() + (CCR_TIMEOUT * 1000), defaultTimerOptions);
    } catch (Exception e1) {
        logger.severe("setupChargingRequestInterface(): error while sending RoCreditControlRequest: " + e1.getMessage(), e1);
        generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_CHARGING, e1.getMessage(), false, true);
    }
}
Also used : MultipleServicesCreditControlAvp(net.java.slee.resource.diameter.cca.events.avp.MultipleServicesCreditControlAvp) ActivityContextInterface(javax.slee.ActivityContextInterface) ArrayList(java.util.ArrayList) RoClientSessionActivity(net.java.slee.resource.diameter.ro.RoClientSessionActivity) RoCreditControlRequest(net.java.slee.resource.diameter.ro.events.RoCreditControlRequest) SubscriptionIdAvp(net.java.slee.resource.diameter.cca.events.avp.SubscriptionIdAvp) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) CreateException(javax.slee.CreateException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) ServiceInformation(net.java.slee.resource.diameter.ro.events.avp.ServiceInformation) DiameterIdentity(net.java.slee.resource.diameter.base.events.avp.DiameterIdentity) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) RequestedServiceUnitAvp(net.java.slee.resource.diameter.cca.events.avp.RequestedServiceUnitAvp)

Aggregations

ArrayList (java.util.ArrayList)1 ActivityContextInterface (javax.slee.ActivityContextInterface)1 CreateException (javax.slee.CreateException)1 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)1 DiameterIdentity (net.java.slee.resource.diameter.base.events.avp.DiameterIdentity)1 MultipleServicesCreditControlAvp (net.java.slee.resource.diameter.cca.events.avp.MultipleServicesCreditControlAvp)1 RequestedServiceUnitAvp (net.java.slee.resource.diameter.cca.events.avp.RequestedServiceUnitAvp)1 SubscriptionIdAvp (net.java.slee.resource.diameter.cca.events.avp.SubscriptionIdAvp)1 RoClientSessionActivity (net.java.slee.resource.diameter.ro.RoClientSessionActivity)1 RoCreditControlRequest (net.java.slee.resource.diameter.ro.events.RoCreditControlRequest)1 ServiceInformation (net.java.slee.resource.diameter.ro.events.avp.ServiceInformation)1 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)1 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)1