Change-Id: Id14a1abcfe1661ff1cbcf0c1b8bc44a631e926c3
This commit is contained in:
Neels Hofmeyr 2017-10-26 21:17:08 +02:00
parent 5e4643f4bc
commit eb8f34b69f
5 changed files with 174 additions and 2 deletions

View File

@ -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;

View File

@ -104,6 +104,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);

View File

@ -1,9 +1,13 @@
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
sccp_test_LDADD = \
@ -11,3 +15,41 @@ sccp_test_LDADD = \
$(top_builddir)/src/sccp.o \
$(NULL)
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)

124
tests/sccp/ni_test.c Normal file
View File

@ -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;
}

View File

@ -31,3 +31,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