Review at  https://gerrit.osmocom.org/5916

HO: Count number of free timeslot on a given BTS

This is needed for handover algorithm to balance free slots and to prevent
congestion of one cell, while other cells still have free capacities.

Change-Id: Ic8bee8a515ee8aa9a99af71756fe60b8dd8f868b
---
M include/osmocom/bsc/chan_alloc.h
M src/libbsc/chan_alloc.c
2 files changed, 67 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/16/5916/1

diff --git a/include/osmocom/bsc/chan_alloc.h b/include/osmocom/bsc/chan_alloc.h
index f2a75c5..748e9cd 100644
--- a/include/osmocom/bsc/chan_alloc.h
+++ b/include/osmocom/bsc/chan_alloc.h
@@ -24,6 +24,9 @@
 
 struct gsm_subscriber_connection;
 
+/* Count number of free TS of given pchan type */
+int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
+
 /* Allocate a logical channel (SDCCH, TCH, ...) */
 struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, int 
allow_bigger);
 
diff --git a/src/libbsc/chan_alloc.c b/src/libbsc/chan_alloc.c
index 9946628..b3056da 100644
--- a/src/libbsc/chan_alloc.c
+++ b/src/libbsc/chan_alloc.c
@@ -68,6 +68,70 @@
        return true;
 }
 
+static int trx_count_free_ts(struct gsm_bts_trx *trx, enum 
gsm_phys_chan_config pchan)
+{
+       struct gsm_bts_trx_ts *ts;
+       int j, ss;
+       int count = 0;
+
+       if (!trx_is_usable(trx))
+               return 0;
+
+       for (j = 0; j < 8; j++) {
+               enum gsm_phys_chan_config ts_pchan_is;
+               ts = &trx->ts[j];
+               if (!ts_is_usable(ts))
+                       continue;
+
+               ts_pchan_is = ts_pchan(ts);
+
+               if (ts_pchan_is == GSM_PCHAN_PDCH) {
+                       /* Dynamic timeslots in PDCH mode will become TCH if 
needed. */
+                       switch (ts->pchan) {
+                       case GSM_PCHAN_TCH_F_PDCH:
+                               if (pchan == GSM_PCHAN_TCH_F)
+                                       count++;
+                               continue;
+
+                       case GSM_PCHAN_TCH_F_TCH_H_PDCH:
+                               if (pchan == GSM_PCHAN_TCH_F)
+                                       count++;
+                               else if (pchan == GSM_PCHAN_TCH_H)
+                                       count += 2;
+                               continue;
+
+                       default:
+                               /* Not dynamic, not applicable. */
+                               continue;
+                       }
+               }
+
+               if (ts_pchan_is != pchan)
+                       continue;
+               /* check if all sub-slots are allocated yet */
+               for (ss = 0; ss < ts_subslots(ts); ss++) {
+                       struct gsm_lchan *lc = &ts->lchan[ss];
+                       if (lc->type == GSM_LCHAN_NONE &&
+                           lc->state == LCHAN_S_NONE)
+                               count++;
+               }
+       }
+
+       return count;
+}
+
+/* Count number of free TS of given pchan type */
+int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
+{
+       struct gsm_bts_trx *trx;
+       int count = 0;
+
+       llist_for_each_entry(trx, &bts->trx_list, list)
+               count += trx_count_free_ts(trx, pchan);
+
+       return count;
+}
+
 static struct gsm_lchan *
 _lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan,
             enum gsm_phys_chan_config dyn_as_pchan)

-- 
To view, visit https://gerrit.osmocom.org/5916
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8bee8a515ee8aa9a99af71756fe60b8dd8f868b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder

Reply via email to