summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-10-26 21:17:08 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2017-10-26 21:18:27 +0200
commit799b24fca46b4b407c9275865aed4174a2d164f2 (patch)
tree8263b8e835f4ba01855f59ea5a53f98ba2d37bad
parenta8929fdb5642c86c23a615e4e00a78269366e846 (diff)
-rw-r--r--include/osmocom/sigtran/mtp_sap.h2
-rw-r--r--src/sccp_scrc.c1
-rw-r--r--tests/sccp/Makefile.am44
-rw-r--r--tests/sccp/ni_test.c124
-rw-r--r--tests/testsuite.at5
5 files changed, 174 insertions, 2 deletions
diff --git a/include/osmocom/sigtran/mtp_sap.h b/include/osmocom/sigtran/mtp_sap.h
index 0ae8592..d8b0e1b 100644
--- a/include/osmocom/sigtran/mtp_sap.h
+++ b/include/osmocom/sigtran/mtp_sap.h
@@ -31,7 +31,7 @@ enum osmo_mtp_prim_type {
OSMO_MTP_PRIM_STATUS,
};
-#define MTP_SIO(service, net_ind) (((net_ind & 0x3) << 6) | (service & 0xF))
+#define MTP_SIO(service, net_ind) (((net_ind & 0x3) << 4) | (service & 0xF))
struct osmo_mtp_transfer_param {
uint32_t opc;
diff --git a/src/sccp_scrc.c b/src/sccp_scrc.c
index 2afd696..e2ddc91 100644
--- a/src/sccp_scrc.c
+++ b/src/sccp_scrc.c
@@ -102,6 +102,7 @@ static int sua2sccp_tx_m3ua(struct osmo_sccp_instance *inst,
param->dpc = remote_pc;
param->sls = sua->mtp.sls;
param->sio = MTP_SIO(MTP_SI_SCCP, s7i->cfg.network_indicator);
+ printf("XXX sio = %d\n", param->sio);
/* 3) send via MTP-SAP (osmo_ss7_instance) */
return osmo_ss7_user_mtp_xfer_req(s7i, omp);
diff --git a/tests/sccp/Makefile.am b/tests/sccp/Makefile.am
index 8cce20c..6548f47 100644
--- a/tests/sccp/Makefile.am
+++ b/tests/sccp/Makefile.am
@@ -1,10 +1,52 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS)
+AM_CFLAGS+=$(LIBOSMONETIF_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBSCTP_CFLAGS) $(LIBOSMOVTY_CFLAGS)
EXTRA_DIST = sccp_test.ok
-noinst_PROGRAMS = sccp_test
+noinst_PROGRAMS = \
+ sccp_test \
+ ni_test \
+ $(NULL)
sccp_test_SOURCES = sccp_test.c $(top_srcdir)/src/sccp.c
sccp_test_LDADD = $(LIBOSMOCORE_LIBS)
+ni_test_SOURCES = \
+ ni_test.c \
+ $(top_srcdir)/src/m3ua.c \
+ $(top_srcdir)/src/xua_msg.c \
+ $(top_srcdir)/src/sccp_helpers.c \
+ $(top_srcdir)/src/osmo_ss7.c \
+ $(top_srcdir)/src/sccp_scrc.c \
+ $(top_srcdir)/src/sccp_user.c \
+ $(top_srcdir)/src/xua_rkm.c \
+ $(top_srcdir)/src/xua_asp_fsm.c \
+ $(top_srcdir)/src/osmo_ss7_hmrt.c \
+ $(top_srcdir)/src/sua.c \
+ $(top_srcdir)/src/sccp_sap.c \
+ $(top_srcdir)/src/sccp_scoc.c \
+ $(top_srcdir)/src/ipa.c \
+ $(top_srcdir)/src/xua_as_fsm.c \
+ $(top_srcdir)/src/xua_default_lm_fsm.c \
+ $(top_srcdir)/src/sccp_sclc.c \
+ $(top_srcdir)/src/sccp2sua.c \
+ $(NULL)
+
+ni_test_CFLAGS = \
+ -I$(top_srcdir)/src \
+ $(NULL)
+
+ni_test_LDFLAGS = \
+ -Wl,--wrap=m3ua_tx_xua_as \
+ $(NULL)
+
+ni_test_LDADD = \
+ $(top_builddir)/src/libxua.a \
+ $(top_builddir)/src/libsccp.a \
+ $(LIBOSMOCORE_LIBS) \
+ $(LIBOSMOGSM_LIBS) \
+ $(LIBOSMOVTY_LIBS) \
+ $(LIBOSMONETIF_LIBS) \
+ $(LIBSCTP_LIBS) \
+ $(NULL)
diff --git a/tests/sccp/ni_test.c b/tests/sccp/ni_test.c
new file mode 100644
index 0000000..860c5a0
--- /dev/null
+++ b/tests/sccp/ni_test.c
@@ -0,0 +1,124 @@
+#include <osmocom/core/logging.h>
+#include <osmocom/core/application.h>
+
+#include <osmocom/sigtran/osmo_ss7.h>
+#include <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/sigtran/xua_msg.h>
+#include <osmocom/sigtran/protocol/m3ua.h>
+#include <osmocom/sigtran/sccp_helpers.h>
+
+#include "xua_internal.h"
+
+void *ctx = NULL;
+
+static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu)
+{
+ struct osmo_scu_prim *scu_prim = (struct osmo_scu_prim *)oph;
+ int rc = 0;
+
+ printf("%s\n", msgb_hexdump(oph->msg));
+
+ switch (OSMO_PRIM_HDR(&scu_prim->oph)) {
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION):
+ printf("inbound connection indication\n");
+ break;
+
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION):
+ printf("incoming connection oriented data\n");
+ break;
+
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION):
+ printf("Handle inbound UNITDATA\n");
+ break;
+
+ default:
+ printf("Unhandled SIGTRAN primitive: %u:%u\n", oph->primitive, oph->operation);
+ break;
+ }
+
+ return rc;
+}
+
+static struct msgb *create_msg(void)
+{
+ struct msgb *msg = msgb_alloc_headroom(128, 128, "test msg");
+ OSMO_ASSERT(msg);
+
+ msgb_printf(msg, "test msg");
+ msg->l3h = msg->data;
+
+ return msg;
+}
+
+static const struct log_info_cat default_categories[] = {
+ [0] = {
+ .name = "DSCCP",
+ .description = "DSCP",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
+};
+
+const struct log_info log_info = {
+ .cat = default_categories,
+ .num_cat = ARRAY_SIZE(default_categories),
+};
+
+struct osmo_ss7_asp *asp;
+struct osmo_sccp_addr addr1;
+struct osmo_ss7_instance *ss7;
+
+/* override, requires '-Wl,--wrap=m3ua_tx_xua_as' */
+int __real_m3ua_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua);
+int __wrap_m3ua_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua)
+{
+ printf("sio = 0x%02x ==> ni = %u\n", xua->mtp.sio, xua->mtp.sio >> 6);
+ /* loopback to self */
+ xua->mtp.dpc = ss7->cfg.primary_pc;
+ return m3ua_hmdc_rx_from_l2(ss7, xua);
+}
+
+int main(void)
+{
+ struct osmo_ss7_as *as;
+ struct osmo_sccp_user *user1;
+ struct osmo_sccp_addr addr2;
+ osmo_sccp_make_addr_pc_ssn(&addr1, 1, 1);
+ osmo_sccp_make_addr_pc_ssn(&addr2, 2, 1);
+
+ int ss7_id = 0;
+
+ osmo_init_logging(&log_info);
+ osmo_ss7_init();
+
+ ss7 = osmo_ss7_instance_find_or_create(ctx, ss7_id);
+ OSMO_ASSERT(ss7);
+
+ as = osmo_ss7_as_find_or_create(ss7, "as", OSMO_SS7_ASP_PROT_M3UA);
+ OSMO_ASSERT(as);
+
+ asp = osmo_ss7_asp_find_or_create(ss7, "asp", 0, 0, OSMO_SS7_ASP_PROT_M3UA);
+ OSMO_ASSERT(asp);
+ osmo_ss7_as_add_asp(as, asp->cfg.name);
+
+ osmo_ss7_route_create(ss7->rtable_system, 0, 0, as->cfg.name);
+ ss7->cfg.primary_pc = addr1.pc;
+
+ asp->cfg.is_server = false;
+
+ ss7->sccp = osmo_sccp_instance_create(ss7, NULL);
+ OSMO_ASSERT(ss7->sccp);
+
+ ss7->cfg.network_indicator = 2;
+
+ user1 = osmo_sccp_user_bind(ss7->sccp, "user1", sccp_sap_up, 1);
+ osmo_sccp_user_bind(ss7->sccp, "user2", sccp_sap_up, 2);
+
+ osmo_sccp_tx_unitdata_msg(user1, &addr1, &addr2, create_msg());
+
+ osmo_ss7_asp_destroy(asp);
+ osmo_ss7_as_destroy(as);
+ osmo_ss7_instance_destroy(ss7);
+
+ return 0;
+}
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index b810bdf..eee67ac 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -30,3 +30,8 @@ AT_KEYWORDS([ss7])
cat $abs_srcdir/ss7/ss7_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/ss7/ss7_test], [], [expout], [ignore])
AT_CLEANUP
+
+AT_SETUP([ni])
+AT_KEYWORDS([ni])
+AT_CHECK([$abs_top_builddir/tests/sccp/ni_test], [], [], [ignore])
+AT_CLEANUP