Search in sources :

Example 46 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class MtTest method prepareSms.

private Sms prepareSms(SmsSet smsSet, int num, SmsDef smsDef) {
    Sms sms = new Sms();
    sms.setStored(true);
    sms.setSmsSet(smsSet);
    sms.setDbId(UUID.randomUUID());
    // sms.setDbId(id);
    sms.setSourceAddr(origDig);
    sms.setSourceAddrTon(1);
    sms.setSourceAddrNpi(1);
    sms.setMessageId(8888888 + num);
    sms.setMoMessageRef(102 + num);
    sms.setMessageId(num);
    sms.setOrigEsmeName("esme_1");
    sms.setOrigSystemId("sys_1");
    sms.setSubmitDate(new Date());
    // sms.setDeliveryDate(new GregorianCalendar(2013, 1, 15, 12, 15 +
    // num).getTime());
    // sms.setServiceType("serv_type__" + num);
    sms.setEsmClass(smsDef.esmClass);
    sms.setProtocolId(7);
    sms.setPriority(0);
    sms.setRegisteredDelivery(0);
    sms.setReplaceIfPresent(0);
    sms.setDataCoding(smsDef.dataCodingScheme);
    sms.setDefaultMsgId(0);
    if (smsDef.receiptRequest) {
        sms.setRegisteredDelivery(1);
    }
    if (smsDef.valididtyPeriodIsOver) {
        Date validityPeriod = MessageUtil.addHours(new Date(), -1);
        // Date validityPeriod = new Date(new Date().getTime() + 1000 * 90);
        sms.setValidityPeriod(validityPeriod);
    } else {
        Date validityPeriod = MessageUtil.addHours(new Date(), 24);
        sms.setValidityPeriod(validityPeriod);
    }
    sms.setShortMessageText(smsDef.msg);
    sms.setShortMessageBin(smsDef.msgUdh);
    if (smsDef.segmentTlv) {
        byte[] msg_ref_num = { 1, 10 };
        Tlv tlv = new Tlv(SmppConstants.TAG_SAR_MSG_REF_NUM, msg_ref_num);
        sms.getTlvSet().addOptionalParameter(tlv);
        tlv = new Tlv(SmppConstants.TAG_SAR_SEGMENT_SEQNUM, new byte[] { 2 });
        sms.getTlvSet().addOptionalParameter(tlv);
        tlv = new Tlv(SmppConstants.TAG_SAR_TOTAL_SEGMENTS, new byte[] { 4 });
        sms.getTlvSet().addOptionalParameter(tlv);
    }
    sms.setStored(smsDef.stored);
    sms.setStoringAfterFailure(smsDef.storingAfterFailure);
    sms.setNationalLanguageLockingShift(smsDef.nationalAlphabet);
    sms.setNationalLanguageSingleShift(smsDef.nationalAlphabet);
    return sms;
}
Also used : Sms(org.mobicents.smsc.library.Sms) Date(java.util.Date) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 47 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class MtTest method onDeliveryErrorTest.

/**
 * onDeliveryError test
 */
@Test(groups = { "Mt" })
public void onDeliveryErrorTest() throws Exception {
    if (!this.cassandraDbInited)
        return;
    MAPServiceSmsProxy serviceSri = (MAPServiceSmsProxy) this.sriSbb.mapProvider.getMAPServiceSms();
    MAPServiceSmsProxy serviceMt = (MAPServiceSmsProxy) this.mtSbb.mapProvider.getMAPServiceSms();
    MAPServiceSmsProxy serviceRsds = (MAPServiceSmsProxy) this.rsdsSbb.mapProvider.getMAPServiceSms();
    SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
    MProcManagement.getInstance("Test");
    ArrayList<SmsDef> lst = new ArrayList<SmsDef>();
    SmsDef sd1 = new SmsDef();
    sd1.valididtyPeriodIsOver = true;
    sd1.msg = "a1";
    lst.add(sd1);
    SmsDef sd2 = new SmsDef();
    sd2.valididtyPeriodIsOver = true;
    sd2.msg = "a2";
    lst.add(sd2);
    SmsDef sd3 = new SmsDef();
    sd3.msg = "b1";
    lst.add(sd3);
    SmsSet smsSet = prepareDatabase(lst);
    Sms sms1 = smsSet.getSms(0);
    Sms sms2 = smsSet.getSms(1);
    Sms sms3 = smsSet.getSms(2);
    UUID smsId1 = sms1.getDbId();
    UUID smsId2 = sms2.getDbId();
    UUID smsId3 = sms3.getDbId();
    SmsProxy smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId1);
    SmsProxy smsx2 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId2);
    SmsProxy smsx3 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId3);
    assertNull(smsx1);
    assertNull(smsx2);
    assertNull(smsx3);
    SmsSet smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
    assertNotNull(smsSetX);
    Sms smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
    assertEquals(smsX.getSmsSet().getInSystem(), 0);
    smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[1]);
    assertEquals(smsX.getSmsSet().getInSystem(), 0);
    smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[2]);
    assertEquals(smsX.getSmsSet().getInSystem(), 0);
    assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 1);
    // initial onSms message
    SmsSetEvent event = new SmsSetEvent();
    event.setSmsSet(smsSet);
    this.sriSbb.onSms(event, null, null);
    this.mtSbb.setTargetId(smsSet.getTargetId());
    // SmsSet smsSet, ErrorAction errorAction, ErrorCode smStatus, String reason, boolean removeSmsSet
    this.sriSbb.onDeliveryError(smsSet, ErrorAction.subscriberBusy, ErrorCode.ABSENT_SUBSCRIBER, "X error", true, null, false, ProcessingType.SS7_MT);
    PreparedStatementCollection[] pscc = this.pers.c2_getPscList();
    long l1 = 0;
    for (PreparedStatementCollection psc : pscc) {
        l1 = this.pers.c2_getDueSlotForTargetId(psc, procTargetId);
        if (l1 != 0)
            break;
    }
    smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId1);
    smsx2 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId2);
    smsx3 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId3);
    assertNotNull(smsx1);
    assertNotNull(smsx2);
    assertNull(smsx3);
    smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
    assertNull(smsSetX);
    smsX = this.pers.obtainLiveSms(l1, procTargetId, procId[0]);
    assertNull(smsX);
    smsX = this.pers.obtainLiveSms(l1, procTargetId, procId[1]);
    assertNull(smsX);
    smsX = this.pers.obtainLiveSms(l1, procTargetId, procId[2]);
    assertEquals(smsX.getSmsSet().getInSystem(), 0);
    assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 0);
}
Also used : MAPServiceSmsProxy(org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy) SmsSetEvent(org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent) ArrayList(java.util.ArrayList) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) SmsProxy(org.mobicents.smsc.slee.resources.persistence.SmsProxy) MAPServiceSmsProxy(org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy) MAPDialogSmsProxy(org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy) Sms(org.mobicents.smsc.library.Sms) UUID(java.util.UUID) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 48 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class CassandraTest method testOldFormatMessage.

@Test(groups = { "cassandra" })
public void testOldFormatMessage(TargetAddress ta, DataCodingScheme dcs, String msg, UserDataHeader udh, int size) throws Exception {
    Date dt = new Date();
    PreparedStatementCollection psc = sbb.getStatementCollection(dt);
    TargetAddress lock = this.sbb.obtainSynchroObject(ta);
    long dueSlot;
    Sms sms;
    try {
        synchronized (lock) {
            SmsSet smsSet = new SmsSet();
            smsSet.setDestAddr(ta.getAddr());
            smsSet.setDestAddrNpi(ta.getAddrNpi());
            smsSet.setDestAddrTon(ta.getAddrTon());
            smsSet.setCorrelationId("CI=0000");
            smsSet.setNetworkId(9);
            sms = new Sms();
            sms.setSmsSet(smsSet);
            sms.setDbId(UUID.randomUUID());
            sms.setSourceAddr("11112");
            sms.setSourceAddrTon(1);
            sms.setSourceAddrNpi(1);
            sms.setMessageId(8888888);
            sms.setOrigNetworkId(49);
            sms.setDataCoding(dcs.getCode());
            sms.setShortMessageText(msg);
            if (udh != null) {
                sms.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
                sms.setShortMessageBin(udh.getEncodedData());
            }
            dueSlot = this.sbb.c2_getDueSlotForTargetId(psc, ta.getTargetId());
            if (dueSlot == 0 || dueSlot <= sbb.c2_getCurrentDueSlot()) {
                dueSlot = sbb.c2_getDueSlotForNewSms();
                sbb.c2_updateDueSlotForTargetId(ta.getTargetId(), dueSlot);
            }
            sms.setDueSlot(dueSlot);
            sbb.c2_registerDueSlotWriting(dueSlot);
            try {
                sbb.c2_createRecordCurrent(sms);
            } finally {
                sbb.c2_unregisterDueSlotWriting(dueSlot);
            }
        }
    } finally {
        this.sbb.obtainSynchroObject(lock);
    }
    lock = this.sbb.obtainSynchroObject(ta);
    try {
        synchronized (lock) {
            sbb.c2_registerDueSlotWriting(dueSlot);
            ArrayList<SmsSet> lst0, lst;
            try {
                lst0 = sbb.c2_getRecordList(dueSlot);
                lst = sbb.c2_sortRecordList(lst0);
            } finally {
                sbb.c2_unregisterDueSlotWriting(dueSlot);
            }
            assertEquals(lst.size(), size);
            SmsSet smsSet;
            if (size == 0) {
                // messages are not in res because smsSet is already in processing
                smsSet = SmsSetCache.getInstance().getProcessingSmsSet(ta.getTargetId());
            } else {
                smsSet = lst.get(0);
            }
            assertEquals(smsSet.getNetworkId(), 9);
            assertEquals(sms.getOrigNetworkId(), 49);
            for (Sms sms1 : smsSet.getRawListLastSegment()) {
                if (sms1.getDbId().equals(sms.getDbId())) {
                    assertEquals(sms1.getDataCoding(), dcs.getCode());
                    if (msg != null)
                        assertEquals(sms1.getShortMessageText(), msg);
                    else
                        assertNull(sms1.getShortMessageText());
                    if (udh != null)
                        assertEquals(sms1.getShortMessageBin(), udh.getEncodedData());
                    else
                        assertNull(sms1.getShortMessageBin());
                    assertEquals(smsSet.getCorrelationId(), "CI=0000");
                }
            }
        }
    } finally {
        this.sbb.obtainSynchroObject(lock);
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) TargetAddress(org.mobicents.smsc.library.TargetAddress) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 49 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class CassandraTest method testingDueSlotForTargetId2.

@Test(groups = { "cassandra" })
public void testingDueSlotForTargetId2() throws Exception {
    long dueSlotLen = sbb.getSlotMSecondsTimeArea();
    if (!this.cassandraDbInited)
        return;
    Date dt = new Date();
    String targetId = ta1.getTargetId();
    Sms sms = this.createTestSms(1, ta1.getAddr(), id1);
    sms.setStored(true);
    sms.setValidityPeriod(null);
    long l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, 0);
    // 1 - create with good date
    sbb.c2_scheduleMessage_ReschedDueSlot(sms, false, true);
    long newDueSlot = sms.getDueSlot();
    boolean b1 = sbb.do_scheduleMessage(sms, newDueSlot, null, false, true);
    assertTrue(b1);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot);
    assertEquals(sms.getDueSlot(), newDueSlot);
    // 2 - update this good date
    sbb.c2_scheduleMessage_ReschedDueSlot(sms, false, true);
    assertEquals(sms.getDueSlot(), newDueSlot);
    b1 = sbb.do_scheduleMessage(sms, newDueSlot, null, false, true);
    assertTrue(b1);
    assertEquals(sms.getDueSlot(), newDueSlot);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot);
    // 3 - date is obsolete
    long newCurSlot = newDueSlot + 10;
    sbb.c2_setCurrentDueSlot(newCurSlot);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot);
    b1 = sbb.do_scheduleMessage(sms, newDueSlot, null, false, true);
    assertFalse(b1);
    sbb.c2_scheduleMessage_ReschedDueSlot(sms, false, true);
    long newDueSlot2 = sms.getDueSlot();
    b1 = sbb.do_scheduleMessage(sms, newDueSlot2, null, false, true);
    // assertTrue(b1);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot2);
    // 4 - new date is in a new table
    long newCurSlot2 = newCurSlot + 60 * 60 * 24 * 1000 / dueSlotLen;
    sbb.c2_setCurrentDueSlot(newCurSlot2);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot2);
    b1 = sbb.do_scheduleMessage(sms, newDueSlot2, null, false, true);
    assertFalse(b1);
    long newDueSlot3 = newCurSlot2 + 10;
    b1 = sbb.do_scheduleMessage(sms, newDueSlot3, null, false, true);
    // assertTrue(b1);
    sbb.c2_updateDueSlotForTargetId_WithTableCleaning(targetId, newDueSlot3);
    l1 = sbb.c2_getDueSlotForTargetId(targetId);
    assertEquals(l1, newDueSlot3);
}
Also used : Sms(org.mobicents.smsc.library.Sms) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 50 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class CassandraTest method createTestSms.

private Sms createTestSms(int num, String number, UUID id) throws Exception {
    PreparedStatementCollection psc = sbb.getStatementCollection(new Date());
    SmsSet smsSet = new SmsSet();
    smsSet.setDestAddr(number);
    smsSet.setDestAddrNpi(1);
    smsSet.setDestAddrTon(5);
    smsSet.setNetworkId(9);
    if (num == 1)
        smsSet.setCorrelationId("CI=100001000022222");
    Sms sms = new Sms();
    // sms.setSmsSet(smsSet);
    smsSet.addSms(sms);
    // sms.setDbId(UUID.randomUUID());
    sms.setDbId(id);
    sms.setSourceAddr("11112_" + num);
    sms.setSourceAddrTon(14 + num);
    sms.setSourceAddrNpi(11 + num);
    sms.setMessageId(8888888 + num);
    sms.setMoMessageRef(102 + num);
    sms.setOrigNetworkId(49);
    sms.setOrigEsmeName("esme_" + num);
    sms.setOrigSystemId("sys_" + num);
    sms.setSubmitDate(new GregorianCalendar(2013, 1, 15, 12, 00 + num).getTime());
    sms.setDeliveryDate(new GregorianCalendar(2013, 1, 15, 12, 15 + num).getTime());
    sms.setServiceType("serv_type__" + num);
    sms.setEsmClass(11 + num);
    sms.setProtocolId(12 + num);
    sms.setPriority(13 + num);
    sms.setRegisteredDelivery(14 + num);
    sms.setReplaceIfPresent(15 + num);
    sms.setDataCoding(16 + num);
    sms.setDefaultMsgId(17 + num);
    // sms.setShortMessage(new byte[] { (byte)(21 + num), 23, 25, 27, 29 });
    if (num != 2)
        sms.setShortMessageText("Mes text" + num);
    if (num != 3)
        sms.setShortMessageBin(new byte[] { (byte) (21 + num), 23, 25, 27, 29 });
    sms.setScheduleDeliveryTime(new GregorianCalendar(2013, 1, 20, 10, 00 + num).getTime());
    sms.setValidityPeriod(new GregorianCalendar(2013, 1, 23, 13, 33 + num).getTime());
    // short tag, byte[] value, String tagName
    Tlv tlv = new Tlv((short) 5, new byte[] { (byte) (1 + num), 2, 3, 4, 5 });
    sms.getTlvSet().addOptionalParameter(tlv);
    tlv = new Tlv((short) 6, new byte[] { (byte) (6 + num), 7, 8 });
    sms.getTlvSet().addOptionalParameter(tlv);
    smsSet.setDueDelay(510);
    sms.setDeliveryCount(9);
    sms.setOriginatorSccpAddress("11224455");
    sms.setStatusReportRequest(true);
    sms.setDeliveryAttempt(321);
    sms.setUserData("userdata");
    sms.setMprocNotes("mproc notes xxx");
    // sms.setExtraData("extradata_1");
    sms.setExtraData_2("extradata_2");
    sms.setExtraData_3("extradata_3");
    sms.setExtraData_4("extradata_4");
    return sms;
}
Also used : Sms(org.mobicents.smsc.library.Sms) GregorianCalendar(java.util.GregorianCalendar) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) Date(java.util.Date) SmsSet(org.mobicents.smsc.library.SmsSet) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

Sms (org.mobicents.smsc.library.Sms)139 SmsSet (org.mobicents.smsc.library.SmsSet)62 Test (org.testng.annotations.Test)43 Date (java.util.Date)42 ArrayList (java.util.ArrayList)35 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)33 TargetAddress (org.mobicents.smsc.library.TargetAddress)30 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)27 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)27 ISDNAddressStringImpl (org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl)26 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)24 SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)23 UUID (java.util.UUID)22 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)21 SmsSetEvent (org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent)21 SmsProxy (org.mobicents.smsc.slee.resources.persistence.SmsProxy)20 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)19 SmsSignalInfo (org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo)19 MAPApplicationContextVersion (org.restcomm.protocols.ss7.map.api.MAPApplicationContextVersion)17 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)17