use of com.cloudhopper.smpp.pdu.PduResponse in project load-balancer by RestComm.
the class ServerConnectionImpl method requestTimeout.
@Override
public void requestTimeout(Pdu packet) {
if (!packetMap.containsKey(packet.getSequenceNumber())) {
if (logger.isDebugEnabled())
logger.debug("<<requestTimeout>> LB received SMPP response from server in time for client " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
} else {
if (logger.isDebugEnabled())
logger.debug("<<requestTimeout>> LB did NOT receive SMPP response from server in time for client " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
lbServerListener.getNotRespondedPackets().incrementAndGet();
packetMap.remove(packet.getSequenceNumber());
PduResponse pduResponse = ((PduRequest<?>) packet).createResponse();
pduResponse.setCommandStatus(SmppConstants.STATUS_SYSERR);
sendResponse(pduResponse);
}
}
use of com.cloudhopper.smpp.pdu.PduResponse 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.PduResponse in project traccar by tananaev.
the class ClientSmppSessionHandler method firePduRequestReceived.
@Override
public PduResponse firePduRequestReceived(PduRequest request) {
PduResponse response = null;
try {
if (request instanceof DeliverSm) {
String sourceAddress = ((DeliverSm) request).getSourceAddress().getAddress();
String message = CharsetUtil.decode(((DeliverSm) request).getShortMessage(), smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding()));
Log.debug("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress);
boolean isDeliveryReceipt = false;
if (smppClient.getDetectDlrByOpts()) {
isDeliveryReceipt = request.getOptionalParameters() != null;
} else {
isDeliveryReceipt = SmppUtil.isMessageTypeAnyDeliveryReceipt(((DeliverSm) request).getEsmClass());
}
if (!isDeliveryReceipt) {
TextMessageEventHandler.handleTextMessage(sourceAddress, message);
}
}
response = request.createResponse();
} catch (Throwable error) {
Log.warning(error);
response = request.createResponse();
response.setResultMessage(error.getMessage());
response.setCommandStatus(SmppConstants.STATUS_UNKNOWNERR);
}
return response;
}
use of com.cloudhopper.smpp.pdu.PduResponse 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.PduResponse in project load-balancer by RestComm.
the class MServerConnectionImpl method requestTimeout.
@Override
public void requestTimeout(Pdu packet) {
if (!packetMap.containsKey(packet.getSequenceNumber())) {
if (logger.isDebugEnabled())
logger.debug("<<requestTimeout>> LB received SMPP response from client in time for server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
} else {
if (logger.isDebugEnabled())
logger.info("<<requestTimeout>> LB did NOT receive SMPP response from client in time for server " + channel.getRemoteAddress().toString() + ". session ID : " + sessionId);
lbServerListener.getNotRespondedPackets().incrementAndGet();
packetMap.remove(packet.getSequenceNumber());
PduResponse pduResponse = ((PduRequest<?>) packet).createResponse();
pduResponse.setCommandStatus(SmppConstants.STATUS_SYSERR);
sendResponse(pduResponse);
}
}
Aggregations