gtphub: tweak logging.

Less spaces in tunnel strings, adjust tests accordingly.

Use side_idx to remove code dup in rate counter output.

Sponsored-by: On-Waves ehi
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index 5736b89..eb463d7 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -986,15 +986,15 @@
 
 	if (!u->peer) {
 		if (c->peer) {
-			APPEND(" / (uninitialized)");
+			APPEND("/(uninitialized)");
 		}
 	} else if ((!c->peer)
 		   || (!gsn_addr_same(&u->peer->peer_addr->addr,
 				      &c->peer->peer_addr->addr))) {
-		APPEND(" / %s", gsn_addr_to_str(&u->peer->peer_addr->addr));
+		APPEND("/%s", gsn_addr_to_str(&u->peer->peer_addr->addr));
 	}
 
-	APPEND(" (TEI C %x=%x / U %x=%x)",
+	APPEND(" (TEI C %x=%x/U %x=%x)",
 	       c->tei_orig, c->tei_repl,
 	       u->tei_orig, u->tei_repl);
 	return buf;
diff --git a/openbsc/src/gprs/gtphub_vty.c b/openbsc/src/gprs/gtphub_vty.c
index 324d155..0eb9261 100644
--- a/openbsc/src/gprs/gtphub_vty.c
+++ b/openbsc/src/gprs/gtphub_vty.c
@@ -290,17 +290,15 @@
 		vty_out(vty, "- %s Plane:%s",
 			gtphub_plane_idx_names[plane_idx], VTY_NEWLINE);
 
-		struct gtphub_bind *b = &g_hub->to_gsns[GTPH_SIDE_GGSN][plane_idx];
-		vty_out(vty, "  - to/from GGSNs: %s port %d%s",
-			gsn_addr_to_str(&b->local_addr), (int)b->local_port,
-			VTY_NEWLINE);
-		vty_out_rate_ctr_group(vty, "    ", b->counters_io);
-
-		b = &g_hub->to_gsns[GTPH_SIDE_SGSN][plane_idx];
-		vty_out(vty, "  - to/from SGSNs: %s port %d%s",
-			gsn_addr_to_str(&b->local_addr), (int)b->local_port,
-			VTY_NEWLINE);
-		vty_out_rate_ctr_group(vty, "    ", b->counters_io);
+		int side_idx;
+		for_each_side(side_idx) {
+			struct gtphub_bind *b = &g_hub->to_gsns[side_idx][plane_idx];
+			vty_out(vty, "  - to/from %ss: %s port %d%s",
+				gtphub_side_idx_names[side_idx],
+				gsn_addr_to_str(&b->local_addr), (int)b->local_port,
+				VTY_NEWLINE);
+			vty_out_rate_ctr_group(vty, "    ", b->counters_io);
+		}
 	}
 }
 
@@ -387,7 +385,7 @@
 	time_t now = gtphub_now();
 
 	vty_out(vty, "All tunnels:%s"
-		"Legend: SGSN <-> GGSN, with each:%s"
+		"Legend: (expiry in minutes) SGSN <-> GGSN, with each:%s"
 		"        <IP-Ctrl>[/<IP-User>] (<TEI-Ctrl>=<mapped>/<TEI-User>=<mapped>)%s",
 		VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
 
@@ -397,7 +395,7 @@
 	llist_for_each_entry(t, &g_hub->tunnels, entry) {
 		vty_out(vty,
 			"(%4dm) %s%s",
-			-(int)((t->expiry_entry.expiry - now) / 60),
+			(int)((t->expiry_entry.expiry - now) / 60),
 			gtphub_tunnel_str(t),
 			VTY_NEWLINE);
 		count ++;
diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c
index bdce99d..f24ace0 100644
--- a/openbsc/tests/gtphub/gtphub_test.c
+++ b/openbsc/tests/gtphub/gtphub_test.c
@@ -943,8 +943,8 @@
 	LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
 
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 / (uninitialized) (TEI C 0=0 / U 0=0)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34/(uninitialized) (TEI C 0=0/U 0=0)"
 		" @21945\n"));
 
 	const char *gtp_resp_from_ggsn =
@@ -1007,8 +1007,8 @@
 	gtphub_gc(hub, now);
 
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"));
 
 	/* TEI Ctrl from above and next sequence after abcd. */
@@ -1022,8 +1022,8 @@
 
 	/* 21945 + 31 = 21976 */
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21976\n"));
 
 	const char *gtp_resp_from_ggsn =
@@ -1049,8 +1049,8 @@
 	gtphub_gc(hub, now);
 
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"));
 
 	/* TEI Ctrl from above and next sequence after abcd. */
@@ -1064,8 +1064,8 @@
 
 	/* 21945 + 31 = 21976 */
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21976\n"));
 
 	const char *gtp_resp_from_sgsn =
@@ -1112,8 +1112,8 @@
 	 * 0x00000567 == 1383 (TEI from GGSN User)
 	 * Mapped TEIs should be 1 and 2. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"));
 
 	if (del_from_side == GTPH_SIDE_SGSN) {
@@ -1136,8 +1136,8 @@
 
 	/* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"));
 
 	LOG("- user data starts");
@@ -1182,8 +1182,8 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @22545\n"));
 
 	const char *u_from_sgsn =
@@ -1218,8 +1218,8 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @22545\n"));
 
 	OSMO_ASSERT(clear_test_hub());
@@ -1263,8 +1263,8 @@
 	OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
 
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=5 / U 123=6)"
-		" <-> 192.168.43.34 / (uninitialized) (TEI C 0=0 / U 0=0)"
+		"192.168.42.23 (TEI C 321=5/U 123=6)"
+		" <-> 192.168.43.34/(uninitialized) (TEI C 0=0/U 0=0)"
 		" @21945\n"));
 
 	const char *gtp_resp_from_ggsn =
@@ -1337,11 +1337,11 @@
 	OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
 
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C cba=5 / U abc=6)"
-		" <-> 192.168.43.34 / (uninitialized) (TEI C 0=0 / U 0=0)"
+		"192.168.42.23 (TEI C cba=5/U abc=6)"
+		" <-> 192.168.43.34/(uninitialized) (TEI C 0=0/U 0=0)"
 		" @21955\n"
-		"(uninitialized) (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"(uninitialized) (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"
 		));
 
@@ -1415,8 +1415,8 @@
 	OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
 
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=5 / U 123=6)"
-		" <-> 192.168.43.34 / (uninitialized) (TEI C 0=0 / U 0=0)"
+		"192.168.42.23 (TEI C 321=5/U 123=6)"
+		" <-> 192.168.43.34/(uninitialized) (TEI C 0=0/U 0=0)"
 		" @21955\n"
 		));
 
@@ -1462,8 +1462,8 @@
 
 	/* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @21945\n"));
 
 	LOG("- user data starts");
@@ -1507,8 +1507,8 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @22545\n"));
 
 	const char *u_from_sgsn =
@@ -1543,8 +1543,8 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=2)"
-		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
+		"192.168.42.23 (TEI C 321=1/U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3/U 567=4)"
 		" @22545\n"));
 
 	OSMO_ASSERT(clear_test_hub());