Add stats: pcu.bts.N.pdch.available/occupied

Count available PDCHs (3GPP TS 52.402 § B.2.1.38) as well as occupied
PDCHs (§ B.2.1.42-44).

Related: SYS#4878
Change-Id: I74760a68ee055510a79e80854ec7bf1521669119
diff --git a/src/pdch.cpp b/src/pdch.cpp
index 49f9eb6..e213c28 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -150,6 +150,7 @@
 	this->ulc = pdch_ulc_alloc(this, trx->bts);
 
 	m_is_enabled = 1;
+	bts_stat_item_inc(trx->bts, STAT_PDCH_AVAILABLE);
 }
 
 void gprs_rlcmac_pdch::disable()
@@ -158,6 +159,7 @@
 	this->free_resources();
 
 	m_is_enabled = 0;
+	bts_stat_item_dec(trx->bts, STAT_PDCH_AVAILABLE);
 }
 
 void gprs_rlcmac_pdch::free_resources()
@@ -1043,6 +1045,12 @@
 			"%s has not been detached, overwriting it\n",
 			m_tbfs[tbf->direction][tbf->tfi()]->name());
 
+	/* Count PDCHs with at least one TBF as "occupied", as in
+	 * 3GPP TS 52.402 § B.2.1.42-44. So if transitioning from 0 TBFs in
+	 * this PDCH to 1, increase the counter by 1. */
+	if (m_num_tbfs[GPRS_RLCMAC_UL_TBF] + m_num_tbfs[GPRS_RLCMAC_DL_TBF] == 0)
+		bts_stat_item_inc(trx->bts, STAT_PDCH_OCCUPIED);
+
 	m_num_tbfs[tbf->direction] += 1;
 	if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
 		ul_tbf = as_ul_tbf(tbf);
@@ -1063,6 +1071,12 @@
 
 	OSMO_ASSERT(m_num_tbfs[tbf->direction] > 0);
 
+	/* Count PDCHs with at least one TBF as "occupied", as in
+	 * 3GPP TS 52.402 § B.2.1.42-44. So if transitioning from 1 TBFs in
+	 * this PDCH to 0, decrease the counter by 1. */
+	if (m_num_tbfs[GPRS_RLCMAC_UL_TBF] + m_num_tbfs[GPRS_RLCMAC_DL_TBF] == 1)
+		bts_stat_item_dec(trx->bts, STAT_PDCH_OCCUPIED);
+
 	m_num_tbfs[tbf->direction] -= 1;
 	if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
 		ul_tbf = as_ul_tbf(tbf);