Search in sources :

Example 1 with GroupedAvp

use of net.java.slee.resource.diameter.base.events.avp.GroupedAvp in project charging-server by RestComm.

the class DiameterChargingServerSbb method fetchDataFromAvp.

/**
 * Fetch data from AVP to be passed in CreditControlInfo, as configured in env entry.
 * @param avp the AVP to look at
 * @param ccInfo the CreditControlInfo object to store properties at
 * @param depth the AVP depth, for recursive calls
 */
private void fetchDataFromAvp(DiameterAvp avp, CreditControlInfo ccInfo, int depth) {
    if (tracer.isFinerEnabled()) {
        tracer.finer("[><] " + sidString + " Scanning AVP at depth " + depth + " with code " + avp.getCode() + " and type " + avp.getType() + " ...");
    }
    if (avp.getType() == DiameterAvpType.GROUPED) {
        GroupedAvp gAvp = (GroupedAvp) avp;
        DiameterAvp[] subAvps = gAvp.getExtensionAvps();
        for (DiameterAvp subAvp : subAvps) {
            fetchDataFromAvp(subAvp, ccInfo, depth + 1);
        }
    } else {
        String name = abmfAVPs.get(String.valueOf(avp.getCode()));
        if (name != null) {
            Object value = null;
            switch(avp.getType().getType()) {
                case DiameterAvpType._ADDRESS:
                case DiameterAvpType._DIAMETER_IDENTITY:
                case DiameterAvpType._DIAMETER_URI:
                case DiameterAvpType._IP_FILTER_RULE:
                case DiameterAvpType._OCTET_STRING:
                case DiameterAvpType._QOS_FILTER_RULE:
                    value = avp.octetStringValue();
                    break;
                case DiameterAvpType._ENUMERATED:
                case DiameterAvpType._INTEGER_32:
                    value = avp.intValue();
                    break;
                case DiameterAvpType._FLOAT_32:
                    value = avp.floatValue();
                    break;
                case DiameterAvpType._FLOAT_64:
                    value = avp.doubleValue();
                    break;
                case DiameterAvpType._INTEGER_64:
                    value = avp.longValue();
                    break;
                case DiameterAvpType._TIME:
                    value = avp.longValue();
                    break;
                case DiameterAvpType._UNSIGNED_32:
                    value = avp.longValue();
                    break;
                case DiameterAvpType._UNSIGNED_64:
                    value = avp.longValue();
                    break;
                case DiameterAvpType._UTF8_STRING:
                    value = avp.octetStringValue();
                    break;
                default:
                    value = avp.byteArrayValue();
                    break;
            }
            if (tracer.isFineEnabled()) {
                tracer.fine("[><] " + sidString + " Storing AVP with code " + avp.getCode() + " as '" + name + "' with value '" + value.toString() + "'");
            }
            ccInfo.addServiceInfo(name, value.toString());
        }
    }
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)

Example 2 with GroupedAvp

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

the class BaseFactoriesTest method getApplicationIdAvpsHash.

// Util methods for several applications
public static int getApplicationIdAvpsHash(DiameterMessage msg) {
    int result = NO_APP_ID_AVPS;
    int vsaiResult = 1;
    for (DiameterAvp avp : msg.getAvps()) {
        if (avp.getCode() == Avp.AUTH_APPLICATION_ID) {
            result += AUTH_APP_ID;
        } else if (avp.getCode() == Avp.ACCT_APPLICATION_ID) {
            result += ACCT_APP_ID;
        }
        if (avp.getCode() == Avp.VENDOR_SPECIFIC_APPLICATION_ID) {
            result += VENDOR_SPECIFIC_APP_ID;
            GroupedAvp vsai = (GroupedAvp) avp;
            for (DiameterAvp subAvp : vsai.getExtensionAvps()) {
                if (subAvp.getCode() == Avp.AUTH_APPLICATION_ID) {
                    vsaiResult *= AUTH_APP_ID;
                } else if (subAvp.getCode() == Avp.ACCT_APPLICATION_ID) {
                    vsaiResult *= ACCT_APP_ID;
                }
            }
        }
    }
    if (result == VENDOR_SPECIFIC_APP_ID) {
        result *= vsaiResult;
    }
    return result;
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)

Example 3 with GroupedAvp

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

the class DiameterMessageFactoryImpl method getApplicationId.

private ApplicationId getApplicationId(DiameterAvp[] avps) {
    ApplicationId applicationId = null;
    long vendorId = 0L;
    // Try to get Application-Id from Message AVPs
    if (avps != null) {
        for (DiameterAvp avp : avps) {
            if (avp.getCode() == DiameterAvpCodes.VENDOR_ID) {
                vendorId = avp.intValue();
            }
            if (avp.getCode() == DiameterAvpCodes.VENDOR_SPECIFIC_APPLICATION_ID) {
                applicationId = getApplicationId(((GroupedAvp) avp).getExtensionAvps());
                break;
            }
            if (avp.getCode() == DiameterAvpCodes.ACCT_APPLICATION_ID) {
                applicationId = ApplicationId.createByAccAppId(vendorId, avp.intValue());
                break;
            } else if (avp.getCode() == DiameterAvpCodes.AUTH_APPLICATION_ID) {
                applicationId = ApplicationId.createByAuthAppId(vendorId, avp.intValue());
                break;
            }
        }
    }
    return applicationId;
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ApplicationId(org.jdiameter.api.ApplicationId)

Example 4 with GroupedAvp

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

the class RxMessageFactoryImpl method getApplicationId.

private ApplicationId getApplicationId(DiameterAvp[] avps) {
    ApplicationId applicationId = null;
    long vendorId = 0L;
    // Try to get Application-Id from Message AVPs
    if (avps != null) {
        for (DiameterAvp avp : avps) {
            if (avp.getCode() == DiameterAvpCodes.VENDOR_ID) {
                vendorId = avp.intValue();
            }
            if (avp.getCode() == DiameterAvpCodes.VENDOR_SPECIFIC_APPLICATION_ID) {
                applicationId = getApplicationId(((GroupedAvp) avp).getExtensionAvps());
                break;
            }
            if (avp.getCode() == DiameterAvpCodes.ACCT_APPLICATION_ID) {
                applicationId = ApplicationId.createByAccAppId(vendorId, avp.intValue());
                break;
            } else if (avp.getCode() == DiameterAvpCodes.AUTH_APPLICATION_ID) {
                applicationId = ApplicationId.createByAuthAppId(vendorId, avp.intValue());
                break;
            }
        }
    }
    return applicationId;
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ApplicationId(org.jdiameter.api.ApplicationId)

Example 5 with GroupedAvp

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

the class ShServerMessageFactoryImpl method addAvp.

protected void addAvp(DiameterAvp avp, AvpSet set) {
    // FIXME: alexandre: Should we look at the types and add them with proper function?
    if (avp instanceof GroupedAvp) {
        AvpSet avpSet = set.addGroupedAvp(avp.getCode(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
        DiameterAvp[] groupedAVPs = ((GroupedAvp) avp).getExtensionAvps();
        for (DiameterAvp avpFromGroup : groupedAVPs) {
            addAvp(avpFromGroup, avpSet);
        }
    } else if (avp != null) {
        set.addAvp(avp.getCode(), avp.byteArrayValue(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
    }
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Aggregations

DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)14 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)14 AvpSet (org.jdiameter.api.AvpSet)9 ApplicationId (org.jdiameter.api.ApplicationId)2 ArrayList (java.util.ArrayList)1 AccountingServerSessionActivity (net.java.slee.resource.diameter.base.AccountingServerSessionActivity)1 AccountingAnswer (net.java.slee.resource.diameter.base.events.AccountingAnswer)1 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)1