gtphub: add more detailed I/O rate counters.

Count bytes and packets per peer port, as well es per tunnel enpoint, which
adds two more levels of detail.

Sponsored-by: On-Waves ehi
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index eb463d7..e2f3a54 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -783,6 +783,7 @@
 {
 	OSMO_ASSERT(pp->ref_count == 0);
 	llist_del(&pp->entry);
+	rate_ctr_group_free(pp->counters_io);
 	talloc_free(pp);
 }
 
@@ -1056,9 +1057,12 @@
 	int side_idx;
 	int plane_idx;
 	for_each_side_and_plane(side_idx, plane_idx) {
+		struct gtphub_tunnel_endpoint *te = &tun->endpoint[side_idx][plane_idx];
+
 		/* clear ref count */
-		gtphub_tunnel_endpoint_set_peer(&tun->endpoint[side_idx][plane_idx],
-						NULL);
+		gtphub_tunnel_endpoint_set_peer(te, NULL);
+
+		rate_ctr_group_free(te->counters_io);
 	}
 
 	talloc_free(tun);
@@ -1073,6 +1077,15 @@
 	INIT_LLIST_HEAD(&tun->entry);
 	expiring_item_init(&tun->expiry_entry);
 
+	int side_idx, plane_idx;
+	for_each_side_and_plane(side_idx, plane_idx) {
+		struct gtphub_tunnel_endpoint *te = &tun->endpoint[side_idx][plane_idx];
+		te->counters_io = rate_ctr_group_alloc(osmo_gtphub_ctx,
+						       &gtphub_ctrg_io_desc,
+						       0);
+		OSMO_ASSERT(te->counters_io);
+	}
+
 	tun->expiry_entry.del_cb = gtphub_tunnel_del_cb;
 	return tun;
 }
@@ -2162,6 +2175,10 @@
 		return -1;
 	}
 
+	rate_ctr_add(&from_peer->counters_io->ctr[GTPH_CTR_BYTES_IN],
+		     received);
+	rate_ctr_inc(&from_peer->counters_io->ctr[GTPH_CTR_PKTS_IN]);
+
 	LOG(LOGL_DEBUG, "from %s peer: %s\n", gtphub_side_idx_names[side_idx],
 	    gtphub_port_str(from_peer));
 
@@ -2174,6 +2191,13 @@
 		return -1;
 	}
 
+	if (p.tun) {
+		struct gtphub_tunnel_endpoint *te = &p.tun->endpoint[p.side_idx][p.plane_idx];
+		rate_ctr_add(&te->counters_io->ctr[GTPH_CTR_BYTES_IN],
+			     received);
+		rate_ctr_inc(&te->counters_io->ctr[GTPH_CTR_PKTS_IN]);
+	}
+
 	if ((!to_peer) && (side_idx == GTPH_SIDE_SGSN)) {
 		if (gtphub_resolve_ggsn(hub, &p, &to_peer) < 0)
 			return -1;
@@ -2216,7 +2240,19 @@
 		rate_ctr_inc(&to_bind->counters_io->ctr[GTPH_CTR_PKTS_OUT]);
 		rate_ctr_add(&to_bind->counters_io->ctr[GTPH_CTR_BYTES_OUT],
 			     received);
+
+		rate_ctr_inc(&to_peer->counters_io->ctr[GTPH_CTR_PKTS_OUT]);
+		rate_ctr_add(&to_peer->counters_io->ctr[GTPH_CTR_BYTES_OUT],
+			     received);
 	}
+
+	if (p.tun) {
+		struct gtphub_tunnel_endpoint *te = &p.tun->endpoint[other_side_idx(p.side_idx)][p.plane_idx];
+		rate_ctr_inc(&te->counters_io->ctr[GTPH_CTR_PKTS_OUT]);
+		rate_ctr_add(&te->counters_io->ctr[GTPH_CTR_BYTES_OUT],
+			     received);
+	}
+
 	LOG(LOGL_DEBUG, "%s Forward to %s: %d bytes to %s\n",
 	    (side_idx == GTPH_SIDE_SGSN)? "-->" : "<--",
 	    gtphub_side_idx_names[other_side_idx(side_idx)],
@@ -2614,6 +2650,9 @@
 		return NULL;
 	}
 
+	pp->counters_io = rate_ctr_group_alloc(osmo_gtphub_ctx,
+					       &gtphub_ctrg_io_desc, 0);
+
 	llist_add(&pp->entry, &a->ports);
 
 	LOG(LOGL_DEBUG, "New peer port: %s port %d\n",