Search in sources :

Example 26 with DiameterAvp

use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.

the class DiameterTestsSbb method onAccountingRequest.

public void onAccountingRequest(net.java.slee.resource.diameter.base.events.AccountingRequest acr, ActivityContextInterface aci) {
    long start = System.currentTimeMillis();
    logger.info("Accounting-Request received. [" + acr + "]");
    boolean actAsProxy = false;
    try {
        // Are we gonna act as a proxy?
        if (actAsProxy) {
            // In here we act as a "proxy". Just for testing we take the original message,
            // replace the Origin/Destination Host/Realm AVPs and send it to the emulator.
            boolean hasDestinationHost = false;
            boolean hasDestinationRealm = false;
            List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
            for (DiameterAvp avp : acr.getAvps()) {
                switch(avp.getCode()) {
                    case Avp.ORIGIN_HOST:
                        avps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, "aaa://127.0.0.1:3868".getBytes()));
                        break;
                    case Avp.ORIGIN_REALM:
                        avps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, "mobicents.org".getBytes()));
                        break;
                    case Avp.DESTINATION_HOST:
                        avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "aaa://127.0.0.1:13868".getBytes()));
                        hasDestinationHost = true;
                        break;
                    case Avp.DESTINATION_REALM:
                        avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes()));
                        hasDestinationRealm = true;
                        break;
                    default:
                        avps.add(avp);
                }
            }
            if (!hasDestinationHost)
                avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "127.0.0.1".getBytes()));
            if (!hasDestinationRealm)
                avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes()));
            logger.info("AVPs ==> " + avps);
            DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
            avpArray = avps.toArray(avpArray);
            logger.info("Creating Custom Message...");
            DiameterMessage ms = messageFactory.createAccountingRequest(avpArray);
            logger.info("Created Custom Message[" + ms + "]");
            logger.info("Sending Custom Message...");
            provider.createActivity().sendMessage(ms);
            logger.info("Sent Custom Message[" + ms + "]");
        } else {
            // In here we act as a server...
            int subscriptionIdType = -1;
            String subscriptionIdData = "";
            int unitType = -1;
            long valueDigits = -1;
            int exponent = 0;
            int requestedAction = -1;
            int serviceParameterType;
            int serviceParameterValue;
            int serviceParameterInfo;
            DiameterAvp subscriptionIdAvp = null;
            DiameterAvp requestedActionAvp = null;
            if (aci.getActivity() instanceof AccountingServerSessionActivity) {
                for (DiameterAvp avp : acr.getAvps()) {
                    switch(avp.getCode()) {
                        case SUBSCRIPTION_ID:
                            {
                                // This should contain a SUBSCRIPTION_ID_TYPE and a SUBSCRIPTION_ID_DATA
                                if (avp instanceof GroupedAvp) {
                                    GroupedAvp gAvp = (GroupedAvp) avp;
                                    for (DiameterAvp subAvp : gAvp.getExtensionAvps()) {
                                        switch(subAvp.getCode()) {
                                            case SUBSCRIPTION_ID_TYPE:
                                                subscriptionIdType = subAvp.intValue();
                                                break;
                                            case SUBSCRIPTION_ID_DATA:
                                                subscriptionIdData = subAvp.stringValue();
                                                break;
                                        }
                                    }
                                }
                            }
                            break;
                        case REQUESTED_SERVICE_UNIT:
                            {
                                // This should contain a UNIT_TYPE and a UNIT_VALUE
                                if (avp instanceof GroupedAvp) {
                                    GroupedAvp gAvp = (GroupedAvp) avp;
                                    for (DiameterAvp subAvp : gAvp.getExtensionAvps()) {
                                        switch(subAvp.getCode()) {
                                            case UNIT_TYPE:
                                                unitType = subAvp.intValue();
                                                break;
                                            case UNIT_VALUE:
                                                {
                                                    // This should contain a VALUE_DIGITS
                                                    if (subAvp instanceof GroupedAvp) {
                                                        GroupedAvp gSubAvp = (GroupedAvp) subAvp;
                                                        for (DiameterAvp subSubAvp : gSubAvp.getExtensionAvps()) {
                                                            switch(subSubAvp.getCode()) {
                                                                case VALUE_DIGITS:
                                                                    valueDigits = subSubAvp.longValue();
                                                                    break;
                                                                case EXPONENT:
                                                                    exponent = subSubAvp.intValue();
                                                                    break;
                                                            }
                                                        }
                                                    }
                                                    break;
                                                }
                                        }
                                    }
                                }
                            }
                            break;
                        case REQUESTED_ACTION:
                            requestedAction = avp.intValue();
                            requestedActionAvp = avp;
                            break;
                        case SERVICE_PARAMETER_TYPE:
                        // We can discard this...
                        case SERVICE_PARAMETER_VALUE:
                        // We can discard this...
                        case SERVICE_PARAMETER_INFO:
                        // We can discard this...
                        default:
                    }
                }
                logger.info("Subscription-Id-Type: " + subscriptionIdType);
                logger.info("Subscription-Id-Data: " + subscriptionIdData);
                logger.info("Unit-Type: " + unitType);
                logger.info("Value-Digits: " + valueDigits);
                logger.info("Exponent: " + exponent);
                logger.info("Requested-Action: " + requestedAction);
                AccountingServerSessionActivity assa = (AccountingServerSessionActivity) aci.getActivity();
                // Aditional AVPs container
                List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
                // By default, let's consider it's OK and create answer with 2001
                AccountingAnswer ans = assa.createAccountingAnswer(acr);
                ans.setResultCode(ResultCode.SUCCESS);
                double chargingValue = valueDigits * Math.pow(10, exponent);
                if (subscriptionIdType == 0 || subscriptionIdType == 1) {
                    DiameterUser user = null;
                    if ((user = users.get(subscriptionIdData)) == null) {
                        // Not a valid user. Reject it with DIAMETER_END_USER_NOT_FOUND.
                        ans = assa.createAccountingAnswer(acr);
                        ans.setResultCode(5241);
                        // Subscription ID
                        DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp(193, 555, subscriptionIdType);
                        DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp(193, 554, subscriptionIdData);
                        avps.add(avpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdTypeAvp, subscriptionIdDataAvp }));
                    } else if (requestedAction == 0 && user.balance < chargingValue) {
                        logger.info("Received Direct Debit Request:");
                        logger.info("User ID " + subscriptionIdData + " (" + user.name + ")");
                        logger.info("Current Balance: " + user.balance);
                        logger.info("Charging Value: " + chargingValue);
                        // Not able to provide the service. not enough balance.
                        ans = assa.createAccountingAnswer(acr);
                        ans.setResultCode(4241);
                        // Subscription ID
                        DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp(193, 555, subscriptionIdType);
                        DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp(193, 554, subscriptionIdData);
                        avps.add(avpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdTypeAvp, subscriptionIdDataAvp }));
                    } else {
                        boolean isError = false;
                        // Refund Account?
                        if (requestedAction == 1) {
                            logger.info("Received Refund Account Request:");
                            logger.info("User ID " + subscriptionIdData + " (" + user.name + ")");
                            logger.info("Old Balance: " + user.balance);
                            user.balance += chargingValue;
                            logger.info("New Balance: " + user.balance);
                        } else if (requestedAction == 0) {
                            logger.info("Received Direct Debit Request:");
                            logger.info("User ID " + subscriptionIdData + " (" + user.name + ")");
                            logger.info("Old Balance: " + user.balance);
                            user.balance -= chargingValue;
                            logger.info("New Balance: " + user.balance);
                        } else {
                            logger.warn("Unknown requested action (" + requestedAction + ")");
                            DiameterAvp failedAvp = avpFactory.createAvp(0, 279, new DiameterAvp[] { requestedActionAvp });
                            ans = assa.createAccountingAnswer(acr);
                            ans.setResultCode(ResultCode.INVALID_AVP_VALUE);
                            avps.add(failedAvp);
                            isError = true;
                        }
                        if (!isError) {
                            // Subscription ID
                            DiameterAvp subscriptionIdTypeAvp = avpFactory.createAvp(193, 555, subscriptionIdType);
                            DiameterAvp subscriptionIdDataAvp = avpFactory.createAvp(193, 554, subscriptionIdData);
                            avps.add(avpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdTypeAvp, subscriptionIdDataAvp }));
                            // Granted Service Unit
                            DiameterAvp unitTypeAvp = avpFactory.createAvp(193, 611, unitType);
                            DiameterAvp valueDigitsAvp = avpFactory.createAvp(193, 617, valueDigits);
                            DiameterAvp unitValueAvp = avpFactory.createAvp(193, 612, new DiameterAvp[] { valueDigitsAvp });
                            avps.add(avpFactory.createAvp(193, 602, new DiameterAvp[] { unitTypeAvp, unitValueAvp }));
                            // Cost Information
                            DiameterAvp costAvp = avpFactory.createAvp(193, 603, chargingValue);
                            DiameterAvp currencyCodeAvp = avpFactory.createAvp(193, 544, 978);
                            avps.add(avpFactory.createAvp(193, 604, new DiameterAvp[] { costAvp, currencyCodeAvp }));
                        }
                    }
                }
                DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
                avpArray = avps.toArray(avpArray);
                ans.setExtensionAvps(avpArray);
                logger.info("Sending Accounting-Answer [" + ans + "]");
                assa.sendAccountingAnswer(ans);
                logger.info("Accounting-Answer sent.");
            }
        }
    } catch (Exception e) {
        logger.error("", e);
    }
    long end = System.currentTimeMillis();
    logger.info("Accounting-Request proccessed. [" + (end - start) + "ms]");
}
Also used : ArrayList(java.util.ArrayList) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) AccountingServerSessionActivity(net.java.slee.resource.diameter.base.AccountingServerSessionActivity) AccountingAnswer(net.java.slee.resource.diameter.base.events.AccountingAnswer) GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)

Example 27 with DiameterAvp

use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.

the class DiameterTestsSbb method sendAccountingRequest.

private void sendAccountingRequest() {
    try {
        List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
        avps.add(avpFactory.createAvp(Avp.SESSION_ID, "12345".getBytes()));
        DiameterAvp avpVendorId = avpFactory.createAvp(Avp.VENDOR_ID, 193);
        DiameterAvp avpAcctApplicationId = avpFactory.createAvp(Avp.ACCT_APPLICATION_ID, 193);
        avps.add(avpFactory.createAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, new DiameterAvp[] { avpVendorId, avpAcctApplicationId }));
        avps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, "aaa://127.0.0.1:3868".getBytes()));
        avps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, "mobicents.org".getBytes()));
        avps.add(avpFactory.createAvp(Avp.DESTINATION_HOST, "aaa://127.0.0.1:13868".getBytes()));
        avps.add(avpFactory.createAvp(Avp.DESTINATION_REALM, "mobicents.org".getBytes()));
        // Subscription ID
        DiameterAvp subscriptionIdType = avpFactory.createAvp(193, 555, 0);
        DiameterAvp subscriptionIdData = avpFactory.createAvp(193, 554, "00001000");
        avps.add(avpFactory.createAvp(193, 553, new DiameterAvp[] { subscriptionIdType, subscriptionIdData }));
        // Requested Service Unit
        DiameterAvp unitType = avpFactory.createAvp(193, 611, 2);
        DiameterAvp valueDigits = avpFactory.createAvp(193, 617, 10L);
        DiameterAvp unitValue = avpFactory.createAvp(193, 612, new DiameterAvp[] { valueDigits });
        avps.add(avpFactory.createAvp(193, 606, new DiameterAvp[] { unitType, unitValue }));
        // Record Number and Type
        avps.add(avpFactory.createAvp(Avp.ACC_RECORD_NUMBER, 0));
        avps.add(avpFactory.createAvp(Avp.ACC_RECORD_TYPE, 1));
        // Requested action
        avps.add(avpFactory.createAvp(193, 615, 0));
        // Service Parameter Type
        DiameterAvp serviceParameterType = avpFactory.createAvp(193, 608, 0);
        DiameterAvp serviceParameterValue = avpFactory.createAvp(193, 609, "510");
        avps.add(avpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType, serviceParameterValue }));
        // Service Parameter Type
        DiameterAvp serviceParameterType2 = avpFactory.createAvp(193, 608, 14);
        DiameterAvp serviceParameterValue2 = avpFactory.createAvp(193, 609, "20");
        avps.add(avpFactory.createAvp(193, 607, new DiameterAvp[] { serviceParameterType2, serviceParameterValue2 }));
        DiameterAvp[] avpArray = new DiameterAvp[avps.size()];
        avpArray = avps.toArray(avpArray);
        logger.info("Creating Custom Message...");
        DiameterMessage ms = messageFactory.createAccountingRequest(avpArray);
        logger.info("Created Custom Message[" + ms + "]");
        logger.info("Sending Custom Message...");
        provider.createActivity().sendMessage(ms);
        logger.info("Sent Custom Message[" + ms + "]");
    } catch (Exception e) {
        logger.error("", e);
    }
}
Also used : DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage)

Example 28 with DiameterAvp

use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.

the class DiameterMessageImpl method getAvpsInternal.

// ===== AVP Management =====
private DiameterAvp[] getAvpsInternal(AvpSet set) throws Exception {
    List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
    for (Avp a : set) {
        AvpRepresentation avpRep = AvpDictionary.INSTANCE.getAvp(a.getCode(), a.getVendorId());
        if (avpRep == null) {
            // log.error("Avp with code: " + a.getCode() + " VendorId: " + a.getVendorId() + " is not listed in dictionary, skipping!");
            continue;
        } else {
            if (avpRep.getType().equals("Grouped")) {
                // TODO: There's no info about if AVP has mandatory or protected flags set...
                GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw());
                gAVP.setExtensionAvps(getAvpsInternal(a.getGrouped()));
                // This is a grouped AVP... let's make it like that.
                avps.add(gAVP);
            } else {
                // TODO: There's no info about if AVP has mandatory or protected flags set...
                avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw(), DiameterAvpType.fromString(avpRep.getType())));
            }
        }
    }
    return avps.toArray(new DiameterAvp[avps.size()]);
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) DiameterAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.DiameterAvpImpl) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) VendorSpecificApplicationIdAvp(net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ProxyInfoAvp(net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp) FailedAvp(net.java.slee.resource.diameter.base.events.avp.FailedAvp) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 29 with DiameterAvp

use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.

the class GroupedAvpImpl method equals.

@Override
public boolean equals(Object other) {
    if (!(other instanceof GroupedAvpImpl)) {
        return false;
    }
    GroupedAvpImpl that = (GroupedAvpImpl) other;
    if (this.code != that.getCode() || this.vendorId != that.getVendorId()) {
        return false;
    }
    List<DiameterAvp> thisArray = Arrays.asList(this.getExtensionAvps());
    List<DiameterAvp> thatArray = Arrays.asList(that.getExtensionAvps());
    if (thisArray.size() != thatArray.size()) {
        return false;
    }
    for (DiameterAvp avp : thisArray) {
        if (!thatArray.contains(avp)) {
            return false;
        }
    }
    return true;
}
Also used : DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)

Example 30 with DiameterAvp

use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp 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

DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)65 Message (org.jdiameter.api.Message)22 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)21 InternalException (org.jdiameter.api.InternalException)21 AvpSet (org.jdiameter.api.AvpSet)18 ArrayList (java.util.ArrayList)15 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)15 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)12 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)9 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)6 AccountingRequest (net.java.slee.resource.diameter.base.events.AccountingRequest)3 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)3 GxCreditControlMessage (net.java.slee.resource.diameter.gx.events.GxCreditControlMessage)3 GxReAuthMessage (net.java.slee.resource.diameter.gx.events.GxReAuthMessage)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 DiameterIdentity (net.java.slee.resource.diameter.base.events.avp.DiameterIdentity)2 CreditControlRequest (net.java.slee.resource.diameter.cca.events.CreditControlRequest)2 RoCreditControlMessage (net.java.slee.resource.diameter.ro.events.RoCreditControlMessage)2 ApplicationId (org.jdiameter.api.ApplicationId)2