diff options
Diffstat (limited to 'src/libosmo-mgcp/mgcp_network.c')
-rw-r--r-- | src/libosmo-mgcp/mgcp_network.c | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 6923b97..3ac93be 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -222,7 +222,7 @@ static int check_rtp_timestamp(struct mgcp_endpoint *endp, if (seq == sstate->last_seq) { if (timestamp != sstate->last_timestamp) { - sstate->err_ts_counter += 1; + rate_ctr_inc(sstate->err_ts_ctr); LOGP(DRTP, LOGL_ERROR, "The %s timestamp delta is != 0 but the sequence " "number %d is the same, " @@ -272,7 +272,7 @@ static int check_rtp_timestamp(struct mgcp_endpoint *endp, ts_alignment_error(sstate, state->packet_duration, timestamp); if (timestamp_error) { - sstate->err_ts_counter += 1; + rate_ctr_inc(sstate->err_ts_ctr); LOGP(DRTP, LOGL_NOTICE, "The %s timestamp has an alignment error of %d " "on 0x%x SSRC: %u " @@ -310,7 +310,7 @@ static int adjust_rtp_timestamp_offset(struct mgcp_endpoint *endp, ENDPOINT_NUMBER(endp), tsdelta, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)); } else { - tsdelta = rtp_end->codec.rate * 20 / 1000; + tsdelta = rtp_end->codec->rate * 20 / 1000; LOGP(DRTP, LOGL_NOTICE, "Fixed packet duration and last timestamp delta " "are not available on 0x%x, " @@ -399,12 +399,12 @@ int mgcp_rtp_processing_default(struct mgcp_endpoint *endp, /*! dummy callback to disable transcoding (see also cfg->setup_rtp_processing_cb). * \param[in] associated endpoint - * \param[in] destination RTP end - * \param[in] source RTP end + * \param[in] destination RTP connnection + * \param[in] source RTP connection * \returns ignores input parameters, return always 0 */ int mgcp_setup_rtp_processing_default(struct mgcp_endpoint *endp, - struct mgcp_rtp_end *dst_end, - struct mgcp_rtp_end *src_end) + struct mgcp_conn_rtp *conn_dst, + struct mgcp_conn_rtp *conn_src) { LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x transcoding disabled\n", ENDPOINT_NUMBER(endp)); @@ -421,8 +421,8 @@ void mgcp_get_net_downlink_format_default(struct mgcp_endpoint *endp, "endpoint:0x%x conn:%s using format defaults\n", ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn)); - *payload_type = conn->end.codec.payload_type; - *audio_name = conn->end.codec.audio_name; + *payload_type = conn->end.codec->payload_type; + *audio_name = conn->end.codec->audio_name; *fmtp_extra = conn->end.fmtp_extra; } @@ -490,7 +490,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, uint16_t seq; uint32_t timestamp, ssrc; struct rtp_hdr *rtp_hdr; - int payload = rtp_end->codec.payload_type; + int payload = rtp_end->codec->payload_type; if (len < sizeof(*rtp_hdr)) return; @@ -498,7 +498,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, rtp_hdr = (struct rtp_hdr *)data; seq = ntohs(rtp_hdr->sequence); timestamp = ntohl(rtp_hdr->timestamp); - arrival_time = get_current_ts(rtp_end->codec.rate); + arrival_time = get_current_ts(rtp_end->codec->rate); ssrc = ntohl(rtp_hdr->ssrc); transit = arrival_time - timestamp; @@ -511,7 +511,9 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, state->in_stream.last_tsdelta = 0; state->packet_duration = mgcp_rtp_packet_duration(endp, rtp_end); - state->out_stream = state->in_stream; + state->out_stream.last_seq = seq - 1; + state->out_stream.ssrc = state->patch.orig_ssrc = ssrc; + state->out_stream.last_tsdelta = 0; state->out_stream.last_timestamp = timestamp; state->out_stream.ssrc = ssrc - 1; /* force output SSRC change */ LOGP(DRTP, LOGL_INFO, @@ -522,7 +524,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)); if (state->packet_duration == 0) { state->packet_duration = - rtp_end->codec.rate * 20 / 1000; + rtp_end->codec->rate * 20 / 1000; LOGP(DRTP, LOGL_NOTICE, "endpoint:0x%x fixed packet duration is not available, " "using fixed 20ms instead: %d from %s:%d\n", @@ -678,12 +680,9 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr, } LOGP(DRTP, LOGL_DEBUG, - "endpoint:0x%x loop:%d, mode:%d ", - ENDPOINT_NUMBER(endp), tcfg->audio_loop, conn_src->conn->mode); - if (conn_src->conn->mode == MGCP_CONN_LOOPBACK) - LOGPC(DRTP, LOGL_DEBUG, "(loopback)\n"); - else - LOGPC(DRTP, LOGL_DEBUG, "\n"); + "endpoint:0x%x loop:%d, mode:%d%s\n", + ENDPOINT_NUMBER(endp), tcfg->audio_loop, conn_src->conn->mode, + conn_src->conn->mode == MGCP_CONN_LOOPBACK ? " (loopback)" : ""); /* Note: In case of loopback configuration, both, the source and the * destination will point to the same connection. */ @@ -692,7 +691,7 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr, dest_name = conn_dst->conn->name; if (!rtp_end->output_enabled) { - rtp_end->stats.dropped_packets += 1; + rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_DROPPED_PACKETS_CTR]); LOGP(DRTP, LOGL_DEBUG, "endpoint:0x%x output disabled, drop to %s %s " "rtp_port:%u rtcp_port:%u\n", @@ -733,11 +732,18 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr, * 'e400', or it will reject the RAB assignment. It seems to not harm other femto * cells (as long as we patch only the first RTP payload in each stream). */ - if (!rtp_state->patched_first_rtp_payload) { + if (!rtp_state->patched_first_rtp_payload + && conn_src->conn->mode == MGCP_CONN_LOOPBACK) { uint8_t *data = (uint8_t *) & buf[12]; - data[0] = 0xe4; - data[1] = 0x00; - rtp_state->patched_first_rtp_payload = true; + if (data[0] == 0xe0) { + data[0] = 0xe4; + data[1] = 0x00; + rtp_state->patched_first_rtp_payload = true; + LOGP(DRTP, LOGL_DEBUG, + "endpoint:0x%x Patching over first two bytes" + " to fake an IuUP Initialization Ack\n", + ENDPOINT_NUMBER(endp)); + } } len = mgcp_udp_send(rtp_end->rtp.fd, @@ -747,8 +753,8 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr, if (len <= 0) return len; - conn_dst->end.stats.packets_tx += 1; - conn_dst->end.stats.octets_tx += len; + rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR]); + rate_ctr_add(&conn_dst->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR], len); nbytes += len; buflen = cont; @@ -767,8 +773,8 @@ int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr, &rtp_end->addr, rtp_end->rtcp_port, buf, len); - conn_dst->end.stats.packets_tx += 1; - conn_dst->end.stats.octets_tx += len; + rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR]); + rate_ctr_add(&conn_dst->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR], len); return len; } @@ -865,6 +871,15 @@ static int check_rtp_destin(struct mgcp_conn_rtp *conn) struct mgcp_endpoint *endp; endp = conn->conn->endp; + /* Note: it is legal to create a connection but never setting a port + * and IP-address for outgoing data. */ + if (strcmp(inet_ntoa(conn->end.addr), "0.0.0.0") == 0 && conn->end.rtp_port == 0) { + LOGP(DRTP, LOGL_DEBUG, + "endpoint:0x%x destination IP-address and rtp port is (not yet) known\n", + ENDPOINT_NUMBER(endp)); + return -1; + } + if (strcmp(inet_ntoa(conn->end.addr), "0.0.0.0") == 0) { LOGP(DRTP, LOGL_ERROR, "endpoint:0x%x destination IP-address is invalid\n", @@ -928,8 +943,8 @@ static int mgcp_recv(int *proto, struct sockaddr_in *addr, char *buf, } /* Increment RX statistics */ - conn->end.stats.packets_rx += 1; - conn->end.stats.octets_rx += rc; + rate_ctr_inc(&conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR]); + rate_ctr_add(&conn->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR], rc); /* Forward a copy of the RTP data to a debug ip/port */ forward_data(fd->fd, &conn->tap_in, buf, rc); |