osmux: Replace deprecated osmux_xfrm_input_* APIs in examples & tests
Change-Id: I7f3f8d40f89ffdd135a73316ee60fd429ba2a5b0
This commit is contained in:
parent
36ca79e708
commit
6fe1f35001
|
@ -83,11 +83,7 @@ static void osmux_deliver(struct msgb *batch_msg, void *data)
|
|||
* 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 @@ int read_cb(struct osmo_dgram *conn)
|
|||
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 @@ int main(int argc, char *argv[])
|
|||
/*
|
||||
* 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.
|
||||
|
|
|
@ -65,11 +65,7 @@ static void deliver(struct msgb *batch_msg)
|
|||
* 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 @@ static int pcap_test_run(struct msgb *msg)
|
|||
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 @@ int main(int argc, char *argv[])
|
|||
|
||||
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);
|
||||
|
|
|
@ -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 @@ static void test_amr_ft_change_middle_batch(void)
|
|||
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 @@ static void test_amr_ft_change_middle_batch(void)
|
|||
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 @@ static void test_amr_ft_change_middle_batch(void)
|
|||
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 @@ static void test_amr_ft_change_middle_batch(void)
|
|||
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 @@ static void test_amr_ft_change_middle_batch(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_last_amr_cmr_f_q_used(void)
|
|||
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 @@ static void test_initial_osmux_seqnum(void)
|
|||
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 @@ static void test_initial_osmux_seqnum(void)
|
|||
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 @@ static void test_initial_osmux_seqnum(void)
|
|||
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 @@ static void test_initial_osmux_seqnum(void)
|
|||
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 @@ int main(int argc, char **argv)
|
|||
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);
|
||||
|
|
|
@ -120,11 +120,7 @@ static void osmux_deliver(struct msgb *batch_msg, void *data)
|
|||
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 @@ static void osmux_test_marker(int num_ccid)
|
|||
}
|
||||
|
||||
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 @@ static void osmux_test_loop(int ccid)
|
|||
* 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 @@ int main(void)
|
|||
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 @@ int main(void)
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue