stats: Start handling stats for a mtp_link
diff --git a/include/bsc_data.h b/include/bsc_data.h
index fa04c3a..992e55b 100644
--- a/include/bsc_data.h
+++ b/include/bsc_data.h
@@ -37,6 +37,7 @@
 
 struct bsc_data;
 struct snmp_mtp_session;
+struct rate_ctr_group;
 
 /**
  * A link to the underlying MTP2 library or such
@@ -62,6 +63,7 @@
 	int pcap_fd;
 	struct bsc_data *bsc;
 	struct mtp_link_set *the_link;
+	struct rate_ctr_group *ctrg;
 
 	int available;
 
diff --git a/src/link_udp.c b/src/link_udp.c
index e05bd17..ef75f41 100644
--- a/src/link_udp.c
+++ b/src/link_udp.c
@@ -25,6 +25,7 @@
 #include <mtp_pcap.h>
 #include <snmp_mtp.h>
 #include <cellmgr_debug.h>
+#include <counter.h>
 
 #include <osmocore/talloc.h>
 
@@ -91,11 +92,13 @@
 
 	if (hdr->data_type == UDP_DATA_RETR_COMPL || hdr->data_type == UDP_DATA_RETR_IMPOS) {
 		LOGP(DINP, LOGL_ERROR, "Link retrieval done. Restarting the link.\n");
+		rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_ERROR]);
 		mtp_link_down(link);
 		mtp_link_up(link);
 		goto exit;
 	} else if (hdr->data_type > UDP_DATA_MSU_PRIO_3) {
 		LOGP(DINP, LOGL_ERROR, "Link failure. retrieved message.\n");
+		rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_ERROR]);
 		mtp_link_down(link);
 		goto exit;
 	}
@@ -113,6 +116,7 @@
 	LOGP(DINP, LOGL_DEBUG, "MSU data on: %p data %s.\n", link, hexdump(msg->data, msg->len));
 	if (link->pcap_fd >= 0)
 		mtp_pcap_write_msu(link->pcap_fd, msg->l2h, msgb_l2len(msg));
+	rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_IN]);
 	mtp_link_set_data(link->the_link, msg);
 
 exit:
diff --git a/src/links.c b/src/links.c
index 016542d..4889135 100644
--- a/src/links.c
+++ b/src/links.c
@@ -24,6 +24,7 @@
 #include <cellmgr_debug.h>
 #include <mtp_data.h>
 #include <snmp_mtp.h>
+#include <counter.h>
 
 #include <osmocore/talloc.h>
 
@@ -73,6 +74,7 @@
 
 void mtp_link_submit(struct link_data *link, struct msgb *msg)
 {
+	rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_OUT]);
 	link->write(link, msg);
 }
 
@@ -110,6 +112,8 @@
 	bsc->link_set->bsc = bsc;
 
 	lnk = talloc_zero(bsc->link_set, struct link_data);
+	lnk->ctrg = rate_ctr_group_alloc(lnk,
+					 mtp_link_rate_ctr_desc(), 1);
 	lnk->bsc = bsc;
 	lnk->udp.link_index = 1;
 	lnk->pcap_fd = bsc->pcap_fd;