<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/25453">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">abis.c: Rearrange code to follow logic state order<br><br>CONNECTING state comes first in logical order of states (as properly<br>seen in enum of states), however, the FSM struct definition and state<br>action functions are swapped. Let's put them in order.<br><br>Change-Id: I0cae561926b460dc5882390db969b7c925903e5d<br>---<br>M src/common/abis.c<br>1 file changed, 55 insertions(+), 55 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/53/25453/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/common/abis.c b/src/common/abis.c</span><br><span>index 7503798..db0a648 100644</span><br><span>--- a/src/common/abis.c</span><br><span>+++ b/src/common/abis.c</span><br><span>@@ -81,53 +81,6 @@</span><br><span>   int line_ctr;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void abis_link_connected(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-   struct abis_link_fsm_priv *priv = fi->priv;</span><br><span style="color: hsl(0, 100%, 40%);">-  struct gsm_bts *bts = priv->bts;</span><br><span style="color: hsl(0, 100%, 40%);">-     struct gsm_bts_trx *trx;</span><br><span style="color: hsl(0, 100%, 40%);">-        bool oml_rsl_was_connected = false;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     OSMO_ASSERT(event == ABIS_LINK_EV_SIGN_LINK_DOWN);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      /* First remove the OML signalling link */</span><br><span style="color: hsl(0, 100%, 40%);">-      if (bts->oml_link) {</span><br><span style="color: hsl(0, 100%, 40%);">-         struct timespec now;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            e1inp_sign_link_destroy(bts->oml_link);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-              /* Log a special notice if the OML connection was dropped relatively quickly. */</span><br><span style="color: hsl(0, 100%, 40%);">-                if (bts->oml_conn_established_timestamp.tv_sec != 0 && clock_gettime(CLOCK_MONOTONIC, &now) == 0 &&</span><br><span style="color: hsl(0, 100%, 40%);">-                  bts->oml_conn_established_timestamp.tv_sec + OSMO_BTS_OML_CONN_EARLY_DISCONNECT >= now.tv_sec) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      LOGP(DABIS, LOGL_FATAL, "OML link was closed early within %" PRIu64 " seconds. "</span><br><span style="color: hsl(0, 100%, 40%);">-                         "If this situation persists, please check your BTS and BSC configuration files for errors. "</span><br><span style="color: hsl(0, 100%, 40%);">-                          "A common error is a mismatch between unit_id configuration parameters of BTS and BSC.\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                            (uint64_t) (now.tv_sec - bts->oml_conn_established_timestamp.tv_sec));</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(0, 100%, 40%);">-               bts->oml_link = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                oml_rsl_was_connected = true;</span><br><span style="color: hsl(0, 100%, 40%);">-   }</span><br><span style="color: hsl(0, 100%, 40%);">-       memset(&bts->oml_conn_established_timestamp, 0, sizeof(bts->oml_conn_established_timestamp));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Then iterate over the RSL signalling links */</span><br><span style="color: hsl(0, 100%, 40%);">-        llist_for_each_entry(trx, &bts->trx_list, list) {</span><br><span style="color: hsl(0, 100%, 40%);">-                if (trx->rsl_link) {</span><br><span style="color: hsl(0, 100%, 40%);">-                 e1inp_sign_link_destroy(trx->rsl_link);</span><br><span style="color: hsl(0, 100%, 40%);">-                      trx->rsl_link = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                        oml_rsl_was_connected = true;</span><br><span style="color: hsl(0, 100%, 40%);">-           }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       /* Note: if there was an OML or RSL connection present (the BTS was connected to a BSC). Then we will not try</span><br><span style="color: hsl(0, 100%, 40%);">-    * to connect to an alternate BSC. Instead we will shut down the BTS process. This will ensure that all states</span><br><span style="color: hsl(0, 100%, 40%);">-   * in the BTS (hardware and software) are reset properly. It is then up to the process management of the host</span><br><span style="color: hsl(0, 100%, 40%);">-    * to restart osmo-bts. */</span><br><span style="color: hsl(0, 100%, 40%);">-      if (oml_rsl_was_connected)</span><br><span style="color: hsl(0, 100%, 40%);">-              osmo_fsm_inst_state_chg(fi, ABIS_LINK_ST_FAILED, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">- else</span><br><span style="color: hsl(0, 100%, 40%);">-            osmo_fsm_inst_state_chg(fi, ABIS_LINK_ST_CONNECTING, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static void abis_link_connecting_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)</span><br><span> {</span><br><span>         struct e1inp_line *line;</span><br><span>@@ -186,6 +139,53 @@</span><br><span>      osmo_fsm_inst_state_chg(fi, ABIS_LINK_ST_CONNECTED, 0, 0);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void abis_link_connected(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct abis_link_fsm_priv *priv = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct gsm_bts *bts = priv->bts;</span><br><span style="color: hsl(120, 100%, 40%);">+   struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+      bool oml_rsl_was_connected = false;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(event == ABIS_LINK_EV_SIGN_LINK_DOWN);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* First remove the OML signalling link */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (bts->oml_link) {</span><br><span style="color: hsl(120, 100%, 40%);">+               struct timespec now;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                e1inp_sign_link_destroy(bts->oml_link);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          /* Log a special notice if the OML connection was dropped relatively quickly. */</span><br><span style="color: hsl(120, 100%, 40%);">+              if (bts->oml_conn_established_timestamp.tv_sec != 0 && clock_gettime(CLOCK_MONOTONIC, &now) == 0 &&</span><br><span style="color: hsl(120, 100%, 40%);">+                bts->oml_conn_established_timestamp.tv_sec + OSMO_BTS_OML_CONN_EARLY_DISCONNECT >= now.tv_sec) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    LOGP(DABIS, LOGL_FATAL, "OML link was closed early within %" PRIu64 " seconds. "</span><br><span style="color: hsl(120, 100%, 40%);">+                       "If this situation persists, please check your BTS and BSC configuration files for errors. "</span><br><span style="color: hsl(120, 100%, 40%);">+                        "A common error is a mismatch between unit_id configuration parameters of BTS and BSC.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                          (uint64_t) (now.tv_sec - bts->oml_conn_established_timestamp.tv_sec));</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             bts->oml_link = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+              oml_rsl_was_connected = true;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(&bts->oml_conn_established_timestamp, 0, sizeof(bts->oml_conn_established_timestamp));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Then iterate over the RSL signalling links */</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%);">+              if (trx->rsl_link) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       e1inp_sign_link_destroy(trx->rsl_link);</span><br><span style="color: hsl(120, 100%, 40%);">+                    trx->rsl_link = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+                      oml_rsl_was_connected = true;</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 style="color: hsl(120, 100%, 40%);">+   /* Note: if there was an OML or RSL connection present (the BTS was connected to a BSC). Then we will not try</span><br><span style="color: hsl(120, 100%, 40%);">+  * to connect to an alternate BSC. Instead we will shut down the BTS process. This will ensure that all states</span><br><span style="color: hsl(120, 100%, 40%);">+         * in the BTS (hardware and software) are reset properly. It is then up to the process management of the host</span><br><span style="color: hsl(120, 100%, 40%);">+  * to restart osmo-bts. */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (oml_rsl_was_connected)</span><br><span style="color: hsl(120, 100%, 40%);">+            osmo_fsm_inst_state_chg(fi, ABIS_LINK_ST_FAILED, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+       else</span><br><span style="color: hsl(120, 100%, 40%);">+          osmo_fsm_inst_state_chg(fi, ABIS_LINK_ST_CONNECTING, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void abis_link_failed_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)</span><br><span> {</span><br><span>         struct abis_link_fsm_priv *priv = fi->priv;</span><br><span>@@ -215,6 +215,14 @@</span><br><span> }</span><br><span> </span><br><span> static struct osmo_fsm_state abis_link_fsm_states[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+     [ABIS_LINK_ST_CONNECTING] = {</span><br><span style="color: hsl(120, 100%, 40%);">+         .name = "CONNECTING",</span><br><span style="color: hsl(120, 100%, 40%);">+               .out_state_mask =</span><br><span style="color: hsl(120, 100%, 40%);">+                     S(ABIS_LINK_ST_CONNECTING) |</span><br><span style="color: hsl(120, 100%, 40%);">+                  S(ABIS_LINK_ST_CONNECTED) |</span><br><span style="color: hsl(120, 100%, 40%);">+                   S(ABIS_LINK_ST_FAILED),</span><br><span style="color: hsl(120, 100%, 40%);">+               .onenter = abis_link_connecting_onenter,</span><br><span style="color: hsl(120, 100%, 40%);">+      },</span><br><span>   [ABIS_LINK_ST_CONNECTED] = {</span><br><span>                 .name = "CONNECTED",</span><br><span>               .in_event_mask =</span><br><span>@@ -224,14 +232,6 @@</span><br><span>                      S(ABIS_LINK_ST_FAILED),</span><br><span>              .action = abis_link_connected,</span><br><span>       },</span><br><span style="color: hsl(0, 100%, 40%);">-      [ABIS_LINK_ST_CONNECTING] = {</span><br><span style="color: hsl(0, 100%, 40%);">-           .name = "CONNECTING",</span><br><span style="color: hsl(0, 100%, 40%);">-         .out_state_mask =</span><br><span style="color: hsl(0, 100%, 40%);">-                       S(ABIS_LINK_ST_CONNECTING) |</span><br><span style="color: hsl(0, 100%, 40%);">-                    S(ABIS_LINK_ST_CONNECTED) |</span><br><span style="color: hsl(0, 100%, 40%);">-                     S(ABIS_LINK_ST_FAILED),</span><br><span style="color: hsl(0, 100%, 40%);">-         .onenter = abis_link_connecting_onenter,</span><br><span style="color: hsl(0, 100%, 40%);">-        },</span><br><span>   [ABIS_LINK_ST_FAILED] = {</span><br><span>            .name = "FAILED",</span><br><span>          .onenter = abis_link_failed_onenter,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/25453">change 25453</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-bts/+/25453"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bts </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I0cae561926b460dc5882390db969b7c925903e5d </div>
<div style="display:none"> Gerrit-Change-Number: 25453 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>