diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-05-25 16:21:35 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-07-31 16:58:26 +0200 |
commit | 0655cac6f1fbb0a669f064780a171a363ce8ef83 (patch) | |
tree | 17bda895ab0b476e73d74e9fdb6deb21dd38689b /tests | |
parent | b05d72d21b8cc91126cf45525f9010df6142e1c2 (diff) |
sysmobts: Verify the structure of IPA and OML messages
Extend the router to verify that the message received is
properly encoded. The code can deal with the basic structure
of ETSI OML and vendor specific messages for ip.access and
the osmocom project.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/Makefile.am | 3 | ||||
-rw-r--r-- | tests/misc/misc_test.c | 75 | ||||
-rw-r--r-- | tests/misc/misc_test.ok | 2 |
3 files changed, 79 insertions, 1 deletions
diff --git a/tests/misc/Makefile.am b/tests/misc/Makefile.am index 4091bc6a..f60325b0 100644 --- a/tests/misc/Makefile.am +++ b/tests/misc/Makefile.am @@ -5,4 +5,5 @@ noinst_PROGRAMS = misc_test EXTRA_DIST = misc_test.ok misc_test_SOURCES = misc_test.c $(srcdir)/../stubs.c -misc_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD) +misc_test_LDADD = $(top_builddir)/src/common/libbts.a \ + $(LIBOSMOABIS_LIBS) $(LIBOSMOTRAU_LIBS) $(LDADD) diff --git a/tests/misc/misc_test.c b/tests/misc/misc_test.c index 91fd73a1..f1b7ce3c 100644 --- a/tests/misc/misc_test.c +++ b/tests/misc/misc_test.c @@ -21,10 +21,81 @@ */ #include <osmo-bts/bts.h> +#include <osmo-bts/msg_utils.h> +#include <osmo-bts/logging.h> + +#include <osmocom/gsm/protocol/ipaccess.h> #include <stdlib.h> #include <stdio.h> +static const uint8_t ipa_rsl_connect[] = { + 0x00, 0x1c, 0xff, 0x10, 0x80, 0x00, 0x0a, 0x0d, + 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x70, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x00, 0xe0, 0x04, 0x00, + 0x00, 0xff, 0x85, 0x00, 0x81, 0x0b, 0xbb +}; + +static void test_msg_utils_ipa(void) +{ + struct msgb *msg; + int rc, size; + + printf("Testing IPA structure\n"); + + msg = msgb_alloc(sizeof(ipa_rsl_connect), "IPA test"); + msg->l1h = msgb_put(msg, sizeof(ipa_rsl_connect)); + memcpy(msg->l1h, ipa_rsl_connect, sizeof(ipa_rsl_connect)); + rc = msg_verify_ipa_structure(msg); + OSMO_ASSERT(rc == 0); + msgb_free(msg); + + /* test truncated messages and they should fail */ + for (size = sizeof(ipa_rsl_connect) - 1; size >= 0; --size) { + msg = msgb_alloc(sizeof(ipa_rsl_connect) - 1, "IPA test"); + msg->l1h = msgb_put(msg, size); + memcpy(msg->l1h, ipa_rsl_connect, size); + rc = msg_verify_ipa_structure(msg); + OSMO_ASSERT(rc == -1); + msgb_free(msg); + } + + /* change the type of the message */ + msg = msgb_alloc(sizeof(ipa_rsl_connect), "IPA test"); + msg->l1h = msgb_put(msg, sizeof(ipa_rsl_connect)); + memcpy(msg->l1h, ipa_rsl_connect, sizeof(ipa_rsl_connect)); + msg->l1h[2] = 0x23; + rc = msg_verify_ipa_structure(msg); + OSMO_ASSERT(rc == -1); + msgb_free(msg); +} + +static void test_msg_utils_oml(void) +{ + static const size_t hh_size = sizeof(struct ipaccess_head); + struct msgb *msg; + int rc, size; + + printf("Testing OML structure\n"); + + msg = msgb_alloc(sizeof(ipa_rsl_connect) - hh_size, "IPA test"); + msg->l2h = msgb_put(msg, sizeof(ipa_rsl_connect) - hh_size); + memcpy(msg->l2h, ipa_rsl_connect + hh_size, sizeof(ipa_rsl_connect) - hh_size); + rc = msg_verify_oml_structure(msg); + OSMO_ASSERT(rc == OML_MSG_TYPE_IPA); + msgb_free(msg); + + /* test truncated messages and they should fail */ + for (size = sizeof(ipa_rsl_connect) - hh_size - 1; size >=0; --size) { + msg = msgb_alloc(size, "IPA test"); + msg->l2h = msgb_put(msg, size); + memcpy(msg->l2h, ipa_rsl_connect + hh_size, size); + rc = msg_verify_oml_structure(msg); + OSMO_ASSERT(rc == -1); + msgb_free(msg); + } +} + static void test_sacch_get(void) { struct gsm_lchan lchan; @@ -53,6 +124,10 @@ static void test_sacch_get(void) int main(int argc, char **argv) { + bts_log_init(NULL); + test_sacch_get(); + test_msg_utils_ipa(); + test_msg_utils_oml(); return EXIT_SUCCESS; } diff --git a/tests/misc/misc_test.ok b/tests/misc/misc_test.ok index c8187a10..58aa3ea1 100644 --- a/tests/misc/misc_test.ok +++ b/tests/misc/misc_test.ok @@ -1 +1,3 @@ Testing lchan_sacch_get +Testing IPA structure +Testing OML structure |