Search in sources :

Example 1 with BaseBind

use of com.cloudhopper.smpp.pdu.BaseBind in project load-balancer by RestComm.

the class ClientConnectionImpl method bind.

@SuppressWarnings("rawtypes")
@Override
public void bind() {
    BaseBind packet = null;
    if (config.getType() == SmppBindType.TRANSCEIVER)
        packet = new BindTransceiver();
    else if (config.getType() == SmppBindType.RECEIVER)
        packet = new BindReceiver();
    else if (config.getType() == SmppBindType.TRANSMITTER)
        packet = new BindTransmitter();
    packet.setSystemId(config.getSystemId());
    packet.setPassword(config.getPassword());
    packet.setSystemType(config.getSystemType());
    packet.setInterfaceVersion(config.getInterfaceVersion());
    packet.setAddressRange(config.getAddressRange());
    packet.setSequenceNumber(lastSequenceNumberSent.incrementAndGet());
    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 (clientState != ClientState.REBINDING)
        clientState = ClientState.BINDING;
    if (logger.isDebugEnabled())
        logger.debug("LB trying to bind to server " + config.getHost() + " " + config.getPort() + ": client state " + clientState);
    channel.write(buffer);
}
Also used : BindTransceiver(com.cloudhopper.smpp.pdu.BindTransceiver) BindReceiver(com.cloudhopper.smpp.pdu.BindReceiver) BindTransmitter(com.cloudhopper.smpp.pdu.BindTransmitter) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with BaseBind

use of com.cloudhopper.smpp.pdu.BaseBind in project load-balancer by RestComm.

the class MClientConnectionImpl method bind.

@SuppressWarnings("rawtypes")
@Override
public void bind() {
    BaseBind packet = null;
    if (config.getType() == SmppBindType.TRANSCEIVER) {
        packet = new BindTransceiver();
    } else if (config.getType() == SmppBindType.RECEIVER) {
        packet = new BindReceiver();
    } else if (config.getType() == SmppBindType.TRANSMITTER) {
        packet = new BindTransmitter();
    }
    packet.setSystemId(config.getSystemId());
    packet.setPassword(config.getPassword());
    packet.setSystemType(config.getSystemType());
    packet.setInterfaceVersion(config.getInterfaceVersion());
    packet.setAddressRange(config.getAddressRange());
    packet.setSequenceNumber(lastSequenceNumberSent.incrementAndGet());
    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 (clientState != ClientState.REBINDING)
        clientState = ClientState.BINDING;
    if (logger.isDebugEnabled())
        logger.debug("LB trying to bind to server " + config.getHost() + " " + config.getPort() + ": client state " + clientState);
    channel.write(buffer);
}
Also used : BindTransceiver(com.cloudhopper.smpp.pdu.BindTransceiver) BindReceiver(com.cloudhopper.smpp.pdu.BindReceiver) BindTransmitter(com.cloudhopper.smpp.pdu.BindTransmitter) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 3 with BaseBind

use of com.cloudhopper.smpp.pdu.BaseBind in project load-balancer by RestComm.

the class UserSpace method validateConnection.

private void validateConnection(MServerConnectionImpl customer) {
    if (logger.isDebugEnabled())
        logger.debug("Validate connection for customer with sessionId : " + customer.getSessionId());
    BaseBindResp bindResponse = (BaseBindResp) customer.getBindRequest().createResponse();
    bindResponse.setSystemId("loadbalancer");
    if (customer.getConfig().getInterfaceVersion() >= SmppConstants.VERSION_3_4 && ((BaseBind<?>) customer.getBindRequest()).getInterfaceVersion() >= SmppConstants.VERSION_3_4) {
        Tlv scInterfaceVersion = new Tlv(SmppConstants.TAG_SC_INTERFACE_VERSION, new byte[] { customer.getConfig().getInterfaceVersion() });
        bindResponse.addOptionalParameter(scInterfaceVersion);
    }
    if (!(customer.getConfig().getPassword().equals(this.password))) {
        if (logger.isDebugEnabled())
            logger.debug("LB sending fail bind response for customer with sessionId : " + customer.getSessionId());
        // SEND BIND FAILED TO CUSTOMER
        bindResponse.setCommandStatus(SmppConstants.STATUS_INVPASWD);
        customer.sendBindResponse(bindResponse);
    } else {
        if (logger.isDebugEnabled())
            logger.debug("LB sending successful bind response for customer with sessionId : " + customer.getSessionId());
        this.customers.put(customer.getSessionId(), customer);
        // SEND BIND SUCCESFULL TO CUSTOMER
        bindResponse.setCommandStatus(SmppConstants.STATUS_OK);
        customer.sendBindResponse(bindResponse);
    }
}
Also used : BaseBindResp(com.cloudhopper.smpp.pdu.BaseBindResp) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 4 with BaseBind

use of com.cloudhopper.smpp.pdu.BaseBind in project load-balancer by RestComm.

the class BinderRunnable method run.

@SuppressWarnings("rawtypes")
@Override
public void run() {
    boolean connectSuccesful = true;
    while (!client.connect()) {
        logger.warn("Connection to " + client.getConfig().getHost() + ":" + client.getConfig().getPort() + " failed we will try next server");
        index++;
        if (index == nodes.size())
            index = 0;
        if (index == nodes.indexOf(firstNode)) {
            connectSuccesful = false;
            break;
        }
        client.getConfig().setHost(nodes.get(index).getIp());
        if (!client.getConfig().isUseSsl())
            client.getConfig().setPort(Integer.parseInt((String) nodes.get(index).getProperties().get("smppPort")));
        else
            client.getConfig().setPort(Integer.parseInt((String) nodes.get(index).getProperties().get("smppSslPort")));
        logger.warn("Next server : " + client.getConfig().getHost() + ":" + client.getConfig().getPort());
    }
    if (connectSuccesful) {
        client.bind();
    } else {
        if (client.getClientState() == ClientState.INITIAL) {
            BaseBindResp bindResponse = (BaseBindResp) ((BaseBind) packet).createResponse();
            bindResponse.setCommandStatus(SmppConstants.STATUS_SYSERR);
            bindResponse.setSystemId(client.getConfig().getSystemId());
            if (client.getConfig().getInterfaceVersion() >= SmppConstants.VERSION_3_4 && ((BaseBind) packet).getInterfaceVersion() >= SmppConstants.VERSION_3_4) {
                Tlv scInterfaceVersion = new Tlv(SmppConstants.TAG_SC_INTERFACE_VERSION, new byte[] { client.getConfig().getInterfaceVersion() });
                bindResponse.addOptionalParameter(scInterfaceVersion);
            }
            serverSessions.get(sessionId).sendBindResponse(bindResponse);
            client.setClientState(ClientState.CLOSED);
            clientSessions.remove(sessionId);
            serverSessions.remove(sessionId);
        } else {
            serverSessions.get(sessionId).sendUnbindRequest(new Unbind());
            clientSessions.remove(sessionId);
        }
    }
}
Also used : BaseBindResp(com.cloudhopper.smpp.pdu.BaseBindResp) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) Unbind(com.cloudhopper.smpp.pdu.Unbind) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 5 with BaseBind

use of com.cloudhopper.smpp.pdu.BaseBind in project load-balancer by RestComm.

the class ServerConnectionImpl method packetReceived.

@SuppressWarnings("rawtypes")
@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 from " + 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 " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                enquireRunnable = new CustomerTimerEnquire(this);
                enquireTimer = monitorExecutor.scheduleAtFixedRate(enquireRunnable, timeoutEnquire, timeoutEnquire, TimeUnit.MILLISECONDS);
                if (connectionTimer != null) {
                    connectionRunnable.cancel();
                    connectionTimer.cancel(false);
                }
                BaseBind bindRequest = (BaseBind) packet;
                config.setName("LoadBalancerSession." + bindRequest.getSystemId() + "." + bindRequest.getSystemType());
                config.setSystemId(bindRequest.getSystemId());
                config.setPassword(bindRequest.getPassword());
                config.setSystemType(bindRequest.getSystemType());
                config.setAddressRange(bindRequest.getAddressRange());
                config.setInterfaceVersion(bindRequest.getInterfaceVersion());
                CustomerTimerResponse responseTimer = new CustomerTimerResponse(this, packet);
                packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(responseTimer, timeoutResponse, TimeUnit.MILLISECONDS), responseTimer));
                lbServerListener.bindRequested(sessionId, this, bindRequest);
                serverState = ServerState.BINDING;
            }
            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 " + 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));
                    lbServerListener.unbindRequested(sessionId, 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:
                case SmppConstants.CMD_ID_GENERIC_NACK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received SMPP request (" + packet + ") from " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    correctPacket = true;
                    responseTimer = new CustomerTimerResponse(this, packet);
                    packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(responseTimer, timeoutResponse, TimeUnit.MILLISECONDS), responseTimer));
                    lbServerListener.smppEntityRequested(sessionId, packet);
                    break;
                case SmppConstants.CMD_ID_ENQUIRE_LINK:
                    if (logger.isDebugEnabled())
                        logger.debug("LB received enquire_link request from " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    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 " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                    Integer originalSequence = sequenceMap.remove(packet.getSequenceNumber());
                    if (originalSequence != null) {
                        packet.setSequenceNumber(originalSequence);
                        correctPacket = true;
                        lbServerListener.smppEntityResponseFromClient(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;
                    isClientSideOk = true;
                    break;
            }
            if (!correctPacket) {
                sendGenericNack(packet);
            }
            break;
        case REBINDING:
            if (logger.isDebugEnabled())
                logger.debug("LB received packet (" + packet + ") in REBINDING state from " + 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 if (packet instanceof EnquireLinkResp) {
                isClientSideOk = true;
            }
            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 " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId + ". packet : " + packet);
            else {
                if (logger.isDebugEnabled())
                    logger.debug("LB received unbind response from " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
                enquireRunnable.cancel();
                enquireTimer.cancel(false);
                Integer originalSequence = sequenceMap.remove(packet.getSequenceNumber());
                if (originalSequence != null) {
                    packet.setSequenceNumber(originalSequence);
                    this.lbServerListener.unbindSuccesfullFromServer(sessionId, packet);
                }
                packetMap.clear();
                sequenceMap.clear();
                channel.close();
                serverState = ServerState.CLOSED;
            }
            break;
        case CLOSED:
            logger.error("LB received packet in incorrect state (CLOSED) from " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId + ". packet : " + packet);
            break;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) BaseBind(com.cloudhopper.smpp.pdu.BaseBind) TimerData(org.mobicents.tools.smpp.balancer.timers.TimerData) CustomerTimerEnquire(org.mobicents.tools.smpp.balancer.timers.CustomerTimerEnquire)

Aggregations

BaseBind (com.cloudhopper.smpp.pdu.BaseBind)5 BaseBindResp (com.cloudhopper.smpp.pdu.BaseBindResp)2 BindReceiver (com.cloudhopper.smpp.pdu.BindReceiver)2 BindTransceiver (com.cloudhopper.smpp.pdu.BindTransceiver)2 BindTransmitter (com.cloudhopper.smpp.pdu.BindTransmitter)2 Tlv (com.cloudhopper.smpp.tlv.Tlv)2 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)2 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 EnquireLinkResp (com.cloudhopper.smpp.pdu.EnquireLinkResp)1 PduRequest (com.cloudhopper.smpp.pdu.PduRequest)1 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)1 Unbind (com.cloudhopper.smpp.pdu.Unbind)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CustomerTimerEnquire (org.mobicents.tools.smpp.balancer.timers.CustomerTimerEnquire)1 CustomerTimerResponse (org.mobicents.tools.smpp.balancer.timers.CustomerTimerResponse)1 TimerData (org.mobicents.tools.smpp.balancer.timers.TimerData)1