[osmo-pcu,1/3] bts, tbf: Separate functions for dl/ul tbf_by_tlli lookup
diff mbox

Message ID e91f24557219b0fd1e01e0f84834adc75e3a8c70.1404316696.git.daniel@totalueberwachung.de
State Accepted
Headers show

Commit Message

Daniel Willmann July 2, 2014, 3:58 p.m. UTC
In the future we want to separate ul and dl tbf into different
classes that inherit from a common base.

Ticket: SYS#389
Sponsored-by: On-Waves ehf
---
 src/bts.cpp           | 24 +++++++++++++++++-------
 src/bts.h             |  4 +++-
 src/tbf.cpp           | 18 +++++++++---------
 tests/tbf/TbfTest.cpp | 12 ++++++------
 4 files changed, 35 insertions(+), 23 deletions(-)

Patch
diff mbox

diff --git a/src/bts.cpp b/src/bts.cpp
index 3dd5705..51be2d9 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -216,6 +216,18 @@  int BTS::add_paging(uint8_t chan_needed, uint8_t *identity_lv)
 	return 0;
 }
 
+/* search for active downlink tbf */
+gprs_rlcmac_tbf *BTS::dl_tbf_by_tlli(uint32_t tlli)
+{
+	return tbf_by_tlli(tlli, GPRS_RLCMAC_DL_TBF);
+}
+
+/* search for active uplink tbf */
+gprs_rlcmac_tbf *BTS::ul_tbf_by_tlli(uint32_t tlli)
+{
+	return tbf_by_tlli(tlli, GPRS_RLCMAC_UL_TBF);
+}
+
 /* search for active downlink or uplink tbf */
 gprs_rlcmac_tbf *BTS::tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir)
 {
@@ -360,7 +372,7 @@  int BTS::rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn)
 	tlli |= (*data++) << 4;
 	tlli |= (*data++) >> 4;
 
-	tbf = tbf_by_tlli(tlli, GPRS_RLCMAC_DL_TBF);
+	tbf = dl_tbf_by_tlli(tlli);
 	if (!tbf) {
 		LOGP(DRLCMAC, LOGL_ERROR, "Got IMM.ASS confirm, but TLLI=%08x "
 			"does not exit\n", tlli);
@@ -725,8 +737,7 @@  void gprs_rlcmac_pdch::rcv_control_ack(Packet_Control_Acknowledgement_t *packet,
 		tbf->n3105 = 0;
 		tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
 		if (tbf->direction == GPRS_RLCMAC_UL_TBF)
-			tbf = bts()->tbf_by_tlli(tbf->tlli(),
-						GPRS_RLCMAC_DL_TBF);
+			tbf = bts()->dl_tbf_by_tlli(tbf->tlli());
 #warning "TBF is changing on the way... *sigh*"
 		if (!tbf) {
 			LOGP(DRLCMAC, LOGL_ERROR, "Got ACK, but DL "
@@ -753,8 +764,7 @@  void gprs_rlcmac_pdch::rcv_control_ack(Packet_Control_Acknowledgement_t *packet,
 		tbf->ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE;
 #warning "TBF is changing on the way... *sigh*"
 		if (tbf->direction == GPRS_RLCMAC_DL_TBF)
-			tbf = bts()->tbf_by_tlli(tbf->tlli(),
-						GPRS_RLCMAC_UL_TBF);
+			tbf = bts()->ul_tbf_by_tlli(tbf->tlli());
 		if (!tbf) {
 			LOGP(DRLCMAC, LOGL_ERROR, "Got ACK, but UL "
 				"TBF is gone TLLI=0x%08x\n", tlli);
@@ -836,7 +846,7 @@  void gprs_rlcmac_pdch::rcv_resource_request(Packet_Resource_Request_t *request,
 		struct gprs_rlcmac_tbf *dl_tbf;
 		uint8_t ta;
 
-		tbf = bts()->tbf_by_tlli(tlli, GPRS_RLCMAC_UL_TBF);
+		tbf = bts()->ul_tbf_by_tlli(tlli);
 		if (tbf) {
 			LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
 				"TLLI=0x%08x while %s still "
@@ -846,7 +856,7 @@  void gprs_rlcmac_pdch::rcv_resource_request(Packet_Resource_Request_t *request,
 			tbf = NULL;
 		}
 
-		if ((dl_tbf = bts()->tbf_by_tlli(tlli, GPRS_RLCMAC_DL_TBF))) {
+		if ((dl_tbf = bts()->dl_tbf_by_tlli(tlli))) {
 			LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
 				"TLLI=0x%08x while %s still exists. "
 				"Killing pending DL TBF\n", tlli,
diff --git a/src/bts.h b/src/bts.h
index aa68ed7..c83bb18 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -192,7 +192,8 @@  public:
 	/** add paging to paging queue(s) */
 	int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
 
-	gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
+	gprs_rlcmac_tbf *dl_tbf_by_tlli(uint32_t tlli);
+	gprs_rlcmac_tbf *ul_tbf_by_tlli(uint32_t tlli);
 	gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
 	gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, uint8_t trx, enum gprs_rlcmac_tbf_direction dir);
 
@@ -238,6 +239,7 @@  private:
 	SBAController m_sba;
 	TimingAdvance m_ta;
 	struct rate_ctr_group *m_ratectrs;
+	gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
 
 private:
 	/* disable copying to avoid slicing */
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 5943674..f913f97 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -82,7 +82,7 @@  static struct gprs_rlcmac_tbf *tbf_lookup_dl(BTS *bts,
 					const uint32_t tlli, const char *imsi)
 {
 	/* TODO: look up by IMSI first, then tlli, then old_tlli */
-	return bts->tbf_by_tlli(tlli, GPRS_RLCMAC_DL_TBF);
+	return bts->dl_tbf_by_tlli(tlli);
 }
 
 int gprs_rlcmac_tbf::append_data(const uint8_t ms_class,
@@ -130,7 +130,7 @@  static int tbf_new_dl_assignment(struct gprs_rlcmac_bts *bts,
 	/* check for uplink data, so we copy our informations */
 #warning "Do the same look up for IMSI, TLLI and OLD_TLLI"
 #warning "Refactor the below lines... into a new method"
-	tbf = bts->bts->tbf_by_tlli(tlli, GPRS_RLCMAC_UL_TBF);
+	tbf = bts->bts->ul_tbf_by_tlli(tlli);
 	if (tbf && tbf->dir.ul.contention_resolution_done
 	 && !tbf->dir.ul.final_ack_sent) {
 		use_trx = tbf->trx->trx_no;
@@ -308,7 +308,7 @@  int gprs_rlcmac_tbf::update()
 	if (direction != GPRS_RLCMAC_DL_TBF)
 		return -EINVAL;
 
-	ul_tbf = bts->tbf_by_tlli(m_tlli, GPRS_RLCMAC_UL_TBF);
+	ul_tbf = bts->ul_tbf_by_tlli(m_tlli);
 
 	tbf_unlink_pdch(this);
 	rc = bts_data->alloc_algorithm(bts_data, ul_tbf, this, bts_data->alloc_algorithm_curst, 0);
@@ -1182,7 +1182,7 @@  struct msgb *gprs_rlcmac_tbf::create_dl_ass(uint32_t fn)
 			return NULL;
 		}
 		#warning "THIS should probably go over the IMSI too"
-		new_tbf = bts->tbf_by_tlli(m_tlli, GPRS_RLCMAC_DL_TBF);
+		new_tbf = bts->dl_tbf_by_tlli(m_tlli);
 	} else
 		new_tbf = this;
 	if (!new_tbf) {
@@ -1252,7 +1252,7 @@  struct msgb *gprs_rlcmac_tbf::create_ul_ass(uint32_t fn)
 	/* on down TBF we get the uplink TBF to be assigned. */
 #warning "Probably want to find by IMSI too"
 	if (direction == GPRS_RLCMAC_DL_TBF)
-		new_tbf = bts->tbf_by_tlli(m_tlli, GPRS_RLCMAC_UL_TBF);
+		new_tbf = bts->ul_tbf_by_tlli(m_tlli);
 	else
 		new_tbf = this;
 
@@ -1497,7 +1497,7 @@  void gprs_rlcmac_tbf::update_tlli(uint32_t tlli)
 	 */
 	if (m_tlli_valid && direction == GPRS_RLCMAC_DL_TBF) {
 		gprs_rlcmac_tbf *ul_tbf;
-		ul_tbf = bts->tbf_by_tlli(m_tlli, GPRS_RLCMAC_UL_TBF);
+		ul_tbf = bts->ul_tbf_by_tlli(m_tlli);
 
 		if (ul_tbf) {
 			ul_tbf->m_tlli = tlli;
@@ -1537,7 +1537,7 @@  int gprs_rlcmac_tbf::extract_tlli(const uint8_t *data, const size_t len)
 	update_tlli(new_tlli);
 	LOGP(DRLCMACUL, LOGL_INFO, "Decoded premier TLLI=0x%08x of "
 		"UL DATA TFI=%d.\n", tlli(), rh->tfi);
-	if ((dl_tbf = bts->tbf_by_tlli(tlli(), GPRS_RLCMAC_DL_TBF))) {
+	if ((dl_tbf = bts->dl_tbf_by_tlli(tlli()))) {
 		LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
 			"TLLI=0x%08x while %s still exists. "
 			"Killing pending DL TBF\n", tlli(),
@@ -1545,9 +1545,9 @@  int gprs_rlcmac_tbf::extract_tlli(const uint8_t *data, const size_t len)
 		tbf_free(dl_tbf);
 		dl_tbf = NULL;
 	}
-	/* tbf_by_tlli will not find your TLLI, because it is not
+	/* ul_tbf_by_tlli will not find your TLLI, because it is not
 	 * yet marked valid */
-	if ((ul_tbf = bts->tbf_by_tlli(tlli(), GPRS_RLCMAC_UL_TBF))) {
+	if ((ul_tbf = bts->ul_tbf_by_tlli(tlli()))) {
 		LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from "
 			"TLLI=0x%08x while %s still exists. "
 			"Killing pending UL TBF\n", tlli(),
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index 86c5bbd..38975f9 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -59,8 +59,8 @@  static void test_tbf_tlli_update()
 	ul_tbf->tlli_mark_valid();
 	
 
-	OSMO_ASSERT(the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_DL_TBF) == dl_tbf);
-	OSMO_ASSERT(the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_UL_TBF) == ul_tbf);
+	OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x2342) == dl_tbf);
+	OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x2342) == ul_tbf);
 
 
 	/*
@@ -68,12 +68,12 @@  static void test_tbf_tlli_update()
 	 * has changed.
 	 */
 	dl_tbf->update_tlli(0x4232);
-	OSMO_ASSERT(!the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_DL_TBF));
-	OSMO_ASSERT(!the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_UL_TBF));
+	OSMO_ASSERT(!the_bts.dl_tbf_by_tlli(0x2342));
+	OSMO_ASSERT(!the_bts.ul_tbf_by_tlli(0x2342));
 
 	
-	OSMO_ASSERT(the_bts.tbf_by_tlli(0x4232, GPRS_RLCMAC_DL_TBF) == dl_tbf);
-	OSMO_ASSERT(the_bts.tbf_by_tlli(0x4232, GPRS_RLCMAC_UL_TBF) == ul_tbf);
+	OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x4232) == dl_tbf);
+	OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x4232) == ul_tbf);
 
 	OSMO_ASSERT(the_bts.timing_advance()->recall(0x4232) == 4);
 }