Search in sources :

Example 16 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage 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 17 with DiameterMessage

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

the class RoSessionActivityImpl method sendSyncMessage.

@Override
public DiameterMessage sendSyncMessage(DiameterMessage message) {
    DiameterMessage answer = null;
    Message receivedMessage = doSendMessage(message);
    if (receivedMessage != null) {
        if (!receivedMessage.isRequest()) {
            if (receivedMessage.isError()) {
                answer = new ErrorAnswerImpl(receivedMessage);
            } else {
                switch(receivedMessage.getCommandCode()) {
                    case RoCreditControlRequest.commandCode:
                        answer = new RoCreditControlAnswerImpl(receivedMessage);
                        break;
                    default:
                        logger.error("Received an unknown type of Message for Ro Activity: " + receivedMessage);
                        break;
                }
            }
        } else {
            logger.error("Received a REQUEST message when expecting an ANSWER.");
        }
    } else {
        logger.debug("No answer received. Returning null.");
    }
    return answer;
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) RoCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)

Example 18 with DiameterMessage

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

the class RxMessageFactoryImpl method createDiameterMessage.

protected DiameterMessage createDiameterMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws IllegalArgumentException {
    boolean creatingRequest = diameterHeader == null;
    Message msg = null;
    if (!creatingRequest) {
        Message raw = createMessage(diameterHeader, avps, 0, appId);
        raw.setRequest(false);
        // just in case. answers never have T flag set
        raw.setReTransmitted(false);
        msg = raw;
    } else {
        Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
        raw.setRequest(true);
        msg = raw;
    }
    int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
    DiameterMessage diamMessage = null;
    switch(commandCode) {
        case AARequest.commandCode:
            diamMessage = creatingRequest ? new AARequestImpl(msg) : new AAAnswerImpl(msg);
            break;
        case Message.ABORT_SESSION_REQUEST:
            diamMessage = creatingRequest ? new AbortSessionRequestImpl(msg) : new AbortSessionAnswerImpl(msg);
            break;
        case Message.RE_AUTH_REQUEST:
            diamMessage = creatingRequest ? new ReAuthRequestImpl(msg) : new ReAuthAnswerImpl(msg);
            break;
        case Message.SESSION_TERMINATION_REQUEST:
            diamMessage = creatingRequest ? new SessionTerminationRequestImpl(msg) : new SessionTerminationAnswerImpl(msg);
            break;
        default:
            throw new IllegalArgumentException();
    }
    // Finally, add Origin-Host and Origin-Realm, if not present.
    addOriginHostAndRealm(diamMessage);
    return diamMessage;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) AbortSessionAnswerImpl(org.mobicents.slee.resource.diameter.rx.events.AbortSessionAnswerImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ReAuthRequestImpl(org.mobicents.slee.resource.diameter.rx.events.ReAuthRequestImpl) AbortSessionRequestImpl(org.mobicents.slee.resource.diameter.rx.events.AbortSessionRequestImpl) SessionTerminationAnswerImpl(org.mobicents.slee.resource.diameter.rx.events.SessionTerminationAnswerImpl) AAAnswerImpl(org.mobicents.slee.resource.diameter.rx.events.AAAnswerImpl) ReAuthAnswerImpl(org.mobicents.slee.resource.diameter.rx.events.ReAuthAnswerImpl) AARequestImpl(org.mobicents.slee.resource.diameter.rx.events.AARequestImpl) SessionTerminationRequestImpl(org.mobicents.slee.resource.diameter.rx.events.SessionTerminationRequestImpl)

Example 19 with DiameterMessage

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

the class RxSessionActivityImpl method sendSyncMessage.

public DiameterMessage sendSyncMessage(DiameterMessage message) {
    DiameterMessage answer = null;
    Message receivedMessage = doSendMessage(message);
    if (receivedMessage != null) {
        if (!receivedMessage.isRequest()) {
            if (receivedMessage.isError()) {
                answer = new ErrorAnswerImpl(receivedMessage);
            } else {
                switch(receivedMessage.getCommandCode()) {
                    case 274:
                        answer = new AbortSessionAnswerImpl(receivedMessage);
                        break;
                    case 258:
                        answer = new ReAuthAnswerImpl(receivedMessage);
                        break;
                    case 275:
                        answer = new SessionTerminationAnswerImpl(receivedMessage);
                        break;
                    case AARequest.commandCode:
                        answer = new AAAnswerImpl(receivedMessage);
                    default:
                        logger.error((new StringBuilder()).append("Received an unknown type of Message for Base Activity: ").append(receivedMessage).toString());
                        break;
                }
            }
        } else {
            logger.error("Received a REQUEST message when expecting an ANSWER.");
        }
    } else {
        logger.debug("No answer received. Returning null.");
    }
    return answer;
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)

Example 20 with DiameterMessage

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

the class S13MessageFactoryImpl method createS13Message.

/**
 * Creates a S13 Message with specified command-code and avps filled. If a header is present an answer will be created, if not
 * it will generate a request.
 *
 * @param diameterHeader
 * @param avps
 * @param _commandCode
 * @param appId
 * @return
 * @throws InternalException
 */
DiameterMessage createS13Message(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws InternalException {
    boolean creatingRequest = diameterHeader == null;
    Message msg = null;
    if (!creatingRequest) {
        Message raw = createMessage(diameterHeader, avps, 0, appId);
        raw.setProxiable(diameterHeader.isProxiable());
        raw.setRequest(false);
        // just in case. answers never have T flag set
        raw.setReTransmitted(false);
        // FIXME ? raw.getAvps().removeAvp(Avp.AUTH_APPLICATION_ID);
        msg = raw;
    } else {
        Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
        raw.setProxiable(true);
        raw.setRequest(true);
        msg = raw;
    }
    int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
    DiameterMessage diamMessage = null;
    switch(commandCode) {
        case MEIdentityCheckRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new MEIdentityCheckRequestImpl(msg) : new MEIdentityCheckAnswerImpl(msg);
            break;
        default:
            diamMessage = new ExtensionDiameterMessageImpl(msg);
    }
    if (!diamMessage.hasSessionId() && session != null) {
        diamMessage.setSessionId(session.getSessionId());
    }
    return diamMessage;
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Message(org.jdiameter.api.Message) MEIdentityCheckRequestImpl(org.mobicents.slee.resource.diameter.s13.events.MEIdentityCheckRequestImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) MEIdentityCheckAnswerImpl(org.mobicents.slee.resource.diameter.s13.events.MEIdentityCheckAnswerImpl) ExtensionDiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl)

Aggregations

DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)34 Message (org.jdiameter.api.Message)14 FireableEventType (javax.slee.resource.FireableEventType)12 ErrorAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)4 ExtensionDiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl)4 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)3 IOException (java.io.IOException)2 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)2 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)2 UserDataRequest (net.java.slee.resource.diameter.sh.events.UserDataRequest)2 ServerShSession (org.jdiameter.api.sh.ServerShSession)2 ShServerSessionDataLocalImpl (org.jdiameter.server.impl.app.sh.ShServerSessionDataLocalImpl)2 ShServerSessionImpl (org.jdiameter.server.impl.app.sh.ShServerSessionImpl)2 DiameterMessageFactoryImpl (org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl)2 AbortSessionAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl)2 AccountingAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl)2 CapabilitiesExchangeAnswerImpl (org.mobicents.slee.resource.diameter.base.events.CapabilitiesExchangeAnswerImpl)2