tbf, gprs_rlcmac_meas: Move the DL bandwidth variables to the DL TBF

The bandwidth calculation as well as loss report is only done for DL TBF
so move everything related to that in there.

Ticket: SYS#389
Sponsored by: On-Waves ehf
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index 148250a..6f8a7a4 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -62,10 +62,10 @@
 	uint8_t block_payload;
 };
 
-int gprs_rlcmac_received_lost(struct gprs_rlcmac_tbf *tbf, uint16_t received,
+int gprs_rlcmac_received_lost(struct gprs_rlcmac_dl_tbf *tbf, uint16_t received,
 	uint16_t lost);
 
-int gprs_rlcmac_lost_rep(struct gprs_rlcmac_tbf *tbf);
+int gprs_rlcmac_lost_rep(struct gprs_rlcmac_dl_tbf *tbf);
 
 int gprs_rlcmac_meas_rep(Packet_Measurement_Report_t *pmr);
 
@@ -73,7 +73,7 @@
 
 int gprs_rlcmac_rssi_rep(struct gprs_rlcmac_tbf *tbf);
 
-int gprs_rlcmac_dl_bw(struct gprs_rlcmac_tbf *tbf, uint16_t octets);
+int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets);
 
 /* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */
 enum gprs_rlcmac_block_type {
diff --git a/src/gprs_rlcmac_meas.cpp b/src/gprs_rlcmac_meas.cpp
index 30958fc..5a2e38e 100644
--- a/src/gprs_rlcmac_meas.cpp
+++ b/src/gprs_rlcmac_meas.cpp
@@ -112,10 +112,10 @@
  */
 
 /* Lost frames reported from RLCMAC layer */
-int gprs_rlcmac_received_lost(struct gprs_rlcmac_tbf *tbf, uint16_t received,
+int gprs_rlcmac_received_lost(struct gprs_rlcmac_dl_tbf *tbf, uint16_t received,
 	uint16_t lost)
 {
-	struct timeval now_tv, *loss_tv = &tbf->meas.dl_loss_tv;
+	struct timeval now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv;
 	uint32_t elapsed;
 	uint16_t sum = received + lost;
 
@@ -126,8 +126,8 @@
 	LOGP(DRLCMACMEAS, LOGL_DEBUG, "DL Loss of TLLI 0x%08x: Received: %4d  "
 		"Lost: %4d  Sum: %4d\n", tbf->tlli(), received, lost, sum);
 
-	tbf->meas.dl_loss_received += received;
-	tbf->meas.dl_loss_lost += lost;
+	tbf->m_bw.dl_loss_received += received;
+	tbf->m_bw.dl_loss_lost += lost;
 
 	gettimeofday(&now_tv, NULL);
 	elapsed = ((now_tv.tv_sec - loss_tv->tv_sec) << 7)
@@ -139,16 +139,16 @@
 
 	/* reset lost values and timestamp */
 	memcpy(loss_tv, &now_tv, sizeof(struct timeval));
-	tbf->meas.dl_loss_received = 0;
-	tbf->meas.dl_loss_lost = 0;
+	tbf->m_bw.dl_loss_received = 0;
+	tbf->m_bw.dl_loss_lost = 0;
 
 	return 0;
 }
 
 /* Give Lost report */
-int gprs_rlcmac_lost_rep(struct gprs_rlcmac_tbf *tbf)
+int gprs_rlcmac_lost_rep(struct gprs_rlcmac_dl_tbf *tbf)
 {
-	uint16_t sum = tbf->meas.dl_loss_lost + tbf->meas.dl_loss_received;
+	uint16_t sum = tbf->m_bw.dl_loss_lost + tbf->m_bw.dl_loss_received;
 
 	/* No measurement values */
 	if (!sum)
@@ -156,7 +156,7 @@
 
 	LOGP(DRLCMACMEAS, LOGL_INFO, "DL packet loss of IMSI=%s / TLLI=0x%08x: "
 		"%d%%\n", tbf->imsi(), tbf->tlli(),
-		tbf->meas.dl_loss_lost * 100 / sum);
+		tbf->m_bw.dl_loss_lost * 100 / sum);
 
 	return 0;
 }
@@ -166,12 +166,12 @@
  * downlink bandwidth
  */
 
-int gprs_rlcmac_dl_bw(struct gprs_rlcmac_tbf *tbf, uint16_t octets)
+int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets)
 {
-	struct timeval now_tv, *bw_tv = &tbf->meas.dl_bw_tv;
+	struct timeval now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv;
 	uint32_t elapsed;
 
-	tbf->meas.dl_bw_octets += octets;
+	tbf->m_bw.dl_bw_octets += octets;
 
 	gettimeofday(&now_tv, NULL);
 	elapsed = ((now_tv.tv_sec - bw_tv->tv_sec) << 7)
@@ -181,11 +181,11 @@
 
 	LOGP(DRLCMACMEAS, LOGL_INFO, "DL Bandwitdh of IMSI=%s / TLLI=0x%08x: "
 		"%d KBits/s\n", tbf->imsi(), tbf->tlli(),
-		tbf->meas.dl_bw_octets / elapsed);
+		tbf->m_bw.dl_bw_octets / elapsed);
 
 	/* reset bandwidth values timestamp */
 	memcpy(bw_tv, &now_tv, sizeof(struct timeval));
-	tbf->meas.dl_bw_octets = 0;
+	tbf->m_bw.dl_bw_octets = 0;
 
 	return 0;
 }
diff --git a/src/tbf.cpp b/src/tbf.cpp
index e5b8863..647710c 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -268,7 +268,10 @@
 {
 	/* Give final measurement report */
 	gprs_rlcmac_rssi_rep(tbf);
-	gprs_rlcmac_lost_rep(tbf);
+	if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
+		gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(tbf);
+		gprs_rlcmac_lost_rep(dl_tbf);
+	}
 
 	LOGP(DRLCMAC, LOGL_INFO, "%s free\n", tbf_name(tbf));
 	if (tbf->ul_ass_state != GPRS_RLCMAC_UL_ASS_NONE)
@@ -519,9 +522,7 @@
 	}
 
 	/* set timestamp */
-	gettimeofday(&tbf->meas.dl_bw_tv, NULL);
 	gettimeofday(&tbf->meas.rssi_tv, NULL);
-	gettimeofday(&tbf->meas.dl_loss_tv, NULL);
 
 	tbf->m_llc.init();
 	return 0;
@@ -591,6 +592,9 @@
 	llist_add(&tbf->list.list, &bts->dl_tbfs);
 	tbf->bts->tbf_dl_created();
 
+	gettimeofday(&tbf->m_bw.dl_bw_tv, NULL);
+	gettimeofday(&tbf->m_bw.dl_loss_tv, NULL);
+
 	return tbf;
 }
 
diff --git a/src/tbf.h b/src/tbf.h
index 22504e7..54781c0 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -179,17 +179,9 @@
 	unsigned int num_fT_exp; /* number of consecutive fT expirations */
 
 	struct {
-		struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
-		uint32_t dl_bw_octets; /* number of octets since bw_tv */
-
 		struct timeval rssi_tv; /* timestamp for rssi calculation */
 		int32_t rssi_sum; /* sum of rssi values */
 		int rssi_num; /* number of rssi values added since rssi_tv */
-
-		struct timeval dl_loss_tv; /* timestamp for loss calculation */
-		uint16_t dl_loss_lost; /* sum of lost packets */
-		uint16_t dl_loss_received; /* sum of received packets */
-
 	} meas;
 
 	uint8_t cs; /* current coding scheme */
@@ -319,6 +311,15 @@
 	int32_t m_tx_counter; /* count all transmitted blocks */
 	uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */
 
+	struct {
+		struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
+		uint32_t dl_bw_octets; /* number of octets since bw_tv */
+
+		struct timeval dl_loss_tv; /* timestamp for loss calculation */
+		uint16_t dl_loss_lost; /* sum of lost packets */
+		uint16_t dl_loss_received; /* sum of received packets */
+	} m_bw;
+
 protected:
 	struct msgb *create_new_bsn(const uint32_t fn, const uint8_t ts);
 	struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,