Search in sources :

Example 1 with DataSm

use of com.cloudhopper.smpp.pdu.DataSm in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testDataSm.

@Test(groups = { "TxSmppServer" })
public void testDataSm() throws Exception {
    if (!this.cassandraDbInited)
        return;
    this.smppSess = new SmppSessionsProxy();
    this.sbb.setSmppServerSessions(smppSess);
    int windowSize = SmppConstants.DEFAULT_WINDOW_SIZE;
    long connectTimeout = SmppConstants.DEFAULT_CONNECT_TIMEOUT;
    long requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
    long clientBindTimeout = SmppConstants.DEFAULT_BIND_TIMEOUT;
    long windowMonitorInterval = SmppConstants.DEFAULT_WINDOW_MONITOR_INTERVAL;
    long windowWaitTimeout = SmppConstants.DEFAULT_WINDOW_WAIT_TIMEOUT;
    Esme esme = new Esme("Esme_1", "Esme_systemId_1", "pwd", "host", 0, false, null, SmppInterfaceVersionType.SMPP34, -1, -1, null, SmppBindType.TRANSCEIVER, SmppSession.Type.CLIENT, windowSize, connectTimeout, requestExpiryTimeout, clientBindTimeout, windowMonitorInterval, windowWaitTimeout, "Esme_1", true, 30000, 0, 0, -1, -1, "^[0-9a-zA-Z]*", -1, -1, "^[0-9a-zA-Z]*", 0, false, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1);
    ActivityContextInterface aci = new SmppTransactionProxy(esme);
    DataSm event = new DataSm();
    Date curDate = new Date();
    this.fillSm(event, curDate, false);
    Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, msgUtf8);
    event.addOptionalParameter(tlv);
    tlv = new Tlv(SmppConstants.TAG_SAR_MSG_REF_NUM, msg_ref_num);
    event.addOptionalParameter(tlv);
    tlv = new Tlv(SmppConstants.TAG_SAR_SEGMENT_SEQNUM, new byte[] { 1 });
    event.addOptionalParameter(tlv);
    tlv = new Tlv(SmppConstants.TAG_SAR_TOTAL_SEGMENTS, new byte[] { 2 });
    event.addOptionalParameter(tlv);
    long dueSlot = this.pers.c2_getDueSlotForTime(new Date());
    PreparedStatementCollection psc = this.pers.getStatementCollection(new Date());
    int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    assertEquals(b1, 0);
    assertEquals(b2, 0L);
    TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Utf8);
    this.sbb.onDataSm(event, aci);
    b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    dueSlot = b2;
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    assertEquals(b2, dueSlot);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    this.checkSmsSet(smsSet, curDate, false);
    Sms sms = smsSet.getSms(0);
    // msgUcs2
    assertEquals(sms.getShortMessageText(), sMsg);
    assertEquals(this.smppSess.getReqList().size(), 0);
    assertEquals(this.smppSess.getRespList().size(), 1);
    PduResponse resp = this.smppSess.getRespList().get(0);
    assertEquals(resp.getCommandStatus(), 0);
    assertEquals(resp.getOptionalParameterCount(), 0);
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) ActivityContextInterface(javax.slee.ActivityContextInterface) Esme(org.restcomm.smpp.Esme) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) DataSm(com.cloudhopper.smpp.pdu.DataSm) Sms(org.mobicents.smsc.library.Sms) SmsSet(org.mobicents.smsc.library.SmsSet) Tlv(com.cloudhopper.smpp.tlv.Tlv) Test(org.testng.annotations.Test)

Example 2 with DataSm

use of com.cloudhopper.smpp.pdu.DataSm in project smscgateway by RestComm.

the class SmppPcapParser method parseSmppPacket.

private void parseSmppPacket(byte[] data) throws Exception {
    ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
    try {
        Pdu pdu = this.dpt.decode(buffer);
        if (pdu instanceof SubmitSm) {
            SubmitSm submitPdu = (SubmitSm) pdu;
            smppAccepter.onNewSmppRequest(submitPdu);
        } else if (pdu instanceof DataSm) {
            DataSm dataPdu = (DataSm) pdu;
            smppAccepter.onNewSmppRequest(dataPdu);
        } else if (pdu instanceof DeliverSm) {
            DeliverSm deliverPdu = (DeliverSm) pdu;
            smppAccepter.onNewSmppRequest(deliverPdu);
        }
    } catch (Exception e) {
        e.printStackTrace();
    // buffer = ChannelBuffers.wrappedBuffer(data);
    // Pdu pdu = this.dpt.decode(buffer);
    // int i1 = 0;
    }
}
Also used : Pdu(com.cloudhopper.smpp.pdu.Pdu) DataSm(com.cloudhopper.smpp.pdu.DataSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm)

Example 3 with DataSm

use of com.cloudhopper.smpp.pdu.DataSm in project smscgateway by RestComm.

the class SmppTestingForm method doSubmitMessage.

private void doSubmitMessage(int dcs, ArrayList<byte[]> msgLst, int msgRef, boolean addSegmTlv, int esmClass, SmppSimulatorParameters.ValidityType validityType, int segmentCnt, String destAddr, int messageClassVal) throws Exception {
    int i1 = 0;
    for (byte[] buf : msgLst) {
        i1++;
        BaseSm pdu;
        switch(this.param.getSendingMessageType()) {
            case SubmitSm:
                SubmitSm submitPdu = new SubmitSm();
                pdu = submitPdu;
                break;
            case DataSm:
                DataSm dataPdu = new DataSm();
                pdu = dataPdu;
                break;
            case DeliverSm:
                DeliverSm deliverPdu = new DeliverSm();
                pdu = deliverPdu;
                break;
            case SubmitMulti:
                SubmitMulti submitMulti = new SubmitMulti();
                pdu = submitMulti;
                break;
            default:
                return;
        }
        pdu.setSourceAddress(new Address((byte) this.param.getSourceTON().getCode(), (byte) this.param.getSourceNPI().getCode(), this.param.getSourceAddress()));
        if (this.param.getSendingMessageType() == SendingMessageType.SubmitMulti) {
            long daOrig = 1;
            try {
                daOrig = Long.parseLong(destAddr);
            } catch (Exception e) {
            }
            for (int i2 = 0; i2 < this.param.getSubmitMultiMessageCnt(); i2++) {
                // this code can be used for testing of address rejections
                // if(i2 == 0){
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // 8, (byte) this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }else {
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // this.param.getDestTON().getCode(), (byte)
                // this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }
                ((SubmitMulti) pdu).addDestAddresses(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), String.valueOf(daOrig + i2)));
            }
        } else {
            pdu.setDestAddress(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), destAddr));
        }
        pdu.setEsmClass((byte) esmClass);
        switch(validityType) {
            case ValidityPeriod_5min:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
            case ValidityPeriod_2hours:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 2, 0, 0));
                break;
            case ScheduleDeliveryTime_5min:
                pdu.setScheduleDeliveryTime(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
        }
        pdu.setDataCoding((byte) dcs);
        pdu.setRegisteredDelivery((byte) this.param.getMcDeliveryReceipt().getCode());
        if (buf.length < 250 && this.param.getSendingMessageType() != SmppSimulatorParameters.SendingMessageType.DataSm)
            pdu.setShortMessage(buf);
        else {
            Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, buf);
            pdu.addOptionalParameter(tlv);
        }
        if (addSegmTlv) {
            byte[] buf1 = new byte[2];
            buf1[0] = 0;
            buf1[1] = (byte) msgRef;
            Tlv tlv = new Tlv(SmppConstants.TAG_SAR_MSG_REF_NUM, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) msgLst.size();
            tlv = new Tlv(SmppConstants.TAG_SAR_TOTAL_SEGMENTS, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) i1;
            tlv = new Tlv(SmppConstants.TAG_SAR_SEGMENT_SEQNUM, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (messageClassVal > 0) {
            byte[] buf1 = new byte[1];
            buf1[0] = (byte) messageClassVal;
            Tlv tlv = new Tlv(SmppConstants.TAG_DEST_ADDR_SUBUNIT, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (this.param.isSendOptionalParameter()) {
            for (Tlv tlv : this.param.getTlvSet().getOptionalParameters()) {
                pdu.addOptionalParameter(tlv);
            }
        }
        WindowFuture<Integer, PduRequest, PduResponse> future0 = session0.sendRequestPdu(pdu, 10000, false);
        this.messagesSent.incrementAndGet();
        if (this.timer == null) {
            this.addMessage("Request=" + pdu.getName(), pdu.toString());
        }
    }
    this.segmentsSent.addAndGet(segmentCnt);
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) Address(com.cloudhopper.smpp.type.Address) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) CharacterCodingException(java.nio.charset.CharacterCodingException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PduRequest(com.cloudhopper.smpp.pdu.PduRequest) DataSm(com.cloudhopper.smpp.pdu.DataSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SubmitMulti(com.cloudhopper.smpp.pdu.SubmitMulti) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

DataSm (com.cloudhopper.smpp.pdu.DataSm)3 DeliverSm (com.cloudhopper.smpp.pdu.DeliverSm)2 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)2 SubmitSm (com.cloudhopper.smpp.pdu.SubmitSm)2 Tlv (com.cloudhopper.smpp.tlv.Tlv)2 BaseSm (com.cloudhopper.smpp.pdu.BaseSm)1 Pdu (com.cloudhopper.smpp.pdu.Pdu)1 PduRequest (com.cloudhopper.smpp.pdu.PduRequest)1 SubmitMulti (com.cloudhopper.smpp.pdu.SubmitMulti)1 Address (com.cloudhopper.smpp.type.Address)1 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)1 IOException (java.io.IOException)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 Date (java.util.Date)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActivityContextInterface (javax.slee.ActivityContextInterface)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)1 Sms (org.mobicents.smsc.library.Sms)1 SmsSet (org.mobicents.smsc.library.SmsSet)1