<p>laforge <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bsc/+/15408">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bsc_subscr_conn_fsm: Cleanly clear BSSAP conn if associated channel closed during WAIT_CC<br><br>TTCN3 BSC_Tests.TC_ms_rel_ind_does_not_cause_bssmap_reset seems to<br>sometimes run into a race condition on the order of messages received by<br>osmo-bsc comming from MSC and BTS.<br><br>Usual (expected) scenario):<br>BTS->BSC      EST IND<br>     BSC->MSC CL3 Info<br>     BSC<-MSC CC<br>BTS->BSC      REL IND<br>BTS<-BSC      DEACT SACCH<br>     BSC->MSC ClearRequest<br>     BSC<-MSC ClearCommand<br>     BSC->MSC ClearComplete<br>BTS<-BSC      RF Chan Release<br>BTS->BSC      RF Chan Release ACK<br><br>Sometimes CC message and REL IND message are received swapped (because they<br>are sent by different components asynchronously in TTCN3).<br><br>As a result, osmo-bsc was failing to go into CLEARING state and was<br>unable to send the ClearRequest because CC was still not received.<br>So the idea is to stay in WAIT_CC until CC is received, then check if<br>the lchan was dropped and in that case go into clearing state.<br><br>Change-Id: Id1abf5ee44c60925b478123409f26bd29006202b<br>---<br>M src/osmo-bsc/bsc_subscr_conn_fsm.c<br>1 file changed, 28 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo-bsc/bsc_subscr_conn_fsm.c b/src/osmo-bsc/bsc_subscr_conn_fsm.c</span><br><span>index f8784f9..60f035d 100644</span><br><span>--- a/src/osmo-bsc/bsc_subscr_conn_fsm.c</span><br><span>+++ b/src/osmo-bsc/bsc_subscr_conn_fsm.c</span><br><span>@@ -332,8 +332,19 @@</span><br><span>  struct gsm_subscriber_connection *conn = fi->priv;</span><br><span>        switch (event) {</span><br><span>     case GSCON_EV_A_CONN_CFM:</span><br><span style="color: hsl(0, 100%, 40%);">-               /* MSC has confirmed the connection, we now change into the</span><br><span style="color: hsl(0, 100%, 40%);">-              * active state and wait there for further operations */</span><br><span style="color: hsl(120, 100%, 40%);">+              /* MSC has confirmed the connection */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+              if (!conn->lchan) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        /* If associated lchan was released while we were waiting for the</span><br><span style="color: hsl(120, 100%, 40%);">+                        confirmed connection, then instead simply drop the connection */</span><br><span style="color: hsl(120, 100%, 40%);">+                   LOGPFSML(fi, LOGL_INFO,</span><br><span style="color: hsl(120, 100%, 40%);">+                                "Connection confirmed but lchan was dropped previously, clearing conn\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                 osmo_fsm_inst_state_chg(conn->fi, ST_CLEARING, 60, 999);</span><br><span style="color: hsl(120, 100%, 40%);">+                   gscon_bssmap_clear(conn, GSM0808_CAUSE_EQUIPMENT_FAILURE);</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</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%);">+           /* We now change into the active state and wait there for further operations. */</span><br><span>             conn_fsm_state_chg(ST_ACTIVE);</span><br><span>               /* if there's user payload, forward it just like EV_MT_DTAP */</span><br><span>           /* FIXME: Question: if there's user payload attached to the CC, forward it like EV_MT_DTAP? */</span><br><span>@@ -589,7 +600,7 @@</span><br><span>     [ST_WAIT_CC] = {</span><br><span>             .name = "WAIT_CC",</span><br><span>                 .in_event_mask = S(GSCON_EV_A_CONN_CFM),</span><br><span style="color: hsl(0, 100%, 40%);">-                .out_state_mask = S(ST_ACTIVE),</span><br><span style="color: hsl(120, 100%, 40%);">+               .out_state_mask = S(ST_ACTIVE) | S(ST_CLEARING),</span><br><span>             .action = gscon_fsm_wait_cc,</span><br><span>         },</span><br><span>   [ST_ACTIVE] = {</span><br><span>@@ -651,10 +662,22 @@</span><br><span>              lchan_forget_conn(conn->lchan);</span><br><span>           conn->lchan = NULL;</span><br><span>       }</span><br><span style="color: hsl(120, 100%, 40%);">+     /* If the conn has no lchan anymore, it was released by the BTS and needs to Clear towards MSC. */</span><br><span>   if (!conn->lchan) {</span><br><span style="color: hsl(0, 100%, 40%);">-          if (conn->fi->state != ST_CLEARING)</span><br><span style="color: hsl(120, 100%, 40%);">+             switch (conn->fi->state) {</span><br><span style="color: hsl(120, 100%, 40%);">+              case ST_WAIT_CC:</span><br><span style="color: hsl(120, 100%, 40%);">+                      /* The SCCP connection was not yet confirmed by a CC, the BSSAP is not fully established</span><br><span style="color: hsl(120, 100%, 40%);">+                         yet so we cannot release it. First wait for the CC, and release in gscon_fsm_wait_cc(). */</span><br><span style="color: hsl(120, 100%, 40%);">+                 break;</span><br><span style="color: hsl(120, 100%, 40%);">+                default:</span><br><span style="color: hsl(120, 100%, 40%);">+                      /* Ensure that the FSM is in ST_CLEARING. */</span><br><span>                         osmo_fsm_inst_state_chg(conn->fi, ST_CLEARING, 60, 999);</span><br><span style="color: hsl(0, 100%, 40%);">-             gscon_bssmap_clear(conn, GSM0808_CAUSE_EQUIPMENT_FAILURE);</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* fall thru, omit an error log if already in ST_CLEARING */</span><br><span style="color: hsl(120, 100%, 40%);">+          case ST_CLEARING:</span><br><span style="color: hsl(120, 100%, 40%);">+                     /* Request a Clear Command from the MSC. */</span><br><span style="color: hsl(120, 100%, 40%);">+                   gscon_bssmap_clear(conn, GSM0808_CAUSE_EQUIPMENT_FAILURE);</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span>    }</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/+/15408">change 15408</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/+/15408"/><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: Id1abf5ee44c60925b478123409f26bd29006202b </div>
<div style="display:none"> Gerrit-Change-Number: 15408 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>