From 5654c43f80a48b99bdbd5179d87f9b1a5cf55fa4 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 20 Oct 2012 20:10:31 +0200 Subject: [PATCH] osmux: remove generic functions to register and get ccid Remove these functions: - osmux_xfrm_input_get_ccid - osmux_xfrm_input_register_ccid The ccid will be managed by the BSC and it will be stored in the mgcp_endpoint structure. Also adjust all tests and examples using the API. --- examples/osmux-test-input.c | 51 +++++++++++++++++++++--- include/osmocom/netif/osmux.h | 4 +- src/osmux.c | 65 ++++++------------------------- tests/osmo-pcap-test/osmux_test.c | 49 +++++++++++++++++++++-- 4 files changed, 104 insertions(+), 65 deletions(-) diff --git a/examples/osmux-test-input.c b/examples/osmux-test-input.c index 3203b4d..67996ad 100644 --- a/examples/osmux-test-input.c +++ b/examples/osmux-test-input.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -84,11 +85,51 @@ struct osmux_in_handle h_input = { .deliver = osmux_deliver, }; +#define MAX_CONCURRENT_CALLS 8 + +static int ccid[MAX_CONCURRENT_CALLS]; + +static int get_ccid(uint32_t ssrc) +{ + int i, found = 0; + + for (i=0; ipayload_type == RTP_PT_AMR) amr_write(msg); - /* now build the osmux frame */ - if (osmux_xfrm_input_get_ccid(&h_input, rtph->ssrc) < 0) - osmux_xfrm_input_register_ccid(&h_input, rtph->ssrc); + ccid = get_ccid(rtph->ssrc); + if (ccid < 0) + register_ccid(rtph->ssrc); - while ((ret = osmux_xfrm_input(&h_input, msg)) > 0) { + while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 0) { /* batch full, deliver it */ osmux_xfrm_input_deliver(&h_input); } diff --git a/include/osmocom/netif/osmux.h b/include/osmocom/netif/osmux.h index f52fcb4..7865e50 100644 --- a/include/osmocom/netif/osmux.h +++ b/include/osmocom/netif/osmux.h @@ -61,10 +61,8 @@ static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh) } void osmux_xfrm_input_init(struct osmux_in_handle *h); -int osmux_xfrm_input_get_ccid(struct osmux_in_handle *h, uint32_t ssrc); -void osmux_xfrm_input_register_ccid(struct osmux_in_handle *h, uint32_t ssrc); -int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg); +int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid); void osmux_xfrm_input_deliver(struct osmux_in_handle *h); void osmux_xfrm_output_init(struct osmux_out_handle *h); diff --git a/src/osmux.c b/src/osmux.c index 4ac1975..206cdd0 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -138,14 +138,13 @@ struct osmux_batch { struct llist_head node_list; unsigned int remaining_bytes; uint8_t seq; - int64_t ccid[OSMUX_MAX_CONCURRENT_CALLS]; }; static int -osmux_batch_add(struct osmux_in_handle *h, struct msgb *out_msg, +osmux_batch_put(struct osmux_in_handle *h, struct msgb *out_msg, struct msgb *msg, struct rtp_hdr *rtph, struct amr_hdr *amrh, uint32_t amr_payload_len, - int add_osmux_header) + int ccid, int add_osmux_header) { struct osmux_batch *batch = (struct osmux_batch *)h->data; struct osmux_hdr *osmuxh; @@ -157,7 +156,7 @@ osmux_batch_add(struct osmux_in_handle *h, struct msgb *out_msg, osmuxh->amr_f = amrh->f; osmuxh->amr_q= amrh->q; osmuxh->seq = batch->seq++; - osmuxh->circuit_id = osmux_xfrm_input_get_ccid(h, rtph->ssrc); + osmuxh->circuit_id = ccid; osmuxh->amr_cmr = amrh->cmr; osmuxh->amr_ft = amrh->ft; msgb_put(out_msg, sizeof(struct osmux_hdr)); @@ -184,7 +183,7 @@ static int osmux_xfrm_encode_amr(struct osmux_in_handle *h, struct msgb *out_msg, struct rtp_hdr *rtph, struct msgb *msg, - int add_osmux_header) + int ccid, int add_osmux_header) { struct amr_hdr *amrh; uint32_t amr_len; @@ -196,8 +195,8 @@ osmux_xfrm_encode_amr(struct osmux_in_handle *h, amr_payload_len = amr_len - sizeof(struct amr_hdr); - if (osmux_batch_add(h, out_msg, msg, rtph, amrh, amr_payload_len, - add_osmux_header) < 0) + if (osmux_batch_put(h, out_msg, msg, rtph, amrh, amr_payload_len, + ccid, add_osmux_header) < 0) return -1; return 0; @@ -206,6 +205,7 @@ osmux_xfrm_encode_amr(struct osmux_in_handle *h, struct batch_list_node { struct llist_head head; uint32_t ssrc; + int ccid; struct llist_head list; }; @@ -245,7 +245,7 @@ static struct msgb *osmux_build_batch(struct osmux_in_handle *h) } osmux_xfrm_encode_amr(h, batch_msg, rtph, cur, - add_osmux_hdr); + node->ccid, add_osmux_hdr); llist_del(&cur->list); msgb_free(cur); ctr++; @@ -289,7 +289,7 @@ static int osmux_rtp_amr_payload_len(struct msgb *msg, struct rtp_hdr *rtph) } static int -osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg) +osmux_batch_add(struct osmux_batch *batch, struct msgb *msg, int ccid) { struct rtp_hdr *rtph; struct batch_list_node *node; @@ -342,6 +342,7 @@ osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg) if (node == NULL) return 0; + node->ccid = ccid; node->ssrc = rtph->ssrc; INIT_LLIST_HEAD(&node->list); llist_add_tail(&node->head, &batch->node_list); @@ -365,7 +366,7 @@ osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg) * an error occured and we have skipped the message. If 1 is returned, you * have to invoke osmux_xfrm_input_deliver and try again. */ -int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg) +int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid) { int ret; struct rtp_hdr *rtph; @@ -389,7 +390,7 @@ int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg) osmo_timer_schedule(&batch->timer, 0, h->batch_factor * DELTA_RTP_MSG); } - ret = osmux_msgb_batch_queue_add(batch, msg); + ret = osmux_batch_add(batch, msg, ccid); break; default: /* Only AMR supported so far, sorry. */ @@ -402,7 +403,6 @@ int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg) void osmux_xfrm_input_init(struct osmux_in_handle *h) { struct osmux_batch *batch; - int i; LOGP(DLMIB, LOGL_DEBUG, "initialized osmux input converter\n"); @@ -415,9 +415,6 @@ void osmux_xfrm_input_init(struct osmux_in_handle *h) batch->timer.cb = osmux_batch_timer_expired; batch->timer.data = h; - for (i=0; iccid[i] = -1; - h->data = (void *)batch; } @@ -500,44 +497,6 @@ osmux_tx_sched(struct llist_head *list, } } -void osmux_xfrm_input_register_ccid(struct osmux_in_handle *h, uint32_t ssrc) -{ - struct osmux_batch *batch = (struct osmux_batch *)h->data;; - int i, found = 0; - - for (i=0; iccid[i] == ssrc) - continue; - if (batch->ccid[i] < 0) { - found = 1; - break; - } - } - - if (found) { - batch->ccid[i] = ssrc; - LOGP(DLMIB, LOGL_DEBUG, "mapping ssrc=%u to ccid=%d\n", - ntohl(ssrc), i); - } else { - LOGP(DLMIB, LOGL_ERROR, "cannot map ssrc to ccid!\n"); - } -} - -int osmux_xfrm_input_get_ccid(struct osmux_in_handle *h, uint32_t ssrc) -{ - struct osmux_batch *batch = (struct osmux_batch *)h->data;; - int i, found = 0; - - for (i=0; iccid[i] == ssrc) { - found = 1; - break; - } - } - - return found ? i : -1; -} - void osmux_xfrm_output_init(struct osmux_out_handle *h) { int i; diff --git a/tests/osmo-pcap-test/osmux_test.c b/tests/osmo-pcap-test/osmux_test.c index 96cb478..4554430 100644 --- a/tests/osmo-pcap-test/osmux_test.c +++ b/tests/osmo-pcap-test/osmux_test.c @@ -73,19 +73,60 @@ struct osmux_in_handle h_input = { .deliver = deliver, }; +#define MAX_CONCURRENT_CALLS 8 + +static int ccid[MAX_CONCURRENT_CALLS]; + +static void register_ccid(uint32_t ssrc) +{ + int i, found = 0; + + for (i=0; issrc) < 0) - osmux_xfrm_input_register_ccid(&h_input, rtph->ssrc); + ccid = get_ccid(&h_input, rtph->ssrc); + if (ccid < 0) + register_ccid(&h_input, rtph->ssrc); - while ((ret = osmux_xfrm_input(&h_input, msg)) > 1) { + while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 1) { /* batch full, deliver it */ osmux_xfrm_input_deliver(&h_input); }