Search in sources :

Example 51 with DiameterAvp

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

the class AccountingServerSessionActivityImpl method createAccountingAnswer.

public AccountingAnswer createAccountingAnswer(AccountingRequest request) {
    try {
        // Get the impl
        DiameterMessageImpl implRequest = (DiameterMessageImpl) request;
        // Extract interesting AVPs
        ArrayList<DiameterAvp> copyAvps = new ArrayList<DiameterAvp>();
        copyAvps.add(avpFactory.createAvp(Avp.SESSION_ID, serverSession.getSessions().get(0).getSessionId()));
        copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, this.originHost.getBytes()));
        copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, this.originRealm.getBytes()));
        for (DiameterAvp avp : request.getAvps()) {
            if (avp.getCode() == Avp.ACC_RECORD_NUMBER || avp.getCode() == Avp.ACC_RECORD_TYPE || avp.getCode() == Avp.ACCT_APPLICATION_ID || avp.getCode() == Avp.VENDOR_SPECIFIC_APPLICATION_ID) {
                copyAvps.add((DiameterAvp) avp.clone());
            }
        }
        DiameterMessageImpl answer = (DiameterMessageImpl) messageFactory.createMessage(implRequest.getHeader(), copyAvps.toArray(new DiameterAvp[copyAvps.size()]));
        // This is an answer.
        Message rawAnswer = answer.getGenericData();
        rawAnswer.setRequest(false);
        // just in case. answers never have T flag set
        rawAnswer.setReTransmitted(false);
        return new AccountingAnswerImpl(rawAnswer);
    } catch (Exception e) {
        logger.error("", e);
    }
    return null;
}
Also used : AccountingAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl) Message(org.jdiameter.api.Message) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) IOException(java.io.IOException) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Example 52 with DiameterAvp

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

the class GroupedAvpImpl method addAvp.

private void addAvp(DiameterAvp avp, AvpSet set) {
    if (avp instanceof GroupedAvp) {
        AvpSet avpSet = set.addGroupedAvp(avp.getCode(), avp.getVendorId(), avp.getMandatoryRule() != DiameterAvp.FLAG_RULE_MUSTNOT, avp.getProtectedRule() == DiameterAvp.FLAG_RULE_MUST);
        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() != DiameterAvp.FLAG_RULE_MUSTNOT, avp.getProtectedRule() == DiameterAvp.FLAG_RULE_MUST);
    }
}
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)

Example 53 with DiameterAvp

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

the class GroupedAvpImpl method getExtensionAvpsInternal.

private DiameterAvp[] getExtensionAvpsInternal(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) {
            if (avpRep.isGrouped()) {
                // warning, this changes getRaw to return byte[0] if successful
                AvpSet grouped = a.getGrouped();
                GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
                gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
                avps.add(gAVP);
            } else {
                avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), DiameterAvpType.fromString(avpRep.getType())));
            }
        } else {
            // we don't have it in dictionary
            try {
                // warning, this changes getRaw to return byte[0] if successful
                AvpSet grouped = a.getGrouped();
                GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
                gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
                avps.add(gAVP);
            } catch (AvpDataException ade) {
                avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), null));
            }
        }
    }
    return avps.toArray(new DiameterAvp[avps.size()]);
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 54 with DiameterAvp

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

the class ShServerMessageFactoryImpl method createProfileUpdateAnswer.

public ProfileUpdateAnswer createProfileUpdateAnswer(ProfileUpdateRequest request) {
    List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
    DiameterAvp sessionIdAvp = null;
    try {
        sessionIdAvp = localFactory.getBaseFactory().createAvp(0, DiameterAvpCodes.SESSION_ID, request.getSessionId());
        avps.add(sessionIdAvp);
    } catch (NoSuchAvpException e) {
        logger.error("Unable to create Session-Id AVP.", e);
    }
    if (request.getUserIdentity() != null) {
        avps.add(request.getUserIdentity());
    }
    Message msg = createShMessage(request.getHeader(), avps.toArray(new DiameterAvp[avps.size()]));
    ProfileUpdateAnswerImpl answer = new ProfileUpdateAnswerImpl(msg);
    answer.setRouteRecords(request.getRouteRecords());
    addOrigin(answer);
    return answer;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) ProfileUpdateAnswerImpl(org.mobicents.slee.resource.diameter.sh.events.ProfileUpdateAnswerImpl) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Example 55 with DiameterAvp

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

the class ShClientMessageFactoryImpl method createSubscribeNotificationsRequest.

public SubscribeNotificationsRequest createSubscribeNotificationsRequest() {
    DiameterAvp[] avps = new DiameterAvp[0];
    if (session != null) {
        try {
            DiameterAvp sessionIdAvp = null;
            sessionIdAvp = baseAvpFactory.createAvp(0, DiameterAvpCodes.SESSION_ID, session.getSessionId());
            avps = new DiameterAvp[] { sessionIdAvp };
        } catch (NoSuchAvpException e) {
            logger.error("Unexpected failure trying to create Session-Id AVP.", e);
        }
    }
    Message msg = createShMessage(null, avps, SubscribeNotificationsRequest.commandCode);
    SubscribeNotificationsRequestImpl snr = new SubscribeNotificationsRequestImpl(msg);
    addOrigin(snr);
    return snr;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException) SubscribeNotificationsRequestImpl(org.mobicents.slee.resource.diameter.sh.events.SubscribeNotificationsRequestImpl)

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