summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/gb/gprs_bssgp_test.c75
-rw-r--r--tests/gb/gprs_bssgp_test.ok4
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/gb/gprs_bssgp_test.c b/tests/gb/gprs_bssgp_test.c
index b454430b..63abf8b3 100644
--- a/tests/gb/gprs_bssgp_test.c
+++ b/tests/gb/gprs_bssgp_test.c
@@ -17,6 +17,7 @@
#include <osmocom/core/prim.h>
#include <osmocom/gprs/gprs_bssgp.h>
#include <osmocom/gprs/gprs_ns.h>
+#include <osmocom/gprs/gprs_bssgp_bss.h>
#include <stdio.h>
#include <stdlib.h>
@@ -60,6 +61,17 @@ int gprs_ns_callback(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
return 0;
}
+struct msgb *last_ns_tx_msg = NULL;
+
+/* override */
+int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg)
+{
+ msgb_free(last_ns_tx_msg);
+ last_ns_tx_msg = msg;
+
+ return msgb_length(msg);
+}
+
int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
{
printf("BSSGP primitive, SAP %d, prim = %d, op = %d, msg = %s\n",
@@ -174,6 +186,68 @@ static void test_bssgp_bad_reset()
msgb_bssgp_send_and_free(msg);
}
+static void test_bssgp_flow_control_bvc(void)
+{
+ struct bssgp_bvc_ctx bctx = {
+ .nsei = 0x1234,
+ .bvci = 0x5678,
+ };
+ const uint8_t tag = 42;
+ const uint32_t bmax = 0x1022 * 100;
+ const uint32_t rate = 0xc040 / 8 * 100;
+ const uint32_t bmax_ms = bmax / 2;
+ const uint32_t rate_ms = rate / 2;
+ uint8_t ratio = 0x78;
+ uint32_t qdelay = 0x1144 * 10;
+ int rc;
+
+ static uint8_t expected_simple_msg[] = {
+ 0x26,
+ 0x1e, 0x81, 0x2a, /* tag */
+ 0x05, 0x82, 0x10, 0x22, /* Bmax */
+ 0x03, 0x82, 0xc0, 0x40, /* R */
+ 0x01, 0x82, 0x08, 0x11, /* Bmax_MS */
+ 0x1c, 0x82, 0x60, 0x20, /* R_MS */
+ };
+
+ static uint8_t expected_ext_msg[] = {
+ 0x26,
+ 0x1e, 0x81, 0x2a, /* tag */
+ 0x05, 0x82, 0x10, 0x22, /* Bmax */
+ 0x03, 0x82, 0xc0, 0x40, /* R */
+ 0x01, 0x82, 0x08, 0x11, /* Bmax_MS */
+ 0x1c, 0x82, 0x60, 0x20, /* R_MS */
+ 0x3c, 0x81, 0x78, /* ratio */
+ 0x06, 0x82, 0x11, 0x44, /* Qdelay */
+ };
+
+ printf("----- %s START\n", __func__);
+
+ rc = bssgp_tx_fc_bvc(&bctx, tag, bmax, rate, bmax_ms, rate_ms,
+ NULL, NULL);
+
+ OSMO_ASSERT(rc >= 0);
+ OSMO_ASSERT(last_ns_tx_msg != NULL);
+ printf("Got message: %s\n", msgb_hexdump(last_ns_tx_msg));
+ OSMO_ASSERT(msgb_length(last_ns_tx_msg) == sizeof(expected_simple_msg));
+ OSMO_ASSERT(0 == memcmp(msgb_data(last_ns_tx_msg),
+ expected_simple_msg, sizeof(expected_simple_msg)));
+
+ rc = bssgp_tx_fc_bvc(&bctx, tag, bmax, rate, bmax_ms, rate_ms,
+ &ratio, &qdelay);
+
+ OSMO_ASSERT(rc >= 0);
+ OSMO_ASSERT(last_ns_tx_msg != NULL);
+ printf("Got message: %s\n", msgb_hexdump(last_ns_tx_msg));
+ OSMO_ASSERT(msgb_length(last_ns_tx_msg) == sizeof(expected_ext_msg));
+ OSMO_ASSERT(0 == memcmp(msgb_data(last_ns_tx_msg),
+ expected_ext_msg, sizeof(expected_ext_msg)));
+
+ msgb_free(last_ns_tx_msg);
+ last_ns_tx_msg = NULL;
+
+ printf("----- %s END\n", __func__);
+}
static struct log_info info = {};
@@ -198,6 +272,7 @@ int main(int argc, char **argv)
test_bssgp_suspend_resume();
test_bssgp_status();
test_bssgp_bad_reset();
+ test_bssgp_flow_control_bvc();
printf("===== BSSGP test END\n\n");
exit(EXIT_SUCCESS);
diff --git a/tests/gb/gprs_bssgp_test.ok b/tests/gb/gprs_bssgp_test.ok
index 0392e6a5..a011bee0 100644
--- a/tests/gb/gprs_bssgp_test.ok
+++ b/tests/gb/gprs_bssgp_test.ok
@@ -7,5 +7,9 @@ BSSGP primitive, SAP 16777219, prim = 4, op = 0, msg = 0e 1f 84 f0 12 34 56 1b 8
BSSGP primitive, SAP 16777221, prim = 11, op = 2, msg = 41 07 81 27
BSSGP primitive, SAP 16777221, prim = 11, op = 2, msg = 41 07 81 05 04 82 04 d2
----- test_bssgp_status END
+----- test_bssgp_flow_control_bvc START
+Got message: 26 1e 81 2a 05 82 10 22 03 82 c0 40 01 82 08 11 1c 82 60 20
+Got message: 26 1e 81 2a 05 82 10 22 03 82 c0 40 01 82 08 11 1c 82 60 20 3c 81 78 06 82 11 44
+----- test_bssgp_flow_control_bvc END
===== BSSGP test END