Search in sources :

Example 6 with TimerData

use of org.mobicents.tools.smpp.balancer.timers.TimerData in project load-balancer by RestComm.

the class ServerConnectionImpl method sendUnbindResponse.

@Override
public void sendUnbindResponse(Pdu packet) {
    enquireRunnable.cancel();
    enquireTimer.cancel(false);
    if (packetMap.containsKey(packet.getSequenceNumber())) {
        TimerData data = packetMap.remove(packet.getSequenceNumber());
        if (data != null) {
            data.getRunnable().cancel();
            data.getScheduledFuture().cancel(false);
        }
    }
    ChannelBuffer buffer = null;
    try {
        buffer = transcoder.encode(packet);
    } catch (UnrecoverablePduException e) {
        logger.error("Encode error: ", e);
    } catch (RecoverablePduException e) {
        logger.error("Encode error: ", e);
    }
    serverState = ServerState.CLOSED;
    packetMap.clear();
    sequenceMap.clear();
    if (logger.isDebugEnabled())
        logger.debug("LB sent  unbind response (" + packet + ") to " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
    channel.write(buffer);
}
Also used : TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 7 with TimerData

use of org.mobicents.tools.smpp.balancer.timers.TimerData in project load-balancer by RestComm.

the class MClientConnectionImpl method sendSmppResponse.

@Override
public void sendSmppResponse(Pdu packet) {
    if (packetMap.containsKey(packet.getSequenceNumber())) {
        TimerData data = packetMap.remove(packet.getSequenceNumber());
        if (data != null) {
            data.getRunnable().cancel();
            data.getScheduledFuture().cancel(false);
        }
    }
    ChannelBuffer buffer = null;
    try {
        buffer = transcoder.encode(packet);
    } catch (UnrecoverablePduException e) {
        logger.error("Encode error: ", e);
    } catch (RecoverablePduException e) {
        logger.error("Encode error: ", e);
    }
    if (logger.isDebugEnabled())
        logger.debug("LB sent SMPP response (" + packet + ") to client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
    channel.write(buffer);
}
Also used : TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 8 with TimerData

use of org.mobicents.tools.smpp.balancer.timers.TimerData in project load-balancer by RestComm.

the class MServerConnectionImpl method packetReceived.

@Override
public void packetReceived(Pdu packet) {
    switch(serverState) {
        case OPEN:
            Boolean correctPacket = false;
            switch(packet.getCommandId()) {
                case SmppConstants.CMD_ID_BIND_RECEIVER:
                    correctPacket = true;
                    config.setType(SmppBindType.RECEIVER);
                    break;
                case SmppConstants.CMD_ID_BIND_TRANSCEIVER:
                    correctPacket = true;
                    config.setType(SmppBindType.TRANSCEIVER);
                    break;
                case SmppConstants.CMD_ID_BIND_TRANSMITTER:
                    correctPacket = true;
                    config.setType(SmppBindType.TRANSMITTER);
                    break;
            }
            if (!correctPacket) {
                logger.error("Unable to convert a BaseBind request of server " + channel.getRemoteAddress().toString() + ". session ID: " + sessionId);
                sendGenericNack(packet);
                channel.close();
                serverState = ServerState.CLOSED;
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("LB received bind request (" + packet + ") from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                serverState = ServerState.BINDING;
                if (connectionTimer != null) {
                    connectionRunnable.cancel();
                    connectionTimer.cancel(false);
                }
                this.bindRequest = (BaseBind<?>) packet;
                // config.setName("LoadBalancerSession." + this.bindRequest.getSystemId() + "." + this.bindRequest.getSystemType());
                config.setSystemId(this.bindRequest.getSystemId());
                config.setPassword(this.bindRequest.getPassword());
                config.setSystemType(this.bindRequest.getSystemType());
                config.setAddressRange(this.bindRequest.getAddressRange());
                config.setInterfaceVersion(this.bindRequest.getInterfaceVersion());
                CustomerTimerResponse responseTimer = new CustomerTimerResponse(this, packet);
                packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(responseTimer, timeoutResponse, TimeUnit.MILLISECONDS), responseTimer));
                userSpace = lbServerListener.bindRequested(sessionId, this, this.bindRequest);
                userSpace.bind(this, packet);
            }
            break;
        case BINDING:
            logger.error("LB received packet in incorrect state (BINDING). session ID : " + sessionId + " .packet : " + packet);
            break;
        case BOUND:
            correctPacket = false;
            switch(packet.getCommandId()) {
                case SmppConstants.CMD_ID_UNBIND:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received unbind request from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    correctPacket = true;
                    enquireRunnable.cancel();
                    enquireTimer.cancel(false);
                    CustomerTimerResponse responseTimer = new CustomerTimerResponse(this, packet);
                    packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(responseTimer, timeoutResponse, TimeUnit.MILLISECONDS), responseTimer));
                    userSpace.unbind(sessionId, (Unbind) packet);
                    serverState = ServerState.UNBINDING;
                    break;
                case SmppConstants.CMD_ID_CANCEL_SM:
                case SmppConstants.CMD_ID_DATA_SM:
                case SmppConstants.CMD_ID_QUERY_SM:
                case SmppConstants.CMD_ID_REPLACE_SM:
                case SmppConstants.CMD_ID_SUBMIT_SM:
                case SmppConstants.CMD_ID_SUBMIT_MULTI:
                    // GENERIC_NACK doesn't have responses so we don't have to start response timer
                    responseTimer = new CustomerTimerResponse(this, packet);
                    packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(responseTimer, timeoutResponse, TimeUnit.MILLISECONDS), responseTimer));
                case SmppConstants.CMD_ID_GENERIC_NACK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received SMPP request (" + packet + ") from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    correctPacket = true;
                    userSpace.sendRequestToServer(sessionId, packet);
                    break;
                case SmppConstants.CMD_ID_ENQUIRE_LINK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received enquire_link request from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    updateLastTimeSMPPLinkUpdated();
                    correctPacket = true;
                    EnquireLinkResp resp = new EnquireLinkResp();
                    resp.setSequenceNumber(packet.getSequenceNumber());
                    sendResponse(resp);
                    break;
                case SmppConstants.CMD_ID_DATA_SM_RESP:
                case SmppConstants.CMD_ID_DELIVER_SM_RESP:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received SMPP response (" + packet + ") from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    CustomerPacket originalSequence = sequenceMap.remove(packet.getSequenceNumber());
                    if (originalSequence != null) {
                        packet.setSequenceNumber(originalSequence.getSequence());
                        correctPacket = true;
                        userSpace.sendResponseToServer(sessionId, packet, originalSequence.getSessionId());
                    }
                    break;
                case SmppConstants.CMD_ID_ENQUIRE_LINK_RESP:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received enquire_link response from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    correctPacket = true;
                    updateLastTimeSMPPLinkUpdated();
                    break;
            }
            if (!correctPacket) {
                sendGenericNack(packet);
            }
            break;
        case REBINDING:
            if (logger.isDebugEnabled())
                logger.debug("LB received packet (" + packet + ") in REBINDING state from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId + ". LB sent SYSERR responses!");
            if (packet instanceof PduRequest<?>) {
                PduResponse pduResponse = ((PduRequest<?>) packet).createResponse();
                pduResponse.setCommandStatus(SmppConstants.STATUS_SYSERR);
                sendResponse(pduResponse);
            } else {
                correctPacket = true;
                updateLastTimeSMPPLinkUpdated();
            }
            break;
        case UNBINDING:
            correctPacket = false;
            if (packet.getCommandId() == SmppConstants.CMD_ID_UNBIND_RESP)
                correctPacket = true;
            if (!correctPacket)
                logger.error("LB received invalid packet in unbinding state from serevr " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId + ". packet : " + packet);
            else {
                if (logger.isDebugEnabled())
                    logger.debug("LB received unbind response from server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                enquireRunnable.cancel();
                enquireTimer.cancel(false);
                packetMap.clear();
                sequenceMap.clear();
                channel.close();
                serverState = ServerState.CLOSED;
            }
            break;
        case CLOSED:
            logger.error("LB received packet in incorrect state (CLOSED) from serevr " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId + ". packet : " + packet);
            break;
    }
}
Also used : PduRequest(com.cloudhopper.smpp.pdu.PduRequest) CustomerTimerResponse(org.mobicents.tools.smpp.balancer.timers.CustomerTimerResponse) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) EnquireLinkResp(com.cloudhopper.smpp.pdu.EnquireLinkResp) TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData)

Example 9 with TimerData

use of org.mobicents.tools.smpp.balancer.timers.TimerData in project load-balancer by RestComm.

the class MServerConnectionImpl method sendBindResponse.

@Override
public void sendBindResponse(Pdu packet) {
    if (packetMap.containsKey(packet.getSequenceNumber())) {
        TimerData data = packetMap.remove(packet.getSequenceNumber());
        if (data != null) {
            data.getRunnable().cancel();
            data.getScheduledFuture().cancel(false);
        }
    }
    ChannelBuffer buffer = null;
    try {
        buffer = transcoder.encode(packet);
    } catch (UnrecoverablePduException e) {
        logger.error("Encode error: ", e);
    } catch (RecoverablePduException e) {
        logger.error("Encode error: ", e);
    }
    if (logger.isDebugEnabled())
        logger.debug("LB  sent response (" + packet + ") to server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
    serverState = ServerState.BOUND;
    channel.write(buffer);
}
Also used : TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 10 with TimerData

use of org.mobicents.tools.smpp.balancer.timers.TimerData in project load-balancer by RestComm.

the class MServerConnectionImpl method sendResponse.

@Override
public void sendResponse(Pdu packet) {
    if (packetMap.containsKey(packet.getSequenceNumber())) {
        TimerData data = packetMap.remove(packet.getSequenceNumber());
        if (data != null) {
            data.getRunnable().cancel();
            data.getScheduledFuture().cancel(false);
        }
    }
    ChannelBuffer buffer = null;
    try {
        buffer = transcoder.encode(packet);
    } catch (UnrecoverablePduException e) {
        logger.error("Encode error: ", e);
    } catch (RecoverablePduException e) {
        logger.error("Encode error: ", e);
    }
    if (logger.isDebugEnabled())
        logger.debug("LB sent SMPP response (" + packet + ") to server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
    channel.write(buffer);
}
Also used : TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

TimerData (org.mobicents.tools.smpp.balancer.timers.TimerData)14 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)10 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)10 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 EnquireLinkResp (com.cloudhopper.smpp.pdu.EnquireLinkResp)4 PduRequest (com.cloudhopper.smpp.pdu.PduRequest)2 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)2 Unbind (com.cloudhopper.smpp.pdu.Unbind)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CustomerTimerResponse (org.mobicents.tools.smpp.balancer.timers.CustomerTimerResponse)2 ServerTimerResponse (org.mobicents.tools.smpp.balancer.timers.ServerTimerResponse)2 BaseBind (com.cloudhopper.smpp.pdu.BaseBind)1 ArrayList (java.util.ArrayList)1 KeySmpp (org.mobicents.tools.sip.balancer.KeySmpp)1 CustomerTimerEnquire (org.mobicents.tools.smpp.balancer.timers.CustomerTimerEnquire)1 ServerTimerEnquire (org.mobicents.tools.smpp.balancer.timers.ServerTimerEnquire)1