E1 Input: Add rate counters for events related to E1 lines
diff --git a/include/osmocom/abis/e1_input.h b/include/osmocom/abis/e1_input.h
index 9825999..8fac79a 100644
--- a/include/osmocom/abis/e1_input.h
+++ b/include/osmocom/abis/e1_input.h
@@ -19,6 +19,14 @@
 };
 const char *e1inp_signtype_name(enum e1inp_sign_type tp);
 
+enum e1inp_ctr {
+	E1I_CTR_HDLC_ABORT,
+	E1I_CTR_HDLC_BADFCS,
+	E1I_CTR_HDLC_OVERR,
+	E1I_CTR_ALARM,
+	E1I_CTR_REMOVED,
+};
+
 struct e1inp_ts;
 
 struct e1inp_sign_link {
@@ -136,6 +144,7 @@
 
 	unsigned int num;
 	const char *name;
+	struct rate_ctr_group *rate_ctr;
 
 	/* array of timestlots */
 	struct e1inp_ts ts[NUM_E1_TS];
diff --git a/src/e1_input.c b/src/e1_input.c
index b8b0130..82ba202 100644
--- a/src/e1_input.c
+++ b/src/e1_input.c
@@ -40,14 +40,12 @@
 #define PF_ISDN AF_ISDN
 #endif
 
-#include <osmocom/core/select.h>
-#include <osmocom/core/msgb.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/rate_ctr.h>
 #include <osmocom/core/logging.h>
 #include <osmocom/core/signal.h>
 #include <osmocom/abis/e1_input.h>
-#include <osmocom/core/linuxlist.h>
-#include <osmocom/abis/subchan_demux.h>
-#include <osmocom/core/talloc.h>
 
 #define NUM_E1_TS	32
 
@@ -61,6 +59,31 @@
 
 static void *tall_sigl_ctx;
 
+static const struct rate_ctr_desc e1inp_ctr_d[] = {
+	[E1I_CTR_HDLC_ABORT]  = {
+		"hdlc.abort", 	"ABORT from E1 Layer1"
+	},
+	[E1I_CTR_HDLC_BADFCS] = {
+		"hdlc.bad_fcs",	"Bad Frame Check Sequence"
+	},
+	[E1I_CTR_HDLC_OVERR]  = {
+		"hdlc.overrun",	"HDLC Overrun"
+	},
+	[E1I_CTR_ALARM] = {
+		"alarm", 	"E1 Alarm (Yellow/Red)"
+	},
+	[E1I_CTR_REMOVED] = {
+		"removed", 	"E1 Line removed"
+	},
+};
+
+static const struct rate_ctr_group_desc e1inp_ctr_g_d = {
+	.group_name_prefix = "e1inp",
+	.group_description = "E1 Input subsystem",
+	.num_ctr = ARRAY_SIZE(e1inp_ctr_d),
+	.ctr_desc = e1inp_ctr_d,
+};
+
 /*
  * pcap writing of the misdn load
  * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat
@@ -307,8 +330,10 @@
 		return NULL;
 
 	line->driver = driver;
-
 	line->num = e1_nr;
+
+	line->rate_ctr = rate_ctr_group_alloc(line, &e1inp_ctr_g_d, line->num);
+
 	for (i = 0; i < NUM_E1_TS; i++) {
 		line->ts[i].num = i+1;
 		line->ts[i].line = line;
diff --git a/src/e1_input_vty.c b/src/e1_input_vty.c
index fe14799..a8ccabb 100644
--- a/src/e1_input_vty.c
+++ b/src/e1_input_vty.c
@@ -21,17 +21,21 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gsm/gsm_utils.h>
+
 #include <osmocom/vty/command.h>
 #include <osmocom/vty/buffer.h>
 #include <osmocom/vty/vty.h>
 #include <osmocom/vty/logging.h>
+#include <osmocom/vty/misc.h>
 #include <osmocom/vty/telnet_interface.h>
 
-#include <osmocom/core/linuxlist.h>
 #include <osmocom/abis/e1_input.h>
-#include <osmocom/core/utils.h>
-#include <osmocom/gsm/gsm_utils.h>
-#include <osmocom/core/talloc.h>
+
+/* CONFIG */
 
 #define E1_DRIVER_NAMES		"(misdn|dahdi|ipa|hsl)"
 #define E1_DRIVER_HELP		"mISDN supported E1 Card\n" \
@@ -112,6 +116,8 @@
 	return CMD_SUCCESS;
 }
 
+/* SHOW */
+
 static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
 {
 	vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
@@ -130,34 +136,43 @@
 	return CMD_SUCCESS;
 }
 
-static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line)
+static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
+			    int stats)
 {
 	vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
 		line->num, line->name ? line->name : "",
 		line->driver->name, VTY_NEWLINE);
+	if (stats)
+		vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
 }
 
 DEFUN(show_e1line,
       show_e1line_cmd,
-      "show e1_line [line_nr]",
+      "show e1_line [line_nr] [stats]",
 	SHOW_STR "Display information about a E1 line\n"
 	"E1 Line Number\n")
 {
 	struct e1inp_line *line;
+	int stats = 0;
 
-	if (argc >= 1) {
+	if (argc >= 1 && strcmp(argv[0], "stats")) {
 		int num = atoi(argv[0]);
+		if (argc >= 2)
+			stats = 1;
 		llist_for_each_entry(line, &e1inp_line_list, list) {
 			if (line->num == num) {
-				e1line_dump_vty(vty, line);
+				e1line_dump_vty(vty, line, stats);
 				return CMD_SUCCESS;
 			}
 		}
 		return CMD_WARNING;
 	}
 
+	if (argc >= 1 && !strcmp(argv[0], "stats"))
+		stats = 1;
+
 	llist_for_each_entry(line, &e1inp_line_list, list)
-		e1line_dump_vty(vty, line);
+		e1line_dump_vty(vty, line, stats);
 
 	return CMD_SUCCESS;
 }