@Override public boolean process(SmppSimulatorSessionHandler session, Channel channel, Pdu pdu) throws Exception { // anything other than a bind is super bad! if (!(pdu instanceof BaseBind)) { if (pdu instanceof PduRequest) { session.addPduToWriteOnNextPduReceived( ((PduRequest) pdu).createGenericNack(SmppConstants.STATUS_INVBNDSTS)); return true; } else { // logger.error("PDU response received, but not bound"); channel.close(); return true; } } BaseBind bind = (BaseBind) pdu; BaseBindResp bindResp = (BaseBindResp) bind.createResponse(); if (!bind.getSystemId().equals(systemId)) { bindResp.setCommandStatus(SmppConstants.STATUS_INVSYSID); } else if (!bind.getPassword().equals(password)) { bindResp.setCommandStatus(SmppConstants.STATUS_INVPASWD); } session.addPduToWriteOnNextPduReceived(bindResp); return true; }
@Test public void serverSessionBindVersion33() throws Exception { DefaultSmppServer server0 = createSmppServer(); server0.start(); try { DefaultSmppClient client0 = new DefaultSmppClient(); SmppSessionConfiguration sessionConfig0 = createDefaultConfiguration(); // set back to version 3.3 sessionConfig0.setInterfaceVersion(SmppConstants.VERSION_3_3); // we will not use the proper method of binding since we need to // access the bind response to verify it's correct DefaultSmppSession session0 = client0.doOpen(sessionConfig0, new DefaultSmppSessionHandler()); // create a bind request based on this config BaseBind bindRequest = client0.createBindRequest(sessionConfig0); // execute a bind request and wait for a bind response BaseBindResp bindResponse = session0.bind(bindRequest, 200); Thread.sleep(100); SmppServerSession serverSession0 = serverHandler.sessions.iterator().next(); Assert.assertEquals(1, serverHandler.sessions.size()); Assert.assertEquals(1, server0.getChannels().size()); Assert.assertEquals(true, serverSession0.isBound()); Assert.assertEquals(SmppBindType.TRANSCEIVER, serverSession0.getBindType()); Assert.assertEquals(SmppSession.Type.SERVER, serverSession0.getLocalType()); Assert.assertEquals(SmppSession.Type.CLIENT, serverSession0.getRemoteType()); // verify "requested" version is still 3.3 Assert.assertEquals( SmppConstants.VERSION_3_3, serverSession0.getConfiguration().getInterfaceVersion()); // verify the session interface version is normalized to 3.3 Assert.assertEquals(SmppConstants.VERSION_3_3, serverSession0.getInterfaceVersion()); Assert.assertEquals(false, serverSession0.areOptionalParametersSupported()); // verify client session version settings are correct Assert.assertEquals((byte) 0x33, session0.getConfiguration().getInterfaceVersion()); Assert.assertEquals((byte) 0x33, session0.getInterfaceVersion()); Assert.assertEquals(false, session0.areOptionalParametersSupported()); // verify NO optional parameters were included in bind response Assert.assertEquals(0, bindResponse.getOptionalParameterCount()); Assert.assertEquals("cloudhopper", bindResponse.getSystemId()); serverSession0.close(); Thread.sleep(200); Assert.assertEquals(0, serverHandler.sessions.size()); Assert.assertEquals(0, server0.getChannels().size()); Assert.assertEquals(false, serverSession0.isBound()); } finally { server0.destroy(); } }
protected BaseBindResp createBindResponse(BaseBind bindRequest, int statusCode) { BaseBindResp bindResponse = (BaseBindResp) bindRequest.createResponse(); bindResponse.setCommandStatus(statusCode); bindResponse.setSystemId(configuration.getSystemId()); // if the server supports an SMPP server version >= 3.4 AND the bind request // included an interface version >= 3.4, include an optional parameter with configured // sc_interface_version TLV if (configuration.getInterfaceVersion() >= SmppConstants.VERSION_3_4 && bindRequest.getInterfaceVersion() >= SmppConstants.VERSION_3_4) { Tlv scInterfaceVersion = new Tlv( SmppConstants.TAG_SC_INTERFACE_VERSION, new byte[] {configuration.getInterfaceVersion()}); bindResponse.addOptionalParameter(scInterfaceVersion); } return bindResponse; }