<p>fixeria <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bsc/+/23649">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">[hopping] Rework generation of Cell/Mobile Allocation<br><br>Calculating the Cell Allocation (basically a bit-vector of all the<br>frequencies allocated to a cell) on the OML link establishment has<br>several downsides and potential problems:<br><br>  * Theoretically, more than 64 ARFCNs can be allocated for a cell<br>    via the VTY interface.  The problem here is that the Mobile<br>    Allocation IE cannot contain more than 64 channels.<br><br>  * The BSC's operator will neither be warned by the interactive<br>    VTY shell during configuration, nor during the startup.<br><br>  * The BSC will accept such a configuration, but then will be<br>    unable to encode the Mobile Allocation IEs at run-time.<br><br>This change aims to improve the situation by separating part of<br>the logic from generate_cell_chan_list(), and invoking this<br>part directly from the VTY commands.  This way it will become<br>impossible to configure more than 64 ARFCNs, neither via the<br>config file, nor interactively from the VTY.<br><br>Change-Id: I98211fb0684a973239f5760e1de52a24a1f4c33c<br>---<br>M include/osmocom/bsc/bts.h<br>M include/osmocom/bsc/system_information.h<br>M src/osmo-bsc/bsc_vty.c<br>M src/osmo-bsc/osmo_bsc_main.c<br>M src/osmo-bsc/system_information.c<br>5 files changed, 92 insertions(+), 35 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/bsc/bts.h b/include/osmocom/bsc/bts.h</span><br><span>index c8cf8b3..c03c75e 100644</span><br><span>--- a/include/osmocom/bsc/bts.h</span><br><span>+++ b/include/osmocom/bsc/bts.h</span><br><span>@@ -451,6 +451,7 @@</span><br><span>           struct bitvec si5_neigh_list;</span><br><span>                struct osmo_earfcn_si2q si2quater_neigh_list;</span><br><span>                size_t uarfcn_length; /* index for uarfcn and scramble lists */</span><br><span style="color: hsl(120, 100%, 40%);">+               size_t cell_chan_num; /* number of channels in Cell Allocation */</span><br><span>            struct {</span><br><span>                     /* bitmask large enough for all possible ARFCN's */</span><br><span>                      uint8_t neigh_list[1024/8];</span><br><span>diff --git a/include/osmocom/bsc/system_information.h b/include/osmocom/bsc/system_information.h</span><br><span>index 35892d9..e86a349 100644</span><br><span>--- a/include/osmocom/bsc/system_information.h</span><br><span>+++ b/include/osmocom/bsc/system_information.h</span><br><span>@@ -7,6 +7,7 @@</span><br><span> </span><br><span> struct gsm_bts;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int generate_cell_chan_alloc(struct gsm_bts *bts);</span><br><span> int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts);</span><br><span> int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type type);</span><br><span> size_t si2q_earfcn_count(const struct osmo_earfcn_si2q *e);</span><br><span>diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c</span><br><span>index 6a6411f..5eb2393 100644</span><br><span>--- a/src/osmo-bsc/bsc_vty.c</span><br><span>+++ b/src/osmo-bsc/bsc_vty.c</span><br><span>@@ -5334,6 +5334,12 @@</span><br><span> </span><br><span>        trx->arfcn = arfcn;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    /* Update Cell Allocation (list of all the frequencies allocated to a cell) */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (generate_cell_chan_alloc(trx->bts) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+             vty_out(vty, "%% Failed to re-generate Cell Allocation%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+            return CMD_WARNING;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  /* FIXME: patch ARFCN into SYSTEM INFORMATION */</span><br><span>     /* FIXME: use OML layer to update the ARFCN */</span><br><span>       /* FIXME: use RSL layer to update SYSTEM INFORMATION */</span><br><span>@@ -5604,6 +5610,13 @@</span><br><span> </span><br><span>         bitvec_set_bit_pos(&ts->hopping.arfcns, arfcn, 1);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Update Cell Allocation (list of all the frequencies allocated to a cell) */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (generate_cell_chan_alloc(ts->trx->bts) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              vty_out(vty, "%% Failed to re-generate Cell Allocation%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+            bitvec_set_bit_pos(&ts->hopping.arfcns, arfcn, ZERO); /* roll-back */</span><br><span style="color: hsl(120, 100%, 40%);">+          return CMD_WARNING;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  return CMD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span>@@ -5630,6 +5643,13 @@</span><br><span> </span><br><span>    bitvec_set_bit_pos(&ts->hopping.arfcns, arfcn, 0);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Update Cell Allocation (list of all the frequencies allocated to a cell) */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (generate_cell_chan_alloc(ts->trx->bts) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              vty_out(vty, "%% Failed to re-generate Cell Allocation%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+            /* It's unlikely to happen on removal, so we don't roll-back */</span><br><span style="color: hsl(120, 100%, 40%);">+               return CMD_WARNING;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  return CMD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span>@@ -5644,6 +5664,13 @@</span><br><span> </span><br><span>    bitvec_zero(&ts->hopping.arfcns);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  /* Update Cell Allocation (list of all the frequencies allocated to a cell) */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (generate_cell_chan_alloc(ts->trx->bts) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              vty_out(vty, "%% Failed to re-generate Cell Allocation%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+            /* It's unlikely to happen on removal, so we don't roll-back */</span><br><span style="color: hsl(120, 100%, 40%);">+               return CMD_WARNING;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  return CMD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span>diff --git a/src/osmo-bsc/osmo_bsc_main.c b/src/osmo-bsc/osmo_bsc_main.c</span><br><span>index 6c7c275..2b4224f 100644</span><br><span>--- a/src/osmo-bsc/osmo_bsc_main.c</span><br><span>+++ b/src/osmo-bsc/osmo_bsc_main.c</span><br><span>@@ -260,10 +260,10 @@</span><br><span> {</span><br><span>       /* we have three bitvecs: the per-timeslot ARFCNs, the cell chan ARFCNs</span><br><span>       * and the MA */</span><br><span style="color: hsl(120, 100%, 40%);">+      const size_t num_cell_arfcns = ts->trx->bts->si_common.cell_chan_num;</span><br><span>       const struct bitvec *cell_chan = &ts->trx->bts->si_common.cell_alloc;</span><br><span>   const struct bitvec *ts_arfcn = &ts->hopping.arfcns;</span><br><span>  struct bitvec *ma = &ts->hopping.ma;</span><br><span style="color: hsl(0, 100%, 40%);">-     unsigned int num_cell_arfcns;</span><br><span>        int i;</span><br><span> </span><br><span>   /* re-set the MA to all-zero */</span><br><span>@@ -273,13 +273,6 @@</span><br><span>       if (!ts->hopping.enabled)</span><br><span>                 return;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-     /* count the number of ARFCNs in the cell channel allocation */</span><br><span style="color: hsl(0, 100%, 40%);">- num_cell_arfcns = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-    for (i = 0; i < 1024; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-         if (bitvec_get_bit_pos(cell_chan, i))</span><br><span style="color: hsl(0, 100%, 40%);">-                   num_cell_arfcns++;</span><br><span style="color: hsl(0, 100%, 40%);">-      }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>    /* pad it to octet-aligned number of bits */</span><br><span>         ts->hopping.ma_len = OSMO_BYTES_FOR_BITS(num_cell_arfcns);</span><br><span>        ma->cur_bit = (ts->hopping.ma_len * 8) - 1;</span><br><span>@@ -305,6 +298,20 @@</span><br><span>     }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void generate_ma_for_bts(struct gsm_bts *bts)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+      unsigned int tn;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_ASSERT(bts->si_common.cell_chan_num > 0);</span><br><span style="color: hsl(120, 100%, 40%);">+  OSMO_ASSERT(bts->si_common.cell_chan_num <= 64);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      llist_for_each_entry(trx, &bts->trx_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+              for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)</span><br><span style="color: hsl(120, 100%, 40%);">+                    generate_ma_for_ts(&trx->ts[tn]);</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void bootstrap_rsl(struct gsm_bts_trx *trx)</span><br><span> {</span><br><span>    unsigned int i;</span><br><span>@@ -388,19 +395,9 @@</span><br><span>       switch (signal) {</span><br><span>    case S_L_INP_TEI_UP:</span><br><span>                 if (isd->link_type == E1INP_SIGN_OML) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      /* TODO: this is required for the Nokia BTS, hopping is configured</span><br><span style="color: hsl(0, 100%, 40%);">-                         during OML, other MA is not set.  */</span><br><span style="color: hsl(0, 100%, 40%);">-                 struct gsm_bts_trx *cur_trx;</span><br><span style="color: hsl(0, 100%, 40%);">-                    uint8_t ca[20];</span><br><span style="color: hsl(0, 100%, 40%);">-                 /* has to be called before generate_ma_for_ts to</span><br><span style="color: hsl(0, 100%, 40%);">-                          set bts->si_common.cell_alloc */</span><br><span style="color: hsl(0, 100%, 40%);">-                   generate_cell_chan_list(ca, trx->bts);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-                       llist_for_each_entry(cur_trx, &trx->bts->trx_list, list) {</span><br><span style="color: hsl(0, 100%, 40%);">-                            int i;</span><br><span style="color: hsl(0, 100%, 40%);">-                          for (i = 0; i < ARRAY_SIZE(cur_trx->ts); i++)</span><br><span style="color: hsl(0, 100%, 40%);">-                                     generate_ma_for_ts(&cur_trx->ts[i]);</span><br><span style="color: hsl(0, 100%, 40%);">-                     }</span><br><span style="color: hsl(120, 100%, 40%);">+                     /* Generate Mobile Allocation bit-masks for all timeslots.</span><br><span style="color: hsl(120, 100%, 40%);">+                     * This needs to be done here, because it's used for TS configuration. */</span><br><span style="color: hsl(120, 100%, 40%);">+                 generate_ma_for_bts(trx->bts);</span><br><span>            }</span><br><span>            if (isd->link_type == E1INP_SIGN_RSL)</span><br><span>                     bootstrap_rsl(trx);</span><br><span>diff --git a/src/osmo-bsc/system_information.c b/src/osmo-bsc/system_information.c</span><br><span>index e2ac04d..0dbf53c 100644</span><br><span>--- a/src/osmo-bsc/system_information.c</span><br><span>+++ b/src/osmo-bsc/system_information.c</span><br><span>@@ -574,31 +574,62 @@</span><br><span>         return -EINVAL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */</span><br><span style="color: hsl(0, 100%, 40%);">-int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)</span><br><span style="color: hsl(120, 100%, 40%);">+/* (Re)generate Cell Allocation (basically a bit-vector of all cell channels) */</span><br><span style="color: hsl(120, 100%, 40%);">+int generate_cell_chan_alloc(struct gsm_bts *bts)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-      struct bitvec *bv = &bts->si_common.cell_alloc;</span><br><span>       const struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int chan, chan_num;</span><br><span style="color: hsl(120, 100%, 40%);">+  unsigned int tn;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    /* Zero-initialize the bit-vector */</span><br><span style="color: hsl(0, 100%, 40%);">-    memset(bv->data, 0, bv->data_len);</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Temporary Cell Allocation bit-vector */</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t ca[1024 / 8] = { 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct bitvec bv = {</span><br><span style="color: hsl(120, 100%, 40%);">+          .data_len = sizeof(ca),</span><br><span style="color: hsl(120, 100%, 40%);">+               .data = &ca[0],</span><br><span style="color: hsl(120, 100%, 40%);">+   };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  /* first we generate a bitvec of all TRX ARFCN's in our BTS */</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Calculate a bit-mask of all assigned ARFCNs */</span><br><span>    llist_for_each_entry(trx, &bts->trx_list, list) {</span><br><span style="color: hsl(0, 100%, 40%);">-                unsigned int i, j;</span><br><span>           /* Always add the TRX's ARFCN */</span><br><span style="color: hsl(0, 100%, 40%);">-            bitvec_set_bit_pos(bv, trx->arfcn, 1);</span><br><span style="color: hsl(0, 100%, 40%);">-               for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                       const struct gsm_bts_trx_ts *ts = &trx->ts[i];</span><br><span style="color: hsl(120, 100%, 40%);">+         bitvec_set_bit_pos(&bv, trx->arfcn, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+                for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  const struct gsm_bts_trx_ts *ts = &trx->ts[tn];</span><br><span>                       /* Add any ARFCNs present in hopping channels */</span><br><span style="color: hsl(0, 100%, 40%);">-                        for (j = 0; j < 1024; j++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                         if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))</span><br><span style="color: hsl(0, 100%, 40%);">-                                  bitvec_set_bit_pos(bv, j, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+                 for (chan = 0; chan < sizeof(ca) * 8; chan++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                            if (bitvec_get_bit_pos(&ts->hopping.arfcns, chan) == ONE)</span><br><span style="color: hsl(120, 100%, 40%);">+                                      bitvec_set_bit_pos(&bv, chan, ONE);</span><br><span>                      }</span><br><span>            }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* then we generate a GSM 04.08 frequency list from the bitvec */</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Calculate the overall number of assigned ARFCNs */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (chan_num = 0, chan = 0; chan < sizeof(ca) * 8; chan++) {</span><br><span style="color: hsl(120, 100%, 40%);">+              if (bitvec_get_bit_pos(&bv, chan) == ONE)</span><br><span style="color: hsl(120, 100%, 40%);">+                 chan_num++;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* The Mobile Allocation IE may contain up to 64 bits, so here we</span><br><span style="color: hsl(120, 100%, 40%);">+      * cannot allow more than 64 channels in Cell Allocation. */</span><br><span style="color: hsl(120, 100%, 40%);">+  if (chan_num > 64) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGP(DRR, LOGL_ERROR, "Failed to (re)generate Cell Allocation: "</span><br><span style="color: hsl(120, 100%, 40%);">+                 "number of channels (%u) exceeds the maximum number of "</span><br><span style="color: hsl(120, 100%, 40%);">+                    "ARFCNs in Mobile Allocation (64)\n", chan_num);</span><br><span style="color: hsl(120, 100%, 40%);">+               return -E2BIG;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Commit the new Channel Allocation */</span><br><span style="color: hsl(120, 100%, 40%);">+       memcpy(&bts->si_common.data.cell_alloc[0], ca, sizeof(ca));</span><br><span style="color: hsl(120, 100%, 40%);">+    bts->si_common.cell_chan_num = chan_num;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */</span><br><span style="color: hsl(120, 100%, 40%);">+int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct bitvec *bv = &bts->si_common.cell_alloc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* generate a Frequency List from the Cell Allocation */</span><br><span>     return bitvec2freq_list(chan_list, bv, bts, false, false);</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bsc/+/23649">change 23649</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-bsc/+/23649"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bsc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I98211fb0684a973239f5760e1de52a24a1f4c33c </div>
<div style="display:none"> Gerrit-Change-Number: 23649 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>