use of com.cloudhopper.smpp.pdu.EnquireLinkResp 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;
}
}
use of com.cloudhopper.smpp.pdu.EnquireLinkResp 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;
}
}
use of com.cloudhopper.smpp.pdu.EnquireLinkResp in project load-balancer by RestComm.
the class DefaultSmppClientHandler method firePduRequestReceived.
@Override
public PduResponse firePduRequestReceived(@SuppressWarnings("rawtypes") PduRequest pduRequest) {
if (pduRequest.getCommandId() == SmppConstants.CMD_ID_ENQUIRE_LINK) {
enqLinkNumber.incrementAndGet();
EnquireLinkResp resp = new EnquireLinkResp();
resp.setSequenceNumber(pduRequest.getSequenceNumber());
return resp;
} else if (pduRequest.getCommandId() == SmppConstants.CMD_ID_DATA_SM) {
requestFromServerNumber.getAndIncrement();
return pduRequest.createResponse();
}
return null;
}
use of com.cloudhopper.smpp.pdu.EnquireLinkResp 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;
}
}
use of com.cloudhopper.smpp.pdu.EnquireLinkResp in project load-balancer by RestComm.
the class MClientConnectionImpl method packetReceived.
@Override
public void packetReceived(Pdu packet) {
switch(clientState) {
case INITIAL:
case OPEN:
logger.error("LB received packet in initial or open state. client session ID : " + serverSessionID + ". packet : " + packet);
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("LB received invalid packet in binding state. server session ID : " + serverSessionID + ". packet : " + packet);
else {
if (packet.getCommandStatus() == SmppConstants.STATUS_OK) {
logger.info("Connection to client : " + config.getHost() + " : " + config.getPort() + " established. client session ID : " + serverSessionID);
if (logger.isDebugEnabled())
logger.debug("LB received bind response (" + packet + ") from client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
enquireRunnable = new ServerTimerEnquire(this);
enquireTimer = monitorExecutor.scheduleAtFixedRate(enquireRunnable, timeoutEnquire, timeoutEnquire, TimeUnit.MILLISECONDS);
clientState = ClientState.BOUND;
userSpace.bindSuccesfull(node, serverSessionID);
} else {
logger.error("Binding to server is unsuccesful.serverSessionId" + serverSessionID + " , error code: " + packet.getCommandStatus());
closeChannel();
userSpace.bindFailed(serverSessionID, packet);
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 + ") form client " + channel.getRemoteAddress().toString() + ". client session ID: " + serverSessionID);
CustomerPacket originalCustomerPacket = sequenceCustomerMap.remove(packet.getSequenceNumber());
correctPacket = true;
userSpace.sendResponseToClient(originalCustomerPacket, packet);
break;
case SmppConstants.CMD_ID_ENQUIRE_LINK_RESP:
if (logger.isDebugEnabled())
logger.debug("LB received enquire_link response from client " + channel.getRemoteAddress().toString() + " with client session ID : " + serverSessionID);
updateLastTimeSMPPLinkUpdated();
correctPacket = true;
connectionCheck.cancel();
connectionCheckServerSideTimer.cancel(false);
userSpace.enquireLinkReceivedFromServer();
break;
case SmppConstants.CMD_ID_DATA_SM:
case SmppConstants.CMD_ID_DELIVER_SM:
case SmppConstants.CMD_ID_GENERIC_NACK:
if (logger.isDebugEnabled())
logger.debug("LB received SMPP request (" + packet + ") from client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
lastSequenceNumberSent.getAndIncrement();
correctPacket = true;
ServerTimerResponse response = new ServerTimerResponse(this, packet);
packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(response, timeoutResponse, TimeUnit.MILLISECONDS), response));
userSpace.sendRequestToClient(packet, serverSessionID);
break;
case SmppConstants.CMD_ID_ENQUIRE_LINK:
if (logger.isDebugEnabled())
logger.debug("LB received enquire_link request from client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
updateLastTimeSMPPLinkUpdated();
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 client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
enquireRunnable.cancel();
enquireTimer.cancel(false);
connectionCheckServerSideTimer.cancel(false);
correctPacket = true;
response = new ServerTimerResponse(this, packet);
packetMap.put(packet.getSequenceNumber(), new TimerData(packet, monitorExecutor.schedule(response, timeoutResponse, TimeUnit.MILLISECONDS), response));
userSpace.unbindRequestedFromServer((Unbind) packet, serverSessionID);
clientState = ClientState.UNBINDING;
break;
}
if (!correctPacket) {
logger.error("LB received invalid packet in bound state. server session ID : " + serverSessionID + ". 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 client " + channel.getRemoteAddress().toString() + ". client session ID : " + serverSessionID);
updateLastTimeSMPPLinkUpdated();
connectionCheckServerSideTimer = monitorExecutor.scheduleAtFixedRate(connectionCheck, timeoutConnection, timeoutConnection, TimeUnit.MILLISECONDS);
if (enquireTimer != null) {
enquireRunnable.cancel();
enquireTimer.cancel(false);
}
enquireRunnable = new ServerTimerEnquire(this);
enquireTimer = monitorExecutor.scheduleAtFixedRate(enquireRunnable, timeoutEnquire, timeoutEnquire, TimeUnit.MILLISECONDS);
userSpace.reconnectSuccesful(serverSessionID, this);
clientState = ClientState.BOUND;
} else {
if (logger.isDebugEnabled())
logger.debug("Reconnection to client unsuccessful. client session ID : " + serverSessionID + ". LB will disconnect all servers!");
userSpace.unbindRequestedFromServer(new Unbind(), serverSessionID);
}
}
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. client session ID : " + serverSessionID + ". packet : " + packet);
else {
if (logger.isDebugEnabled())
logger.debug("LB received unbind response form client " + channel.getRemoteAddress().toString() + ". client sessionId : " + serverSessionID);
sequenceMap.clear();
packetMap.clear();
closeChannel();
clientState = ClientState.CLOSED;
}
break;
case CLOSED:
logger.error("LB received packet in closed state. client session ID : " + serverSessionID + ". packet : " + packet);
break;
}
}
Aggregations