[MERGED] osmo-mgw[master]: mgcp_rtp_end: Group statistics members into 'stats' sub-struct

2017-12-25 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: mgcp_rtp_end: Group statistics members into 'stats' sub-struct
..


mgcp_rtp_end: Group statistics members into 'stats' sub-struct

Change-Id: I4e0ecdcd9a75fe08abc55b730780c01617f3d4af
---
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_osmux.c
M src/libosmo-mgcp/mgcp_stat.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
7 files changed, 26 insertions(+), 28 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/mgcp/mgcp_internal.h 
b/include/osmocom/mgcp/mgcp_internal.h
index 9e7246e..11bafe7 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -97,11 +97,14 @@
 
 struct mgcp_rtp_end {
/* statistics */
-   unsigned int packets_rx;
-   unsigned int octets_rx;
-   unsigned int packets_tx;
-   unsigned int octets_tx;
-   unsigned int dropped_packets;
+   struct {
+   unsigned int packets_rx;
+   unsigned int octets_rx;
+   unsigned int packets_tx;
+   unsigned int octets_tx;
+   unsigned int dropped_packets;
+   } stats;
+
struct in_addr addr;
 
/* in network byte order */
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 4090a9f..9063bec 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -93,12 +93,7 @@
 
end->rtp.fd = -1;
end->rtcp.fd = -1;
-   end->local_port = 0;
-   end->packets_rx = 0;
-   end->octets_rx = 0;
-   end->packets_tx = 0;
-   end->octets_tx = 0;
-   end->dropped_packets = 0;
+   memset(>stats, 0, sizeof(end->stats));
end->rtp_port = end->rtcp_port = 0;
talloc_free(end->fmtp_extra);
end->fmtp_extra = NULL;
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 2056a8e..dc5628a 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -693,7 +693,7 @@
dest_name = conn_dst->conn->name;
 
if (!rtp_end->output_enabled) {
-   rtp_end->dropped_packets += 1;
+   rtp_end->stats.dropped_packets += 1;
LOGP(DRTP, LOGL_DEBUG,
 "endpoint:0x%x output disabled, drop to %s %s "
 "rtp_port:%u rtcp_port:%u\n",
@@ -748,8 +748,8 @@
if (len <= 0)
return len;
 
-   conn_dst->end.packets_tx += 1;
-   conn_dst->end.octets_tx += len;
+   conn_dst->end.stats.packets_tx += 1;
+   conn_dst->end.stats.octets_tx += len;
 
nbytes += len;
buflen = cont;
@@ -768,8 +768,8 @@
_end->addr,
rtp_end->rtcp_port, buf, len);
 
-   conn_dst->end.packets_tx += 1;
-   conn_dst->end.octets_tx += len;
+   conn_dst->end.stats.packets_tx += 1;
+   conn_dst->end.stats.octets_tx += len;
 
return len;
}
@@ -929,8 +929,8 @@
}
 
/* Increment RX statistics */
-   conn->end.packets_rx += 1;
-   conn->end.octets_rx += rc;
+   conn->end.stats.packets_rx += 1;
+   conn->end.stats.octets_rx += rc;
 
/* Forward a copy of the RTP data to a debug ip/port */
forward_data(fd->fd, >tap_in, buf, rc);
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index 5030812..6e19611 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -255,8 +255,8 @@
.sin_port = conn_net->end.rtp_port,
};
 
-   conn_bts->end.octets_tx += msg->len;
-   conn_bts->end.packets_tx++;
+   conn_bts->end.stats.octets_tx += msg->len;
+   conn_bts->end.stats.packets_tx++;
 
/* Send RTP data to NET */
/* FIXME: Get rid of conn_bts and conn_net! */
@@ -282,8 +282,8 @@
.sin_port = conn_bts->end.rtp_port,
};
 
-   conn_net->end.octets_tx += msg->len;
-   conn_net->end.packets_tx++;
+   conn_net->end.stats.octets_tx += msg->len;
+   conn_net->end.stats.packets_tx++;
 
/* Send RTP data to BTS */
/* FIXME: Get rid of conn_bts and conn_net! */
diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c
index 54c4b66..88a2d69 100644
--- a/src/libosmo-mgcp/mgcp_stat.c
+++ b/src/libosmo-mgcp/mgcp_stat.c
@@ -43,8 +43,8 @@
 * Make sure the sign is correct and use the biggest
 * positive/negative number that fits.
 */
-   *loss = *expected - end->packets_rx;
-   if (*expected < end->packets_rx) {
+   

osmo-mgw[master]: mgcp_rtp_end: Group statistics members into 'stats' sub-struct

2017-12-25 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/5583
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I4e0ecdcd9a75fe08abc55b730780c01617f3d4af
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-mgw[master]: mgcp_rtp_end: Group statistics members into 'stats' sub-struct

2017-12-25 Thread Harald Welte

Review at  https://gerrit.osmocom.org/5583

mgcp_rtp_end: Group statistics members into 'stats' sub-struct

Change-Id: I4e0ecdcd9a75fe08abc55b730780c01617f3d4af
---
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_osmux.c
M src/libosmo-mgcp/mgcp_stat.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
7 files changed, 26 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/83/5583/1

diff --git a/include/osmocom/mgcp/mgcp_internal.h 
b/include/osmocom/mgcp/mgcp_internal.h
index 9e7246e..11bafe7 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -97,11 +97,14 @@
 
 struct mgcp_rtp_end {
/* statistics */
-   unsigned int packets_rx;
-   unsigned int octets_rx;
-   unsigned int packets_tx;
-   unsigned int octets_tx;
-   unsigned int dropped_packets;
+   struct {
+   unsigned int packets_rx;
+   unsigned int octets_rx;
+   unsigned int packets_tx;
+   unsigned int octets_tx;
+   unsigned int dropped_packets;
+   } stats;
+
struct in_addr addr;
 
/* in network byte order */
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 4090a9f..9063bec 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -93,12 +93,7 @@
 
end->rtp.fd = -1;
end->rtcp.fd = -1;
-   end->local_port = 0;
-   end->packets_rx = 0;
-   end->octets_rx = 0;
-   end->packets_tx = 0;
-   end->octets_tx = 0;
-   end->dropped_packets = 0;
+   memset(>stats, 0, sizeof(end->stats));
end->rtp_port = end->rtcp_port = 0;
talloc_free(end->fmtp_extra);
end->fmtp_extra = NULL;
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 4f88341..9bf6f85 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -692,7 +692,7 @@
dest_name = conn_dst->conn->name;
 
if (!rtp_end->output_enabled) {
-   rtp_end->dropped_packets += 1;
+   rtp_end->stats.dropped_packets += 1;
LOGP(DRTP, LOGL_DEBUG,
 "endpoint:0x%x output disabled, drop to %s %s "
 "rtp_port:%u rtcp_port:%u\n",
@@ -747,8 +747,8 @@
if (len <= 0)
return len;
 
-   conn_dst->end.packets_tx += 1;
-   conn_dst->end.octets_tx += len;
+   conn_dst->end.stats.packets_tx += 1;
+   conn_dst->end.stats.octets_tx += len;
 
nbytes += len;
buflen = cont;
@@ -767,8 +767,8 @@
_end->addr,
rtp_end->rtcp_port, buf, len);
 
-   conn_dst->end.packets_tx += 1;
-   conn_dst->end.octets_tx += len;
+   conn_dst->end.stats.packets_tx += 1;
+   conn_dst->end.stats.octets_tx += len;
 
return len;
}
@@ -928,8 +928,8 @@
}
 
/* Increment RX statistics */
-   conn->end.packets_rx += 1;
-   conn->end.octets_rx += rc;
+   conn->end.stats.packets_rx += 1;
+   conn->end.stats.octets_rx += rc;
 
/* Forward a copy of the RTP data to a debug ip/port */
forward_data(fd->fd, >tap_in, buf, rc);
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index 5030812..6e19611 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -255,8 +255,8 @@
.sin_port = conn_net->end.rtp_port,
};
 
-   conn_bts->end.octets_tx += msg->len;
-   conn_bts->end.packets_tx++;
+   conn_bts->end.stats.octets_tx += msg->len;
+   conn_bts->end.stats.packets_tx++;
 
/* Send RTP data to NET */
/* FIXME: Get rid of conn_bts and conn_net! */
@@ -282,8 +282,8 @@
.sin_port = conn_bts->end.rtp_port,
};
 
-   conn_net->end.octets_tx += msg->len;
-   conn_net->end.packets_tx++;
+   conn_net->end.stats.octets_tx += msg->len;
+   conn_net->end.stats.packets_tx++;
 
/* Send RTP data to BTS */
/* FIXME: Get rid of conn_bts and conn_net! */
diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c
index 54c4b66..88a2d69 100644
--- a/src/libosmo-mgcp/mgcp_stat.c
+++ b/src/libosmo-mgcp/mgcp_stat.c
@@ -43,8 +43,8 @@
 * Make sure the sign is correct and use the biggest
 * positive/negative number that fits.
 */
-   *loss = *expected - end->packets_rx;
-   if (*expected < end->packets_rx) {
+   *loss = *expected - end->stats.packets_rx;
+   if (*expected < end->stats.packets_rx) {
if (*loss > 0)
*loss = INT_MIN;
}