Search in sources :

Example 1 with TimerData

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

the class ClientConnectionImpl method packetReceived.

@Override
public void packetReceived(Pdu packet) {
    switch(clientState) {
        case INITIAL:
        case OPEN:
            logger.error("LB received packet (" + packet + ") in initial or open state from " + channel.getRemoteAddress().toString() + " sessionId : " + sessionId);
            break;
        case BINDING:
            Boolean correctPacket = false;
            switch(config.getType()) {
                case TRANSCEIVER:
                    if (packet.getCommandId() == SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP)
                        correctPacket = true;
                    break;
                case RECEIVER:
                    if (packet.getCommandId() == SmppConstants.CMD_ID_BIND_RECEIVER_RESP)
                        correctPacket = true;
                    break;
                case TRANSMITTER:
                    if (packet.getCommandId() == SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP)
                        correctPacket = true;
                    break;
            }
            if (!correctPacket)
                logger.error("Received invalid packet in binding state, packet type: " + packet.getName());
            else {
                if (packet.getCommandStatus() == SmppConstants.STATUS_OK) {
                    if (logger.isDebugEnabled())
                        logger.debug("LB received bind response (" + packet + ") from " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                    clientState = ClientState.BOUND;
                    lbClientListener.bindSuccesfull(sessionId, packet);
                } else {
                    logger.error("Binding to " + channel.getRemoteAddress().toString() + " is unsuccesful. sessionId" + sessionId + " , error code: " + packet.getCommandStatus());
                    lbClientListener.bindFailed(sessionId, packet);
                    closeChannel();
                    clientState = ClientState.CLOSED;
                }
            }
            break;
        case BOUND:
            correctPacket = false;
            switch(packet.getCommandId()) {
                case SmppConstants.CMD_ID_CANCEL_SM_RESP:
                case SmppConstants.CMD_ID_DATA_SM_RESP:
                case SmppConstants.CMD_ID_QUERY_SM_RESP:
                case SmppConstants.CMD_ID_REPLACE_SM_RESP:
                case SmppConstants.CMD_ID_SUBMIT_SM_RESP:
                case SmppConstants.CMD_ID_SUBMIT_MULTI_RESP:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received SMPP response (" + packet + ") from " + channel.getRemoteAddress().toString() + ". sessionId: " + sessionId);
                    Integer originalSequence = sequenceMap.remove(packet.getSequenceNumber());
                    if (originalSequence != null) {
                        packet.setSequenceNumber(originalSequence);
                        correctPacket = true;
                        this.lbClientListener.smppEntityResponse(sessionId, packet);
                    }
                    break;
                case SmppConstants.CMD_ID_GENERIC_NACK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received generic nack (" + packet + ") from " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                    correctPacket = true;
                    this.lbClientListener.smppEntityResponse(sessionId, packet);
                    break;
                case SmppConstants.CMD_ID_ENQUIRE_LINK_RESP:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received enquire_link response from " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    correctPacket = true;
                    isEnquireLinkSent = false;
                    connectionCheck.cancel();
                    // connectionCheckServerSideTimer.cancel(false);
                    this.lbClientListener.enquireLinkReceivedFromServer(sessionId);
                    break;
                case SmppConstants.CMD_ID_DATA_SM:
                case SmppConstants.CMD_ID_DELIVER_SM:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received SMPP request (" + packet + ") from " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                    correctPacket = true;
                    ServerTimerResponse response = new ServerTimerResponse(this, packet);
                    packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(response, timeoutResponse, TimeUnit.MILLISECONDS), response));
                    this.lbClientListener.smppEntityRequestFromServer(sessionId, packet);
                    break;
                case SmppConstants.CMD_ID_ENQUIRE_LINK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received enquire_link request from " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                    correctPacket = true;
                    EnquireLinkResp resp = new EnquireLinkResp();
                    resp.setSequenceNumber(packet.getSequenceNumber());
                    sendSmppResponse(resp);
                    break;
                case SmppConstants.CMD_ID_UNBIND:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received unbind request from " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                    correctPacket = true;
                    response = new ServerTimerResponse(this, packet);
                    packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(response, timeoutResponse, TimeUnit.MILLISECONDS), response));
                    lbClientListener.unbindRequestedFromServer(sessionId, packet);
                    clientState = ClientState.UNBINDING;
                    break;
            }
            if (!correctPacket) {
                logger.error("LB received invalid packet in bound state. sessionId : " + sessionId + ". packet : " + packet);
            }
            break;
        case REBINDING:
            switch(packet.getCommandId()) {
                case SmppConstants.CMD_ID_BIND_RECEIVER_RESP:
                case SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP:
                case SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP:
                    if (packet.getCommandStatus() == SmppConstants.STATUS_OK) {
                        if (logger.isDebugEnabled())
                            logger.debug("Connection reconnected to " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                        this.lbClientListener.reconnectSuccesful(sessionId);
                        clientState = ClientState.BOUND;
                        if (invocationContext.activeNodeKey != null)
                            invocationContext.activeNodeKey = new KeySmpp((Node) new ArrayList(invocationContext.smppNodeMap.values()).get(0));
                    } else {
                        logger.debug("Reconnection to client unsuccessful. client session ID : " + sessionId + ". LB will close session!");
                        this.lbClientListener.unbindRequestedFromServer(sessionId, new Unbind());
                    }
            }
            break;
        case UNBINDING:
            correctPacket = false;
            if (packet.getCommandId() == SmppConstants.CMD_ID_UNBIND_RESP)
                correctPacket = true;
            if (!correctPacket)
                logger.error("LB received invalid packet (" + packet + ") form " + channel.getRemoteAddress().toString() + " in unbinding state. sessionId : " + sessionId);
            else {
                if (logger.isDebugEnabled())
                    logger.debug("LB received unbind response form  " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
                Integer originalSequence = sequenceMap.remove(packet.getSequenceNumber());
                if (originalSequence != null) {
                    packet.setSequenceNumber(originalSequence);
                    this.lbClientListener.unbindSuccesfull(sessionId, packet);
                }
                sequenceMap.clear();
                packetMap.clear();
                closeChannel();
                clientState = ClientState.CLOSED;
            }
            break;
        case CLOSED:
            logger.error("LB received packet (" + packet + ") in closed state from " + channel.getRemoteAddress().toString() + " sessionId : " + sessionId);
            break;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerTimerResponse(org.mobicents.tools.smpp.balancer.timers.ServerTimerResponse) KeySmpp(org.mobicents.tools.sip.balancer.KeySmpp) EnquireLinkResp(com.cloudhopper.smpp.pdu.EnquireLinkResp) TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) ArrayList(java.util.ArrayList) Unbind(com.cloudhopper.smpp.pdu.Unbind)

Example 2 with TimerData

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

the class ClientConnectionImpl method sendUnbindResponse.

@Override
public void sendUnbindResponse(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);
    }
    clientState = ClientState.CLOSED;
    sequenceMap.clear();
    packetMap.clear();
    if (logger.isDebugEnabled())
        logger.debug("LB sent unbind response (" + packet + ") to " + channel.getRemoteAddress().toString() + ". sessionId : " + sessionId);
    channel.write(buffer);
    closeChannel();
}
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 3 with TimerData

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

the class ClientConnectionImpl 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 " + channel.getRemoteAddress().toString() + ". sessionId : " + 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 4 with TimerData

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

the class ServerConnectionImpl 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 " + 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 5 with TimerData

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

the class ServerConnectionImpl 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);
    }
    serverState = ServerState.BOUND;
    if (logger.isDebugEnabled())
        logger.debug("LB  sent bind 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)

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