diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-01-02 11:23:54 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-01-17 11:21:09 +0100 |
commit | a99b04b700891e39d0a10444224fc77a86945970 (patch) | |
tree | 1eb5b9226ccce3e9051f2f5ebab5f11436b759f5 | |
parent | f9b4a86e8dc16e85c09e37861f6de081167ccd7b (diff) |
mtp: Move the link code into a new file called links.
-rw-r--r-- | include/bsc_data.h | 1 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/links.c | 94 | ||||
-rw-r--r-- | src/main.c | 72 | ||||
-rw-r--r-- | src/main_udt.c | 71 |
5 files changed, 101 insertions, 141 deletions
diff --git a/include/bsc_data.h b/include/bsc_data.h index 6684348..b8c9b26 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -143,6 +143,7 @@ unsigned int sls_for_src_ref(struct sccp_source_reference *ref); /* udp init */ int link_udp_init(struct link_data *data, int src_port, const char *dest_ip, int port); +int link_init(struct bsc_data *bsc); /* MGCP */ void mgcp_forward(struct bsc_data *bsc, const uint8_t *data, unsigned int length); diff --git a/src/Makefile.am b/src/Makefile.am index 4ca99f7..83acf8d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,13 +10,13 @@ mgcp_mgw_LDADD = $(LAFORGE_LIBS) $(NEXUSWARE_C7_LIBS) $(NEXUSWARE_UNIPORTE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOCORE_LIBS) -lpthread cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \ - bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c \ + bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c links.c \ msc_conn.c link_udp.c snmp_mtp.c debug.c vty_interface.c isup.c cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto udt_relay_SOURCES = main_udt.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \ msc_conn.c link_udp.c snmp_mtp.c debug.c vty_interface.c \ - bss_patch.c isup.c + bss_patch.c isup.c links.c udt_relay_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto diff --git a/src/links.c b/src/links.c new file mode 100644 index 0000000..cc0f358 --- /dev/null +++ b/src/links.c @@ -0,0 +1,94 @@ +/* link management code */ +/* + * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> + * (C) 2010-2011 by On-Waves + * 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. + * + */ + +#include <bsc_data.h> +#include <cellmgr_debug.h> +#include <mtp_data.h> +#include <snmp_mtp.h> + +extern struct bsc_data bsc; + +void mtp_link_submit(struct mtp_link *link, struct msgb *msg) +{ + bsc.link.write(&bsc.link, msg); +} + +void mtp_link_restart(struct mtp_link *link) +{ + LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); + bsc.link.reset(&bsc.link); +} + +static void start_rest(void *start) +{ + bsc.setup = 1; + + if (msc_init(&bsc, 1) != 0) { + fprintf(stderr, "Failed to init MSC part.\n"); + exit(3); + } + + bsc.link.start(&bsc.link); +} + +int link_init(struct bsc_data *bsc) +{ + bsc->link.the_link = mtp_link_alloc(); + bsc->link.the_link->dpc = bsc->dpc; + bsc->link.the_link->opc = bsc->opc; + bsc->link.the_link->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc; + bsc->link.the_link->link = 0; + bsc->link.the_link->sltm_once = bsc->once; + bsc->link.the_link->ni = bsc->ni_ni; + bsc->link.the_link->spare = bsc->ni_spare; + bsc->link.bsc = bsc; + + if (!bsc->src_port) { + LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n"); + return -1; + } + + LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); + + /* setup SNMP first, it is blocking */ + bsc->link.udp.session = snmp_mtp_session_create(bsc->udp_ip); + if (!bsc->link.udp.session) + return -1; + + /* now connect to the transport */ + if (link_udp_init(&bsc->link, bsc->src_port, bsc->udp_ip, bsc->udp_port) != 0) + return -1; + + /* + * We will ask the MTP link to be taken down for two + * timeouts of the BSC to make sure we are missing the + * SLTM and it begins a reset. Then we will take it up + * again and do the usual business. + */ + snmp_mtp_deactivate(bsc->link.udp.session); + bsc->start_timer.cb = start_rest; + bsc->start_timer.data = &bsc; + bsc_schedule_timer(&bsc->start_timer, bsc->link.udp.reset_timeout, 0); + LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); + + return 0; +} @@ -26,7 +26,6 @@ #include <bss_patch.h> #include <bssap_sccp.h> #include <bsc_data.h> -#include <snmp_mtp.h> #include <cellmgr_debug.h> #include <bsc_sccp.h> @@ -84,17 +83,6 @@ static void mgcp_reset(struct bsc_data *bsc) /* * methods called from the MTP Level3 part */ -void mtp_link_submit(struct mtp_link *link, struct msgb *msg) -{ - bsc.link.write(&bsc.link, msg); -} - -void mtp_link_restart(struct mtp_link *link) -{ - LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); - bsc.link.reset(&bsc.link); -} - void mtp_link_sccp_down(struct mtp_link *link) { msc_clear_queue(&bsc); @@ -646,19 +634,6 @@ static void handle_options(int argc, char **argv) } } -static void start_rest(void *start) -{ - bsc.setup = 1; - - if (msc_init(&bsc, 1) != 0) { - fprintf(stderr, "Failed to init MSC part.\n"); - exit(3); - } - - bsc.link.start(&bsc.link); -} - - int main(int argc, char **argv) { int rc; @@ -716,51 +691,8 @@ int main(int argc, char **argv) if (rc < 0) return rc; - bsc.link.the_link = mtp_link_alloc(); - bsc.link.the_link->dpc = bsc.dpc; - bsc.link.the_link->opc = bsc.opc; - bsc.link.the_link->sccp_opc = bsc.sccp_opc > -1 ? bsc.sccp_opc : bsc.opc; - bsc.link.the_link->link = 0; - bsc.link.the_link->sltm_once = bsc.once; - bsc.link.the_link->ni = bsc.ni_ni; - bsc.link.the_link->spare = bsc.ni_spare; - bsc.link.bsc = &bsc; - - if (bsc.udp_ip) { - LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); - - /* setup SNMP first, it is blocking */ - bsc.link.udp.session = snmp_mtp_session_create(bsc.udp_ip); - if (!bsc.link.udp.session) - return -1; - - /* now connect to the transport */ - if (link_udp_init(&bsc.link, bsc.src_port, bsc.udp_ip, bsc.udp_port) != 0) - return -1; - - /* - * We will ask the MTP link to be taken down for two - * timeouts of the BSC to make sure we are missing the - * SLTM and it begins a reset. Then we will take it up - * again and do the usual business. - */ - snmp_mtp_deactivate(bsc.link.udp.session); - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, bsc.link.udp.reset_timeout, 0); - LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); - } else { - LOGP(DINP, LOGL_NOTICE, "Using NexusWare C7 input.\n"); - if (link_c7_init(&bsc.link) != 0) - return -1; - - /* give time to things to start*/ - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, 30, 0); - LOGP(DMSC, LOGL_NOTICE, "Waiting to continue to startup.\n"); - } - + if (link_init(&bsc) != 0) + return -1; while (1) { bsc_select_main(0); diff --git a/src/main_udt.c b/src/main_udt.c index ef5fce2..07bf587 100644 --- a/src/main_udt.c +++ b/src/main_udt.c @@ -65,17 +65,6 @@ extern void cell_vty_init(void); /* * methods called from the MTP Level3 part */ -void mtp_link_submit(struct mtp_link *link, struct msgb *msg) -{ - bsc.link.write(&bsc.link, msg); -} - -void mtp_link_restart(struct mtp_link *link) -{ - LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); - bsc.link.reset(&bsc.link); -} - void mtp_link_sccp_down(struct mtp_link *link) { msc_clear_queue(&bsc); @@ -198,19 +187,6 @@ static void handle_options(int argc, char **argv) } } -static void start_rest(void *start) -{ - bsc.setup = 1; - - if (msc_init(&bsc, 0) != 0) { - fprintf(stderr, "Failed to init MSC part.\n"); - exit(3); - } - - bsc.link.start(&bsc.link); -} - - int main(int argc, char **argv) { int rc; @@ -269,51 +245,8 @@ int main(int argc, char **argv) if (rc < 0) return rc; - bsc.link.the_link = mtp_link_alloc(); - bsc.link.the_link->dpc = bsc.dpc; - bsc.link.the_link->opc = bsc.opc; - bsc.link.the_link->sccp_opc = bsc.sccp_opc > -1 ? bsc.sccp_opc : bsc.opc; - bsc.link.the_link->link = 0; - bsc.link.the_link->sltm_once = bsc.once; - bsc.link.the_link->ni = bsc.ni_ni; - bsc.link.the_link->spare = bsc.ni_spare; - bsc.link.bsc = &bsc; - - if (bsc.udp_ip) { - LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); - - /* setup SNMP first, it is blocking */ - bsc.link.udp.session = snmp_mtp_session_create(bsc.udp_ip); - if (!bsc.link.udp.session) - return -1; - - /* now connect to the transport */ - if (link_udp_init(&bsc.link, bsc.src_port, bsc.udp_ip, bsc.udp_port) != 0) - return -1; - - /* - * We will ask the MTP link to be taken down for two - * timeouts of the BSC to make sure we are missing the - * SLTM and it begins a reset. Then we will take it up - * again and do the usual business. - */ - snmp_mtp_deactivate(bsc.link.udp.session); - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, bsc.link.udp.reset_timeout, 0); - LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); - } else { - LOGP(DINP, LOGL_NOTICE, "Using NexusWare C7 input.\n"); - if (link_c7_init(&bsc.link) != 0) - return -1; - - /* give time to things to start*/ - bsc.start_timer.cb = start_rest; - bsc.start_timer.data = &bsc; - bsc_schedule_timer(&bsc.start_timer, 30, 0); - LOGP(DMSC, LOGL_NOTICE, "Waiting to continue to startup.\n"); - } - + if (link_init(&bsc) != 0) + return -1; while (1) { bsc_select_main(0); |