Search in sources :

Example 1 with BaseBindResp

use of com.cloudhopper.smpp.pdu.BaseBindResp 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 2 with BaseBindResp

use of com.cloudhopper.smpp.pdu.BaseBindResp 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)

Aggregations

BaseBind (com.cloudhopper.smpp.pdu.BaseBind)2 BaseBindResp (com.cloudhopper.smpp.pdu.BaseBindResp)2 Tlv (com.cloudhopper.smpp.tlv.Tlv)2 Unbind (com.cloudhopper.smpp.pdu.Unbind)1