aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-10-22 18:09:35 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2013-06-17 09:50:23 +0200
commit93e4dbb9be6402afadd7be90d8c439c3da540534 (patch)
tree05a31109ac68fe03db4ab7eb862e7e12a603e9e7
parent2fc06364d907f0f6ee6dfda9e7fd5541bec7b749 (diff)
mgcp: Calculate the packet loss as of Appendix A of RFC 3550
Calculate the expected packages and packet loss as of RFC 3550. The values should be clamped but our packet loss counter is 32 bits and not 24 and we should clamp at other values but I am waiting for some issues first before dealing with that. Conflicts: openbsc/tests/mgcp/mgcp_test.c openbsc/tests/mgcp/mgcp_test.ok
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h3
-rw-r--r--openbsc/src/libmgcp/mgcp_network.c32
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c10
3 files changed, 41 insertions, 4 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index e028a8ad4..6039c28c7 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -156,5 +156,8 @@ static inline int endp_back_channel(int endpoint)
struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index);
struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index);
+void mgcp_state_calc_loss(struct mgcp_rtp_state *s, struct mgcp_rtp_end *,
+ uint32_t *expected, int *loss);
+
#endif
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index 075e40b23..1e7459da1 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -2,8 +2,8 @@
/* The protocol implementation */
/*
- * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
- * (C) 2009-2011 by On-Waves
+ * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009-2012 by On-Waves
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
@@ -602,3 +602,31 @@ int mgcp_free_rtp_port(struct mgcp_rtp_end *end)
return 0;
}
+
+
+void mgcp_state_calc_loss(struct mgcp_rtp_state *state,
+ struct mgcp_rtp_end *end, uint32_t *expected,
+ int *loss)
+{
+ *expected = state->cycles + state->max_seq;
+ *expected = *expected - state->base_seq + 1;
+
+ if (!state->initialized) {
+ *expected = 0;
+ *loss = 0;
+ return;
+ }
+
+ /*
+ * Make sure the sign is correct and use the biggest
+ * positive/negative number that fits.
+ */
+ *loss = *expected - end->packets;
+ if (*expected < end->packets) {
+ if (*loss > 0)
+ *loss = INT_MIN;
+ } else {
+ if (*loss < 0)
+ *loss = INT_MAX;
+ }
+}
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 02fb72054..625b990fe 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -1163,8 +1163,14 @@ int mgcp_reset_transcoder(struct mgcp_config *cfg)
void mgcp_format_stats(struct mgcp_endpoint *endp, char *msg, size_t size)
{
- snprintf(msg, size, "\r\nP: PS=%u, OS=%u, PR=%u, OR=%u",
+ uint32_t expected;
+ int ploss;
+ mgcp_state_calc_loss(&endp->net_state, &endp->net_end,
+ &expected, &ploss);
+
+ snprintf(msg, size, "\r\nP: PS=%u, OS=%u, PR=%u, OR=%u, PL=%d",
endp->bts_end.packets, endp->bts_end.octets,
- endp->net_end.packets, endp->net_end.octets);
+ endp->net_end.packets, endp->net_end.octets,
+ ploss);
msg[size - 1] = '\0';
}