diff options
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/configure.ac | 1 | ||||
-rw-r--r-- | openbsc/include/openbsc/db.h | 11 | ||||
-rw-r--r-- | openbsc/src/libmsc/db.c | 61 | ||||
-rw-r--r-- | openbsc/src/libmsc/sms_queue.c | 68 | ||||
-rw-r--r-- | openbsc/src/libmsc/vty_interface_layer3.c | 11 | ||||
-rw-r--r-- | openbsc/src/libvlr/vlr.c | 4 | ||||
-rw-r--r-- | openbsc/tests/Makefile.am | 1 | ||||
-rw-r--r-- | openbsc/tests/sms_queue/Makefile.am | 45 | ||||
-rw-r--r-- | openbsc/tests/sms_queue/sms_queue_test.c | 215 | ||||
-rw-r--r-- | openbsc/tests/sms_queue/sms_queue_test.err | 0 | ||||
-rw-r--r-- | openbsc/tests/sms_queue/sms_queue_test.ok | 98 | ||||
-rw-r--r-- | openbsc/tests/testsuite.at | 7 |
12 files changed, 463 insertions, 59 deletions
diff --git a/openbsc/configure.ac b/openbsc/configure.ac index 0da7c9c21..0ba73b911 100644 --- a/openbsc/configure.ac +++ b/openbsc/configure.ac @@ -260,6 +260,7 @@ AC_OUTPUT( tests/nanobts_omlattr/Makefile tests/vlr/Makefile tests/msc_vlr/Makefile + tests/sms_queue/Makefile doc/Makefile doc/examples/Makefile Makefile) diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h index 660451a50..988c9bd6e 100644 --- a/openbsc/include/openbsc/db.h +++ b/openbsc/include/openbsc/db.h @@ -38,9 +38,14 @@ int db_fini(void); /* SMS store-and-forward */ int db_sms_store(struct gsm_sms *sms); struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id); -struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long min_id); -struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, unsigned long long min_subscr_id, unsigned int failed); -struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub); +struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net, + unsigned long long min_sms_id, + unsigned int max_failed); +struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, + const char *last_msisdn, + unsigned int max_failed); +struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub, + unsigned int max_failed); int db_sms_mark_delivered(struct gsm_sms *sms); int db_sms_inc_deliver_attempts(struct gsm_sms *sms); int db_sms_delete_by_msisdn(const char *msisdn); diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c index 035d5488f..28e978213 100644 --- a/openbsc/src/libmsc/db.c +++ b/openbsc/src/libmsc/db.c @@ -643,20 +643,21 @@ struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id) return sms; } -/* retrieve the next unsent SMS with ID >= min_id */ -struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long min_id) +struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net, + unsigned long long min_sms_id, + unsigned int max_failed) { dbi_result result; struct gsm_sms *sms; result = dbi_conn_queryf(conn, - "SELECT SMS.* " - "FROM SMS JOIN Subscriber ON " - "SMS.dest_addr = Subscriber.extension " - "WHERE SMS.id >= %llu AND SMS.sent IS NULL " - "AND Subscriber.lac > 0 " - "ORDER BY SMS.id LIMIT 1", - min_id); + "SELECT * FROM SMS" + " WHERE sent IS NULL" + " AND id >= %llu" + " AND deliver_attempts <= %u" + " ORDER BY id LIMIT 1", + min_sms_id, max_failed); + if (!result) return NULL; @@ -672,21 +673,24 @@ struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long mi return sms; } -struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, - unsigned long long min_subscr_id, - unsigned int failed) +/* retrieve the next unsent SMS for a given subscriber */ +struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub, + unsigned int max_failed) { + struct gsm_network *net = vsub->vlr->user_ctx; dbi_result result; struct gsm_sms *sms; + if (!vsub->lu_complete) + return NULL; + result = dbi_conn_queryf(conn, - "SELECT SMS.* " - "FROM SMS JOIN Subscriber ON " - "SMS.dest_addr = Subscriber.extension " - "WHERE Subscriber.id >= %llu AND SMS.sent IS NULL " - "AND Subscriber.lac > 0 AND SMS.deliver_attempts < %u " - "ORDER BY Subscriber.id, SMS.id LIMIT 1", - min_subscr_id, failed); + "SELECT * FROM SMS" + " WHERE sent IS NULL" + " AND dest_addr=%s" + " AND deliver_attempts <= %u" + " ORDER BY id LIMIT 1", + vsub->msisdn, max_failed); if (!result) return NULL; @@ -702,21 +706,20 @@ struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, return sms; } -/* retrieve the next unsent SMS for a given subscriber */ -struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub) +struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, + const char *last_msisdn, + unsigned int max_failed) { - struct gsm_network *net = vsub->vlr->user_ctx; dbi_result result; struct gsm_sms *sms; result = dbi_conn_queryf(conn, - "SELECT SMS.* " - "FROM SMS JOIN Subscriber ON " - "SMS.dest_addr = Subscriber.extension " - "WHERE Subscriber.id = %llu AND SMS.sent IS NULL " - "AND Subscriber.lac > 0 " - "ORDER BY SMS.id LIMIT 1", - vsub->id); + "SELECT * FROM SMS" + " WHERE sent IS NULL" + " AND dest_addr > '%s'" + " AND deliver_attempts <= %u" + " ORDER BY dest_addr, id LIMIT 1", + last_msisdn, max_failed); if (!result) return NULL; diff --git a/openbsc/src/libmsc/sms_queue.c b/openbsc/src/libmsc/sms_queue.c index e3b554d88..a01177dac 100644 --- a/openbsc/src/libmsc/sms_queue.c +++ b/openbsc/src/libmsc/sms_queue.c @@ -28,6 +28,8 @@ * things up by collecting data from other parts of the system. */ +#include <limits.h> + #include <openbsc/sms_queue.h> #include <openbsc/chan_alloc.h> #include <openbsc/db.h> @@ -63,7 +65,8 @@ struct gsm_sms_queue { int pending; struct llist_head pending_sms; - unsigned long long last_subscr_id; + + char last_msisdn[GSM_EXTENSION_LENGTH+1]; }; static int sms_subscr_cb(unsigned int, unsigned int, void *, void *); @@ -189,29 +192,49 @@ static void sms_resend_pending(void *_data) } } -static struct gsm_sms *take_next_sms(struct gsm_sms_queue *smsq) +/* Find the next pending SMS by cycling through the recipients. We could also + * cycle through the pending SMS, but that might cause us to keep trying to + * send SMS to the same few subscribers repeatedly while not servicing other + * subscribers for a long time. By walking the list of recipient MSISDNs, we + * ensure that all subscribers get their fair time to receive SMS. */ +struct gsm_sms *smsq_take_next_sms(struct gsm_network *net, + char *last_msisdn, + size_t last_msisdn_buflen) { struct gsm_sms *sms; + int wrapped = 0; + int sanity = 100; + char started_with_msisdn[last_msisdn_buflen]; + + osmo_strlcpy(started_with_msisdn, last_msisdn, + sizeof(started_with_msisdn)); + + while (wrapped < 2 && (--sanity)) { + /* If we wrapped around and passed the first msisdn, we're + * through the entire SMS DB; end it. */ + if (wrapped && strcmp(last_msisdn, started_with_msisdn) >= 0) + break; + + sms = db_sms_get_next_unsent_rr_msisdn(net, last_msisdn, 9); + if (!sms) { + last_msisdn[0] = '\0'; + wrapped ++; + continue; + } + + /* Whatever happens, next time around service another recipient + */ + osmo_strlcpy(last_msisdn, sms->dst.addr, last_msisdn_buflen); + + /* Is the subscriber attached? If not, go to next SMS */ + if (!sms->receiver || !sms->receiver->lu_complete) + continue; - sms = db_sms_get_unsent_by_subscr(smsq->network, smsq->last_subscr_id, 10); - DEBUGP(DLSMS, "db_sms_get_unsent_by_subscr(id = %llu) returned %p\n", - smsq->last_subscr_id, sms); - if (sms) { - smsq->last_subscr_id = sms->receiver->id + 1; - DEBUGP(DLSMS, "take_next_sms() returns %p\n", sms); return sms; } - /* need to wrap around */ - smsq->last_subscr_id = 0; - sms = db_sms_get_unsent_by_subscr(smsq->network, - smsq->last_subscr_id, 10); - DEBUGP(DLSMS, "db_sms_get_unsent_by_subscr(id = %llu) returned %p\n", - smsq->last_subscr_id, sms); - if (sms) - smsq->last_subscr_id = sms->receiver->id + 1; - DEBUGP(DLSMS, "take_next_sms() returns %p\n", sms); - return sms; + DEBUGP(DLSMS, "SMS queue: no SMS to be sent\n"); + return NULL; } /** @@ -233,7 +256,8 @@ static void sms_submit_pending(void *_data) struct gsm_sms *sms; - sms = take_next_sms(smsq); + sms = smsq_take_next_sms(smsq->network, smsq->last_msisdn, + sizeof(smsq->last_msisdn)); if (!sms) { LOGP(DLSMS, LOGL_DEBUG, "Sending SMS done (%d attempted)\n", attempted); @@ -309,11 +333,11 @@ static void sms_send_next(struct vlr_subscr *vsub) OSMO_ASSERT(!sms_subscriber_is_pending(smsq, vsub)); /* check for more messages for this subscriber */ - sms = db_sms_get_unsent_for_subscr(vsub); + sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX); if (!sms) goto no_pending_sms; - /* No sms should be scheduled right now */ + /* The sms should not be scheduled right now */ OSMO_ASSERT(!sms_is_in_pending(smsq, sms)); /* Remember that we deliver this SMS and send it */ @@ -408,7 +432,7 @@ static int sub_ready_for_sm(struct gsm_network *net, struct vlr_subscr *vsub) return -1; /* Now try to deliver any pending SMS to this sub */ - sms = db_sms_get_unsent_for_subscr(vsub); + sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX); if (!sms) return -1; gsm411_send_sms(conn, sms); diff --git a/openbsc/src/libmsc/vty_interface_layer3.c b/openbsc/src/libmsc/vty_interface_layer3.c index 5ed0b0fe1..7fa66d3e4 100644 --- a/openbsc/src/libmsc/vty_interface_layer3.c +++ b/openbsc/src/libmsc/vty_interface_layer3.c @@ -158,16 +158,17 @@ DEFUN(sms_send_pend, { struct gsm_network *gsmnet = gsmnet_from_vty(vty); struct gsm_sms *sms; - int id = 0; + unsigned long long sms_id = 0; while (1) { - sms = db_sms_get_unsent_by_subscr(gsmnet, id, UINT_MAX); + sms = db_sms_get_next_unsent(gsmnet, sms_id, UINT_MAX); if (!sms) break; - gsm411_send_sms_subscr(sms->receiver, sms); + if (sms->receiver) + gsm411_send_sms_subscr(sms->receiver, sms); - id = sms->receiver->id + 1; + sms_id = sms->id + 1; } return CMD_SUCCESS; @@ -268,7 +269,7 @@ DEFUN(subscriber_send_pending_sms, return CMD_WARNING; } - sms = db_sms_get_unsent_by_subscr(gsmnet, vsub->id, UINT_MAX); + sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX); if (sms) gsm411_send_sms_subscr(sms->receiver, sms); diff --git a/openbsc/src/libvlr/vlr.c b/openbsc/src/libvlr/vlr.c index f0123012b..bc8d43d92 100644 --- a/openbsc/src/libvlr/vlr.c +++ b/openbsc/src/libvlr/vlr.c @@ -176,6 +176,8 @@ static int vlr_tx_gsup_error_reply(struct vlr_instance *vlr, struct vlr_subscr *_vlr_subscr_get(struct vlr_subscr *sub, const char *file, int line) { + if (!sub) + return NULL; OSMO_ASSERT(sub->use_count < INT_MAX); sub->use_count++; LOGPSRC(DREF, LOGL_DEBUG, file, line, @@ -186,6 +188,8 @@ struct vlr_subscr *_vlr_subscr_get(struct vlr_subscr *sub, const char *file, int struct vlr_subscr *_vlr_subscr_put(struct vlr_subscr *sub, const char *file, int line) { + if (!sub) + return NULL; sub->use_count--; LOGPSRC(DREF, sub->use_count >= 0? LOGL_DEBUG : LOGL_ERROR, file, line, diff --git a/openbsc/tests/Makefile.am b/openbsc/tests/Makefile.am index 6c18d05ec..cde76d36f 100644 --- a/openbsc/tests/Makefile.am +++ b/openbsc/tests/Makefile.am @@ -11,6 +11,7 @@ SUBDIRS = \ nanobts_omlattr \ vlr \ msc_vlr \ + sms_queue \ $(NULL) if BUILD_NAT diff --git a/openbsc/tests/sms_queue/Makefile.am b/openbsc/tests/sms_queue/Makefile.am new file mode 100644 index 000000000..b2266ebb8 --- /dev/null +++ b/openbsc/tests/sms_queue/Makefile.am @@ -0,0 +1,45 @@ +AM_CPPFLAGS = \ + $(all_includes) \ + -I$(top_srcdir)/include \ + $(NULL) + +AM_CFLAGS = \ + -Wall \ + -ggdb3 \ + $(LIBOSMOCORE_CFLAGS) \ + $(LIBOSMOGSM_CFLAGS) \ + $(NULL) + +EXTRA_DIST = \ + sms_queue_test.ok \ + sms_queue_test.err \ + $(NULL) + +noinst_PROGRAMS = \ + sms_queue_test \ + $(NULL) + +sms_queue_test_SOURCES = \ + sms_queue_test.c \ + $(NULL) + +sms_queue_test_LDADD = \ + $(top_builddir)/src/libmsc/libmsc.a \ + $(top_builddir)/src/libvlr/libvlr.a \ + $(top_builddir)/src/libbsc/libbsc.a \ + $(top_builddir)/src/libtrau/libtrau.a \ + $(top_builddir)/src/libcommon/libcommon.a \ + $(top_builddir)/src/libcommon-cs/libcommon-cs.a \ + $(LIBSMPP34_LIBS) \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOGSM_LIBS) \ + $(LIBCRYPTO_LIBS) \ + $(LIBOSMOVTY_LIBS) \ + $(LIBOSMOABIS_LIBS) \ + -ldbi \ + -lrt \ + $(NULL) + +sms_queue_test_LDFLAGS = \ + -Wl,--wrap=db_sms_get_next_unsent_rr_msisdn \ + $(NULL) diff --git a/openbsc/tests/sms_queue/sms_queue_test.c b/openbsc/tests/sms_queue/sms_queue_test.c new file mode 100644 index 000000000..af25b0645 --- /dev/null +++ b/openbsc/tests/sms_queue/sms_queue_test.c @@ -0,0 +1,215 @@ +/* Test Osmocom SMS queue */ + +/* + * (C) 2017 by sysmocom s.f.m.c. GmbH + * All Rights Reserved + * + * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <osmocom/core/application.h> + +#include <openbsc/debug.h> +#include <openbsc/vlr.h> + +static void *talloc_ctx = NULL; + +struct gsm_sms *smsq_take_next_sms(struct gsm_network *net, + char *last_msisdn, + size_t last_msisdn_buflen); + +static void _test_take_next_sms_print(int i, + struct gsm_sms *sms, + const char *last_msisdn) +{ + printf("#%d: ", i); + if (sms) + printf("sending SMS to %s", sms->text); + else + printf("no SMS to send"); + printf(" (last_msisdn='%s')\n", last_msisdn? last_msisdn : "NULL"); +} + +static struct gsm_sms fake_sms = { 0 }; + +struct { + const char *msisdn; + int nr_of_sms; + int failed_attempts; + bool vsub_attached; +} fake_sms_db[] = { + { + .msisdn = "1111", + .nr_of_sms = 0, + .vsub_attached = true, + }, + { + .msisdn = "2222", + .nr_of_sms = 2, + .failed_attempts = 2, + .vsub_attached = true, + }, + { + .msisdn = "3333", + .nr_of_sms = 2, + .failed_attempts = 3, + .vsub_attached = true, + }, + { + .msisdn = "4444", + .nr_of_sms = 0, + .vsub_attached = true, + }, + { + .msisdn = "5555", + .nr_of_sms = 2, + .failed_attempts = 5, + .vsub_attached = false, + }, +}; + +/* override, requires '-Wl,--wrap=db_sms_get_next_unsent_rr_msisdn' */ +struct gsm_sms *__real_db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, + const char *last_msisdn, + unsigned int max_failed); +struct gsm_sms *__wrap_db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, + const char *last_msisdn, + unsigned int max_failed) +{ + static struct vlr_subscr arbitrary_vsub = { .lu_complete = true }; + int i; + printf(" hitting database: looking for MSISDN > '%s', failed_attempts <= %d\n", + last_msisdn, max_failed); + + for (i = 0; i < ARRAY_SIZE(fake_sms_db); i++) { + if (!fake_sms_db[i].nr_of_sms) + continue; + if (strcmp(fake_sms_db[i].msisdn, last_msisdn) <= 0) + continue; + if (fake_sms_db[i].failed_attempts > max_failed) + continue; + osmo_strlcpy(fake_sms.dst.addr, fake_sms_db[i].msisdn, + sizeof(fake_sms.dst.addr)); + fake_sms.receiver = fake_sms_db[i].vsub_attached? &arbitrary_vsub : NULL; + osmo_strlcpy(fake_sms.text, fake_sms_db[i].msisdn, sizeof(fake_sms.text)); + if (fake_sms_db[i].vsub_attached) + fake_sms_db[i].nr_of_sms --; + return &fake_sms; + } + return NULL; +} + +void show_fake_sms_db() +{ + int i; + for (i = 0; i < ARRAY_SIZE(fake_sms_db); i++) { + printf(" %s%s has %u SMS pending, %u failed attempts\n", + fake_sms_db[i].msisdn, + fake_sms_db[i].vsub_attached ? "" : " (NOT attached)", + fake_sms_db[i].nr_of_sms, + fake_sms_db[i].failed_attempts); + } + printf("-->\n"); +} + +static void test_next_sms() +{ + int i; + char last_msisdn[GSM_EXTENSION_LENGTH+1] = ""; + + printf("Testing smsq_take_next_sms()\n"); + + printf("\n- vsub 2, 3 and 5 each have 2 SMS pending, but 5 is not attached\n"); + last_msisdn[0] = '\0'; + show_fake_sms_db(); + for (i = 0; i < 7; i++) { + struct gsm_sms *sms = smsq_take_next_sms(NULL, last_msisdn, sizeof(last_msisdn)); + _test_take_next_sms_print(i, sms, last_msisdn); + OSMO_ASSERT(i >= 4 || sms); + } + + printf("\n- SMS are pending at various nr failed attempts (cutoff at >= 10)\n"); + last_msisdn[0] = '\0'; + for (i = 0; i < ARRAY_SIZE(fake_sms_db); i++) { + fake_sms_db[i].vsub_attached = true; + fake_sms_db[i].nr_of_sms = 1 + i; + fake_sms_db[i].failed_attempts = i*5; + + } + show_fake_sms_db(); + for (i = 0; i < 7; i++) { + struct gsm_sms *sms = smsq_take_next_sms(NULL, last_msisdn, sizeof(last_msisdn)); + _test_take_next_sms_print(i, sms, last_msisdn); + OSMO_ASSERT(i >= 2 || sms); + } + + printf("\n- iterate the SMS DB at most once\n"); + osmo_strlcpy(last_msisdn, "2345", sizeof(last_msisdn)); + for (i = 0; i < ARRAY_SIZE(fake_sms_db); i++) { + fake_sms_db[i].vsub_attached = false; + fake_sms_db[i].nr_of_sms = 1; + fake_sms_db[i].failed_attempts = 0; + } + show_fake_sms_db(); + for (i = 0; i < 3; i++) { + struct gsm_sms *sms = smsq_take_next_sms(NULL, last_msisdn, sizeof(last_msisdn)); + _test_take_next_sms_print(i, sms, last_msisdn); + OSMO_ASSERT(!sms); + } + + printf("\n- there are no SMS in the DB\n"); + last_msisdn[0] = '\0'; + for (i = 0; i < ARRAY_SIZE(fake_sms_db); i++) { + fake_sms_db[i].vsub_attached = true; + fake_sms_db[i].nr_of_sms = 0; + fake_sms_db[i].failed_attempts = 0; + } + show_fake_sms_db(); + for (i = 0; i < 3; i++) { + struct gsm_sms *sms = smsq_take_next_sms(NULL, last_msisdn, sizeof(last_msisdn)); + _test_take_next_sms_print(i, sms, last_msisdn); + OSMO_ASSERT(!sms); + } +} + + +static struct log_info_cat sms_queue_test_categories[] = { +}; + +static struct log_info info = { + .cat = sms_queue_test_categories, + .num_cat = ARRAY_SIZE(sms_queue_test_categories), +}; + +int main(int argc, char **argv) +{ + talloc_ctx = talloc_named_const(NULL, 1, "sms_queue_test"); + msgb_talloc_ctx_init(talloc_ctx, 0); + osmo_init_logging(&info); + + OSMO_ASSERT(osmo_stderr_target); + log_set_use_color(osmo_stderr_target, 0); + log_set_print_timestamp(osmo_stderr_target, 0); + log_set_print_filename(osmo_stderr_target, 0); + log_set_print_category(osmo_stderr_target, 1); + log_parse_category_mask(osmo_stderr_target, "DLOAP,1"); + + test_next_sms(); + printf("Done\n"); + + return 0; +} diff --git a/openbsc/tests/sms_queue/sms_queue_test.err b/openbsc/tests/sms_queue/sms_queue_test.err new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/openbsc/tests/sms_queue/sms_queue_test.err diff --git a/openbsc/tests/sms_queue/sms_queue_test.ok b/openbsc/tests/sms_queue/sms_queue_test.ok new file mode 100644 index 000000000..146400d21 --- /dev/null +++ b/openbsc/tests/sms_queue/sms_queue_test.ok @@ -0,0 +1,98 @@ +Testing smsq_take_next_sms() + +- vsub 2, 3 and 5 each have 2 SMS pending, but 5 is not attached + 1111 has 0 SMS pending, 0 failed attempts + 2222 has 2 SMS pending, 2 failed attempts + 3333 has 2 SMS pending, 3 failed attempts + 4444 has 0 SMS pending, 0 failed attempts + 5555 (NOT attached) has 2 SMS pending, 5 failed attempts +--> + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#0: sending SMS to 2222 (last_msisdn='2222') + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 +#1: sending SMS to 3333 (last_msisdn='3333') + hitting database: looking for MSISDN > '3333', failed_attempts <= 9 + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#2: sending SMS to 2222 (last_msisdn='2222') + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 +#3: sending SMS to 3333 (last_msisdn='3333') + hitting database: looking for MSISDN > '3333', failed_attempts <= 9 + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#4: no SMS to send (last_msisdn='5555') + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#5: no SMS to send (last_msisdn='5555') + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#6: no SMS to send (last_msisdn='5555') + +- SMS are pending at various nr failed attempts (cutoff at >= 10) + 1111 has 1 SMS pending, 0 failed attempts + 2222 has 2 SMS pending, 5 failed attempts + 3333 has 3 SMS pending, 10 failed attempts + 4444 has 4 SMS pending, 15 failed attempts + 5555 has 5 SMS pending, 20 failed attempts +--> + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#0: sending SMS to 1111 (last_msisdn='1111') + hitting database: looking for MSISDN > '1111', failed_attempts <= 9 +#1: sending SMS to 2222 (last_msisdn='2222') + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#2: sending SMS to 2222 (last_msisdn='2222') + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#3: no SMS to send (last_msisdn='') + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#4: no SMS to send (last_msisdn='') + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#5: no SMS to send (last_msisdn='') + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#6: no SMS to send (last_msisdn='') + +- iterate the SMS DB at most once + 1111 (NOT attached) has 1 SMS pending, 0 failed attempts + 2222 (NOT attached) has 1 SMS pending, 0 failed attempts + 3333 (NOT attached) has 1 SMS pending, 0 failed attempts + 4444 (NOT attached) has 1 SMS pending, 0 failed attempts + 5555 (NOT attached) has 1 SMS pending, 0 failed attempts +--> + hitting database: looking for MSISDN > '2345', failed_attempts <= 9 + hitting database: looking for MSISDN > '3333', failed_attempts <= 9 + hitting database: looking for MSISDN > '4444', failed_attempts <= 9 + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 + hitting database: looking for MSISDN > '1111', failed_attempts <= 9 + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 +#0: no SMS to send (last_msisdn='3333') + hitting database: looking for MSISDN > '3333', failed_attempts <= 9 + hitting database: looking for MSISDN > '4444', failed_attempts <= 9 + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 + hitting database: looking for MSISDN > '1111', failed_attempts <= 9 + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 +#1: no SMS to send (last_msisdn='3333') + hitting database: looking for MSISDN > '3333', failed_attempts <= 9 + hitting database: looking for MSISDN > '4444', failed_attempts <= 9 + hitting database: looking for MSISDN > '5555', failed_attempts <= 9 + hitting database: looking for MSISDN > '', failed_attempts <= 9 + hitting database: looking for MSISDN > '1111', failed_attempts <= 9 + hitting database: looking for MSISDN > '2222', failed_attempts <= 9 +#2: no SMS to send (last_msisdn='3333') + +- there are no SMS in the DB + 1111 has 0 SMS pending, 0 failed attempts + 2222 has 0 SMS pending, 0 failed attempts + 3333 has 0 SMS pending, 0 failed attempts + 4444 has 0 SMS pending, 0 failed attempts + 5555 has 0 SMS pending, 0 failed attempts +--> + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#0: no SMS to send (last_msisdn='') + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#1: no SMS to send (last_msisdn='') + hitting database: looking for MSISDN > '', failed_attempts <= 9 +#2: no SMS to send (last_msisdn='') +Done diff --git a/openbsc/tests/testsuite.at b/openbsc/tests/testsuite.at index 0161ebc96..375bd8228 100644 --- a/openbsc/tests/testsuite.at +++ b/openbsc/tests/testsuite.at @@ -214,3 +214,10 @@ cat $abs_srcdir/msc_vlr/msc_vlr_test_rest.ok > expout cat $abs_srcdir/msc_vlr/msc_vlr_test_rest.err > experr AT_CHECK([$abs_top_builddir/tests/msc_vlr/msc_vlr_test_rest], [], [expout], [experr]) AT_CLEANUP + +AT_SETUP([sms_queue_test]) +AT_KEYWORDS([sms_queue_test]) +cat $abs_srcdir/sms_queue/sms_queue_test.ok > expout +cat $abs_srcdir/sms_queue/sms_queue_test.err > experr +AT_CHECK([$abs_top_builddir/tests/sms_queue/sms_queue_test], [], [expout], [experr]) +AT_CLEANUP |