tbf/bts: Move the tfi_find_free into the bts
This commit is contained in:
parent
f63cabd931
commit
70ddde6929
55
src/bts.cpp
55
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue