This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.
Neels Hofmeyr nhofmeyr at sysmocom.deTweak the hardcoded default ports/interfaces for the test. Sponsored-by: On-Waves ehf --- openbsc/configure.ac | 1 + openbsc/src/gprs/gtphub_main.c | 14 ++++---- openbsc/tests/Makefile.am | 2 +- openbsc/tests/gtphub/Makefile.am | 3 ++ openbsc/tests/gtphub/gtphub_nc_test.ok | 7 ++++ openbsc/tests/gtphub/gtphub_nc_test.sh | 58 ++++++++++++++++++++++++++++++++++ openbsc/tests/testsuite.at | 7 ++++ 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 openbsc/tests/gtphub/Makefile.am create mode 100644 openbsc/tests/gtphub/gtphub_nc_test.ok create mode 100755 openbsc/tests/gtphub/gtphub_nc_test.sh diff --git a/openbsc/configure.ac b/openbsc/configure.ac index 78302dd..7809feb 100644 --- a/openbsc/configure.ac +++ b/openbsc/configure.ac @@ -209,6 +209,7 @@ AC_OUTPUT( tests/trau/Makefile tests/sgsn/Makefile tests/subscr/Makefile + tests/gtphub/Makefile doc/Makefile doc/examples/Makefile Makefile) diff --git a/openbsc/src/gprs/gtphub_main.c b/openbsc/src/gprs/gtphub_main.c index aa35952..f8bcd59 100644 --- a/openbsc/src/gprs/gtphub_main.c +++ b/openbsc/src/gprs/gtphub_main.c @@ -227,16 +227,18 @@ int main(int argc, char **argv) int rc; - const char* clients_addr_str = "localhost"; - uint16_t clients_port = 3386; + /* Which local interface to use to listen for GTP clients */ + const char* clients_addr_str = "127.0.0.3"; + uint16_t clients_port = 2123; - const char* server_addr_str = "localhost"; - uint16_t server_port = 1234; + /* Where the GTP server sits that we're relaying for */ + const char* server_addr_str = "127.0.0.2"; + uint16_t server_port = 2123; /* Which local interface to use to listen for the GTP server's * responses */ - const char* server_rx_addr_str = "localhost"; - uint16_t server_rx_port = 4321; + const char* server_rx_addr_str = "127.0.0.4"; + uint16_t server_rx_port = 2123; rc = osmo_sockaddr_init(&server_addr, &server_addr_len, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, server_addr_str, server_port); diff --git a/openbsc/tests/Makefile.am b/openbsc/tests/Makefile.am index 773830b..7dda124 100644 --- a/openbsc/tests/Makefile.am +++ b/openbsc/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = gsm0408 db channel mgcp gprs abis gbproxy trau subscr +SUBDIRS = gsm0408 db channel mgcp gprs abis gbproxy trau subscr gtphub if BUILD_NAT SUBDIRS += bsc-nat bsc-nat-trie diff --git a/openbsc/tests/gtphub/Makefile.am b/openbsc/tests/gtphub/Makefile.am new file mode 100644 index 0000000..d53c19d --- /dev/null +++ b/openbsc/tests/gtphub/Makefile.am @@ -0,0 +1,3 @@ +EXTRA_DIST = \ + gtphub_nc_test.sh \ + gtphub_nc_test.ok diff --git a/openbsc/tests/gtphub/gtphub_nc_test.ok b/openbsc/tests/gtphub/gtphub_nc_test.ok new file mode 100644 index 0000000..e4f641b --- /dev/null +++ b/openbsc/tests/gtphub/gtphub_nc_test.ok @@ -0,0 +1,7 @@ +--- recv_server: +[msg 1: client to server] +OK +--- recv_client: +[msg 2: server to client] +OK +done diff --git a/openbsc/tests/gtphub/gtphub_nc_test.sh b/openbsc/tests/gtphub/gtphub_nc_test.sh new file mode 100755 index 0000000..179bad7 --- /dev/null +++ b/openbsc/tests/gtphub/gtphub_nc_test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# gtphub_nc_test.sh + +# TODO does this work with all relevant netcat implementations? +# TODO skip if netcat not found? + +gtphub_bin="$1" +if [ ! -x "$gtphub_bin" ]; then + echo "executable not found: $gtphub_bin" + exit 1; +fi + +# client osmo-gtphub gtp server +# 127.0.0.1:9876 <--> 127.0.0.3:2123 | 127.0.0.4:2123 <--> 127.0.0.2 2123 +# (netcat) ($gtphub_bin) (netcat) + +# start gtphub relay +"$gtphub_bin" & +sleep 0.1 + +# log what reaches client and server +nc --recv-only -u -l -p 9876 -s 127.0.0.1 > recv_client & +nc --recv-only -u -l -p 2123 -s 127.0.0.2 > recv_server & +sleep .1 + +# send test messages, both ways +msg1="[msg 1: client to server]" +echo "$msg1" | nc --send-only -u -s 127.0.0.1 -p 9876 127.0.0.3 2123 + +msg2="[msg 2: server to client]" +echo "$msg2" | nc --send-only -u -s 127.0.0.2 -p 2123 127.0.0.4 2123 + +sleep .1 +kill %1 %2 %3 + +# log what has reached the server and client ends, matched against +# gtphub_nc_test.ok +retval=0 +echo "--- recv_server:" +cat recv_server +if [ "$(cat recv_server)" == "$msg1" ]; then + echo "OK" +else + echo "*** FAILURE" + retval=1 +fi + +echo "--- recv_client:" +cat recv_client +if [ "$(cat recv_client)" == "$msg2" ]; then + echo "OK" +else + echo "*** FAILURE" + retval=2 +fi + +echo "done" +exit "$retval" diff --git a/openbsc/tests/testsuite.at b/openbsc/tests/testsuite.at index 74aaef0..14d1f72 100644 --- a/openbsc/tests/testsuite.at +++ b/openbsc/tests/testsuite.at @@ -103,3 +103,10 @@ AT_CHECK([test "$enable_sgsn_test" != no || exit 77]) cat $abs_srcdir/sgsn/sgsn_test.ok > expout AT_CHECK([$abs_top_builddir/tests/sgsn/sgsn_test], [], [expout], [ignore]) AT_CLEANUP + +AT_SETUP([gtphub]) +AT_KEYWORDS([gtphub]) +AT_CHECK([test "$enable_gtphub_test" != no || exit 77]) +cat $abs_srcdir/gtphub/gtphub_nc_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/gtphub/gtphub_nc_test.sh $abs_top_builddir/src/gprs/osmo-gtphub], [], [expout], [ignore]) +AT_CLEANUP -- 2.1.4