Search in sources :

Example 1 with Avp

use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.

the class AvpAssistant method checkAvpFlags.

/**
 * @param set
 *          the set to check
 * @return an array of offending AVPs
 */
protected static ArrayList<String> checkAvpFlags(AvpSet set) {
    ArrayList<String> failedAvps = new ArrayList<String>();
    for (Avp avp : set) {
        // System.out.println(avp.getVendorId() + ":" + avp.getCode() + " V[" + avp.isVendorId() + "] M[" +
        // avp.isMandatory() + "] P[" + avp.isEncrypted() + "]");
        AvpRepresentation avpRep = DictionaryImpl.INSTANCE.getAvp(avp.getCode(), avp.getVendorId());
        // Mandatory must not be set if rule is MUST NOT or SHOULD NOT
        if (avp.isMandatory() && (avpRep.getRuleMandatory().equals("mustnot") || avpRep.getRuleMandatory().equals("shouldnot"))) {
            failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[M / '" + avp.isMandatory() + "' vs '" + avpRep.getRuleMandatory() + "']");
        }
        // Protected must not be set if rule is MUST or MAY
        if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
            failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
        }
        // Vendor must be set if rule is MUST or MAY
        if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
            failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
        }
        AvpSet subAvps = null;
        try {
            subAvps = avp.getGrouped();
        } catch (Exception e) {
        }
        if (subAvps != null) {
            failedAvps.addAll(checkAvpFlags(subAvps));
        }
    }
    return failedAvps;
}
Also used : ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) 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) ExperimentalResultAvp(net.java.slee.resource.diameter.base.events.avp.ExperimentalResultAvp) ProxyInfoAvp(net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp) FailedAvp(net.java.slee.resource.diameter.base.events.avp.FailedAvp) AvpRepresentation(org.jdiameter.api.validation.AvpRepresentation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Avp

use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.

the class AvpUtilities method setAvpAsString.

/**
 * Adds AVP to {@link AvpSet} as String (Octet or UTF-8) with the given code and given Vendor-Id plus defined mandatory and protected flags.
 *
 * @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed.
 * @param avpCode the code of the AVP
 * @param vendorId the Vendor-Id of the AVP
 * @param isOctetString if true added as OctetString type, otherwise as UTF8String
 * @param set the AvpSet to add AVP
 * @param isMandatory the value for the mandatory bit
 * @param isProtected the value for the protected bit
 * @param value the value of the AVP to add
 */
public static void setAvpAsString(Object parent, int avpCode, long vendorId, boolean isOctetString, AvpSet set, boolean isMandatory, boolean isProtected, String value) {
    performPreAddOperations(parent, avpCode, vendorId, set);
    switch(avpCode) {
        case Avp.SESSION_ID:
            // (...) All messages pertaining to a specific session MUST include only one Session-Id AVP (...)
            set.removeAvp(avpCode);
            // (...) the Session-Id SHOULD appear immediately following the Diameter Header
            set.insertAvp(0, avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
            break;
        case Avp.ORIGIN_HOST:
        case Avp.ORIGIN_REALM:
        case Avp.DESTINATION_HOST:
        case Avp.DESTINATION_REALM:
            // This AVP SHOULD be placed as close to the Diameter header as possible.
            Avp firstAvp = set.size() > 0 ? set.getAvpByIndex(0) : null;
            int index = (firstAvp != null && firstAvp.getCode() == Avp.SESSION_ID) ? 1 : 0;
            set.insertAvp(index, avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
            break;
        default:
            set.addAvp(avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
            break;
    }
}
Also used : Avp(org.jdiameter.api.Avp)

Example 3 with Avp

use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.

the class AvpUtilities method getAvpsAsUnsigned32.

public static long[] getAvpsAsUnsigned32(int avpCode, long vendorId, AvpSet set) {
    try {
        AvpSet avpSet = set.getAvps(avpCode, vendorId);
        long[] values = new long[avpSet.size()];
        int i = 0;
        for (Avp avp : avpSet) {
            values[i++] = avp.getUnsigned32();
        }
        return values;
    } catch (AvpDataException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to obtain AVP with code " + avpCode + " and Vendor-Id " + vendorId + " as type Unsigned32.", e);
        }
        return new long[0];
    }
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp)

Example 4 with Avp

use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.

the class AvpUtilities method getAvpsAsInteger32.

public static int[] getAvpsAsInteger32(int avpCode, AvpSet set) {
    try {
        AvpSet avpSet = set.getAvps(avpCode);
        int[] values = new int[avpSet.size()];
        int i = 0;
        for (Avp avp : avpSet) {
            values[i++] = avp.getInteger32();
        }
        return values;
    } catch (AvpDataException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to obtain AVP with code " + avpCode + " as type Integer32.", e);
        }
        return new int[0];
    }
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp)

Example 5 with Avp

use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.

the class AvpUtilities method getAvpsAsOctetString.

public static byte[][] getAvpsAsOctetString(int avpCode, AvpSet set) {
    try {
        AvpSet avpSet = set.getAvps(avpCode);
        byte[][] values = new byte[avpSet.size()][];
        int i = 0;
        for (Avp avp : avpSet) {
            values[i++] = avp.getOctetString();
        }
        return values;
    } catch (AvpDataException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to obtain AVP with code " + avpCode + " as type OctetString.", e);
        }
        return new byte[0][];
    }
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp)

Aggregations

Avp (org.jdiameter.api.Avp)37 AvpSet (org.jdiameter.api.AvpSet)30 AvpDataException (org.jdiameter.api.AvpDataException)28 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)6 URISyntaxException (java.net.URISyntaxException)5 ParseException (org.jdiameter.client.api.parser.ParseException)5 AvpRepresentation (org.mobicents.diameter.dictionary.AvpRepresentation)5 ArrayList (java.util.ArrayList)4 FailedAvp (net.java.slee.resource.diameter.base.events.avp.FailedAvp)4 ProxyInfoAvp (net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp)4 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)4 Constructor (java.lang.reflect.Constructor)3 Date (java.util.Date)2 AvpRepresentation (org.jdiameter.api.validation.AvpRepresentation)2 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)1 DiameterHeader (net.java.slee.resource.diameter.base.events.DiameterHeader)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 ExperimentalResultAvp (net.java.slee.resource.diameter.base.events.avp.ExperimentalResultAvp)1 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)1