diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-12-24 13:48:27 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-12-26 09:40:03 +0100 |
commit | 11b28f9c26cdafe448eae1dbf6b06a7d1050083a (patch) | |
tree | 3051857c4123c0f0605c8902711e8c920486ff3d | |
parent | 04144c1905d2ccc7b6783b0cccc2f9c11079354b (diff) |
sms: Introduce a SMS queue that will be responsible for delivery
The SMSqueue will be responsible of sending to the user. It will
do so in a loop and will also try not to overload the BTS. This
means the throughput of SMS will be limited.
-rw-r--r-- | openbsc/include/openbsc/Makefile.am | 2 | ||||
-rw-r--r-- | openbsc/include/openbsc/gsm_04_11.h | 2 | ||||
-rw-r--r-- | openbsc/include/openbsc/gsm_data.h | 2 | ||||
-rw-r--r-- | openbsc/include/openbsc/sms_queue.h | 8 | ||||
-rw-r--r-- | openbsc/src/Makefile.am | 2 | ||||
-rw-r--r-- | openbsc/src/bsc_hack.c | 4 | ||||
-rw-r--r-- | openbsc/src/gsm_04_11.c | 33 | ||||
-rw-r--r-- | openbsc/src/sms_queue.c | 97 |
8 files changed, 116 insertions, 34 deletions
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index 3dffe4bf4..6cf8c3b57 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -11,7 +11,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \ gb_proxy.h gprs_sgsn.h gsm_04_08_gprs.h sgsn.h \ gprs_ns_frgre.h auth.h osmo_msc.h bsc_msc.h bsc_nat.h \ osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h \ - osmo_msc_data.h osmo_bsc_grace.h + osmo_msc_data.h osmo_bsc_grace.h sms_queue.h openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h openbscdir = $(includedir)/openbsc diff --git a/openbsc/include/openbsc/gsm_04_11.h b/openbsc/include/openbsc/gsm_04_11.h index d62a392f7..20787788a 100644 --- a/openbsc/include/openbsc/gsm_04_11.h +++ b/openbsc/include/openbsc/gsm_04_11.h @@ -33,5 +33,7 @@ void sms_free(struct gsm_sms *sms); void _gsm411_sms_trans_free(struct gsm_trans *trans); int gsm411_send_sms_subscr(struct gsm_subscriber *subscr, struct gsm_sms *sms); +int gsm411_send_sms(struct gsm_subscriber_connection *conn, + struct gsm_sms *sms); void gsm411_sapi_n_reject(struct gsm_subscriber_connection *conn); #endif diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h index 5badde260..4c87f8354 100644 --- a/openbsc/include/openbsc/gsm_data.h +++ b/openbsc/include/openbsc/gsm_data.h @@ -5,6 +5,7 @@ struct osmo_msc_data; struct osmo_bsc_sccp_con; +struct gsm_sms_queue; enum gsm_phys_chan_config { GSM_PCHAN_NONE, @@ -734,6 +735,7 @@ struct gsm_network { /* subscriber related features */ int keep_subscr; + struct gsm_sms_queue *sms_queue; }; #define SMS_HDR_SIZE 128 diff --git a/openbsc/include/openbsc/sms_queue.h b/openbsc/include/openbsc/sms_queue.h new file mode 100644 index 000000000..d377aca40 --- /dev/null +++ b/openbsc/include/openbsc/sms_queue.h @@ -0,0 +1,8 @@ +#ifndef SMS_QUEUE_H +#define SMS_QUEUE_H + +struct gsm_network; + +int sms_queue_start(struct gsm_network *, int in_flight); + +#endif diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am index 2766d938c..4f3bf9e31 100644 --- a/openbsc/src/Makefile.am +++ b/openbsc/src/Makefile.am @@ -35,7 +35,7 @@ libvty_a_SOURCES = common_vty.c libmgcp_a_SOURCES = mgcp/mgcp_protocol.c mgcp/mgcp_network.c mgcp/mgcp_vty.c -bsc_hack_SOURCES = bsc_hack.c bsc_init.c bsc_vty.c vty_interface_layer3.c +bsc_hack_SOURCES = bsc_hack.c bsc_init.c bsc_vty.c vty_interface_layer3.c sms_queue.c bsc_hack_LDADD = libmsc.a libbsc.a libvty.a libmsc.a \ -ldl -ldbi $(LIBCRYPT) $(LIBOSMOVTY_LIBS) diff --git a/openbsc/src/bsc_hack.c b/openbsc/src/bsc_hack.c index 4efc7821e..2b0af2e9a 100644 --- a/openbsc/src/bsc_hack.c +++ b/openbsc/src/bsc_hack.c @@ -274,6 +274,10 @@ int main(int argc, char **argv) signal(SIGUSR2, &signal_handler); signal(SIGPIPE, SIG_IGN); + /* start the SMS queue */ + if (sms_queue_start(bsc_gsmnet, 5) != 0) + return -1; + if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { diff --git a/openbsc/src/gsm_04_11.c b/openbsc/src/gsm_04_11.c index 31bdf38c7..25fe467d6 100644 --- a/openbsc/src/gsm_04_11.c +++ b/openbsc/src/gsm_04_11.c @@ -101,7 +101,6 @@ static const struct value_string rp_cause_strs[] = { { 0, NULL } }; -static int gsm411_send_sms(struct gsm_subscriber_connection *conn, struct gsm_sms *sms); struct gsm_sms *sms_alloc(void) { @@ -1047,7 +1046,7 @@ int gsm0411_rcv_sms(struct gsm_subscriber_connection *conn, /* Take a SMS in gsm_sms structure and send it through an already * existing lchan. We also assume that the caller ensured this lchan already * has a SAPI3 RLL connection! */ -static int gsm411_send_sms(struct gsm_subscriber_connection *conn, struct gsm_sms *sms) +int gsm411_send_sms(struct gsm_subscriber_connection *conn, struct gsm_sms *sms) { struct msgb *msg = gsm411_msgb_alloc(); struct gsm_trans *trans; @@ -1174,32 +1173,6 @@ int gsm411_send_sms_subscr(struct gsm_subscriber *subscr, return 0; } -static int subscr_sig_cb(unsigned int subsys, unsigned int signal, - void *handler_data, void *signal_data) -{ - struct gsm_subscriber *subscr; - struct gsm_subscriber_connection *conn; - struct gsm_sms *sms; - - switch (signal) { - case S_SUBSCR_ATTACHED: - /* A subscriber has attached. Check if there are - * any pending SMS for him to be delivered */ - subscr = signal_data; - conn = connection_for_subscr(subscr); - if (!conn) - break; - sms = db_sms_get_unsent_for_subscr(subscr); - if (!sms) - break; - gsm411_send_sms(conn, sms); - break; - default: - break; - } - return 0; -} - void _gsm411_sms_trans_free(struct gsm_trans *trans) { if (trans->sms.sms) { @@ -1233,7 +1206,3 @@ void gsm411_sapi_n_reject(struct gsm_subscriber_connection *conn) gsm411_release_conn(conn); } -static __attribute__((constructor)) void on_dso_load_sms(void) -{ - register_signal_handler(SS_SUBSCR, subscr_sig_cb, NULL); -} diff --git a/openbsc/src/sms_queue.c b/openbsc/src/sms_queue.c new file mode 100644 index 000000000..f61cf6326 --- /dev/null +++ b/openbsc/src/sms_queue.c @@ -0,0 +1,97 @@ +/* SMS queue to continously attempt to deliver SMS */ +/* + * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +/** + * The difficulty of such a queue is to send a lot of SMS without + * overloading the paging subsystem and the database and other users + * of the MSC. To make the best use we would need to know the number + * of pending paging requests, then throttle the number of SMS we + * want to send and such. + * We will start with a very simple SMS Queue and then try to speed + * things up by collecting data from other parts of the system. + */ + +#include <openbsc/sms_queue.h> +#include <openbsc/chan_alloc.h> +#include <openbsc/db.h> +#include <openbsc/debug.h> +#include <openbsc/gsm_data.h> +#include <openbsc/gsm_04_11.h> +#include <openbsc/signal.h> + +#include <osmocore/talloc.h> + + +struct gsm_sms_queue { + struct gsm_network *network; + int max_pending; + int pending; +}; + + +int sms_queue_start(struct gsm_network *network, int max_pending) +{ + struct gsm_sms_queue *sms = talloc_zero(network, struct gsm_sms_queue); + if (!sms) { + LOGP(DMSC, LOGL_ERROR, "Failed to create the SMS queue.\n"); + return -1; + } + + network->sms_queue = sms; + sms->network = network; + sms->max_pending = max_pending; + + return 0; +} + +static int sub_ready_for_sm(struct gsm_subscriber *subscr) +{ + struct gsm_subscriber_connection *conn; + struct gsm_sms *sms; + + /* A subscriber has attached. Check if there are + * any pending SMS for him to be delivered */ + conn = connection_for_subscr(subscr); + if (!conn) + return -1; + sms = db_sms_get_unsent_for_subscr(subscr); + if (!sms) + return -1; + gsm411_send_sms(conn, sms); + return 0; +} + +static int sms_subscr_cb(unsigned int subsys, unsigned int signal, + void *handler_data, void *signal_data) +{ + struct gsm_subscriber *subscr = signal_data; + + if (signal != S_SUBSCR_ATTACHED) + return 0; + + /* this is readyForSM */ + return sub_ready_for_sm(subscr); +} + +static __attribute__((constructor)) void on_dso_load_sms(void) +{ + register_signal_handler(SS_SUBSCR, sms_subscr_cb, NULL); +} |