aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bts.cpp55
-rw-r--r--src/bts.h2
-rw-r--r--src/gprs_rlcmac.cpp55
-rw-r--r--src/gprs_rlcmac_data.cpp2
-rw-r--r--src/tbf.cpp4
-rw-r--r--src/tbf.h3
-rw-r--r--tests/alloc/AllocTest.cpp6
7 files changed, 63 insertions, 64 deletions
diff --git a/src/bts.cpp b/src/bts.cpp
index cbe6303b..cc53f254 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -236,6 +236,61 @@ gprs_rlcmac_tbf *BTS::tbf_by_tfi(uint8_t tfi, uint8_t trx,
return NULL;
}
+/* FIXME: spread resources over multiple TRX. Also add option to use same
+ * TRX in case of existing TBF for TLLI in the other direction. */
+/* search for free TFI and return TFI, TRX */
+int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir,
+ uint8_t *_trx, int8_t use_trx)
+{
+ struct gprs_rlcmac_pdch *pdch;
+ struct gprs_rlcmac_tbf **tbfp;
+ uint8_t trx_from, trx_to, trx, ts, tfi;
+
+ if (use_trx >= 0 && use_trx < 8)
+ trx_from = trx_to = use_trx;
+ else {
+ trx_from = 0;
+ trx_to = 7;
+ }
+
+ /* on TRX find first enabled TS */
+ for (trx = trx_from; trx <= trx_to; trx++) {
+ for (ts = 0; ts < 8; ts++) {
+ pdch = &m_bts.trx[trx].pdch[ts];
+ if (!pdch->is_enabled())
+ continue;
+ break;
+ }
+ if (ts < 8)
+ break;
+ }
+ if (trx > trx_to) {
+ LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n");
+ return -EINVAL;
+ }
+
+
+ LOGP(DRLCMAC, LOGL_DEBUG, "Searching for first unallocated TFI: "
+ "TRX=%d first TS=%d\n", trx, ts);
+ if (dir == GPRS_RLCMAC_UL_TBF)
+ tbfp = m_bts.trx[trx].ul_tbf;
+ else
+ tbfp = m_bts.trx[trx].dl_tbf;
+ for (tfi = 0; tfi < 32; tfi++) {
+ if (!tbfp[tfi])
+ break;
+ }
+
+ if (tfi < 32) {
+ LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi);
+ *_trx = trx;
+ return tfi;
+ }
+ LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available.\n");
+
+ return -1;
+}
+
/*
* PDCH code below. TODO: move to a separate file
diff --git a/src/bts.h b/src/bts.h
index f785899a..4d6b6645 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -166,6 +166,8 @@ public:
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);
+ int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx);
+
private:
int m_cur_fn;
struct gprs_rlcmac_bts m_bts;
diff --git a/src/gprs_rlcmac.cpp b/src/gprs_rlcmac.cpp
index 62e8ea7b..8abe4752 100644
--- a/src/gprs_rlcmac.cpp
+++ b/src/gprs_rlcmac.cpp
@@ -113,61 +113,6 @@ void debug_diagram(BTS *bts, int diag, const char *format, ...)
}
#endif
-/* FIXME: spread resources over multiple TRX. Also add option to use same
- * TRX in case of existing TBF for TLLI in the other direction. */
-/* search for free TFI and return TFI, TRX */
-int tfi_find_free(struct gprs_rlcmac_bts *bts, enum gprs_rlcmac_tbf_direction dir,
- uint8_t *_trx, int8_t use_trx)
-{
- struct gprs_rlcmac_pdch *pdch;
- struct gprs_rlcmac_tbf **tbfp;
- uint8_t trx_from, trx_to, trx, ts, tfi;
-
- if (use_trx >= 0 && use_trx < 8)
- trx_from = trx_to = use_trx;
- else {
- trx_from = 0;
- trx_to = 7;
- }
-
- /* on TRX find first enabled TS */
- for (trx = trx_from; trx <= trx_to; trx++) {
- for (ts = 0; ts < 8; ts++) {
- pdch = &bts->trx[trx].pdch[ts];
- if (!pdch->is_enabled())
- continue;
- break;
- }
- if (ts < 8)
- break;
- }
- if (trx > trx_to) {
- LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n");
- return -EINVAL;
- }
-
-
- LOGP(DRLCMAC, LOGL_DEBUG, "Searching for first unallocated TFI: "
- "TRX=%d first TS=%d\n", trx, ts);
- if (dir == GPRS_RLCMAC_UL_TBF)
- tbfp = bts->trx[trx].ul_tbf;
- else
- tbfp = bts->trx[trx].dl_tbf;
- for (tfi = 0; tfi < 32; tfi++) {
- if (!tbfp[tfi])
- break;
- }
-
- if (tfi < 32) {
- LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi);
- *_trx = trx;
- return tfi;
- }
- LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available.\n");
-
- return -1;
-}
-
/* Send Uplink unit-data to SGSN. */
int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf)
{
diff --git a/src/gprs_rlcmac_data.cpp b/src/gprs_rlcmac_data.cpp
index d5bebff1..a9720ca2 100644
--- a/src/gprs_rlcmac_data.cpp
+++ b/src/gprs_rlcmac_data.cpp
@@ -334,7 +334,7 @@ int gprs_rlcmac_rcv_rach(struct gprs_rlcmac_bts *bts,
} else {
// Create new TBF
#warning "Copy and pate with other routines.."
- tfi = tfi_find_free(bts, GPRS_RLCMAC_UL_TBF, &trx, -1);
+ tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx, -1);
if (tfi < 0) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH ressource\n");
/* FIXME: send reject */
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 2282aeac..4225b3be 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -158,7 +158,7 @@ static int tbf_new_dl_assignment(struct gprs_rlcmac_bts *bts,
// Create new TBF (any TRX)
#warning "Copy and paste with alloc_ul_tbf"
- tfi = tfi_find_free(bts, GPRS_RLCMAC_DL_TBF, &trx, use_trx);
+ tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx, use_trx);
if (tfi < 0) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
/* FIXME: send reject */
@@ -227,7 +227,7 @@ struct gprs_rlcmac_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
#warning "Copy and paste with tbf_new_dl_assignment"
/* create new TBF, use sme TRX as DL TBF */
- tfi = tfi_find_free(bts, GPRS_RLCMAC_UL_TBF, &trx, use_trx);
+ tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx, use_trx);
if (tfi < 0) {
LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH ressource\n");
/* FIXME: send reject */
diff --git a/src/tbf.h b/src/tbf.h
index 0181dffa..0f8e77d1 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -219,9 +219,6 @@ struct gprs_rlcmac_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
int8_t use_trx, uint8_t ms_class,
uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf);
-int tfi_find_free(struct gprs_rlcmac_bts *bts, enum gprs_rlcmac_tbf_direction dir,
- uint8_t *_trx, int8_t use_trx);
-
struct gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
struct gprs_rlcmac_tbf *old_tbf,
enum gprs_rlcmac_tbf_direction dir, uint8_t tfi, uint8_t trx,
diff --git a/tests/alloc/AllocTest.cpp b/tests/alloc/AllocTest.cpp
index 281ac652..5790ade1 100644
--- a/tests/alloc/AllocTest.cpp
+++ b/tests/alloc/AllocTest.cpp
@@ -62,13 +62,13 @@ static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count)
for (int i = 0; i < count; ++i) {
struct gprs_rlcmac_tbf *tbf;
- tfi = tfi_find_free(bts, dir, &used_trx, 0);
+ tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
OSMO_ASSERT(tfi >= 0);
tbfs[i] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0);
}
/* Now check that there are still some TFIs */
- tfi = tfi_find_free(bts, dir, &used_trx, 0);
+ tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
switch (dir) {
case GPRS_RLCMAC_UL_TBF:
OSMO_ASSERT(tfi >= 0);
@@ -83,7 +83,7 @@ static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count)
if (tbfs[i])
tbf_free(tbfs[i]);
- tfi = tfi_find_free(bts, dir, &used_trx, 0);
+ tfi = the_bts.tfi_find_free(dir, &used_trx, 0);
OSMO_ASSERT(tfi >= 0);
tbfs[tfi] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0);