aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Whyte <keith@rhizomatica.org>2022-06-22 23:02:32 +0100
committerKeith Whyte <keith@rhizomatica.org>2023-11-23 20:58:09 +0000
commit64226a454a5598e760ee9a596b8d0a8e5c83d391 (patch)
treebd9c3d3f926f9121b32363129eda479476e72179
parentdaf0a82dc56552f708c6ddce4d482e5c93a605c2 (diff)
SMS optimisations
After RX of an SMPP Submit, send the SMS we just received. Previously, after we have stored the new SMS in the db, we then signalled the queue to run, but this is not good enough. The queue may not pick up this new SMS on the next run, if there are sufficient older messages in the queue. So let's specifically send the message that was just submitted. when fetching from the DB, Prioritise SMS with least number of delivery attempts Try to send ALL pending SMS for subscriber in sub_ready_for_sms() callback Change-Id: I9af51ef0d9c2e6c5acc5128efd6195df881b680c
-rw-r--r--include/osmocom/msc/signal.h2
-rw-r--r--src/libmsc/db.c2
-rw-r--r--src/libmsc/gsm_04_11.c1
-rw-r--r--src/libmsc/sms_queue.c42
-rw-r--r--src/libsmpputil/smpp_msc.c3
5 files changed, 46 insertions, 4 deletions
diff --git a/include/osmocom/msc/signal.h b/include/osmocom/msc/signal.h
index 915313131..77a9bcf34 100644
--- a/include/osmocom/msc/signal.h
+++ b/include/osmocom/msc/signal.h
@@ -86,4 +86,6 @@ struct sms_signal_data {
struct gsm_sms *sms;
/* true when paging was successful */
bool paging_result;
+ /* the id of the last inserted SMS */
+ unsigned long long id;
};
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index 24f1d002c..a8baacc5c 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -282,7 +282,7 @@ static const char *stmt_sql[] = {
" WHERE sent IS NULL"
" AND dest_addr = $dest_addr"
" AND deliver_attempts <= $attempts"
- " ORDER BY id LIMIT 1",
+ " ORDER BY deliver_attempts, id LIMIT 1",
[DB_STMT_SMS_GET_NEXT_UNSENT_RR_MSISDN] =
"SELECT " SEL_COLUMNS " FROM SMS"
" WHERE sent IS NULL"
diff --git a/src/libmsc/gsm_04_11.c b/src/libmsc/gsm_04_11.c
index 7e2869d50..1b125c649 100644
--- a/src/libmsc/gsm_04_11.c
+++ b/src/libmsc/gsm_04_11.c
@@ -119,6 +119,7 @@ static void send_signal(int sig_no,
struct sms_signal_data sig;
sig.trans = trans;
sig.sms = sms;
+ sig.id = sms->id;
sig.paging_result = paging_result;
osmo_signal_dispatch(SS_SMS, sig_no, &sig);
}
diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c
index 4a362db8a..9b46dcbdc 100644
--- a/src/libmsc/sms_queue.c
+++ b/src/libmsc/sms_queue.c
@@ -547,6 +547,8 @@ static int sub_ready_for_sm(struct gsm_network *net, struct vlr_subscr *vsub)
return -1;
_gsm411_send_sms(net, vsub, sms);
+ if (!sms_subscriber_is_pending(net->sms_queue, vsub))
+ sms_send_next(vsub);
return 0;
}
@@ -572,10 +574,46 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
struct sms_signal_data *sig_sms = signal_data;
struct gsm_sms_pending *pending;
struct vlr_subscr *vsub;
+ struct gsm_sms *sms;
/* We got a new SMS and maybe should launch the queue again. */
- if (signal == S_SMS_SUBMITTED || signal == S_SMS_SMMA) {
- /* TODO: For SMMA we might want to re-use the radio connection. */
+ if (signal == S_SMS_SUBMITTED) {
+ if (sig_sms->id) {
+ LOGP(DLSMS, LOGL_INFO, "Got Signal for new Sms Submitted with ID [%llu]\n",
+ sig_sms->id);
+ sms = db_sms_get(network, sig_sms->id);
+ if (!sms)
+ return -1;
+ if (!sms->receiver || !sms->receiver->lu_complete) {
+ LOGP(DLSMS, LOGL_DEBUG,
+ "Subscriber %s%s is not attached, skipping SMS.\n",
+ sms->receiver ? "" : "MSISDN-",
+ sms->receiver ? vlr_subscr_msisdn_or_name(sms->receiver) : sms->dst.addr);
+ return -1;
+ }
+
+ /* Check somehow it's not already in the pending list */
+ if (sms_queue_sms_is_pending(smq, sms->id)) {
+ sms_free(sms);
+ return 0;
+ }
+ /* Or that this sub is not already pending */
+ if (sms_subscriber_is_pending(smq, sms->receiver)) {
+ sms_free(sms);
+ return 0;
+ }
+ /* Now add this SMS to the Queue for immediate sending. */
+ pending = sms_pending_from(smq, sms);
+ sms_free(sms);
+ /* Schedule the timer to send this SMS */
+ sms_pending_resend(pending);
+ return 0;
+ }
+ }
+
+ if (signal == S_SMS_SMMA) {
+ /* TODO: For SMMA we might want to re-use the radio connection.
+ */
sms_queue_trigger(smq);
return 0;
}
diff --git a/src/libsmpputil/smpp_msc.c b/src/libsmpputil/smpp_msc.c
index cf175407a..5d44a897f 100644
--- a/src/libsmpputil/smpp_msc.c
+++ b/src/libsmpputil/smpp_msc.c
@@ -306,6 +306,8 @@ int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit,
case 1: /* datagram */
case 3: /* store-and-forward */
rc = db_sms_store(sms);
+ memset(&sig, 0, sizeof(sig));
+ sig.id = sms->id;
sms_free(sms);
sms = NULL;
if (rc < 0) {
@@ -317,7 +319,6 @@ int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit,
strcpy((char *)submit_r->message_id, "msg_id_not_implemented");
LOGP(DLSMS, LOGL_INFO, "SMPP SUBMIT-SM: Stored in DB\n");
- memset(&sig, 0, sizeof(sig));
osmo_signal_dispatch(SS_SMS, S_SMS_SUBMITTED, &sig);
rc = 0;
break;