aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-06-29 14:18:46 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-07-03 13:17:22 +0200
commitac89a555fa73b24a77bb861811774a5af885bc84 (patch)
treed0edad2d9003d7355f5637e61aa4f8f2f73879f8
parent699b8dca49df30b7bf6db7090eb416d1ad4fd46d (diff)
ms: Add tbf() method to get the TBF based on the direction
To avoid the need for a switch or conditional statement when needing a TBF from an MS object in direction independant code, this method contains that case distinction. For additional flexibility, a reverse() function is added to get the opposite direction. Sponsored-by: On-Waves ehf
-rw-r--r--src/gprs_ms.cpp9
-rw-r--r--src/gprs_ms.h2
-rw-r--r--src/tbf.h5
-rw-r--r--tests/ms/MsTest.cpp3
-rw-r--r--tests/tbf/TbfTest.cpp12
-rw-r--r--tests/tbf/TbfTest.ok2
6 files changed, 33 insertions, 0 deletions
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index 1014ea3..4c0ecfd 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -529,3 +529,12 @@ int GprsMs::first_common_ts() const
return -1;
}
+gprs_rlcmac_tbf *GprsMs::tbf(enum gprs_rlcmac_tbf_direction dir) const
+{
+ switch (dir) {
+ case GPRS_RLCMAC_DL_TBF: return m_dl_tbf;
+ case GPRS_RLCMAC_UL_TBF: return m_ul_tbf;
+ }
+
+ return NULL;
+}
diff --git a/src/gprs_ms.h b/src/gprs_ms.h
index 17ee41b..2c6061c 100644
--- a/src/gprs_ms.h
+++ b/src/gprs_ms.h
@@ -26,6 +26,7 @@ struct gprs_rlcmac_ul_tbf;
#include "cxx_linuxlist.h"
#include "llc.h"
+#include "tbf.h"
#include "pcu_l1_if.h"
extern "C" {
@@ -60,6 +61,7 @@ public:
gprs_rlcmac_ul_tbf *ul_tbf() const {return m_ul_tbf;}
gprs_rlcmac_dl_tbf *dl_tbf() const {return m_dl_tbf;}
+ gprs_rlcmac_tbf *tbf(enum gprs_rlcmac_tbf_direction dir) const;
uint32_t tlli() const;
void set_tlli(uint32_t tlli);
bool confirm_tlli(uint32_t tlli);
diff --git a/src/tbf.h b/src/tbf.h
index cf8cdfc..840125a 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -395,6 +395,11 @@ protected:
void maybe_schedule_uplink_acknack(const rlc_ul_header *rh);
};
+inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir)
+{
+ return (enum gprs_rlcmac_tbf_direction)
+ ((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF);
+}
#endif
#ifdef __cplusplus
diff --git a/tests/ms/MsTest.cpp b/tests/ms/MsTest.cpp
index f2faefc..5a25d76 100644
--- a/tests/ms/MsTest.cpp
+++ b/tests/ms/MsTest.cpp
@@ -69,6 +69,9 @@ static void test_ms_state()
OSMO_ASSERT(ms->ul_tbf() == ul_tbf);
OSMO_ASSERT(ms->dl_tbf() == dl_tbf);
+ OSMO_ASSERT(ms->tbf(GPRS_RLCMAC_UL_TBF) == ul_tbf);
+ OSMO_ASSERT(ms->tbf(GPRS_RLCMAC_DL_TBF) == dl_tbf);
+
ms->detach_tbf(ul_tbf);
OSMO_ASSERT(!ms->is_idle());
OSMO_ASSERT(ms->ul_tbf() == NULL);
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index c9b01db..47c090a 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -61,6 +61,17 @@ static unsigned inc_fn(fn)
}
*/
+static void test_tbf_base()
+{
+
+ printf("=== start %s ===\n", __func__);
+
+ OSMO_ASSERT(GPRS_RLCMAC_DL_TBF == reverse(GPRS_RLCMAC_UL_TBF));
+ OSMO_ASSERT(GPRS_RLCMAC_UL_TBF == reverse(GPRS_RLCMAC_DL_TBF));
+
+ printf("=== end %s ===\n", __func__);
+}
+
static void test_tbf_tlli_update()
{
BTS the_bts;
@@ -667,6 +678,7 @@ int main(int argc, char **argv)
vty_init(&pcu_vty_info);
pcu_vty_init(&debug_log_info);
+ test_tbf_base();
test_tbf_tlli_update();
test_tbf_final_ack(TEST_MODE_STANDARD);
test_tbf_final_ack(TEST_MODE_REVERSE_FREE);
diff --git a/tests/tbf/TbfTest.ok b/tests/tbf/TbfTest.ok
index 8c2c0e7..274f069 100644
--- a/tests/tbf/TbfTest.ok
+++ b/tests/tbf/TbfTest.ok
@@ -1,3 +1,5 @@
+=== start test_tbf_base ===
+=== end test_tbf_base ===
=== start test_tbf_delayed_release ===
=== end test_tbf_delayed_release ===
=== start test_tbf_imsi ===