<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/19847">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">lapd_test: add a test checking SAPI0/SAPI3 prioritization<br><br>Recently we've encountered a situation where during MT SMS delivery,<br>the func=SABM for SAPI=3 was sent on Downlink *before* the BTS<br>replied with the func=UA for SAPI=0 (contetion resolution procedure,<br>where we echo the (RR) Paging Response back to the MS).<br><br>This change adds a unit test reprodicing the problem.<br><br>Change-Id: Ied0f8bb683de8e37bcfa984c2877aa1cec1c0b4b<br>Related: SYS#5047, OS#4731<br>---<br>M tests/lapd/lapd_test.c<br>M tests/lapd/lapd_test.ok<br>2 files changed, 84 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/47/19847/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/lapd/lapd_test.c b/tests/lapd/lapd_test.c</span><br><span>index 3ea2706..ccc84e6 100644</span><br><span>--- a/tests/lapd/lapd_test.c</span><br><span>+++ b/tests/lapd/lapd_test.c</span><br><span>@@ -73,6 +73,19 @@</span><br><span>    0x00, 0x00, 0x80, 0x2b, 0x2b, 0x2b, 0x2b</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t pr[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+     0x06, 0x27, 0x07, 0x03, 0x50, 0x58, 0x92, 0x05,</span><br><span style="color: hsl(120, 100%, 40%);">+       0xf4, 0x44, 0x59, 0xba, 0x63,</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%);">+#if 0</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t ua_pr[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+  0x01, 0x73, 0x35, 0x06, 0x27, 0x07, 0x03, 0x50,</span><br><span style="color: hsl(120, 100%, 40%);">+       0x58, 0x92, 0x05, 0xf4, 0x44, 0x59, 0xba, 0x63,</span><br><span style="color: hsl(120, 100%, 40%);">+       0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static const uint8_t mm[] = {</span><br><span>     0x00, 0x0c, 0x00, 0x03, 0x01, 0x01, 0x20, 0x02,</span><br><span>      0x00, 0x0b, 0x00, 0x03, 0x05, 0x04, 0x0d</span><br><span>@@ -757,6 +770,61 @@</span><br><span>      lapdm_channel_exit(&bts_to_ms_channel);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void test_lapdm_sapi_prio(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct osmo_phsap_prim pp1, pp2;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct lapdm_channel lc = { };</span><br><span style="color: hsl(120, 100%, 40%);">+        struct msgb *msg;</span><br><span style="color: hsl(120, 100%, 40%);">+     int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     printf("\n=== I test SAPI0/SAPI3 prioritization ===\n\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* BTS to MS in polling mode */</span><br><span style="color: hsl(120, 100%, 40%);">+       lapdm_channel_init(&lc, LAPDM_MODE_BTS);</span><br><span style="color: hsl(120, 100%, 40%);">+  lapdm_channel_set_flags(&lc, LAPDM_ENT_F_POLLING_ONLY);</span><br><span style="color: hsl(120, 100%, 40%);">+   lapdm_channel_set_l1(&lc, NULL, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+    lapdm_channel_set_l3(&lc, bts_to_ms_dummy_tx_cb, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* MS establishes a SAPI=0 link by sending func=SABM on SDCCH */</span><br><span style="color: hsl(120, 100%, 40%);">+      printf("MS is establishing a SAPI=0 link\n");</span><br><span style="color: hsl(120, 100%, 40%);">+       send_sabm(&lc, 0, pr, sizeof(pr));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* BTS establishes a SAPI=3 link by sending func=SABM on SDCCH */</span><br><span style="color: hsl(120, 100%, 40%);">+     msg = create_est_req(est_req_sdcch_sapi3, sizeof(est_req_sdcch_sapi3));</span><br><span style="color: hsl(120, 100%, 40%);">+       printf("BTS is establishing a SAPI=3 link\n");</span><br><span style="color: hsl(120, 100%, 40%);">+      rc = lapdm_rslms_recvmsg(msg, &lc);</span><br><span style="color: hsl(120, 100%, 40%);">+       OSMO_ASSERT(rc == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Make sure that we get func=UA on SDCCH from the BTS first */</span><br><span style="color: hsl(120, 100%, 40%);">+       rc = dequeue_prim(&lc.lapdm_dcch, &pp1, "DCCH");</span><br><span style="color: hsl(120, 100%, 40%);">+    CHECK_RC(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Contention resolution is completed, we should get func=SAMB now */</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = dequeue_prim(&lc.lapdm_dcch, &pp2, "DCCH");</span><br><span style="color: hsl(120, 100%, 40%);">+    CHECK_RC(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#if 0</span><br><span style="color: hsl(120, 100%, 40%);">+        /* OS#4731: currently these checks would fail, uncomment when the bug is fixed */</span><br><span style="color: hsl(120, 100%, 40%);">+     OSMO_ASSERT(memcmp(pp1.oph.msg->l2h, ua_pr, sizeof(ua_pr)) == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+  OSMO_ASSERT(memcmp(pp2.oph.msg->l2h, est_req_sdcch_sapi3,</span><br><span style="color: hsl(120, 100%, 40%);">+                     sizeof(est_req_sdcch_sapi3)) == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      msgb_free(pp1.oph.msg);</span><br><span style="color: hsl(120, 100%, 40%);">+       msgb_free(pp2.oph.msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Make sure that the queue is empty now */</span><br><span style="color: hsl(120, 100%, 40%);">+   printf("\nChecking whether the DL/DCCH queue is empty\n");</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = dequeue_prim(&lc.lapdm_dcch, &pp1, "DCCH");</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_ASSERT(rc < 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Clean up */</span><br><span style="color: hsl(120, 100%, 40%);">+        lapdm_channel_exit(&lc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* Check if exit is idempotent */</span><br><span style="color: hsl(120, 100%, 40%);">+     lapdm_channel_exit(&lc);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int main(int argc, char **argv)</span><br><span> {</span><br><span>    void *ctx = talloc_named_const(NULL, 0, "lapd_test");</span><br><span>@@ -773,6 +841,7 @@</span><br><span>        test_lapdm_contention_resolution();</span><br><span>  test_lapdm_establishment();</span><br><span>  test_lapdm_desync();</span><br><span style="color: hsl(120, 100%, 40%);">+  test_lapdm_sapi_prio();</span><br><span> </span><br><span>  printf("Success.\n");</span><br><span> </span><br><span>diff --git a/tests/lapd/lapd_test.ok b/tests/lapd/lapd_test.ok</span><br><span>index 16f6fc3..5796582 100644</span><br><span>--- a/tests/lapd/lapd_test.ok</span><br><span>+++ b/tests/lapd/lapd_test.ok</span><br><span>@@ -124,4 +124,19 @@</span><br><span> MSGB: L3 is undefined</span><br><span> Took message from DCCH queue: L2 header size 23, L3 size 0, SAP 0x1000000, 0/0, Link 0x03</span><br><span> Message: [L2]> 0d 21 01 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+=== I test SAPI0/SAPI3 prioritization ===</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+MS is establishing a SAPI=0 link</span><br><span style="color: hsl(120, 100%, 40%);">+bts_to_ms_dummy_tx_cb: MS->BTS(us) message 22</span><br><span style="color: hsl(120, 100%, 40%);">+BTS is establishing a SAPI=3 link</span><br><span style="color: hsl(120, 100%, 40%);">+lapdm_phsap_dequeue_prim(): got rc 0: Success</span><br><span style="color: hsl(120, 100%, 40%);">+Took message from DCCH queue: L2 header size 3, L3 size 20, SAP 0x1000000, 0/0, Link 0x03</span><br><span style="color: hsl(120, 100%, 40%);">+Message: [L2]> 0f 3f 01 [L3]> 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b </span><br><span style="color: hsl(120, 100%, 40%);">+lapdm_phsap_dequeue_prim(): got rc 0: Success</span><br><span style="color: hsl(120, 100%, 40%);">+Took message from DCCH queue: L2 header size 3, L3 size 20, SAP 0x1000000, 0/0, Link 0x00</span><br><span style="color: hsl(120, 100%, 40%);">+Message: [L2]> 01 73 35 [L3]> 06 27 07 03 50 58 92 05 f4 44 59 ba 63 2b 2b 2b 2b 2b 2b 2b </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Checking whether the DL/DCCH queue is empty</span><br><span style="color: hsl(120, 100%, 40%);">+lapdm_phsap_dequeue_prim(): got rc -19: No such device</span><br><span> Success.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/19847">change 19847</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/libosmocore/+/19847"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ied0f8bb683de8e37bcfa984c2877aa1cec1c0b4b </div>
<div style="display:none"> Gerrit-Change-Number: 19847 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>