lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

September 2022

  • 2 participants
  • 1860 discussions
Change in libosmo-netif[master]: osmux: Split input and output code into separate files
by pespin 29 Sep '22

29 Sep '22
Attention is currently required from: pespin. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29524 ) Change subject: osmux: Split input and output code into separate files ...................................................................... Patch Set 1: Verified+1 (1 comment) Patchset: PS1: I'll fix all these linter errors as a follow up patch, in here I'm just copying stuff over. -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29524 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5 Gerrit-Change-Number: 29524 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 29 Sep 2022 11:01:00 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in libosmo-netif[master]: osmux: Split input and output code into separate files
by Jenkins Builder 29 Sep '22

29 Sep '22
Jenkins Builder has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29524 ) Change subject: osmux: Split input and output code into separate files ...................................................................... Patch Set 1: (7 comments) File src/osmux_input.c: Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/bcb7c216_ce917ff3 PS1, Line 181: osmuxh->amr_q= 0; spaces required around that '=' (ctx:VxW) Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/cbf8427e_1443446a PS1, Line 373: for (i=1; i<diff; i++) { spaces required around that '=' (ctx:VxV) Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/4f57d475_7eb937b5 PS1, Line 373: for (i=1; i<diff; i++) { spaces required around that '<' (ctx:VxV) Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/117827fb_137ffe21 PS1, Line 559: switch(rtph->payload_type) { switch and case should be at the same indent Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/d5211fcc_3a86b400 PS1, Line 559: switch(rtph->payload_type) { space required before the open parenthesis '(' File src/osmux_output.c: Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/3acfd949_18b0623d PS1, Line 206: * them for transmission at appropiate time. 'appropiate' may be misspelled - perhaps 'appropriate'? Robot Comment from checkpatch (run ID jenkins-gerrit-libosmo-netif-lint-112): https://gerrit.osmocom.org/c/libosmo-netif/+/29524/comment/1b6b9206_24ec5611 PS1, Line 255: if(was_empty && !llist_empty(&h->list)) space required before the open parenthesis '(' -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29524 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5 Gerrit-Change-Number: 29524 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-CC: Jenkins Builder Gerrit-Comment-Date: Thu, 29 Sep 2022 10:59:53 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
1 0
0 0
Change in libosmo-netif[master]: osmux: Split input and output code into separate files
by pespin 29 Sep '22

29 Sep '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29524 ) Change subject: osmux: Split input and output code into separate files ...................................................................... osmux: Split input and output code into separate files The output and input paths are totally independent, they share no code or structures holding state. They can be operated totally independently. Hence, let's split the cod einto separate file since when someone looks at the osmux code one is really looking specifically at Tx or Rx side, but not at both sides. Moreover, the "input" and "output" concepts have always been a bit difficult to understand (would have been better calling them "src" and "sink" instead), which adds more confusion when trying to find the relevant part of code. Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5 --- M src/Makefile.am M src/osmux.c A src/osmux_input.c A src/osmux_output.c 4 files changed, 1,065 insertions(+), 959 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/24/29524/1 diff --git a/src/Makefile.am b/src/Makefile.am index 60211e1..0dc9616 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,8 @@ ipa_unit.c \ jibuf.c \ osmux.c \ + osmux_input.c \ + osmux_output.c \ prim.c \ rs232.c \ rtp.c \ diff --git a/src/osmux.c b/src/osmux.c index e51e212..d3294de 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -1,7 +1,7 @@ /* * (C) 2012-2017 by Pablo Neira Ayuso <pablo(a)gnumonks.org> * (C) 2012 by On Waves ehf <http://www.on-waves.com> - * (C) 2015-2017 by sysmocom - s.f.m.c. GmbH + * (C) 2015-2022 by sysmocom - s.f.m.c. GmbH * * SPDX-License-Identifier: GPL-2.0+ * @@ -44,969 +44,11 @@ * \brief Osmocom multiplex protocol helpers */ -/* This allows you to debug osmux message transformations (spamming) */ -#if 0 -#define DEBUG_MSG 0 -#endif - -/* delta time between two RTP messages (in microseconds) */ -#define DELTA_RTP_MSG 20000 -/* delta time between two RTP messages (in samples, 8kHz) */ -#define DELTA_RTP_TIMESTAMP 160 - -static void *osmux_ctx; - static uint32_t osmux_get_payload_len(struct osmux_hdr *osmuxh) { return osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1); } -static uint32_t osmux_ft_dummy_size(uint8_t amr_ft, uint8_t batch_factor) -{ - return sizeof(struct osmux_hdr) + (osmo_amr_bytes(amr_ft) * batch_factor); -} - -struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg) -{ - struct osmux_hdr *osmuxh; -next: - osmuxh = NULL; - if (msg->len > sizeof(struct osmux_hdr)) { - size_t len; - - osmuxh = (struct osmux_hdr *)msg->data; - - switch (osmuxh->ft) { - case OSMUX_FT_VOICE_AMR: - break; - case OSMUX_FT_DUMMY: - len = osmux_ft_dummy_size(osmuxh->amr_ft, osmuxh->ctr + 1); - if (msgb_length(msg) < len) { - LOGP(DLMUX, LOGL_ERROR, "Discarding bad Dummy FT: %s\n", - osmo_hexdump(msg->data, msgb_length(msg))); - return NULL; - } - msgb_pull(msg, len); - goto next; - default: - LOGP(DLMUX, LOGL_ERROR, "Discarding unsupported Osmux FT %d\n", - osmuxh->ft); - return NULL; - } - if (!osmo_amr_ft_valid(osmuxh->amr_ft)) { - LOGP(DLMUX, LOGL_ERROR, "Discarding bad AMR FT %d\n", - osmuxh->amr_ft); - return NULL; - } - - len = osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1) + - sizeof(struct osmux_hdr); - - if (msgb_length(msg) < len) { - LOGP(DLMUX, LOGL_ERROR, - "Discarding malformed OSMUX message: %s\n", - osmo_hexdump(msg->data, msgb_length(msg))); - return NULL; - } - - msgb_pull(msg, len); - } else if (msg->len > 0) { - LOGP(DLMUX, LOGL_ERROR, - "remaining %d bytes, broken osmuxhdr?\n", msg->len); - } - - return osmuxh; -} - -static struct msgb * -osmux_rebuild_rtp(struct osmux_out_handle *h, struct osmux_hdr *osmuxh, - void *payload, int payload_len, bool first_pkt) -{ - struct msgb *prev_msg, *out_msg; - struct timespec *prev_ts, *out_ts; - struct rtp_hdr *rtph; - struct amr_hdr *amrh; - struct timespec delta = { .tv_sec = 0, .tv_nsec = DELTA_RTP_MSG*1000 }; - unsigned int msg_len = sizeof(struct rtp_hdr) + - sizeof(struct amr_hdr) + - payload_len; - - if (h->rtp_msgb_alloc_cb) { - out_msg = h->rtp_msgb_alloc_cb(h->rtp_msgb_alloc_cb_data, msg_len); - } else { - out_msg = msgb_alloc(msg_len, "osmux-rtp"); - } - if (out_msg == NULL) - return NULL; - - /* Reconstruct RTP header */ - rtph = (struct rtp_hdr *)out_msg->data; - rtph->csrc_count = 0; - rtph->extension = 0; - rtph->version = RTP_VERSION; - rtph->payload_type = h->rtp_payload_type; - /* ... emulate timestamp and ssrc */ - rtph->timestamp = htonl(h->rtp_timestamp); - rtph->sequence = htons(h->rtp_seq); - rtph->ssrc = htonl(h->rtp_ssrc); - /* rtp packet with the marker bit is always guaranteed to be the first - * one. We want to notify with marker in 2 scenarios: - * 1- Sender told us through osmux frame rtp_m. - * 2- Intermediate osmux frame lost (seq gap), otherwise rtp receiver only sees - * steady increase of delay - */ - rtph->marker = first_pkt && - (osmuxh->rtp_m || (osmuxh->seq != ((h->osmux_seq_ack + 1) & 0xff))); - - msgb_put(out_msg, sizeof(struct rtp_hdr)); - - /* Reconstruct AMR header */ - amrh = (struct amr_hdr *)out_msg->tail; - amrh->cmr = osmuxh->amr_cmr; - amrh->f = osmuxh->amr_f; - amrh->ft = osmuxh->amr_ft; - amrh->q = osmuxh->amr_q; - - msgb_put(out_msg, sizeof(struct amr_hdr)); - - /* add AMR speech data */ - memcpy(out_msg->tail, payload, payload_len); - msgb_put(out_msg, payload_len); - - /* bump last RTP sequence number and timestamp that has been used */ - h->rtp_seq++; - h->rtp_timestamp += DELTA_RTP_TIMESTAMP; - - out_ts = ((struct timespec *)&((out_msg)->cb[0])); - if (first_pkt || llist_empty(&h->list)) { - osmo_clock_gettime(CLOCK_MONOTONIC, out_ts); - } else { - prev_msg = llist_last_entry(&h->list, struct msgb, list); - prev_ts = ((struct timespec *)&((prev_msg)->cb[0])); - timespecadd(prev_ts, &delta, out_ts); - } - - return out_msg; -} - -static void osmux_xfrm_output_trigger(void *data) -{ - struct osmux_out_handle *h = data; - struct timespec delay_ts, now; - struct msgb *msg, *next; - - llist_for_each_entry_safe(msg, next, &h->list, list) { - osmo_clock_gettime(CLOCK_MONOTONIC, &now); - struct timespec *msg_ts = ((struct timespec *)&((msg)->cb[0])); - if (timespeccmp(msg_ts, &now, >)) { - timespecsub(msg_ts, &now, &delay_ts); - osmo_timer_schedule(&h->timer, - delay_ts.tv_sec, delay_ts.tv_nsec / 1000); - return; - } - - /* Transmit the rtp packet */ - llist_del(&msg->list); - if (h->tx_cb) - h->tx_cb(msg, h->data); - else - msgb_free(msg); - } -} - -/*! \brief Generate RTP packets from osmux frame AMR payload set and schedule - * them for transmission at appropiate time. - * \param[in] h the osmux out handle handling a specific CID - * \param[in] osmuxh Buffer pointing to osmux frame header structure and AMR payload - * \return Number of generated RTP packets - * - * The osmux frame passed to this function must be of the type OSMUX_FT_VOICE_AMR. - * The generated RTP packets are kept into h's internal list and sent to the - * callback configured through osmux_xfrm_output_set_tx_cb when are ready to be - * transmitted according to schedule. - */ -int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh) -{ - struct timespec now, *msg_ts; - struct msgb *msg; - int i; - bool was_empty = llist_empty(&h->list); - - if (!was_empty) { - /* If we received new data it means we are behind schedule and - * we should flush all previous quickly */ - osmo_clock_gettime(CLOCK_MONOTONIC, &now); - llist_for_each_entry(msg, &h->list, list) { - msg_ts = ((struct timespec *)&((msg)->cb[0])); - *msg_ts = now; - } - osmo_timer_schedule(&h->timer, 0, 0); - } - - for (i = 0; i < osmuxh->ctr + 1; i++) { - struct rtp_hdr *rtph; - - msg = osmux_rebuild_rtp(h, osmuxh, - osmux_get_payload(osmuxh) + - i * osmo_amr_bytes(osmuxh->amr_ft), - osmo_amr_bytes(osmuxh->amr_ft), !i); - if (msg == NULL) - continue; - - rtph = osmo_rtp_get_hdr(msg); - if (rtph == NULL) - continue; - - llist_add_tail(&msg->list, &h->list); - } - - /* Update last seen seq number: */ - h->osmux_seq_ack = osmuxh->seq; - - /* In case list is still empty after parsing messages, no need to rearm */ - if(was_empty && !llist_empty(&h->list)) - osmux_xfrm_output_trigger(h); - return i; -} - -/*! \brief Flush all scheduled RTP packets still pending to be transmitted - * \param[in] h the osmux out handle to flush - * - * This function will immediately call the transmit callback for all queued RTP - * packets, making sure the list ends up empty. It will also stop all internal - * timers to make sure the osmux_out_handle can be dropped or re-used by calling - * osmux_xfrm_output on it. - */ -void osmux_xfrm_output_flush(struct osmux_out_handle *h) -{ - struct msgb *msg, *next; - - if (osmo_timer_pending(&h->timer)) - osmo_timer_del(&h->timer); - - llist_for_each_entry_safe(msg, next, &h->list, list) { - llist_del(&msg->list); - if (h->tx_cb) - h->tx_cb(msg, h->data); - else - msgb_free(msg); - } -} - -struct osmux_batch { - struct osmo_timer_list timer; - struct osmux_hdr *osmuxh; - struct llist_head circuit_list; - unsigned int remaining_bytes; - uint32_t nmsgs; - int ndummy; -}; - -struct osmux_circuit { - struct llist_head head; - int ccid; - struct llist_head msg_list; - int nmsgs; - int dummy; - uint8_t seq; -}; - -/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ -static int osmux_batch_enqueue(struct msgb *msg, struct osmux_circuit *circuit, - uint8_t batch_factor) -{ - /* Validate amount of messages per batch. The counter field of the - * osmux header is just 3 bits long, so make sure it doesn't overflow. - */ - OSMO_ASSERT(batch_factor <= 8); - if (circuit->nmsgs >= batch_factor) { - struct rtp_hdr *rtph; - - rtph = osmo_rtp_get_hdr(msg); - if (rtph == NULL) - return -1; - - LOGP(DLMUX, LOGL_DEBUG, "Batch is full for RTP sssrc=%u\n", rtph->ssrc); - return 1; - } - - llist_add_tail(&msg->list, &circuit->msg_list); - circuit->nmsgs++; - return 0; -} - -static void osmux_batch_dequeue(struct msgb *msg, struct osmux_circuit *circuit) -{ - llist_del(&msg->list); - circuit->nmsgs--; -} - -static void osmux_circuit_del_msgs(struct osmux_batch *batch, struct osmux_circuit *circuit) -{ - struct msgb *cur, *tmp; - llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) { - osmux_batch_dequeue(cur, circuit); - msgb_free(cur); - batch->nmsgs--; - } -} - -struct osmux_input_state { - struct msgb *out_msg; - struct msgb *msg; - struct rtp_hdr *rtph; - struct amr_hdr *amrh; - uint32_t amr_payload_len; - struct osmux_circuit *circuit; - int add_osmux_hdr; -}; - -static int osmux_batch_put(struct osmux_batch *batch, - struct osmux_input_state *state) -{ - if (state->add_osmux_hdr) { - struct osmux_hdr *osmuxh; - osmuxh = (struct osmux_hdr *)msgb_put(state->out_msg, - sizeof(struct osmux_hdr)); - osmuxh->ft = OSMUX_FT_VOICE_AMR; - osmuxh->ctr = 0; - osmuxh->rtp_m = osmuxh->rtp_m || state->rtph->marker; - osmuxh->seq = state->circuit->seq++; - osmuxh->circuit_id = state->circuit->ccid; - osmuxh->amr_ft = state->amrh->ft; - - /* annotate current osmux header */ - batch->osmuxh = osmuxh; - } else { - if (batch->osmuxh->ctr == 0x7) { - LOGP(DLMUX, LOGL_ERROR, "cannot add msg=%p, " - "too many messages for this RTP ssrc=%u\n", - state->msg, state->rtph->ssrc); - return 0; - } - batch->osmuxh->ctr++; - } - /* For fields below, we only use the last included in batch and ignore any previous: */ - batch->osmuxh->amr_cmr = state->amrh->cmr; - batch->osmuxh->amr_f = state->amrh->f; - batch->osmuxh->amr_q = state->amrh->q; - - memcpy(state->out_msg->tail, osmo_amr_get_payload(state->amrh), - state->amr_payload_len); - msgb_put(state->out_msg, state->amr_payload_len); - - return 0; -} - -static void osmux_encode_dummy(struct osmux_batch *batch, uint8_t batch_factor, - struct osmux_input_state *state) -{ - struct osmux_hdr *osmuxh; - /* TODO: This should be configurable at some point. */ - uint32_t payload_size = osmux_ft_dummy_size(AMR_FT_3, batch_factor) - - sizeof(struct osmux_hdr); - - osmuxh = (struct osmux_hdr *)state->out_msg->tail; - osmuxh->ft = OSMUX_FT_DUMMY; - osmuxh->ctr = batch_factor - 1; - osmuxh->amr_f = 0; - osmuxh->amr_q= 0; - osmuxh->seq = 0; - osmuxh->circuit_id = state->circuit->ccid; - osmuxh->amr_cmr = 0; - osmuxh->amr_ft = AMR_FT_3; - msgb_put(state->out_msg, sizeof(struct osmux_hdr)); - - memset(state->out_msg->tail, 0xff, payload_size); - msgb_put(state->out_msg, payload_size); -} - -static struct msgb *osmux_build_batch(struct osmux_batch *batch, - uint32_t batch_size, uint8_t batch_factor) -{ - struct msgb *batch_msg; - struct osmux_circuit *circuit; - -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "Now building batch\n"); -#endif - - batch_msg = msgb_alloc(batch_size, "osmux"); - if (batch_msg == NULL) { - LOGP(DLMUX, LOGL_ERROR, "Not enough memory\n"); - return NULL; - } - - llist_for_each_entry(circuit, &batch->circuit_list, head) { - struct msgb *cur, *tmp; - int ctr = 0; - int prev_amr_ft; - - if (circuit->dummy) { - struct osmux_input_state state = { - .out_msg = batch_msg, - .circuit = circuit, - }; - osmux_encode_dummy(batch, batch_factor, &state); - continue; - } - - llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) { - struct osmux_input_state state = { - .msg = cur, - .out_msg = batch_msg, - .circuit = circuit, - }; - uint32_t amr_len; -#ifdef DEBUG_MSG - char buf[4096]; - - osmo_rtp_snprintf(buf, sizeof(buf), cur); - buf[sizeof(buf)-1] = '\0'; - LOGP(DLMUX, LOGL_DEBUG, "to BSC-NAT: %s\n", buf); -#endif - - state.rtph = osmo_rtp_get_hdr(cur); - if (!state.rtph) - return NULL; - state.amrh = osmo_rtp_get_payload(state.rtph, state.msg, &amr_len); - if (!state.amrh) - return NULL; - state.amr_payload_len = amr_len - sizeof(struct amr_hdr); - - if (ctr == 0) { -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "Add osmux header (First in batch)\n"); -#endif - state.add_osmux_hdr = 1; - } else if (prev_amr_ft != state.amrh->ft) { - /* If AMR FT changed, we have to generate an extra batch osmux header: */ -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "Add osmux header (New AMR FT)\n"); -#endif - state.add_osmux_hdr = 1; - } - - osmux_batch_put(batch, &state); - osmux_batch_dequeue(cur, circuit); - prev_amr_ft = state.amrh->ft; - ctr++; - msgb_free(cur); - batch->nmsgs--; - } - } - return batch_msg; -} - -void osmux_xfrm_input_deliver(struct osmux_in_handle *h) -{ - struct msgb *batch_msg; - struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; - -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "invoking delivery function\n"); -#endif - batch_msg = osmux_build_batch(batch, h->batch_size, h->batch_factor); - if (!batch_msg) - return; - h->stats.output_osmux_msgs++; - h->stats.output_osmux_bytes += batch_msg->len; - - h->deliver(batch_msg, h->data); - osmo_timer_del(&batch->timer); - batch->remaining_bytes = h->batch_size; - - if (batch->ndummy) { - osmo_timer_schedule(&batch->timer, 0, - h->batch_factor * DELTA_RTP_MSG); - } -} - -static void osmux_batch_timer_expired(void *data) -{ - struct osmux_in_handle *h = data; - -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "osmux_batch_timer_expired\n"); -#endif - osmux_xfrm_input_deliver(h); -} - -static int osmux_rtp_amr_payload_len(struct amr_hdr *amrh, uint32_t amr_len) -{ - int amr_payload_len; - - if (!osmo_amr_ft_valid(amrh->ft)) - return -1; - - amr_payload_len = amr_len - sizeof(struct amr_hdr); - - /* The AMR payload does not fit with what we expect */ - if (osmo_amr_bytes(amrh->ft) != amr_payload_len) { - LOGP(DLMUX, LOGL_ERROR, - "Bad AMR frame, expected %zd bytes, got %d bytes\n", - osmo_amr_bytes(amrh->ft), amr_len); - return -1; - } - return amr_payload_len; -} - -/* Last stored AMR FT to be added in the current osmux batch. -1 if none stored yet */ -static int osmux_circuit_get_last_stored_amr_ft(struct osmux_circuit *circuit) -{ - struct msgb *last; - struct rtp_hdr *rtph; - struct amr_hdr *amrh; - uint32_t amr_len; - /* Have we seen any RTP packet in this batch before? */ - if (llist_empty(&circuit->msg_list)) - return -1; - OSMO_ASSERT(circuit->nmsgs > 0); - - /* Get last RTP packet seen in this batch */ - last = llist_entry(circuit->msg_list.prev, struct msgb, list); - rtph = osmo_rtp_get_hdr(last); - amrh = osmo_rtp_get_payload(rtph, last, &amr_len); - if (amrh == NULL) - return -1; - return amrh->ft; - -} - -/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ -static int osmux_replay_lost_packets(struct osmux_circuit *circuit, - struct rtp_hdr *cur_rtph, int batch_factor) -{ - int16_t diff; - struct msgb *last; - struct rtp_hdr *rtph; - int i, rc; - - /* Have we seen any RTP packet in this batch before? */ - if (llist_empty(&circuit->msg_list)) - return 0; - - /* Get last RTP packet seen in this batch */ - last = llist_entry(circuit->msg_list.prev, struct msgb, list); - rtph = osmo_rtp_get_hdr(last); - if (rtph == NULL) - return -1; - - diff = ntohs(cur_rtph->sequence) - ntohs(rtph->sequence); - - /* Lifesaver: make sure bugs don't spawn lots of clones */ - if (diff > 16) - diff = 16; - - rc = 0; - /* If diff between last RTP packet seen and this one is > 1, - * then we lost several RTP packets, let's replay them. - */ - for (i=1; i<diff; i++) { - struct msgb *clone; - - /* Clone last RTP packet seen */ - clone = msgb_alloc(last->data_len, "RTP clone"); - if (!clone) - continue; - - memcpy(clone->data, last->data, last->len); - msgb_put(clone, last->len); - - /* The original RTP message has been already sanity checked. */ - rtph = osmo_rtp_get_hdr(clone); - - /* Adjust sequence number and timestamp */ - rtph->sequence = htons(ntohs(rtph->sequence) + i); - rtph->timestamp = htonl(ntohl(rtph->timestamp) + - DELTA_RTP_TIMESTAMP); - - /* No more room in this batch, skip padding with more clones */ - rc = osmux_batch_enqueue(clone, circuit, batch_factor); - if (rc != 0) { - msgb_free(clone); - return rc; - } - - LOGP(DLMUX, LOGL_ERROR, "adding cloned RTP\n"); - } - return rc; -} - -static struct osmux_circuit * -osmux_batch_find_circuit(struct osmux_batch *batch, int ccid) -{ - struct osmux_circuit *circuit; - - llist_for_each_entry(circuit, &batch->circuit_list, head) { - if (circuit->ccid == ccid) - return circuit; - } - return NULL; -} - -static void osmux_batch_del_circuit(struct osmux_batch *batch, struct osmux_circuit *circuit) -{ - if (circuit->dummy) - batch->ndummy--; - llist_del(&circuit->head); - osmux_circuit_del_msgs(batch, circuit); - talloc_free(circuit); -} - -/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ -static int -osmux_batch_add(struct osmux_batch *batch, uint32_t batch_factor, struct msgb *msg, - struct rtp_hdr *rtph, int ccid) -{ - int bytes = 0, amr_payload_len; - struct osmux_circuit *circuit; - struct msgb *cur; - int rc; - struct amr_hdr *amrh; - uint32_t amr_len; - - circuit = osmux_batch_find_circuit(batch, ccid); - if (!circuit) - return -1; - - /* We've seen the first RTP message, disable dummy padding */ - if (circuit->dummy) { - circuit->dummy = 0; - batch->ndummy--; - } - - amrh = osmo_rtp_get_payload(rtph, msg, &amr_len); - if (amrh == NULL) - return -1; - amr_payload_len = osmux_rtp_amr_payload_len(amrh, amr_len); - if (amr_payload_len < 0) { - LOGP(DLMUX, LOGL_NOTICE, "AMR payload invalid\n"); - return -1; - } - - /* Init of talkspurt (RTP M marker bit) needs to be in the first AMR slot - * of the OSMUX packet, enforce sending previous batch if required: - */ - if (rtph->marker && circuit->nmsgs != 0) - return 1; - - /* Extra validation: check if this message already exists, should not - * happen but make sure we don't propagate duplicated messages. - */ - llist_for_each_entry(cur, &circuit->msg_list, list) { - struct rtp_hdr *rtph2 = osmo_rtp_get_hdr(cur); - if (rtph2 == NULL) - return -1; - - /* Already exists message with this sequence, skip */ - if (rtph2->sequence == rtph->sequence) { - LOGP(DLMUX, LOGL_ERROR, "already exists " - "message with seq=%u, skip it\n", - rtph->sequence); - return -1; - } - } - - /* First check if there is room for this message in the batch */ - /* First in batch comes after the batch header: */ - if (circuit->nmsgs == 0) - bytes += sizeof(struct osmux_hdr); - /* If AMR FT changes in the middle of current batch a new header is - * required to adapt to size change: */ - else if (osmux_circuit_get_last_stored_amr_ft(circuit) != amrh->ft) - bytes += sizeof(struct osmux_hdr); - bytes += amr_payload_len; - - /* No room, sorry. You'll have to retry */ - if (bytes > batch->remaining_bytes) - return 1; - - /* Handle RTP packet loss scenario */ - rc = osmux_replay_lost_packets(circuit, rtph, batch_factor); - if (rc != 0) - return rc; - - /* This batch is full, force batch delivery */ - rc = osmux_batch_enqueue(msg, circuit, batch_factor); - if (rc != 0) - return rc; - -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "adding msg with ssrc=%u to batch\n", - rtph->ssrc); -#endif - - /* Update remaining room in this batch */ - batch->remaining_bytes -= bytes; - - if (batch->nmsgs == 0) { -#ifdef DEBUG_MSG - LOGP(DLMUX, LOGL_DEBUG, "osmux start timer batch\n"); -#endif - osmo_timer_schedule(&batch->timer, 0, - batch_factor * DELTA_RTP_MSG); - } - batch->nmsgs++; - - return 0; -} - -/** - * osmux_xfrm_input - add RTP message to OSmux batch - * \param msg: RTP message that you want to batch into one OSmux message - * - * If 0 is returned, this indicates that the message has been batched and the - * msgb is now owned by the osmux layer. - * If negative value is returned, an error occurred and the message has been - * dropped (and freed). - * If 1 is returned, you have to invoke osmux_xfrm_input_deliver and try again. - * - * The function takes care of releasing the messages in case of error and - * when building the batch. - */ -int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid) -{ - int ret; - struct rtp_hdr *rtph; - struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; - - /* Ignore too big RTP/RTCP messages, most likely forged. Sanity check - * to avoid a possible forever loop in the caller. - */ - if (msg->len > h->batch_size - sizeof(struct osmux_hdr)) { - LOGP(DLMUX, LOGL_NOTICE, "RTP payload too big (%u) for configured batch size (%u)\n", - msg->len, h->batch_size); - msgb_free(msg); - return -1; - } - - rtph = osmo_rtp_get_hdr(msg); - if (rtph == NULL) { - LOGP(DLMUX, LOGL_NOTICE, "msg not containing an RTP header\n"); - msgb_free(msg); - return -1; - } - - switch(rtph->payload_type) { - case RTP_PT_RTCP: - LOGP(DLMUX, LOGL_INFO, "Dropping RTCP packet\n"); - msgb_free(msg); - return 0; - default: - /* The RTP payload type is dynamically allocated, - * although we use static ones. Assume that we always - * receive AMR traffic. - */ - - /* Add this RTP to the OSMUX batch */ - ret = osmux_batch_add(batch, h->batch_factor, - msg, rtph, ccid); - if (ret < 0) { - /* Cannot put this message into the batch. - * Malformed, duplicated, OOM. Drop it and tell - * the upper layer that we have digest it. - */ - LOGP(DLMUX, LOGL_DEBUG, "Dropping RTP packet instead of adding to batch\n"); - msgb_free(msg); - return ret; - } - - h->stats.input_rtp_msgs++; - h->stats.input_rtp_bytes += msg->len; - break; - } - return ret; -} - -void osmux_xfrm_input_init(struct osmux_in_handle *h) -{ - struct osmux_batch *batch; - - /* Default to osmux packet size if not specified */ - if (h->batch_size == 0) - h->batch_size = OSMUX_BATCH_DEFAULT_MAX; - - batch = talloc_zero(osmux_ctx, struct osmux_batch); - if (batch == NULL) - return; - - INIT_LLIST_HEAD(&batch->circuit_list); - batch->remaining_bytes = h->batch_size; - osmo_timer_setup(&batch->timer, osmux_batch_timer_expired, h); - - h->internal_data = (void *)batch; - - LOGP(DLMUX, LOGL_DEBUG, "initialized osmux input converter\n"); -} - -int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, - int dummy) -{ - struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; - struct osmux_circuit *circuit; - - circuit = osmux_batch_find_circuit(batch, ccid); - if (circuit != NULL) { - LOGP(DLMUX, LOGL_ERROR, "circuit %u already exists!\n", ccid); - return -1; - } - - circuit = talloc_zero(osmux_ctx, struct osmux_circuit); - if (circuit == NULL) { - LOGP(DLMUX, LOGL_ERROR, "OOM on circuit %u\n", ccid); - return -1; - } - - circuit->ccid = ccid; - circuit->seq = h->osmux_seq; - INIT_LLIST_HEAD(&circuit->msg_list); - llist_add_tail(&circuit->head, &batch->circuit_list); - - if (dummy) { - circuit->dummy = dummy; - batch->ndummy++; - if (!osmo_timer_pending(&batch->timer)) - osmo_timer_schedule(&batch->timer, 0, - h->batch_factor * DELTA_RTP_MSG); - } - return 0; -} - -void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid) -{ - struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; - struct osmux_circuit *circuit; - - circuit = osmux_batch_find_circuit(batch, ccid); - if (circuit == NULL) { - LOGP(DLMUX, LOGL_NOTICE, "Unable to close circuit %d: Not found\n", - ccid); - return; - } - - osmux_batch_del_circuit(batch, circuit); -} - -void osmux_xfrm_input_fini(struct osmux_in_handle *h) -{ - struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; - struct osmux_circuit *circuit, *next; - - llist_for_each_entry_safe(circuit, next, &batch->circuit_list, head) - osmux_batch_del_circuit(batch, circuit); - - osmo_timer_del(&batch->timer); - talloc_free(batch); -} - -struct osmux_tx_handle { - struct osmo_timer_list timer; - struct msgb *msg; - void (*tx_cb)(struct msgb *msg, void *data); - void *data; -}; - -static int osmux_xfrm_output_talloc_destructor(struct osmux_out_handle *h) -{ - osmux_xfrm_output_flush(h); - return 0; -} - -/*! \brief Allocate a new osmux out handle - * \param[in] ctx talloc context to use when allocating the returned struct - * \return Allocated osmux out handle - * - * This object contains configuration and state to handle a specific CID in - * incoming network Osmux messages, repackaging the frames for that CID as RTP - * packets and pushing them up the protocol stack. - * Returned pointer can be freed with regular talloc_free, queue will be flushed - * and all internal data will be freed. */ -struct osmux_out_handle *osmux_xfrm_output_alloc(void *ctx) -{ - struct osmux_out_handle *h; - - h = talloc_zero(ctx, struct osmux_out_handle); - OSMO_ASSERT(h); - - h->rtp_seq = (uint16_t)random(); - h->rtp_timestamp = (uint32_t)random(); - h->rtp_ssrc = (uint32_t)random(); - h->rtp_payload_type = 98; - INIT_LLIST_HEAD(&h->list); - osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h); - - talloc_set_destructor(h, osmux_xfrm_output_talloc_destructor); - return h; -} - -/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */ -void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type) -{ - memset(h, 0, sizeof(*h)); - h->rtp_seq = (uint16_t)random(); - h->rtp_timestamp = (uint32_t)random(); - h->rtp_ssrc = rtp_ssrc; - h->rtp_payload_type = rtp_payload_type; - INIT_LLIST_HEAD(&h->list); - osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h); -} - -/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */ -void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) -{ - /* backward compatibility with old users, where 98 was harcoded in osmux_rebuild_rtp() */ - osmux_xfrm_output_init2(h, rtp_ssrc, 98); -} - -/*! \brief Set transmission callback to call when a generated RTP packet is to be transmitted - * \param[in] h the osmux out handle handling a specific CID - * \param[in] osmuxh Buffer pointing to osmux frame header structure and AMR payload - * \return Number of generated RTP packets - * - * This Function sets the callback called by the interal timer set by - * osmux_xfrm_out_sched function. - */ -void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, - void (*tx_cb)(struct msgb *msg, void *data), - void *data) -{ - h->tx_cb = tx_cb; - h->data = data; -} - -/*! \brief Set callback to call when an RTP packet to be generated is to be allocated - * \param[in] h the osmux out handle handling a specific CID - * \param[in] cb User defined msgb alloc function for generated RTP pkts - * \param[in] cb_data Opaque data pointer set by user and passed in \ref cb - * \return msgb structure to be used to fill in generated RTP pkt content - */ -void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, - rtp_msgb_alloc_cb_t cb, - void *cb_data) -{ - h->rtp_msgb_alloc_cb = cb; - h->rtp_msgb_alloc_cb_data = cb_data; -} - -/*! \brief Set SSRC of generated RTP packets from Osmux frames - * \param[in] h the osmux out handle handling a specific CID - * \param[in] rtp_ssrc the RTP SSRC to set - */ -void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc) -{ - h->rtp_ssrc = rtp_ssrc; -} - -/*! \brief Set Payload Type of generated RTP packets from Osmux frames - * \param[in] h the osmux out handle handling a specific CID - * \param[in] rtp_payload_type the RTP Payload Type to set - */ -void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type) -{ - h->rtp_payload_type = rtp_payload_type; -} - #define SNPRINTF_BUFFER_SIZE(ret, remain, offset) \ if (ret < 0) \ ret = 0; \ diff --git a/src/osmux_input.c b/src/osmux_input.c new file mode 100644 index 0000000..2b388f2 --- /dev/null +++ b/src/osmux_input.c @@ -0,0 +1,671 @@ +/* + * (C) 2012-2017 by Pablo Neira Ayuso <pablo(a)gnumonks.org> + * (C) 2012 by On Waves ehf <http://www.on-waves.com> + * (C) 2015-2022 by sysmocom - s.f.m.c. GmbH + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <stdio.h> +#include <string.h> + +#include <osmocom/core/msgb.h> +#include <osmocom/core/timer.h> +#include <osmocom/core/timer_compat.h> +#include <osmocom/core/select.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/logging.h> + +#include <osmocom/netif/amr.h> +#include <osmocom/netif/rtp.h> +#include <osmocom/netif/osmux.h> + +#include <arpa/inet.h> + +/*! \addtogroup osmux Osmocom Multiplex Protocol + * @{ + * + * This code implements a variety of utility functions related to the + * OSMUX user-plane multiplexing protocol, an efficient alternative to + * plain UDP/RTP streams for voice transport in back-haul of cellular + * networks. + * + * For information about the OSMUX protocol design, please see the + * OSMUX reference manual at + * http://ftp.osmocom.org/docs/latest/osmux-reference.pdf + */ + +/*! \file osmux_input.c + * \brief Osmocom multiplex protocol helpers (input) + */ + +/* This allows you to debug osmux message transformations (spamming) */ +#if 0 +#define DEBUG_MSG 0 +#endif + +/* delta time between two RTP messages (in microseconds) */ +#define DELTA_RTP_MSG 20000 +/* delta time between two RTP messages (in samples, 8kHz) */ +#define DELTA_RTP_TIMESTAMP 160 + +static void *osmux_ctx; + +static uint32_t osmux_ft_dummy_size(uint8_t amr_ft, uint8_t batch_factor) +{ + return sizeof(struct osmux_hdr) + (osmo_amr_bytes(amr_ft) * batch_factor); +} + +struct osmux_batch { + struct osmo_timer_list timer; + struct osmux_hdr *osmuxh; + struct llist_head circuit_list; + unsigned int remaining_bytes; + uint32_t nmsgs; + int ndummy; +}; + +struct osmux_circuit { + struct llist_head head; + int ccid; + struct llist_head msg_list; + int nmsgs; + int dummy; + uint8_t seq; +}; + +/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ +static int osmux_batch_enqueue(struct msgb *msg, struct osmux_circuit *circuit, + uint8_t batch_factor) +{ + /* Validate amount of messages per batch. The counter field of the + * osmux header is just 3 bits long, so make sure it doesn't overflow. + */ + OSMO_ASSERT(batch_factor <= 8); + if (circuit->nmsgs >= batch_factor) { + struct rtp_hdr *rtph; + + rtph = osmo_rtp_get_hdr(msg); + if (rtph == NULL) + return -1; + + LOGP(DLMUX, LOGL_DEBUG, "Batch is full for RTP sssrc=%u\n", rtph->ssrc); + return 1; + } + + llist_add_tail(&msg->list, &circuit->msg_list); + circuit->nmsgs++; + return 0; +} + +static void osmux_batch_dequeue(struct msgb *msg, struct osmux_circuit *circuit) +{ + llist_del(&msg->list); + circuit->nmsgs--; +} + +static void osmux_circuit_del_msgs(struct osmux_batch *batch, struct osmux_circuit *circuit) +{ + struct msgb *cur, *tmp; + llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) { + osmux_batch_dequeue(cur, circuit); + msgb_free(cur); + batch->nmsgs--; + } +} + +struct osmux_input_state { + struct msgb *out_msg; + struct msgb *msg; + struct rtp_hdr *rtph; + struct amr_hdr *amrh; + uint32_t amr_payload_len; + struct osmux_circuit *circuit; + int add_osmux_hdr; +}; + +static int osmux_batch_put(struct osmux_batch *batch, + struct osmux_input_state *state) +{ + if (state->add_osmux_hdr) { + struct osmux_hdr *osmuxh; + osmuxh = (struct osmux_hdr *)msgb_put(state->out_msg, + sizeof(struct osmux_hdr)); + osmuxh->ft = OSMUX_FT_VOICE_AMR; + osmuxh->ctr = 0; + osmuxh->rtp_m = osmuxh->rtp_m || state->rtph->marker; + osmuxh->seq = state->circuit->seq++; + osmuxh->circuit_id = state->circuit->ccid; + osmuxh->amr_ft = state->amrh->ft; + + /* annotate current osmux header */ + batch->osmuxh = osmuxh; + } else { + if (batch->osmuxh->ctr == 0x7) { + LOGP(DLMUX, LOGL_ERROR, "cannot add msg=%p, " + "too many messages for this RTP ssrc=%u\n", + state->msg, state->rtph->ssrc); + return 0; + } + batch->osmuxh->ctr++; + } + /* For fields below, we only use the last included in batch and ignore any previous: */ + batch->osmuxh->amr_cmr = state->amrh->cmr; + batch->osmuxh->amr_f = state->amrh->f; + batch->osmuxh->amr_q = state->amrh->q; + + memcpy(state->out_msg->tail, osmo_amr_get_payload(state->amrh), + state->amr_payload_len); + msgb_put(state->out_msg, state->amr_payload_len); + + return 0; +} + +static void osmux_encode_dummy(struct osmux_batch *batch, uint8_t batch_factor, + struct osmux_input_state *state) +{ + struct osmux_hdr *osmuxh; + /* TODO: This should be configurable at some point. */ + uint32_t payload_size = osmux_ft_dummy_size(AMR_FT_3, batch_factor) - + sizeof(struct osmux_hdr); + + osmuxh = (struct osmux_hdr *)state->out_msg->tail; + osmuxh->ft = OSMUX_FT_DUMMY; + osmuxh->ctr = batch_factor - 1; + osmuxh->amr_f = 0; + osmuxh->amr_q= 0; + osmuxh->seq = 0; + osmuxh->circuit_id = state->circuit->ccid; + osmuxh->amr_cmr = 0; + osmuxh->amr_ft = AMR_FT_3; + msgb_put(state->out_msg, sizeof(struct osmux_hdr)); + + memset(state->out_msg->tail, 0xff, payload_size); + msgb_put(state->out_msg, payload_size); +} + +static struct msgb *osmux_build_batch(struct osmux_batch *batch, + uint32_t batch_size, uint8_t batch_factor) +{ + struct msgb *batch_msg; + struct osmux_circuit *circuit; + +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "Now building batch\n"); +#endif + + batch_msg = msgb_alloc(batch_size, "osmux"); + if (batch_msg == NULL) { + LOGP(DLMUX, LOGL_ERROR, "Not enough memory\n"); + return NULL; + } + + llist_for_each_entry(circuit, &batch->circuit_list, head) { + struct msgb *cur, *tmp; + int ctr = 0; + int prev_amr_ft; + + if (circuit->dummy) { + struct osmux_input_state state = { + .out_msg = batch_msg, + .circuit = circuit, + }; + osmux_encode_dummy(batch, batch_factor, &state); + continue; + } + + llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) { + struct osmux_input_state state = { + .msg = cur, + .out_msg = batch_msg, + .circuit = circuit, + }; + uint32_t amr_len; +#ifdef DEBUG_MSG + char buf[4096]; + + osmo_rtp_snprintf(buf, sizeof(buf), cur); + buf[sizeof(buf)-1] = '\0'; + LOGP(DLMUX, LOGL_DEBUG, "to BSC-NAT: %s\n", buf); +#endif + + state.rtph = osmo_rtp_get_hdr(cur); + if (!state.rtph) + return NULL; + state.amrh = osmo_rtp_get_payload(state.rtph, state.msg, &amr_len); + if (!state.amrh) + return NULL; + state.amr_payload_len = amr_len - sizeof(struct amr_hdr); + + if (ctr == 0) { +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "Add osmux header (First in batch)\n"); +#endif + state.add_osmux_hdr = 1; + } else if (prev_amr_ft != state.amrh->ft) { + /* If AMR FT changed, we have to generate an extra batch osmux header: */ +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "Add osmux header (New AMR FT)\n"); +#endif + state.add_osmux_hdr = 1; + } + + osmux_batch_put(batch, &state); + osmux_batch_dequeue(cur, circuit); + prev_amr_ft = state.amrh->ft; + ctr++; + msgb_free(cur); + batch->nmsgs--; + } + } + return batch_msg; +} + +void osmux_xfrm_input_deliver(struct osmux_in_handle *h) +{ + struct msgb *batch_msg; + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "invoking delivery function\n"); +#endif + batch_msg = osmux_build_batch(batch, h->batch_size, h->batch_factor); + if (!batch_msg) + return; + h->stats.output_osmux_msgs++; + h->stats.output_osmux_bytes += batch_msg->len; + + h->deliver(batch_msg, h->data); + osmo_timer_del(&batch->timer); + batch->remaining_bytes = h->batch_size; + + if (batch->ndummy) { + osmo_timer_schedule(&batch->timer, 0, + h->batch_factor * DELTA_RTP_MSG); + } +} + +static void osmux_batch_timer_expired(void *data) +{ + struct osmux_in_handle *h = data; + +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "osmux_batch_timer_expired\n"); +#endif + osmux_xfrm_input_deliver(h); +} + +static int osmux_rtp_amr_payload_len(struct amr_hdr *amrh, uint32_t amr_len) +{ + int amr_payload_len; + + if (!osmo_amr_ft_valid(amrh->ft)) + return -1; + + amr_payload_len = amr_len - sizeof(struct amr_hdr); + + /* The AMR payload does not fit with what we expect */ + if (osmo_amr_bytes(amrh->ft) != amr_payload_len) { + LOGP(DLMUX, LOGL_ERROR, + "Bad AMR frame, expected %zd bytes, got %d bytes\n", + osmo_amr_bytes(amrh->ft), amr_len); + return -1; + } + return amr_payload_len; +} + +/* Last stored AMR FT to be added in the current osmux batch. -1 if none stored yet */ +static int osmux_circuit_get_last_stored_amr_ft(struct osmux_circuit *circuit) +{ + struct msgb *last; + struct rtp_hdr *rtph; + struct amr_hdr *amrh; + uint32_t amr_len; + /* Have we seen any RTP packet in this batch before? */ + if (llist_empty(&circuit->msg_list)) + return -1; + OSMO_ASSERT(circuit->nmsgs > 0); + + /* Get last RTP packet seen in this batch */ + last = llist_entry(circuit->msg_list.prev, struct msgb, list); + rtph = osmo_rtp_get_hdr(last); + amrh = osmo_rtp_get_payload(rtph, last, &amr_len); + if (amrh == NULL) + return -1; + return amrh->ft; + +} + +/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ +static int osmux_replay_lost_packets(struct osmux_circuit *circuit, + struct rtp_hdr *cur_rtph, int batch_factor) +{ + int16_t diff; + struct msgb *last; + struct rtp_hdr *rtph; + int i, rc; + + /* Have we seen any RTP packet in this batch before? */ + if (llist_empty(&circuit->msg_list)) + return 0; + + /* Get last RTP packet seen in this batch */ + last = llist_entry(circuit->msg_list.prev, struct msgb, list); + rtph = osmo_rtp_get_hdr(last); + if (rtph == NULL) + return -1; + + diff = ntohs(cur_rtph->sequence) - ntohs(rtph->sequence); + + /* Lifesaver: make sure bugs don't spawn lots of clones */ + if (diff > 16) + diff = 16; + + rc = 0; + /* If diff between last RTP packet seen and this one is > 1, + * then we lost several RTP packets, let's replay them. + */ + for (i=1; i<diff; i++) { + struct msgb *clone; + + /* Clone last RTP packet seen */ + clone = msgb_alloc(last->data_len, "RTP clone"); + if (!clone) + continue; + + memcpy(clone->data, last->data, last->len); + msgb_put(clone, last->len); + + /* The original RTP message has been already sanity checked. */ + rtph = osmo_rtp_get_hdr(clone); + + /* Adjust sequence number and timestamp */ + rtph->sequence = htons(ntohs(rtph->sequence) + i); + rtph->timestamp = htonl(ntohl(rtph->timestamp) + + DELTA_RTP_TIMESTAMP); + + /* No more room in this batch, skip padding with more clones */ + rc = osmux_batch_enqueue(clone, circuit, batch_factor); + if (rc != 0) { + msgb_free(clone); + return rc; + } + + LOGP(DLMUX, LOGL_ERROR, "adding cloned RTP\n"); + } + return rc; +} + +static struct osmux_circuit * +osmux_batch_find_circuit(struct osmux_batch *batch, int ccid) +{ + struct osmux_circuit *circuit; + + llist_for_each_entry(circuit, &batch->circuit_list, head) { + if (circuit->ccid == ccid) + return circuit; + } + return NULL; +} + +static void osmux_batch_del_circuit(struct osmux_batch *batch, struct osmux_circuit *circuit) +{ + if (circuit->dummy) + batch->ndummy--; + llist_del(&circuit->head); + osmux_circuit_del_msgs(batch, circuit); + talloc_free(circuit); +} + +/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */ +static int +osmux_batch_add(struct osmux_batch *batch, uint32_t batch_factor, struct msgb *msg, + struct rtp_hdr *rtph, int ccid) +{ + int bytes = 0, amr_payload_len; + struct osmux_circuit *circuit; + struct msgb *cur; + int rc; + struct amr_hdr *amrh; + uint32_t amr_len; + + circuit = osmux_batch_find_circuit(batch, ccid); + if (!circuit) + return -1; + + /* We've seen the first RTP message, disable dummy padding */ + if (circuit->dummy) { + circuit->dummy = 0; + batch->ndummy--; + } + + amrh = osmo_rtp_get_payload(rtph, msg, &amr_len); + if (amrh == NULL) + return -1; + amr_payload_len = osmux_rtp_amr_payload_len(amrh, amr_len); + if (amr_payload_len < 0) { + LOGP(DLMUX, LOGL_NOTICE, "AMR payload invalid\n"); + return -1; + } + + /* Init of talkspurt (RTP M marker bit) needs to be in the first AMR slot + * of the OSMUX packet, enforce sending previous batch if required: + */ + if (rtph->marker && circuit->nmsgs != 0) + return 1; + + /* Extra validation: check if this message already exists, should not + * happen but make sure we don't propagate duplicated messages. + */ + llist_for_each_entry(cur, &circuit->msg_list, list) { + struct rtp_hdr *rtph2 = osmo_rtp_get_hdr(cur); + if (rtph2 == NULL) + return -1; + + /* Already exists message with this sequence, skip */ + if (rtph2->sequence == rtph->sequence) { + LOGP(DLMUX, LOGL_ERROR, "already exists " + "message with seq=%u, skip it\n", + rtph->sequence); + return -1; + } + } + + /* First check if there is room for this message in the batch */ + /* First in batch comes after the batch header: */ + if (circuit->nmsgs == 0) + bytes += sizeof(struct osmux_hdr); + /* If AMR FT changes in the middle of current batch a new header is + * required to adapt to size change: */ + else if (osmux_circuit_get_last_stored_amr_ft(circuit) != amrh->ft) + bytes += sizeof(struct osmux_hdr); + bytes += amr_payload_len; + + /* No room, sorry. You'll have to retry */ + if (bytes > batch->remaining_bytes) + return 1; + + /* Handle RTP packet loss scenario */ + rc = osmux_replay_lost_packets(circuit, rtph, batch_factor); + if (rc != 0) + return rc; + + /* This batch is full, force batch delivery */ + rc = osmux_batch_enqueue(msg, circuit, batch_factor); + if (rc != 0) + return rc; + +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "adding msg with ssrc=%u to batch\n", + rtph->ssrc); +#endif + + /* Update remaining room in this batch */ + batch->remaining_bytes -= bytes; + + if (batch->nmsgs == 0) { +#ifdef DEBUG_MSG + LOGP(DLMUX, LOGL_DEBUG, "osmux start timer batch\n"); +#endif + osmo_timer_schedule(&batch->timer, 0, + batch_factor * DELTA_RTP_MSG); + } + batch->nmsgs++; + + return 0; +} + +/** + * osmux_xfrm_input - add RTP message to OSmux batch + * \param msg: RTP message that you want to batch into one OSmux message + * + * If 0 is returned, this indicates that the message has been batched and the + * msgb is now owned by the osmux layer. + * If negative value is returned, an error occurred and the message has been + * dropped (and freed). + * If 1 is returned, you have to invoke osmux_xfrm_input_deliver and try again. + * + * The function takes care of releasing the messages in case of error and + * when building the batch. + */ +int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid) +{ + int ret; + struct rtp_hdr *rtph; + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + + /* Ignore too big RTP/RTCP messages, most likely forged. Sanity check + * to avoid a possible forever loop in the caller. + */ + if (msg->len > h->batch_size - sizeof(struct osmux_hdr)) { + LOGP(DLMUX, LOGL_NOTICE, "RTP payload too big (%u) for configured batch size (%u)\n", + msg->len, h->batch_size); + msgb_free(msg); + return -1; + } + + rtph = osmo_rtp_get_hdr(msg); + if (rtph == NULL) { + LOGP(DLMUX, LOGL_NOTICE, "msg not containing an RTP header\n"); + msgb_free(msg); + return -1; + } + + switch(rtph->payload_type) { + case RTP_PT_RTCP: + LOGP(DLMUX, LOGL_INFO, "Dropping RTCP packet\n"); + msgb_free(msg); + return 0; + default: + /* The RTP payload type is dynamically allocated, + * although we use static ones. Assume that we always + * receive AMR traffic. + */ + + /* Add this RTP to the OSMUX batch */ + ret = osmux_batch_add(batch, h->batch_factor, + msg, rtph, ccid); + if (ret < 0) { + /* Cannot put this message into the batch. + * Malformed, duplicated, OOM. Drop it and tell + * the upper layer that we have digest it. + */ + LOGP(DLMUX, LOGL_DEBUG, "Dropping RTP packet instead of adding to batch\n"); + msgb_free(msg); + return ret; + } + + h->stats.input_rtp_msgs++; + h->stats.input_rtp_bytes += msg->len; + break; + } + return ret; +} + +void osmux_xfrm_input_init(struct osmux_in_handle *h) +{ + struct osmux_batch *batch; + + /* Default to osmux packet size if not specified */ + if (h->batch_size == 0) + h->batch_size = OSMUX_BATCH_DEFAULT_MAX; + + batch = talloc_zero(osmux_ctx, struct osmux_batch); + if (batch == NULL) + return; + + INIT_LLIST_HEAD(&batch->circuit_list); + batch->remaining_bytes = h->batch_size; + osmo_timer_setup(&batch->timer, osmux_batch_timer_expired, h); + + h->internal_data = (void *)batch; + + LOGP(DLMUX, LOGL_DEBUG, "initialized osmux input converter\n"); +} + +int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, + int dummy) +{ + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + struct osmux_circuit *circuit; + + circuit = osmux_batch_find_circuit(batch, ccid); + if (circuit != NULL) { + LOGP(DLMUX, LOGL_ERROR, "circuit %u already exists!\n", ccid); + return -1; + } + + circuit = talloc_zero(osmux_ctx, struct osmux_circuit); + if (circuit == NULL) { + LOGP(DLMUX, LOGL_ERROR, "OOM on circuit %u\n", ccid); + return -1; + } + + circuit->ccid = ccid; + circuit->seq = h->osmux_seq; + INIT_LLIST_HEAD(&circuit->msg_list); + llist_add_tail(&circuit->head, &batch->circuit_list); + + if (dummy) { + circuit->dummy = dummy; + batch->ndummy++; + if (!osmo_timer_pending(&batch->timer)) + osmo_timer_schedule(&batch->timer, 0, + h->batch_factor * DELTA_RTP_MSG); + } + return 0; +} + +void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid) +{ + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + struct osmux_circuit *circuit; + + circuit = osmux_batch_find_circuit(batch, ccid); + if (circuit == NULL) { + LOGP(DLMUX, LOGL_NOTICE, "Unable to close circuit %d: Not found\n", + ccid); + return; + } + + osmux_batch_del_circuit(batch, circuit); +} + +void osmux_xfrm_input_fini(struct osmux_in_handle *h) +{ + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + struct osmux_circuit *circuit, *next; + + llist_for_each_entry_safe(circuit, next, &batch->circuit_list, head) + osmux_batch_del_circuit(batch, circuit); + + osmo_timer_del(&batch->timer); + talloc_free(batch); +} + +/*! @} */ diff --git a/src/osmux_output.c b/src/osmux_output.c new file mode 100644 index 0000000..069bdd9 --- /dev/null +++ b/src/osmux_output.c @@ -0,0 +1,391 @@ +/* + * (C) 2012-2017 by Pablo Neira Ayuso <pablo(a)gnumonks.org> + * (C) 2012 by On Waves ehf <http://www.on-waves.com> + * (C) 2015-2022 by sysmocom - s.f.m.c. GmbH + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <stdio.h> +#include <string.h> + +#include <osmocom/core/msgb.h> +#include <osmocom/core/timer.h> +#include <osmocom/core/timer_compat.h> +#include <osmocom/core/select.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/logging.h> + +#include <osmocom/netif/amr.h> +#include <osmocom/netif/rtp.h> +#include <osmocom/netif/osmux.h> + +#include <arpa/inet.h> + +/*! \addtogroup osmux Osmocom Multiplex Protocol + * @{ + * + * This code implements a variety of utility functions related to the + * OSMUX user-plane multiplexing protocol, an efficient alternative to + * plain UDP/RTP streams for voice transport in back-haul of cellular + * networks. + * + * For information about the OSMUX protocol design, please see the + * OSMUX reference manual at + * http://ftp.osmocom.org/docs/latest/osmux-reference.pdf + */ + +/*! \file osmux_output.c + * \brief Osmocom multiplex protocol helpers (output) + */ + +/* delta time between two RTP messages (in microseconds) */ +#define DELTA_RTP_MSG 20000 +/* delta time between two RTP messages (in samples, 8kHz) */ +#define DELTA_RTP_TIMESTAMP 160 + +static uint32_t osmux_ft_dummy_size(uint8_t amr_ft, uint8_t batch_factor) +{ + return sizeof(struct osmux_hdr) + (osmo_amr_bytes(amr_ft) * batch_factor); +} + +struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg) +{ + struct osmux_hdr *osmuxh; +next: + osmuxh = NULL; + if (msg->len > sizeof(struct osmux_hdr)) { + size_t len; + + osmuxh = (struct osmux_hdr *)msg->data; + + switch (osmuxh->ft) { + case OSMUX_FT_VOICE_AMR: + break; + case OSMUX_FT_DUMMY: + len = osmux_ft_dummy_size(osmuxh->amr_ft, osmuxh->ctr + 1); + if (msgb_length(msg) < len) { + LOGP(DLMUX, LOGL_ERROR, "Discarding bad Dummy FT: %s\n", + osmo_hexdump(msg->data, msgb_length(msg))); + return NULL; + } + msgb_pull(msg, len); + goto next; + default: + LOGP(DLMUX, LOGL_ERROR, "Discarding unsupported Osmux FT %d\n", + osmuxh->ft); + return NULL; + } + if (!osmo_amr_ft_valid(osmuxh->amr_ft)) { + LOGP(DLMUX, LOGL_ERROR, "Discarding bad AMR FT %d\n", + osmuxh->amr_ft); + return NULL; + } + + len = osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1) + + sizeof(struct osmux_hdr); + + if (msgb_length(msg) < len) { + LOGP(DLMUX, LOGL_ERROR, + "Discarding malformed OSMUX message: %s\n", + osmo_hexdump(msg->data, msgb_length(msg))); + return NULL; + } + + msgb_pull(msg, len); + } else if (msg->len > 0) { + LOGP(DLMUX, LOGL_ERROR, + "remaining %d bytes, broken osmuxhdr?\n", msg->len); + } + + return osmuxh; +} + +static struct msgb * +osmux_rebuild_rtp(struct osmux_out_handle *h, struct osmux_hdr *osmuxh, + void *payload, int payload_len, bool first_pkt) +{ + struct msgb *prev_msg, *out_msg; + struct timespec *prev_ts, *out_ts; + struct rtp_hdr *rtph; + struct amr_hdr *amrh; + struct timespec delta = { .tv_sec = 0, .tv_nsec = DELTA_RTP_MSG*1000 }; + unsigned int msg_len = sizeof(struct rtp_hdr) + + sizeof(struct amr_hdr) + + payload_len; + + if (h->rtp_msgb_alloc_cb) { + out_msg = h->rtp_msgb_alloc_cb(h->rtp_msgb_alloc_cb_data, msg_len); + } else { + out_msg = msgb_alloc(msg_len, "osmux-rtp"); + } + if (out_msg == NULL) + return NULL; + + /* Reconstruct RTP header */ + rtph = (struct rtp_hdr *)out_msg->data; + rtph->csrc_count = 0; + rtph->extension = 0; + rtph->version = RTP_VERSION; + rtph->payload_type = h->rtp_payload_type; + /* ... emulate timestamp and ssrc */ + rtph->timestamp = htonl(h->rtp_timestamp); + rtph->sequence = htons(h->rtp_seq); + rtph->ssrc = htonl(h->rtp_ssrc); + /* rtp packet with the marker bit is always guaranteed to be the first + * one. We want to notify with marker in 2 scenarios: + * 1- Sender told us through osmux frame rtp_m. + * 2- Intermediate osmux frame lost (seq gap), otherwise rtp receiver only sees + * steady increase of delay + */ + rtph->marker = first_pkt && + (osmuxh->rtp_m || (osmuxh->seq != ((h->osmux_seq_ack + 1) & 0xff))); + + msgb_put(out_msg, sizeof(struct rtp_hdr)); + + /* Reconstruct AMR header */ + amrh = (struct amr_hdr *)out_msg->tail; + amrh->cmr = osmuxh->amr_cmr; + amrh->f = osmuxh->amr_f; + amrh->ft = osmuxh->amr_ft; + amrh->q = osmuxh->amr_q; + + msgb_put(out_msg, sizeof(struct amr_hdr)); + + /* add AMR speech data */ + memcpy(out_msg->tail, payload, payload_len); + msgb_put(out_msg, payload_len); + + /* bump last RTP sequence number and timestamp that has been used */ + h->rtp_seq++; + h->rtp_timestamp += DELTA_RTP_TIMESTAMP; + + out_ts = ((struct timespec *)&((out_msg)->cb[0])); + if (first_pkt || llist_empty(&h->list)) { + osmo_clock_gettime(CLOCK_MONOTONIC, out_ts); + } else { + prev_msg = llist_last_entry(&h->list, struct msgb, list); + prev_ts = ((struct timespec *)&((prev_msg)->cb[0])); + timespecadd(prev_ts, &delta, out_ts); + } + + return out_msg; +} + +static void osmux_xfrm_output_trigger(void *data) +{ + struct osmux_out_handle *h = data; + struct timespec delay_ts, now; + struct msgb *msg, *next; + + llist_for_each_entry_safe(msg, next, &h->list, list) { + osmo_clock_gettime(CLOCK_MONOTONIC, &now); + struct timespec *msg_ts = ((struct timespec *)&((msg)->cb[0])); + if (timespeccmp(msg_ts, &now, >)) { + timespecsub(msg_ts, &now, &delay_ts); + osmo_timer_schedule(&h->timer, + delay_ts.tv_sec, delay_ts.tv_nsec / 1000); + return; + } + + /* Transmit the rtp packet */ + llist_del(&msg->list); + if (h->tx_cb) + h->tx_cb(msg, h->data); + else + msgb_free(msg); + } +} + +/*! \brief Generate RTP packets from osmux frame AMR payload set and schedule + * them for transmission at appropiate time. + * \param[in] h the osmux out handle handling a specific CID + * \param[in] osmuxh Buffer pointing to osmux frame header structure and AMR payload + * \return Number of generated RTP packets + * + * The osmux frame passed to this function must be of the type OSMUX_FT_VOICE_AMR. + * The generated RTP packets are kept into h's internal list and sent to the + * callback configured through osmux_xfrm_output_set_tx_cb when are ready to be + * transmitted according to schedule. + */ +int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh) +{ + struct timespec now, *msg_ts; + struct msgb *msg; + int i; + bool was_empty = llist_empty(&h->list); + + if (!was_empty) { + /* If we received new data it means we are behind schedule and + * we should flush all previous quickly */ + osmo_clock_gettime(CLOCK_MONOTONIC, &now); + llist_for_each_entry(msg, &h->list, list) { + msg_ts = ((struct timespec *)&((msg)->cb[0])); + *msg_ts = now; + } + osmo_timer_schedule(&h->timer, 0, 0); + } + + for (i = 0; i < osmuxh->ctr + 1; i++) { + struct rtp_hdr *rtph; + + msg = osmux_rebuild_rtp(h, osmuxh, + osmux_get_payload(osmuxh) + + i * osmo_amr_bytes(osmuxh->amr_ft), + osmo_amr_bytes(osmuxh->amr_ft), !i); + if (msg == NULL) + continue; + + rtph = osmo_rtp_get_hdr(msg); + if (rtph == NULL) + continue; + + llist_add_tail(&msg->list, &h->list); + } + + /* Update last seen seq number: */ + h->osmux_seq_ack = osmuxh->seq; + + /* In case list is still empty after parsing messages, no need to rearm */ + if(was_empty && !llist_empty(&h->list)) + osmux_xfrm_output_trigger(h); + return i; +} + +/*! \brief Flush all scheduled RTP packets still pending to be transmitted + * \param[in] h the osmux out handle to flush + * + * This function will immediately call the transmit callback for all queued RTP + * packets, making sure the list ends up empty. It will also stop all internal + * timers to make sure the osmux_out_handle can be dropped or re-used by calling + * osmux_xfrm_output on it. + */ +void osmux_xfrm_output_flush(struct osmux_out_handle *h) +{ + struct msgb *msg, *next; + + if (osmo_timer_pending(&h->timer)) + osmo_timer_del(&h->timer); + + llist_for_each_entry_safe(msg, next, &h->list, list) { + llist_del(&msg->list); + if (h->tx_cb) + h->tx_cb(msg, h->data); + else + msgb_free(msg); + } +} + +struct osmux_tx_handle { + struct osmo_timer_list timer; + struct msgb *msg; + void (*tx_cb)(struct msgb *msg, void *data); + void *data; +}; + +static int osmux_xfrm_output_talloc_destructor(struct osmux_out_handle *h) +{ + osmux_xfrm_output_flush(h); + return 0; +} + +/*! \brief Allocate a new osmux out handle + * \param[in] ctx talloc context to use when allocating the returned struct + * \return Allocated osmux out handle + * + * This object contains configuration and state to handle a specific CID in + * incoming network Osmux messages, repackaging the frames for that CID as RTP + * packets and pushing them up the protocol stack. + * Returned pointer can be freed with regular talloc_free, queue will be flushed + * and all internal data will be freed. */ +struct osmux_out_handle *osmux_xfrm_output_alloc(void *ctx) +{ + struct osmux_out_handle *h; + + h = talloc_zero(ctx, struct osmux_out_handle); + OSMO_ASSERT(h); + + h->rtp_seq = (uint16_t)random(); + h->rtp_timestamp = (uint32_t)random(); + h->rtp_ssrc = (uint32_t)random(); + h->rtp_payload_type = 98; + INIT_LLIST_HEAD(&h->list); + osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h); + + talloc_set_destructor(h, osmux_xfrm_output_talloc_destructor); + return h; +} + +/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */ +void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type) +{ + memset(h, 0, sizeof(*h)); + h->rtp_seq = (uint16_t)random(); + h->rtp_timestamp = (uint32_t)random(); + h->rtp_ssrc = rtp_ssrc; + h->rtp_payload_type = rtp_payload_type; + INIT_LLIST_HEAD(&h->list); + osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h); +} + +/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */ +void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) +{ + /* backward compatibility with old users, where 98 was harcoded in osmux_rebuild_rtp() */ + osmux_xfrm_output_init2(h, rtp_ssrc, 98); +} + +/*! \brief Set transmission callback to call when a generated RTP packet is to be transmitted + * \param[in] h the osmux out handle handling a specific CID + * \param[in] osmuxh Buffer pointing to osmux frame header structure and AMR payload + * \return Number of generated RTP packets + * + * This Function sets the callback called by the interal timer set by + * osmux_xfrm_out_sched function. + */ +void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, + void (*tx_cb)(struct msgb *msg, void *data), + void *data) +{ + h->tx_cb = tx_cb; + h->data = data; +} + +/*! \brief Set callback to call when an RTP packet to be generated is to be allocated + * \param[in] h the osmux out handle handling a specific CID + * \param[in] cb User defined msgb alloc function for generated RTP pkts + * \param[in] cb_data Opaque data pointer set by user and passed in \ref cb + * \return msgb structure to be used to fill in generated RTP pkt content + */ +void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, + rtp_msgb_alloc_cb_t cb, + void *cb_data) +{ + h->rtp_msgb_alloc_cb = cb; + h->rtp_msgb_alloc_cb_data = cb_data; +} + +/*! \brief Set SSRC of generated RTP packets from Osmux frames + * \param[in] h the osmux out handle handling a specific CID + * \param[in] rtp_ssrc the RTP SSRC to set + */ +void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc) +{ + h->rtp_ssrc = rtp_ssrc; +} + +/*! \brief Set Payload Type of generated RTP packets from Osmux frames + * \param[in] h the osmux out handle handling a specific CID + * \param[in] rtp_payload_type the RTP Payload Type to set + */ +void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type) +{ + h->rtp_payload_type = rtp_payload_type; +} + +/*! @} */ -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29524 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5 Gerrit-Change-Number: 29524 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in libosmo-netif[master]: osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circu...
by fixeria 29 Sep '22

29 Sep '22
Attention is currently required from: pespin. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29523 ) Change subject: osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circuit() ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29523 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ie4c6b55827ac27bcdfbe1b14fb238f5873243000 Gerrit-Change-Number: 29523 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 29 Sep 2022 10:22:30 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in libosmo-netif[master]: osmux: Fix unwanted RTP marker bit upon rx of osmux seqnum wrap around
by pespin 29 Sep '22

29 Sep '22
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29521 ) Change subject: osmux: Fix unwanted RTP marker bit upon rx of osmux seqnum wrap around ...................................................................... osmux: Fix unwanted RTP marker bit upon rx of osmux seqnum wrap around The wrap around case was not properly considered in the condition setting the Marker bit. Let's fix it. Related: SYS#5987 Change-Id: I6e01f29a6239f930c9be2bcb2efe447e5de8fedf --- M src/osmux.c M tests/osmux/osmux_output_test.ok 2 files changed, 2 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved diff --git a/src/osmux.c b/src/osmux.c index 20b6798..ec5712d 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -156,7 +156,7 @@ * steady increase of delay */ rtph->marker = first_pkt && - (osmuxh->rtp_m || (osmuxh->seq != h->osmux_seq_ack + 1)); + (osmuxh->rtp_m || (osmuxh->seq != ((h->osmux_seq_ack + 1) & 0xff))); msgb_put(out_msg, sizeof(struct rtp_hdr)); diff --git a/tests/osmux/osmux_output_test.ok b/tests/osmux/osmux_output_test.ok index f69c0a9..f08748f 100644 --- a/tests/osmux/osmux_output_test.ok +++ b/tests/osmux/osmux_output_test.ok @@ -108,7 +108,7 @@ ===test_output_seqnum_wraparound=== sys={0.000000}, mono={0.000000}: clock_override_set sys={0.000000}, mono={0.000000}: Sending osmux frame with seqnum=0 -sys={0.000000}, mono={0.000000}: dequeue: seq=50 ts=500 M enqueued=5 +sys={0.000000}, mono={0.000000}: dequeue: seq=50 ts=500 enqueued=5 sys={0.040000}, mono={0.040000}: clock_override_add sys={0.040000}, mono={0.040000}: dequeue: seq=51 ts=660 enqueued=4 sys={0.040000}, mono={0.040000}: dequeue: seq=52 ts=820 enqueued=3 2 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/+/29521 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: I6e01f29a6239f930c9be2bcb2efe447e5de8fedf Gerrit-Change-Number: 29521 Gerrit-PatchSet: 3 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
1 0
0 0
Change in libosmo-netif[master]: tests/osmux: Properly flush and free out_handle in osmux_test
by pespin 29 Sep '22

29 Sep '22
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29519 ) Change subject: tests/osmux: Properly flush and free out_handle in osmux_test ...................................................................... tests/osmux: Properly flush and free out_handle in osmux_test Change-Id: Ia86e4324e21ccc4bd4b138fa5b2b748df23b0aed --- M tests/osmux/osmux_test.c M tests/osmux/osmux_test.ok 2 files changed, 15 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified fixeria: Looks good to me, approved diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c index 3af32e2..d6b7040 100644 --- a/tests/osmux/osmux_test.c +++ b/tests/osmux/osmux_test.c @@ -320,6 +320,15 @@ osmux_xfrm_input_fini(&h_input); + for (i = 0; i < ARRAY_SIZE(h_output); i++) { + clock_debug("Flushing CID %u\n", i); + osmux_xfrm_output_flush(h_output[i]); + } + + for (i = 0; i < ARRAY_SIZE(h_output); i++) { + TALLOC_FREE(h_output[i]); + } + clock_debug("OK: Test passed\n"); return EXIT_SUCCESS; } diff --git a/tests/osmux/osmux_test.ok b/tests/osmux/osmux_test.ok index 81f1928..3a5f321 100644 --- a/tests/osmux/osmux_test.ok +++ b/tests/osmux/osmux_test.ok @@ -1077,4 +1077,10 @@ sys={28.604242}, mono={5.180000}: extracted packet: RTP ver=2 ssrc=117440512 type=98 marker=0 ext=0 csrc_count=0 sequence=9316 timestamp=1681718057 [20 14 ff d4 f9 ff fb e7 eb f9 9f f8 f2 26 33 65 54 ] sys={28.604242}, mono={5.180000}: extracted packet: RTP ver=2 ssrc=117440513 type=98 marker=0 ext=0 csrc_count=0 sequence=9316 timestamp=1681718057 [20 14 ff d4 f9 ff fb e7 eb f9 9f f8 f2 26 33 65 54 ] sys={28.624242}, mono={5.200000}: clock_override_add +sys={28.624242}, mono={5.200000}: Flushing CID 0 +sys={28.624242}, mono={5.200000}: extracted packet: RTP ver=2 ssrc=117440512 type=98 marker=0 ext=0 csrc_count=0 sequence=9317 timestamp=1681718217 [20 14 ff d4 f9 ff fb e7 eb f9 9f f8 f2 26 33 65 54 ] +sys={28.624242}, mono={5.200000}: Flushing CID 1 +sys={28.624242}, mono={5.200000}: extracted packet: RTP ver=2 ssrc=117440513 type=98 marker=0 ext=0 csrc_count=0 sequence=9317 timestamp=1681718217 [20 14 ff d4 f9 ff fb e7 eb f9 9f f8 f2 26 33 65 54 ] +sys={28.624242}, mono={5.200000}: Flushing CID 2 +sys={28.624242}, mono={5.200000}: Flushing CID 3 sys={28.624242}, mono={5.200000}: OK: Test passed -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29519 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ia86e4324e21ccc4bd4b138fa5b2b748df23b0aed Gerrit-Change-Number: 29519 Gerrit-PatchSet: 3 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
1 0
0 0
Change in libosmo-netif[master]: tests/osmux: Test rx of osmux seqnum wrap around
by pespin 29 Sep '22

29 Sep '22
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29520 ) Change subject: tests/osmux: Test rx of osmux seqnum wrap around ...................................................................... tests/osmux: Test rx of osmux seqnum wrap around This test shows that there's a bug where the first RTP packet extracted from the received osmux batch with seqnum=0 has the M bit marked for no good reason. Related: SYS#5987 Change-Id: Ida658c681e84878f209ab4965d8aa821a570a580 --- M tests/osmux/osmux_output_test.c M tests/osmux/osmux_output_test.ok 2 files changed, 42 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved diff --git a/tests/osmux/osmux_output_test.c b/tests/osmux/osmux_output_test.c index 46065fe..94d6a5b 100644 --- a/tests/osmux/osmux_output_test.c +++ b/tests/osmux/osmux_output_test.c @@ -390,6 +390,36 @@ talloc_free(h_output); } +/* Test how the osmux_out_handle behaves when seqnum 0xff->0x00 is received */ +static void test_output_seqnum_wraparound(void) +{ + struct osmux_out_handle *h_output; + + printf("===test_output_seqnum_wraparound===\n"); + + clock_override_enable(true); + clock_override_set(0, 0); + osmux_init(0xff); + + h_output = osmux_xfrm_output_alloc(NULL); + osmux_xfrm_output_set_rtp_ssrc(h_output, 0x7000000); + osmux_xfrm_output_set_rtp_pl_type(h_output, 98); + osmux_xfrm_output_set_tx_cb(h_output, tx_cb, h_output); + h_output->rtp_seq = (uint16_t)50; + h_output->rtp_timestamp = (uint32_t)500; + h_output->osmux_seq_ack = 0xff; + + clock_debug("Sending osmux frame with seqnum=0"); + PULL_NEXT(h_output); + clock_override_add(0, 2*TIME_RTP_PKT_MS*1000); + osmo_select_main(0); + + clock_debug("flushing other RTP packets"); + osmux_xfrm_output_flush(h_output); + + talloc_free(h_output); +} + int main(int argc, char **argv) { @@ -412,6 +442,7 @@ test_output_2together(); test_output_frame_lost(); test_output_flush(); + test_output_seqnum_wraparound(); fprintf(stdout, "OK: Test passed\n"); return EXIT_SUCCESS; diff --git a/tests/osmux/osmux_output_test.ok b/tests/osmux/osmux_output_test.ok index 53ab67d..f69c0a9 100644 --- a/tests/osmux/osmux_output_test.ok +++ b/tests/osmux/osmux_output_test.ok @@ -105,4 +105,15 @@ sys={0.040000}, mono={0.040000}: dequeue: seq=59 ts=1940 enqueued=2 sys={0.040000}, mono={0.040000}: dequeue: seq=60 ts=2100 enqueued=1 sys={0.040000}, mono={0.040000}: dequeue: seq=61 ts=2260 enqueued=0 +===test_output_seqnum_wraparound=== +sys={0.000000}, mono={0.000000}: clock_override_set +sys={0.000000}, mono={0.000000}: Sending osmux frame with seqnum=0 +sys={0.000000}, mono={0.000000}: dequeue: seq=50 ts=500 M enqueued=5 +sys={0.040000}, mono={0.040000}: clock_override_add +sys={0.040000}, mono={0.040000}: dequeue: seq=51 ts=660 enqueued=4 +sys={0.040000}, mono={0.040000}: dequeue: seq=52 ts=820 enqueued=3 +sys={0.040000}, mono={0.040000}: flushing other RTP packets +sys={0.040000}, mono={0.040000}: dequeue: seq=53 ts=980 enqueued=2 +sys={0.040000}, mono={0.040000}: dequeue: seq=54 ts=1140 enqueued=1 +sys={0.040000}, mono={0.040000}: dequeue: seq=55 ts=1300 enqueued=0 OK: Test passed 2 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/+/29520 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ida658c681e84878f209ab4965d8aa821a570a580 Gerrit-Change-Number: 29520 Gerrit-PatchSet: 3 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
1 0
0 0
Change in libosmo-netif[master]: osmux: Fix osmux seqnum incremented globally instead of per circuit
by pespin 29 Sep '22

29 Sep '22
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29518 ) Change subject: osmux: Fix osmux seqnum incremented globally instead of per circuit ...................................................................... osmux: Fix osmux seqnum incremented globally instead of per circuit There's no real use in having a global seqnum. The seqnum, as specified by the osmux protocol specification, relates to that of the RTP seq+timestamp, hence it is per circuit. Having it per circuit allows detecting gaps and lost batches on the receiver side, applying the Marker bit on the re-assembled RTP packets. As a resut of the fix, tests/osmux/osmux_test part validating Marker bit started failing. It failed because it was wrongly written to start with, since it used only one osmux_out_handle for the 4 CIDs in use, which was wrong, since each CID must have its own osmux_out_handle as state is kept there per circuit. Related: SYS#5987 Change-Id: I562de6a871d8a35475c314ca107c2a12b55d6683 --- M src/osmux.c M tests/osmux/osmux_test.c M tests/osmux/osmux_test.ok 3 files changed, 589 insertions(+), 587 deletions(-) Approvals: Jenkins Builder: Verified fixeria: Looks good to me, approved -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29518 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: I562de6a871d8a35475c314ca107c2a12b55d6683 Gerrit-Change-Number: 29518 Gerrit-PatchSet: 3 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
1 0
0 0
Change in libosmo-netif[master]: osmux: Take into account configured osmux_in_handle->osmux_seq field
by pespin 29 Sep '22

29 Sep '22
Attention is currently required from: fixeria. Hello Jenkins Builder, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmo-netif/+/29517 to look at the new patch set (#3). Change subject: osmux: Take into account configured osmux_in_handle->osmux_seq field ...................................................................... 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 --- M include/osmocom/netif/osmux.h M src/osmux.c M tests/osmux/osmux_input_test.c M tests/osmux/osmux_input_test.ok 4 files changed, 78 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/17/29517/3 -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29517 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ia26fcba5d7364a5744b2d64d0542a2b3880eee34 Gerrit-Change-Number: 29517 Gerrit-PatchSet: 3 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: newpatchset
1 0
0 0
Change in libosmo-netif[master]: osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circu...
by pespin 29 Sep '22

29 Sep '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/29523 ) Change subject: osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circuit() ...................................................................... osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circuit() There's no real use in having it split, it just makes it more difficult to extend since extra prams must be passed over 2 functions. In fact, the duplicity of "struct osmux_in_handle" and "struct osmux_batch" as its ->internal_data should go away in the future. Change-Id: Ie4c6b55827ac27bcdfbe1b14fb238f5873243000 --- M src/osmux.c 1 file changed, 25 insertions(+), 33 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/23/29523/1 diff --git a/src/osmux.c b/src/osmux.c index ec5712d..30661d2 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -645,38 +645,6 @@ return NULL; } -static struct osmux_circuit * -osmux_batch_add_circuit(struct osmux_batch *batch, int ccid, int dummy, - uint8_t batch_factor) -{ - struct osmux_circuit *circuit; - - circuit = osmux_batch_find_circuit(batch, ccid); - if (circuit != NULL) { - LOGP(DLMUX, LOGL_ERROR, "circuit %u already exists!\n", ccid); - return NULL; - } - - circuit = talloc_zero(osmux_ctx, struct osmux_circuit); - if (circuit == NULL) { - LOGP(DLMUX, LOGL_ERROR, "OOM on circuit %u\n", ccid); - return NULL; - } - - circuit->ccid = ccid; - INIT_LLIST_HEAD(&circuit->msg_list); - llist_add_tail(&circuit->head, &batch->circuit_list); - - if (dummy) { - circuit->dummy = dummy; - batch->ndummy++; - if (!osmo_timer_pending(&batch->timer)) - osmo_timer_schedule(&batch->timer, 0, - batch_factor * DELTA_RTP_MSG); - } - return circuit; -} - static void osmux_batch_del_circuit(struct osmux_batch *batch, struct osmux_circuit *circuit) { if (circuit->dummy) @@ -876,8 +844,32 @@ int dummy) { struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + struct osmux_circuit *circuit; - return osmux_batch_add_circuit(batch, ccid, dummy, h->batch_factor) ? 0 : -1; + circuit = osmux_batch_find_circuit(batch, ccid); + if (circuit != NULL) { + LOGP(DLMUX, LOGL_ERROR, "circuit %u already exists!\n", ccid); + return -1; + } + + circuit = talloc_zero(osmux_ctx, struct osmux_circuit); + if (circuit == NULL) { + LOGP(DLMUX, LOGL_ERROR, "OOM on circuit %u\n", ccid); + return -1; + } + + circuit->ccid = ccid; + INIT_LLIST_HEAD(&circuit->msg_list); + llist_add_tail(&circuit->head, &batch->circuit_list); + + if (dummy) { + circuit->dummy = dummy; + batch->ndummy++; + if (!osmo_timer_pending(&batch->timer)) + osmo_timer_schedule(&batch->timer, 0, + h->batch_factor * DELTA_RTP_MSG); + } + return 0; } void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid) -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/29523 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ie4c6b55827ac27bcdfbe1b14fb238f5873243000 Gerrit-Change-Number: 29523 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • ...
  • 186
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.