aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-04-16 22:31:41 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-04-16 22:32:09 +0200
commit6a441c86fe4de07e90f36ea1816fdc329c9ec288 (patch)
treea17c7e1bb1ab36f94053631773dbaf110ef4a08b
parent0bcf47ba0541e486dc9893e4f2c3e9de5f3e132e (diff)
m3ua: Make the traffic-mode configurable
-rw-r--r--include/sctp_m3ua.h5
-rw-r--r--src/Makefile.am3
-rw-r--r--src/sctp_m3ua_client.c3
-rw-r--r--src/sctp_m3ua_misc.c44
-rw-r--r--src/vty_interface.c21
-rw-r--r--tests/mtp/Makefile.am4
-rw-r--r--tests/mtp/mtp_parse_test.c17
7 files changed, 92 insertions, 5 deletions
diff --git a/include/sctp_m3ua.h b/include/sctp_m3ua.h
index 0cc405f..dfada73 100644
--- a/include/sctp_m3ua.h
+++ b/include/sctp_m3ua.h
@@ -22,6 +22,7 @@ struct mtp_m3ua_client_link {
struct sockaddr_in remote;
int link_index;
int routing_context;
+ uint32_t traffic_mode;
/* state of the link */
@@ -30,3 +31,7 @@ struct mtp_m3ua_client_link {
};
struct mtp_m3ua_client_link *mtp_m3ua_client_link_init(struct mtp_link *link);
+
+
+const char *m3ua_traffic_mode_name(uint32_t mode);
+uint32_t m3ua_traffic_mode_num(const char *argv);
diff --git a/src/Makefile.am b/src/Makefile.am
index b4fe733..2052851 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,7 +26,8 @@ osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c
bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c input/ipaccess.c \
mtp_link.c counter.c bsc.c ss7_application.c \
vty_interface.c vty_interface_cmds.c mgcp_patch.c \
- mgcp_callagent.c isup_filter.c sctp_m3ua_client.c
+ mgcp_callagent.c isup_filter.c sctp_m3ua_client.c \
+ sctp_m3ua_misc.c
osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
$(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \
-lpthread -lnetsnmp -lcrypto -lxua -lsctp
diff --git a/src/sctp_m3ua_client.c b/src/sctp_m3ua_client.c
index 26a63f1..f76a0b0 100644
--- a/src/sctp_m3ua_client.c
+++ b/src/sctp_m3ua_client.c
@@ -368,6 +368,7 @@ struct mtp_m3ua_client_link *mtp_m3ua_client_link_init(struct mtp_link *blnk)
osmo_wqueue_init(&lnk->queue, 10);
lnk->queue.bfd.fd = -1;
+ lnk->traffic_mode = 2;
return lnk;
}
@@ -423,7 +424,7 @@ static void m3ua_send_aspac(struct mtp_m3ua_client_link *link)
aspac->hdr.msg_class = M3UA_CLS_ASPTM;
aspac->hdr.msg_type = M3UA_ASPTM_ACTIV;
- traffic_mode = htonl(2);
+ traffic_mode = htonl(link->traffic_mode);
xua_msg_add_data(aspac, 11, 4, (uint8_t *) &traffic_mode);
routing_ctx = htonl(link->routing_context);
diff --git a/src/sctp_m3ua_misc.c b/src/sctp_m3ua_misc.c
new file mode 100644
index 0000000..71eda49
--- /dev/null
+++ b/src/sctp_m3ua_misc.c
@@ -0,0 +1,44 @@
+/* (C) 2015 by Holger Hans Peter Freyther
+ *
+ * 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 "sctp_m3ua.h"
+
+/*
+ * Conversion
+ */
+const char *m3ua_traffic_mode_name(uint32_t mode)
+{
+ switch (mode) {
+ case 1:
+ return "override";
+ case 2:
+ return "loadshare";
+ case 3:
+ return "broadcast";
+ }
+ abort();
+}
+
+uint32_t m3ua_traffic_mode_num(const char *name)
+{
+ if (name[0] == 'o')
+ return 1;
+ if (name[0] == 'l')
+ return 2;
+ if (name[0] == 'b')
+ return 3;
+ abort();
+}
+
diff --git a/src/vty_interface.c b/src/vty_interface.c
index dd4412b..b0ce06b 100644
--- a/src/vty_interface.c
+++ b/src/vty_interface.c
@@ -201,6 +201,9 @@ static void write_link(struct vty *vty, struct mtp_link *link)
m3ua_client->link_index, VTY_NEWLINE);
vty_out(vty, " m3ua-client routing-context %d%s",
m3ua_client->routing_context, VTY_NEWLINE);
+ vty_out(vty, " m3ua-client traffic-mode %s%s",
+ m3ua_traffic_mode_name(m3ua_client->traffic_mode),
+ VTY_NEWLINE);
break;
case SS7_LTYPE_NONE:
break;
@@ -883,6 +886,23 @@ DEFUN(cfg_link_m3ua_client_routing_ctx, cfg_link_m3ua_client_routing_ctx_cmd,
return CMD_SUCCESS;
}
+DEFUN(cfg_link_m3ua_client_traffic_mode, cfg_link_m3ua_client_traffic_mode_cmd,
+ "m3ua-client traffic-mode (override|loadshare|broadcast)",
+ "M3UA Client\n" "Traffic Mode\n" "Override" "Loadshare\n" "Broadcast\n")
+{
+ struct mtp_link *link = vty->index;
+ struct mtp_m3ua_client_link *m3ua_link;
+
+ if (link->type != SS7_LTYPE_M3UA_CLIENT) {
+ vty_out(vty, "%%This only applies to M3UA client links.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ m3ua_link = link->data;
+ m3ua_link->traffic_mode = m3ua_traffic_mode_num(argv[0]);
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_ss7_msc, cfg_ss7_msc_cmd,
"msc <0-100>",
"MSC Connection\n" "MSC Number\n")
@@ -1305,6 +1325,7 @@ void cell_vty_init(void)
install_element(LINK_NODE, &cfg_link_m3ua_client_dest_port_cmd);
install_element(LINK_NODE, &cfg_link_m3ua_client_link_index_cmd);
install_element(LINK_NODE, &cfg_link_m3ua_client_routing_ctx_cmd);
+ install_element(LINK_NODE, &cfg_link_m3ua_client_traffic_mode_cmd);
install_element(SS7_NODE, &cfg_ss7_msc_cmd);
install_node(&msc_node, config_write_msc);
diff --git a/tests/mtp/Makefile.am b/tests/mtp/Makefile.am
index 21cc2c0..cf48d6a 100644
--- a/tests/mtp/Makefile.am
+++ b/tests/mtp/Makefile.am
@@ -3,4 +3,6 @@ noinst_PROGRAMS = mtp_parse_test
EXTRA_DIST = mtp_parse_test.ok
-mtp_parse_test_SOURCES = mtp_parse_test.c
+mtp_parse_test_SOURCES = mtp_parse_test.c $(top_srcdir)/src/sctp_m3ua_misc.c
+mtp_parse_test_LDADD = \
+ $(LIBOSMOCORE_LIBS)
diff --git a/tests/mtp/mtp_parse_test.c b/tests/mtp/mtp_parse_test.c
index c13d295..1c4e409 100644
--- a/tests/mtp/mtp_parse_test.c
+++ b/tests/mtp/mtp_parse_test.c
@@ -1,5 +1,8 @@
/* MTP Layer3 parsing tests */
+#include "sctp_m3ua.h"
+
#include <osmocom/mtp/mtp_level3.h>
+#include <osmocom/core/utils.h>
#include <arpa/inet.h>
@@ -7,8 +10,6 @@
#include <stdlib.h>
#include <string.h>
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
-
struct mtp_test {
const uint8_t *input;
const uint16_t length;
@@ -578,6 +579,17 @@ static void check_prohib(const uint8_t *data, const struct mtp_level_3_prohib *t
abort();
}
+void test_m3ua_traffic_mode(void)
+{
+ OSMO_ASSERT(strcmp(m3ua_traffic_mode_name(1), "override") == 0);
+ OSMO_ASSERT(strcmp(m3ua_traffic_mode_name(2), "loadshare") == 0);
+ OSMO_ASSERT(strcmp(m3ua_traffic_mode_name(3), "broadcast") == 0);
+
+ OSMO_ASSERT(m3ua_traffic_mode_num("override") == 1);
+ OSMO_ASSERT(m3ua_traffic_mode_num("loadshare") == 2);
+ OSMO_ASSERT(m3ua_traffic_mode_num("broadcast") == 3);
+}
+
int main(int argc, char **argv)
{
uint32_t addr;
@@ -636,6 +648,7 @@ int main(int argc, char **argv)
}
}
+ test_m3ua_traffic_mode();
printf("All tests passed.\n");
return 0;
}