mgcp/rtp: Add counter for invalid RTP timestamp deltas

This patch modifies the patch_and_count() function to check for RTP
timestamp inconsistencies. It basically checks, whether dTS/dSeqNo
remains constant. If this fails, the corresponding counter is
incremented. There are four counter for this: Incoming and outgoing,
each for streams from the BTS and the net.

Note that this approach presumes, that the per RTP packet duration
(in samples) remains the same throughout the entire stream. Changing
the number of speech frames per channel and packet will be detected
as error.

In addition, the VTY command 'show mgcp' is extended by an optional
'stats' to show the counter values, too.

Ticket: OW#964
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c
index 3c239d8..5aeb393 100644
--- a/openbsc/src/libmgcp/mgcp_vty.c
+++ b/openbsc/src/libmgcp/mgcp_vty.c
@@ -114,7 +114,7 @@
 	return CMD_SUCCESS;
 }
 
-static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg)
+static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg, int verbose)
 {
 	int i;
 
@@ -139,18 +139,31 @@
 			endp->bts_end.packets, endp->net_end.packets,
 			endp->trans_net.packets, endp->trans_bts.packets,
 			VTY_NEWLINE);
+
+		if (verbose)
+			vty_out(vty,
+				"  Timestamp Errs: BTS %d->%d, Net %d->%d%s",
+				endp->bts_state.in_stream.err_ts_counter,
+				endp->bts_state.out_stream.err_ts_counter,
+				endp->net_state.in_stream.err_ts_counter,
+				endp->net_state.out_stream.err_ts_counter,
+				VTY_NEWLINE);
 	}
 }
 
-DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
-      SHOW_STR "Display information about the MGCP Media Gateway")
+DEFUN(show_mcgp, show_mgcp_cmd,
+      "show mgcp [stats]",
+      SHOW_STR
+      "Display information about the MGCP Media Gateway\n"
+      "Include Statistics\n")
 {
 	struct mgcp_trunk_config *trunk;
+	int show_stats = argc >= 1;
 
-	dump_trunk(vty, &g_cfg->trunk);
+	dump_trunk(vty, &g_cfg->trunk, show_stats);
 
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry)
-		dump_trunk(vty, trunk);
+		dump_trunk(vty, trunk, show_stats);
 
 	return CMD_SUCCESS;
 }