diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2022-09-28 17:57:26 +0200 |
---|---|---|
committer | pespin <pespin@sysmocom.de> | 2022-10-03 09:29:18 +0000 |
commit | b0369f375f1f123c84c12bc3113012d3f1cf0991 (patch) | |
tree | ad79074002040b5e064dd50684f5759e44bf5a8d | |
parent | 11f725ae78e73596ee1dadbf12638e9b14b554d0 (diff) |
osmux: Take into account configured osmux_in_handle->osmux_seq field
It was not being used anywhere, yet older applications used to set it
(always to 0, which was the default value applied internally).
Let's make use of it and apply it as first seqnum to be used on a
circuit.
This value is applied upon call to osmux_xfrm_input_open_circuit(),
hence it can be set independently for every new circuit.
Change-Id: Ia26fcba5d7364a5744b2d64d0542a2b3880eee34
-rw-r--r-- | include/osmocom/netif/osmux.h | 1 | ||||
-rw-r--r-- | src/osmux.c | 1 | ||||
-rw-r--r-- | tests/osmux/osmux_input_test.c | 69 | ||||
-rw-r--r-- | tests/osmux/osmux_input_test.ok | 7 |
4 files changed, 78 insertions, 0 deletions
diff --git a/include/osmocom/netif/osmux.h b/include/osmocom/netif/osmux.h index c663c1b..6e200cc 100644 --- a/include/osmocom/netif/osmux.h +++ b/include/osmocom/netif/osmux.h @@ -57,6 +57,7 @@ struct osmux_hdr { /* one to handle all existing RTP flows */ struct osmux_in_handle { + /* Initial Osmux seqnum for each circuit, set during osmux_xfrm_input_open_circuit() */ uint8_t osmux_seq; uint8_t batch_factor; uint16_t batch_size; diff --git a/src/osmux.c b/src/osmux.c index 30661d2..e51e212 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -859,6 +859,7 @@ int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, } circuit->ccid = ccid; + circuit->seq = h->osmux_seq; INIT_LLIST_HEAD(&circuit->msg_list); llist_add_tail(&circuit->head, &batch->circuit_list); diff --git a/tests/osmux/osmux_input_test.c b/tests/osmux/osmux_input_test.c index ff5379a..5a311c8 100644 --- a/tests/osmux/osmux_input_test.c +++ b/tests/osmux/osmux_input_test.c @@ -346,6 +346,74 @@ static void test_last_amr_cmr_f_q_used(void) osmux_xfrm_input_fini(&h_input); } +static void test_initial_osmux_seqnum_osmux_deliver_cb(struct msgb *batch_msg, void *data) +{ + struct osmux_hdr *osmuxh; + char buf[2048]; + bool *osmux_transmitted = (bool *)data; + + osmux_snprintf(buf, sizeof(buf), batch_msg); + clock_debug("OSMUX message (len=%d): %s\n", batch_msg->len, buf); + + /* We expect 1 batch: */ + osmuxh = osmux_xfrm_output_pull(batch_msg); + /* Check seqnum is the one configured beforehand: */ + OSMO_ASSERT(osmuxh->seq == 123); + + osmuxh = osmux_xfrm_output_pull(batch_msg); + OSMO_ASSERT(osmuxh == NULL); + + msgb_free(batch_msg); + + *osmux_transmitted = true; +} +/* Test that the first transmitted osmux header is set according to what has been configured. */ +static void test_initial_osmux_seqnum(void) +{ + struct msgb *msg; + int rc; + const uint8_t cid = 33; + bool osmux_transmitted = false; + struct amr_hdr *amrh; + + printf("===%s===\n", __func__); + + + + clock_override_enable(true); + clock_override_set(0, 0); + rtp_init(0, 0); + + struct osmux_in_handle h_input = { + .osmux_seq = 123, /* sequence number to start OSmux message from */ + .batch_factor = 1, /* batch up to 1 RTP messages */ + .deliver = test_initial_osmux_seqnum_osmux_deliver_cb, + .data = &osmux_transmitted, + }; + + osmux_xfrm_input_init(&h_input); + osmux_xfrm_input_open_circuit(&h_input, cid, false); + + /* First RTP frame at t=0 */ + msg = rtp_next(); + amrh = rtp_append_amr(msg, AMR_FT_2); + amrh->f = 1; + amrh->q = 1; + amrh->cmr = 0; + rc = osmux_xfrm_input(&h_input, msg, cid); + OSMO_ASSERT(rc == 0); + + /* t=20, osmux batch is scheduled to be transmitted: */ + clock_debug("Submit 2nd RTP packet, CMR changes"); + clock_override_add(0, TIME_RTP_PKT_MS*1000); + osmo_select_main(0); + OSMO_ASSERT(osmux_transmitted == true); + + clock_debug("Closing circuit"); + osmux_xfrm_input_close_circuit(&h_input, cid); + osmux_xfrm_input_fini(&h_input); +} + int main(int argc, char **argv) { @@ -365,6 +433,7 @@ int main(int argc, char **argv) test_amr_ft_change_middle_batch(); test_last_amr_cmr_f_q_used(); + test_initial_osmux_seqnum(); fprintf(stdout, "OK: Test passed\n"); return EXIT_SUCCESS; diff --git a/tests/osmux/osmux_input_test.ok b/tests/osmux/osmux_input_test.ok index 0464fd4..60daf26 100644 --- a/tests/osmux/osmux_input_test.ok +++ b/tests/osmux/osmux_input_test.ok @@ -21,4 +21,11 @@ sys={0.060000}, mono={0.060000}: Osmux frame should now be transmitted sys={0.060000}, mono={0.060000}: OSMUX message (len=49): OSMUX seq=000 ccid=032 ft=1 rtp_m=0 ctr=2 amr_f=0 amr_q=0 amr_ft=02 amr_cmr=02 [ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] sys={0.060000}, mono={0.060000}: Closing circuit +===test_initial_osmux_seqnum=== +sys={0.000000}, mono={0.000000}: clock_override_set +sys={0.000000}, mono={0.000000}: Submit 2nd RTP packet, CMR changes +sys={0.020000}, mono={0.020000}: clock_override_add +sys={0.020000}, mono={0.020000}: OSMUX message (len=19): OSMUX seq=123 ccid=033 ft=1 rtp_m=0 ctr=0 amr_f=1 amr_q=1 amr_ft=02 amr_cmr=00 [ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] + +sys={0.020000}, mono={0.020000}: Closing circuit OK: Test passed |