<p>Harald Welte has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/10403">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">HLR: Add HLR_EUSE.ttcn to implement minimal external USSD Entity<br><br>As OsmoHLR is getting support for external USSD Entities (EUSEs),<br>we have to implement this function in the test logic in order to<br>test it.<br><br>Change-Id: Ibab210b06abfd5a21e81c7f7fbe574c4f67414a0<br>---<br>A hlr/HLR_EUSE.ttcn<br>1 file changed, 124 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/03/10403/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/hlr/HLR_EUSE.ttcn b/hlr/HLR_EUSE.ttcn</span><br><span>new file mode 100644</span><br><span>index 0000000..1e7574b</span><br><span>--- /dev/null</span><br><span>+++ b/hlr/HLR_EUSE.ttcn</span><br><span>@@ -0,0 +1,124 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* Simple / General implementation of an External USSD Entity using OsmoHLR's GSUP Protocol</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * The idea is that a test case can simply start an instance of this component in parallel to its</span><br><span style="color: hsl(120, 100%, 40%);">+ * normal test components.   HLR_EUSE_CT will then connect via GSUP to the HLR as the specified EUSE</span><br><span style="color: hsl(120, 100%, 40%);">+ * name.  Any USSD related GSUP message received will be passed to a user-provided call-back</span><br><span style="color: hsl(120, 100%, 40%);">+ * function, which will return whatever PDU to send in response back to the HLR.</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%);">+/* (C) 2018 by Harald Welte <laforge@gnumonks.org> */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+module HLR_EUSE {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import from GSUP_Types all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from IPA_Emulation all;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import from General_Types all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from Osmocom_Types all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from SS_Types all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from SS_Templates all;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* emulating an external USSD Entity towards OsmoHLR */</span><br><span style="color: hsl(120, 100%, 40%);">+type component HLR_EUSE_CT {</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Component reference + config of underlying IPA emulation */</span><br><span style="color: hsl(120, 100%, 40%);">+        var IPA_Emulation_CT vc_IPA_EUSE;</span><br><span style="color: hsl(120, 100%, 40%);">+     var IPA_CCM_Parameters ccm_pars;</span><br><span style="color: hsl(120, 100%, 40%);">+      /* port towards the underlying IPA emulation */</span><br><span style="color: hsl(120, 100%, 40%);">+       port IPA_GSUP_PT EUSE;</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%);">+private function f_init(charstring hlr_ip, uint16_t hlr_gsup_port, charstring name) runs on HLR_EUSE_CT {</span><br><span style="color: hsl(120, 100%, 40%);">+        var charstring id := "EUSE-" & name;</span><br><span style="color: hsl(120, 100%, 40%);">+    ccm_pars := c_IPA_default_ccm_pars;</span><br><span style="color: hsl(120, 100%, 40%);">+   ccm_pars.name := "Osmocom TTCN-3 EUSE Simulator";</span><br><span style="color: hsl(120, 100%, 40%);">+   ccm_pars.ser_nr := id;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      vc_IPA_EUSE := IPA_Emulation_CT.create("IPA-" & id);</span><br><span style="color: hsl(120, 100%, 40%);">+    map(vc_IPA_EUSE:IPA_PORT, system:IPA_CODEC_PT);</span><br><span style="color: hsl(120, 100%, 40%);">+       connect(vc_IPA_EUSE:IPA_GSUP_PORT, self:EUSE);</span><br><span style="color: hsl(120, 100%, 40%);">+        vc_IPA_EUSE.start(IPA_Emulation.main_client(hlr_ip, hlr_gsup_port, "", 0, ccm_pars));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     timer T := 10.0;</span><br><span style="color: hsl(120, 100%, 40%);">+      T.start;</span><br><span style="color: hsl(120, 100%, 40%);">+      alt {</span><br><span style="color: hsl(120, 100%, 40%);">+ [] EUSE.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) { repeat; }</span><br><span style="color: hsl(120, 100%, 40%);">+      [] EUSE.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) { }</span><br><span style="color: hsl(120, 100%, 40%);">+  [] T.timeout {</span><br><span style="color: hsl(120, 100%, 40%);">+                setverdict(fail, "EUSE: Timeout waiting for GSUP IPA Link to come up");</span><br><span style="color: hsl(120, 100%, 40%);">+             self.stop;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+type function f_euse_cb(GSUP_SessionState ss_state, GSUP_PDU rx_pdu) return GSUP_PDU;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+function f_ss_echo_continue(GSUP_SessionState ss_state, GSUP_PDU rx_pdu) return GSUP_PDU {</span><br><span style="color: hsl(120, 100%, 40%);">+   var GSUP_SessionState ss_next_state;</span><br><span style="color: hsl(120, 100%, 40%);">+  var GSUP_IeValue ss_ie;</span><br><span style="color: hsl(120, 100%, 40%);">+       var SS_FacilityInformation dec_fac, rsp_fac;</span><br><span style="color: hsl(120, 100%, 40%);">+  var octetstring ss_rsp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     f_gsup_find_ie(rx_pdu, OSMO_GSUP_SS_INFO_IE, ss_ie);</span><br><span style="color: hsl(120, 100%, 40%);">+  dec_fac := dec_SS_FacilityInformation(ss_ie.ss_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ log("dec_fac: ", dec_fac);</span><br><span style="color: hsl(120, 100%, 40%);">+  rsp_fac := valueof(ts_SS_USSD_FACILITY_RETURN_RESULT(dec_fac[0].invoke.invokeId.present_,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     SS_OP_CODE_PROCESS_USS_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+                                   dec_fac[0].invoke.argument.uSSD_Arg.ussd_DataCodingScheme,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    dec_fac[0].invoke.argument.uSSD_Arg.ussd_String));</span><br><span style="color: hsl(120, 100%, 40%);">+    ss_rsp := enc_SS_FacilityInformation(rsp_fac);</span><br><span style="color: hsl(120, 100%, 40%);">+        select (ss_state) {</span><br><span style="color: hsl(120, 100%, 40%);">+   case (OSMO_GSUP_SESSION_STATE_BEGIN) { ss_next_state := OSMO_GSUP_SESSION_STATE_CONTINUE; }</span><br><span style="color: hsl(120, 100%, 40%);">+   case (OSMO_GSUP_SESSION_STATE_CONTINUE) { ss_next_state := OSMO_GSUP_SESSION_STATE_END; }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     return valueof(ts_GSUP_PROC_SS_RES(rx_pdu.ies[0].val.imsi, rx_pdu.ies[1].val.session_id,</span><br><span style="color: hsl(120, 100%, 40%);">+                                         ss_next_state, ss_rsp));</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%);">+function f_ss_echo(GSUP_SessionState ss_state, GSUP_PDU rx_pdu) return GSUP_PDU {</span><br><span style="color: hsl(120, 100%, 40%);">+   var GSUP_IeValue ss_ie;</span><br><span style="color: hsl(120, 100%, 40%);">+       var SS_FacilityInformation dec_fac, rsp_fac;</span><br><span style="color: hsl(120, 100%, 40%);">+  var octetstring ss_rsp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     f_gsup_find_ie(rx_pdu, OSMO_GSUP_SS_INFO_IE, ss_ie);</span><br><span style="color: hsl(120, 100%, 40%);">+  dec_fac := dec_SS_FacilityInformation(ss_ie.ss_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ log("dec_fac: ", dec_fac);</span><br><span style="color: hsl(120, 100%, 40%);">+  rsp_fac := valueof(ts_SS_USSD_FACILITY_RETURN_RESULT(dec_fac[0].invoke.invokeId.present_,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     SS_OP_CODE_PROCESS_USS_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+                                   dec_fac[0].invoke.argument.uSSD_Arg.ussd_DataCodingScheme,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    dec_fac[0].invoke.argument.uSSD_Arg.ussd_String));</span><br><span style="color: hsl(120, 100%, 40%);">+    ss_rsp := enc_SS_FacilityInformation(rsp_fac);</span><br><span style="color: hsl(120, 100%, 40%);">+        return valueof(ts_GSUP_PROC_SS_RES(rx_pdu.ies[0].val.imsi, rx_pdu.ies[1].val.session_id,</span><br><span style="color: hsl(120, 100%, 40%);">+                                         OSMO_GSUP_SESSION_STATE_END, ss_rsp));</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%);">+/* main function for handling mobile-originated USSD via GSUP */</span><br><span style="color: hsl(120, 100%, 40%);">+function f_main_mo(charstring hlr_ip, uint16_t hlr_gsup_port, charstring name, f_euse_cb cb_fn)</span><br><span style="color: hsl(120, 100%, 40%);">+runs on HLR_EUSE_CT {</span><br><span style="color: hsl(120, 100%, 40%);">+      var GSUP_PDU rx_pdu, tx_pdu;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        f_init(hlr_ip, hlr_gsup_port, name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        while (true) {</span><br><span style="color: hsl(120, 100%, 40%);">+                alt {</span><br><span style="color: hsl(120, 100%, 40%);">+         [] EUSE.receive(tr_GSUP_PROC_SS_REQ(?, ?, OSMO_GSUP_SESSION_STATE_BEGIN)) -> value rx_pdu {</span><br><span style="color: hsl(120, 100%, 40%);">+                        EUSE.send(cb_fn.apply(OSMO_GSUP_SESSION_STATE_BEGIN, rx_pdu));</span><br><span style="color: hsl(120, 100%, 40%);">+                        }</span><br><span style="color: hsl(120, 100%, 40%);">+             [] EUSE.receive(tr_GSUP_PROC_SS_REQ(?, ?, OSMO_GSUP_SESSION_STATE_CONTINUE)) -> value rx_pdu {</span><br><span style="color: hsl(120, 100%, 40%);">+                     EUSE.send(cb_fn.apply(OSMO_GSUP_SESSION_STATE_CONTINUE, rx_pdu));</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%);">+           [] EUSE.receive(tr_GSUP_PROC_SS_REQ(?, ?, OSMO_GSUP_SESSION_STATE_END)) -> value rx_pdu {</span><br><span style="color: hsl(120, 100%, 40%);">+                  EUSE.send(cb_fn.apply(OSMO_GSUP_SESSION_STATE_END, rx_pdu));</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%);">+         [] EUSE.receive {</span><br><span style="color: hsl(120, 100%, 40%);">+                     setverdict(fail, "EUSE: Unexpected Rx from HLR");</span><br><span style="color: hsl(120, 100%, 40%);">+                   self.stop;</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%);">+}</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></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/10403">change 10403</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/10403"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ttcn3-hacks </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ibab210b06abfd5a21e81c7f7fbe574c4f67414a0 </div>
<div style="display:none"> Gerrit-Change-Number: 10403 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>