pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-netif/+/29529 )
Change subject: osmux: Replace deprecated osmux_xfrm_input_* APIs in examples & tests
......................................................................
osmux: Replace deprecated osmux_xfrm_input_* APIs in examples & tests
Change-Id: I7f3f8d40f89ffdd135a73316ee60fd429ba2a5b0
---
M examples/osmux-test-input.c
M tests/osmo-pcap-test/osmux_test.c
M tests/osmux/osmux_input_test.c
M tests/osmux/osmux_test.c
4 files changed, 81 insertions(+), 81 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
diff --git a/examples/osmux-test-input.c b/examples/osmux-test-input.c
index 57e199c..d91ee15 100644
--- a/examples/osmux-test-input.c
+++ b/examples/osmux-test-input.c
@@ -83,11 +83,7 @@
* This is the input handle for osmux. It stores the last osmux sequence that
* has been used and the deliver function that sends the osmux batch.
*/
-struct osmux_in_handle h_input = {
- .osmux_seq = 0, /* sequence number to start OSmux message from */
- .batch_factor = 4, /* batch up to 4 RTP messages */
- .deliver = osmux_deliver,
-};
+struct osmux_in_handle *h_input;
#define MAX_CONCURRENT_CALLS 8
@@ -165,9 +161,9 @@
if (ccid < 0)
register_ccid(rtph->ssrc);
- while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 0) {
+ while ((ret = osmux_xfrm_input(h_input, msg, ccid)) > 0) {
/* batch full, deliver it */
- osmux_xfrm_input_deliver(&h_input);
+ osmux_xfrm_input_deliver(h_input);
}
if (ret == -1)
printf("something is wrong\n");
@@ -217,7 +213,10 @@
/*
* initialize OSMUX handlers.
*/
- osmux_xfrm_input_init(&h_input);
+ h_input = osmux_xfrm_input_alloc(tall_test);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 4);
+ osmux_xfrm_input_set_deliver_cb(h_input, osmux_deliver, NULL);
/*
* initialize datagram server.
diff --git a/tests/osmo-pcap-test/osmux_test.c b/tests/osmo-pcap-test/osmux_test.c
index bbb395c..891743a 100644
--- a/tests/osmo-pcap-test/osmux_test.c
+++ b/tests/osmo-pcap-test/osmux_test.c
@@ -65,11 +65,7 @@
* This is the input handle for osmux. It stores the last osmux sequence that
* has been used and the deliver function that sends the osmux batch.
*/
-struct osmux_in_handle h_input = {
- .osmux_seq = 0, /* sequence number to start OSmux message from */
- .batch_factor = 4, /* batch up to 4 RTP messages */
- .deliver = deliver,
-};
+struct osmux_in_handle *h_input;
#define MAX_CONCURRENT_CALLS 8
@@ -124,9 +120,9 @@
if (ccid < 0)
register_ccid(rtph->ssrc);
- while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 0) {
+ while ((ret = osmux_xfrm_input(h_input, msg, ccid)) > 0) {
/* batch full, deliver it */
- osmux_xfrm_input_deliver(&h_input);
+ osmux_xfrm_input_deliver(h_input);
}
if (ret == -1)
printf("something is wrong\n");
@@ -189,7 +185,10 @@
osmo_pcap.timer.cb = osmo_pcap_pkt_timer_cb;
- osmux_xfrm_input_init(&h_input);
+ h_input = osmux_xfrm_input_alloc(tall_test);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 4);
+ osmux_xfrm_input_set_deliver_cb(h_input, deliver, NULL);
h_output = osmux_xfrm_output_alloc(tall_test);
osmux_xfrm_output_set_rtp_ssrc(h_output, 0);
diff --git a/tests/osmux/osmux_input_test.c b/tests/osmux/osmux_input_test.c
index 5a311c8..8645929 100644
--- a/tests/osmux/osmux_input_test.c
+++ b/tests/osmux/osmux_input_test.c
@@ -33,6 +33,8 @@
static uint16_t rtp_next_seq;
static uint16_t rtp_next_ts;
+void *tall_ctx;
+
#define TIME_RTP_PKT_MS 20
#define BATCH_FACTOR 6
/* ----------------------------- */
@@ -194,6 +196,7 @@
int rc;
const uint8_t cid = 30;
bool osmux_transmitted = false;
+ struct osmux_in_handle *h_input;
printf("===%s===\n", __func__);
@@ -202,27 +205,25 @@
clock_override_set(0, 0);
rtp_init(0, 0);
- struct osmux_in_handle h_input = {
- .osmux_seq = 0, /* sequence number to start OSmux message from */
- .batch_factor = 4, /* batch up to 4 RTP messages */
- .deliver = test_amr_ft_change_middle_batch_osmux_deliver_cb,
- .data = &osmux_transmitted,
- };
-
- osmux_xfrm_input_init(&h_input);
- osmux_xfrm_input_open_circuit(&h_input, cid, false);
+ h_input = osmux_xfrm_input_alloc(tall_ctx);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 4);
+ osmux_xfrm_input_set_deliver_cb(h_input,
+ test_amr_ft_change_middle_batch_osmux_deliver_cb,
+ &osmux_transmitted);
+ osmux_xfrm_input_open_circuit(h_input, cid, false);
/* First RTP frame at t=0 */
msg = rtp_next();
rtp_append_amr(msg, AMR_FT_2);
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* Second RTP frame at t=20 */
clock_override_add(0, TIME_RTP_PKT_MS*1000);
msg = rtp_next();
rtp_append_amr(msg, AMR_FT_2);
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* Third RTP frame at t=40, AMR FT changes: */
@@ -230,7 +231,7 @@
clock_override_add(0, TIME_RTP_PKT_MS*1000);
msg = rtp_next();
rtp_append_amr(msg, AMR_FT_6);
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* Forth RTP frame at t=60, AMR FT changes again: */
@@ -238,7 +239,7 @@
clock_override_add(0, TIME_RTP_PKT_MS*1000);
msg = rtp_next();
rtp_append_amr(msg, AMR_FT_1);
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* t=80, osmux batch is scheduled to be transmitted: */
@@ -248,8 +249,8 @@
OSMO_ASSERT(osmux_transmitted == true);
clock_debug("Closing circuit");
- osmux_xfrm_input_close_circuit(&h_input, cid);
- osmux_xfrm_input_fini(&h_input);
+ osmux_xfrm_input_close_circuit(h_input, cid);
+ talloc_free(h_input);
}
static void test_last_amr_cmr_f_q_used_osmux_deliver_cb(struct msgb *batch_msg, void
*data)
@@ -285,6 +286,7 @@
const uint8_t cid = 32;
bool osmux_transmitted = false;
struct amr_hdr *amrh;
+ struct osmux_in_handle *h_input;
printf("===%s===\n", __func__);
@@ -294,15 +296,13 @@
clock_override_set(0, 0);
rtp_init(0, 0);
- struct osmux_in_handle h_input = {
- .osmux_seq = 0, /* sequence number to start OSmux message from */
- .batch_factor = 3, /* batch up to 3 RTP messages */
- .deliver = test_last_amr_cmr_f_q_used_osmux_deliver_cb,
- .data = &osmux_transmitted,
- };
-
- osmux_xfrm_input_init(&h_input);
- osmux_xfrm_input_open_circuit(&h_input, cid, false);
+ h_input = osmux_xfrm_input_alloc(tall_ctx);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 3);
+ osmux_xfrm_input_set_deliver_cb(h_input,
+ test_last_amr_cmr_f_q_used_osmux_deliver_cb,
+ &osmux_transmitted);
+ osmux_xfrm_input_open_circuit(h_input, cid, false);
/* First RTP frame at t=0 */
msg = rtp_next();
@@ -310,7 +310,7 @@
amrh->f = 1;
amrh->q = 1;
amrh->cmr = 0;
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* Second RTP frame at t=20, CMR changes 0->1 */
@@ -321,7 +321,7 @@
amrh->f = 1;
amrh->q = 1;
amrh->cmr = 1;
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* Third RTP frame at t=40, q changes 1->0, CMR changes 1->2: */
@@ -332,7 +332,7 @@
amrh->f = 0;
amrh->q = 0;
amrh->cmr = 2;
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* t=60, osmux batch is scheduled to be transmitted: */
@@ -342,8 +342,8 @@
OSMO_ASSERT(osmux_transmitted == true);
clock_debug("Closing circuit");
- osmux_xfrm_input_close_circuit(&h_input, cid);
- osmux_xfrm_input_fini(&h_input);
+ osmux_xfrm_input_close_circuit(h_input, cid);
+ talloc_free(h_input);
}
static void test_initial_osmux_seqnum_osmux_deliver_cb(struct msgb *batch_msg, void
*data)
@@ -375,6 +375,7 @@
const uint8_t cid = 33;
bool osmux_transmitted = false;
struct amr_hdr *amrh;
+ struct osmux_in_handle *h_input;
printf("===%s===\n", __func__);
@@ -384,15 +385,13 @@
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);
+ h_input = osmux_xfrm_input_alloc(tall_ctx);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 123);
+ osmux_xfrm_input_set_batch_factor(h_input, 1);
+ osmux_xfrm_input_set_deliver_cb(h_input,
+ test_initial_osmux_seqnum_osmux_deliver_cb,
+ &osmux_transmitted);
+ osmux_xfrm_input_open_circuit(h_input, cid, false);
/* First RTP frame at t=0 */
msg = rtp_next();
@@ -400,7 +399,7 @@
amrh->f = 1;
amrh->q = 1;
amrh->cmr = 0;
- rc = osmux_xfrm_input(&h_input, msg, cid);
+ rc = osmux_xfrm_input(h_input, msg, cid);
OSMO_ASSERT(rc == 0);
/* t=20, osmux batch is scheduled to be transmitted: */
@@ -410,8 +409,8 @@
OSMO_ASSERT(osmux_transmitted == true);
clock_debug("Closing circuit");
- osmux_xfrm_input_close_circuit(&h_input, cid);
- osmux_xfrm_input_fini(&h_input);
+ osmux_xfrm_input_close_circuit(h_input, cid);
+ talloc_free(h_input);
}
int main(int argc, char **argv)
@@ -422,7 +421,7 @@
exit(EXIT_FAILURE);
}
- void *tall_ctx = talloc_named_const(NULL, 1, "Root context");
+ tall_ctx = talloc_named_const(NULL, 1, "Root context");
msgb_talloc_ctx_init(tall_ctx, 0);
osmo_init_logging2(tall_ctx, &log_info);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
index d6b7040..8edb3fd 100644
--- a/tests/osmux/osmux_test.c
+++ b/tests/osmux/osmux_test.c
@@ -120,11 +120,7 @@
msgb_free(batch_msg);
}
-struct osmux_in_handle h_input = {
- .osmux_seq = 0, /* sequence number to start OSmux message from */
- .batch_factor = 4, /* batch up to 4 RTP messages */
- .deliver = osmux_deliver,
-};
+struct osmux_in_handle *h_input;
static void sigalarm_handler(int foo)
{
@@ -161,8 +157,8 @@
}
rtp_pkts++;
- while (osmux_xfrm_input(&h_input, msg, j) > 0) {
- osmux_xfrm_input_deliver(&h_input);
+ while (osmux_xfrm_input(h_input, msg, j) > 0) {
+ osmux_xfrm_input_deliver(h_input);
}
}
clock_override_add(0, PKT_TIME_USEC);
@@ -215,13 +211,13 @@
* gaps between two messages to test the osmux replaying
* feature.
*/
- osmux_xfrm_input(&h_input, msg, (i % 2) + ccid);
+ osmux_xfrm_input(h_input, msg, (i % 2) + ccid);
if (i % 4 == 0) {
/* After four RTP messages, squash them into the OSMUX
* batch and call the routine to deliver it.
*/
- osmux_xfrm_input_deliver(&h_input);
+ osmux_xfrm_input_deliver(h_input);
/* The first two RTP message (one per circuit ID batch)
* are delivered immediately, wait until the three RTP
@@ -280,22 +276,29 @@
alarm(10);
/* Check if marker bit features work correctly */
- osmux_xfrm_input_init(&h_input);
+ h_input = osmux_xfrm_input_alloc(tall_ctx);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 4);
+ osmux_xfrm_input_set_deliver_cb(h_input, osmux_deliver, NULL);
+
for (i = 0; i < 4; i++)
- osmux_xfrm_input_open_circuit(&h_input, i, 0);
+ osmux_xfrm_input_open_circuit(h_input, i, 0);
osmux_test_marker(4);
for (i = 0; i < 4; i++)
- osmux_xfrm_input_close_circuit(&h_input, i);
- osmux_xfrm_input_fini(&h_input);
+ osmux_xfrm_input_close_circuit(h_input, i);
+ TALLOC_FREE(h_input);
- osmux_xfrm_input_init(&h_input);
+ h_input = osmux_xfrm_input_alloc(tall_ctx);
+ osmux_xfrm_input_set_initial_seqnum(h_input, 0);
+ osmux_xfrm_input_set_batch_factor(h_input, 4);
+ osmux_xfrm_input_set_deliver_cb(h_input, osmux_deliver, NULL);
for (i = 0; i < 2; i++)
- osmux_xfrm_input_open_circuit(&h_input, i, 0);
+ osmux_xfrm_input_open_circuit(h_input, i, 0);
/* Add two circuits with dummy padding */
- osmux_xfrm_input_open_circuit(&h_input, 2, 1);
- osmux_xfrm_input_open_circuit(&h_input, 3, 1);
+ osmux_xfrm_input_open_circuit(h_input, 2, 1);
+ osmux_xfrm_input_open_circuit(h_input, 3, 1);
/* Wait 10 times to make sure dummy padding timer works fine */
for (i = 0; i < 10; i++)
@@ -309,16 +312,16 @@
osmux_test_loop(2);
for (i = 0; i < 4; i++)
- osmux_xfrm_input_close_circuit(&h_input, i);
+ osmux_xfrm_input_close_circuit(h_input, i);
/* Reopen with two circuits and retest */
- osmux_xfrm_input_open_circuit(&h_input, 0, 0);
- osmux_xfrm_input_open_circuit(&h_input, 1, 1);
+ osmux_xfrm_input_open_circuit(h_input, 0, 0);
+ osmux_xfrm_input_open_circuit(h_input, 1, 1);
osmux_test_loop(0);
- osmux_xfrm_input_close_circuit(&h_input, 0);
- osmux_xfrm_input_close_circuit(&h_input, 1);
+ osmux_xfrm_input_close_circuit(h_input, 0);
+ osmux_xfrm_input_close_circuit(h_input, 1);
- osmux_xfrm_input_fini(&h_input);
+ TALLOC_FREE(h_input);
for (i = 0; i < ARRAY_SIZE(h_output); i++) {
clock_debug("Flushing CID %u\n", i);
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-netif/+/29529
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I7f3f8d40f89ffdd135a73316ee60fd429ba2a5b0
Gerrit-Change-Number: 29529
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged