diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2013-10-11 13:33:59 +0200 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2013-10-11 13:33:59 +0200 |
commit | 1c8a3d828612a6bea343a268072a7dddf4a22480 (patch) | |
tree | 59fbd4220ead81b03a9725533c4a96b16f841268 | |
parent | 0e40c97a76ffcf071e918e1b906cdee41cb9d48e (diff) |
dyn PDCH: Add algorithm to defragment shared TCH/F+PDCH channelsjolly/dyn_pdch
This algorithm ensures that gaps between active TCH/F+PDCH channels are
removed, by assigning active connections to standard TCH/F or by assigning
them to consecutive TCH/F+PDCH channels.
-rw-r--r-- | openbsc/include/openbsc/Makefile.am | 2 | ||||
-rw-r--r-- | openbsc/include/openbsc/pdch_defrag.h | 6 | ||||
-rw-r--r-- | openbsc/src/libbsc/Makefile.am | 2 | ||||
-rw-r--r-- | openbsc/src/libbsc/pdch_defrag.c | 183 |
4 files changed, 191 insertions, 2 deletions
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index 93b30bb0c..e8182f77f 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -13,7 +13,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \ osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h \ osmo_msc_data.h osmo_bsc_grace.h sms_queue.h abis_om2000.h \ bss.h gsm_data_shared.h control_cmd.h ipaccess.h mncc_int.h \ - arfcn_range_encode.h + arfcn_range_encode.h pdch_defrag.h openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h openbscdir = $(includedir)/openbsc diff --git a/openbsc/include/openbsc/pdch_defrag.h b/openbsc/include/openbsc/pdch_defrag.h new file mode 100644 index 000000000..97b61fa7d --- /dev/null +++ b/openbsc/include/openbsc/pdch_defrag.h @@ -0,0 +1,6 @@ +#ifndef _PDCH_DEFRAG_H +#define _PDCH_DEFRAG_H + +void do_pdch_defrag(struct gsm_bts *bts); + +#endif /* _PDCH_DEFRAG_H */ diff --git a/openbsc/src/libbsc/Makefile.am b/openbsc/src/libbsc/Makefile.am index 77e2d884e..69e887eee 100644 --- a/openbsc/src/libbsc/Makefile.am +++ b/openbsc/src/libbsc/Makefile.am @@ -23,5 +23,5 @@ libbsc_a_SOURCES = abis_nm.c abis_nm_vty.c \ bsc_api.c bsc_msc.c bsc_vty.c \ gsm_04_08_utils.c \ bsc_init.c bts_init.c bsc_rf_ctrl.c \ - arfcn_range_encode.c + arfcn_range_encode.c pdch_defrag.c diff --git a/openbsc/src/libbsc/pdch_defrag.c b/openbsc/src/libbsc/pdch_defrag.c new file mode 100644 index 000000000..5f075f65d --- /dev/null +++ b/openbsc/src/libbsc/pdch_defrag.c @@ -0,0 +1,183 @@ +/* (C) 2013 by Andreas Eversberg <andreas@eversberg.eu> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdlib.h> +#include <errno.h> + +#include <openbsc/debug.h> +#include <openbsc/gsm_data.h> +#include <openbsc/handover.h> +#include <openbsc/pdch_defrag.h> +#include <openbsc/chan_alloc.h> + +static struct gsm_lchan *find_shared_forward(struct gsm_bts *bts) +{ + struct gsm_bts_trx *trx; + struct gsm_lchan *lc; + int j; + + llist_for_each_entry(trx, &bts->trx_list, list) { + for (j = 0; j < 8; j++) { + /* find first TCH/F+PDCH */ + if (trx->ts[j].pchan == GSM_PCHAN_TCH_F_PDCH) { + lc = &trx->ts[j].lchan[0]; + if (lc->state == LCHAN_S_ACTIVE) + return lc; + } + } + } + + return NULL; +} + +static struct gsm_lchan *find_shared_reverse(struct gsm_bts *bts) +{ + struct gsm_bts_trx *trx; + struct gsm_lchan *lc; + int j; + + llist_for_each_entry_reverse(trx, &bts->trx_list, list) { + for (j = 7; j >= 0; j--) { + /* find last TCH/F+PDCH */ + if (trx->ts[j].pchan == GSM_PCHAN_TCH_F_PDCH) { + lc = &trx->ts[j].lchan[0]; + if (lc->state == LCHAN_S_ACTIVE) + return lc; + } + } + } + + return NULL; +} + +static void debug_bts_trx_ts(struct gsm_bts_trx_ts *ts) +{ + LOGPC(DHODEC, LOGL_DEBUG, " (BTS %u, TRX %u, TS %u)\n", + ts->trx->bts->nr, ts->trx->nr, ts->nr); +} + +/* Try to move a TCH/F+PDCH candidate to maintain as much free and consecutive + * GSM_PCHAN_TCH_F_PDCH slots as possible. + * + * This algorithm is triggered whenever a channel has been released. + * + * The last (highest TRX/TS number) and active TCH/F+PDCH is searched. If there + * is a TCH/F or a free TCH/F+PDCH on a lower TRX/TS number, assignment is + * triggered. (When allocation order is reversed, this algorithm handles TRX/TS + * numbers in reversed order also. + * + * This algorithm ensures that gaps between active TCH/F+PDCH channels are + * removed, by assigning active connections to standard TCH/F or by assigning + * them to consecutive TCH/F+PDCH channels. + */ +void do_pdch_defrag(struct gsm_bts *bts) +{ + struct gsm_lchan *old_lchan = NULL, *new_lchan; + int rc; + + /* search TCH/F+PDCH in reverse order of allocation */ + if (bts->chan_alloc_reverse) { + /* search from first to last TRX/TS */ + old_lchan = find_shared_forward(bts); + } else { + /* search from last to first TRX/TS */ + old_lchan = find_shared_reverse(bts); + } + + /* if there is no candidate on GSM_PCHAN_TCH_F_PDCH, we are done */ + if (!old_lchan) + return; + + LOGP(DHODEC, LOGL_DEBUG, "A shared TCH/F+PDCH is in use, check if we " + "can move connection."); + debug_bts_trx_ts(old_lchan->ts); + + /* allocate new lchan */ + new_lchan = lchan_alloc(bts, GSM_LCHAN_TCH_F, 0); + /* no free destination for candidate */ + if (!new_lchan) { + LOGP(DHODEC, LOGL_DEBUG, "-> Cannot move, no other TCH/F " + "available.\n"); + return; + } + + /* if new TS is also a GSM_PCHAN_TCH_F_PDCH */ + if (new_lchan->ts->pchan == GSM_PCHAN_TCH_F_PDCH) { + LOGP(DHODEC, LOGL_DEBUG, "-> New channel for candidate is also " + "a TCH/F+PDCH."); + debug_bts_trx_ts(new_lchan->ts); + /* be sure to move down (or up at reverse allocation) */ + if (bts->chan_alloc_reverse) { + /* new TS is lower */ + if (new_lchan->ts->trx->nr < old_lchan->ts->trx->nr) { + LOGP(DHODEC, LOGL_DEBUG, "-> Move does not " + "lower fragmentation, new TRX has " + "lower number.\n"); + goto free_lchan; + } + if (new_lchan->ts->trx->nr == old_lchan->ts->trx->nr + && new_lchan->ts->nr < old_lchan->ts->nr) { + LOGP(DHODEC, LOGL_DEBUG, "-> Move does not " + "lower fragmentation, new TS has " + "lower number.\n"); + goto free_lchan; + } + } else { + /* new TS is higher */ + if (new_lchan->ts->trx->nr > old_lchan->ts->trx->nr) { + goto free_lchan; + LOGP(DHODEC, LOGL_DEBUG, "-> Move does not " + "lower fragmentation, new TRX has " + "higher number.\n"); + } + if (new_lchan->ts->trx->nr == old_lchan->ts->trx->nr + && new_lchan->ts->nr > old_lchan->ts->nr) { + LOGP(DHODEC, LOGL_DEBUG, "-> Move does not " + "lower fragmentation, new TS has " + "higher number.\n"); + goto free_lchan; + } + } + } else { + LOGP(DHODEC, LOGL_DEBUG, "-> New channel for candidate is a " + "TCH/F."); + debug_bts_trx_ts(new_lchan->ts); + } + + rc = bsc_handover_start(old_lchan, new_lchan, new_lchan->ts->trx->bts, + 1); + if (rc) { + LOGP(DHODEC, LOGL_NOTICE, "Cannot trigger assignment to " + "defragment TCH/F+PDCH slots.\n"); + } else { + LOGP(DHODEC, LOGL_NOTICE, "Triggered assignment to defragment " + "TCH/F+PDCH slots.\n"); + } + + /* We do not need to check, if assignment is ongoing or if it fails, + * because in both cases a channel is freed, so this defragmentation + * is triggered again. + */ + + return; + +free_lchan: + lchan_free(new_lchan); +} + |