osmo-pcu[master]: TBF: make network counters internal

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6609
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I89c7186f74bde7e6ac5f6e98f0b3e4c35274
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-pcu[master]: TBF: make network counters internal

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: TBF: make network counters internal
..


TBF: make network counters internal

* store N310* counters in shared array similar to corresponding timers
* add functions to increment/reset counters

This avoids direct access to TBF counters from PDCH.

Change-Id: I89c7186f74bde7e6ac5f6e98f0b3e4c35274
Related: OS#1539
---
M src/pdch.cpp
M src/tbf.cpp
M src/tbf.h
M src/tbf_dl.cpp
M src/tbf_ul.cpp
5 files changed, 88 insertions(+), 35 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/pdch.cpp b/src/pdch.cpp
index ee9df31..22a1605 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -290,7 +290,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
 
@@ -310,7 +310,7 @@
if (tbf->dl_ass_state_is(GPRS_RLCMAC_DL_ASS_WAIT_ACK)) {
LOGPTBF(tbf, LOGL_DEBUG, "[UPLINK] DOWNLINK ASSIGNED\n");
/* reset N3105 */
-   tbf->n3105 = 0;
+   tbf->n_reset(N3105);
TBF_SET_ASS_STATE_DL(tbf, GPRS_RLCMAC_DL_ASS_NONE);
 
new_tbf = tbf->ms() ? tbf->ms()->dl_tbf() : NULL;
@@ -342,7 +342,7 @@
if (tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_WAIT_ACK)) {
LOGPTBF(tbf, LOGL_DEBUG, "[DOWNLINK] UPLINK ASSIGNED\n");
/* reset N3105 */
-   tbf->n3105 = 0;
+   tbf->n_reset(N3105);
TBF_SET_ASS_STATE_UL(tbf, GPRS_RLCMAC_UL_ASS_NONE);
 
new_tbf = tbf->ms() ? tbf->ms()->ul_tbf() : NULL;
@@ -399,7 +399,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
if (tbf->handle_ack_nack())
LOGPTBF(tbf, LOGL_NOTICE, "Recovered downlink ack\n");
@@ -466,7 +466,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
if (tbf->handle_ack_nack())
LOGPTBF(tbf, LOGL_NOTICE, "Recovered EGPRS downlink ack\n");
@@ -638,7 +638,7 @@
"RX: [PCU <- BTS] FIXME: Packet resource request\n");
 
/* Reset N3101 counter: */
-   dl_tbf->m_n3101 = 0;
+   dl_tbf->n_reset(N3101);
} else {
struct gprs_rlcmac_ul_tbf *ul_tbf;
int8_t tfi = request->ID.u.Global_TFI.u.UPLINK_TFI;
@@ -651,7 +651,7 @@
"RX: [PCU <- BTS] FIXME: Packet resource request\n");
 
/* Reset N3101 counter: */
-   ul_tbf->m_n3101 = 0;
+   ul_tbf->n_reset(N3101);
}
 }
 
@@ -806,7 +806,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
return tbf->rcv_data_block_acknowledged(_dec, data, meas);
 }
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 72b39ec..7036ea1 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -80,6 +80,13 @@
{ 0, NULL }
 };
 
+static const struct value_string tbf_counters_names[] = {
+   OSMO_VALUE_STRING(N3101),
+   OSMO_VALUE_STRING(N3103),
+   OSMO_VALUE_STRING(N3105),
+   { 0, NULL }
+};
+
 static const struct value_string tbf_timers_names[] = {
OSMO_VALUE_STRING(T0),
OSMO_VALUE_STRING(T3169),
@@ -187,13 +194,11 @@
control_ts(0xff),
poll_fn(0),
poll_ts(0),
-   n3105(0),
fT(0),
num_fT_exp(0),
was_releasing(0),
upgrade_to_multislot(0),
bts(bts_),
-   m_n3101(0),
m_tfi(0),
m_created_ts(0),
m_ctrs(NULL),
@@ -213,6 +218,7 @@
 * Just set them to 0 like talloc_zero did */
memset(, 0, sizeof(pdch));
memset(, 0, sizeof(T));
+   memset(, 0, sizeof(N));
memset(_rlc, 0, sizeof(m_rlc));
memset(_timer, 0, sizeof(gsm_timer));
 
@@ -546,6 +552,55 @@
"RELEASING",
 };
 
+void gprs_rlcmac_tbf::n_reset(enum tbf_counters n)
+{
+   if (n >= N_MAX) {
+   LOGPTBF(this, LOGL_ERROR, "attempting to reset unknown counter 
%s\n",
+   get_value_string(tbf_counters_names, n));
+   return;
+   }
+
+   N[n] = 0;
+}
+
+/* Increment counter and check for MAX value (return true if we hit it) */
+bool gprs_rlcmac_tbf::n_inc(enum tbf_counters n)
+{
+   uint8_t chk;
+
+   if (n >= N_MAX) {
+   LOGPTBF(this, LOGL_ERROR, "attempting to increment unknown 
counter %s\n",
+   get_value_string(tbf_counters_names, n));
+   return true;
+   }
+
+   N[n]++;
+
+   switch(n) {
+   case N3101:
+   chk = bts->bts_data()->n3101;
+   break;
+   case N3103:
+   chk = bts->bts_data()->n3103;
+   break;
+   case N3105:
+