pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41968?usp=email )


Change subject: RAN_Emulation: Handle N-PCSTATE.ind to wait for peer 
availability
......................................................................

RAN_Emulation: Handle N-PCSTATE.ind to wait for peer availability

Take the chance to explicitly log and discard other .ind primitives
which would otherwise block the processing of messages.

Change-Id: I86b481fca9b7be84f3cda9fbce83e60820fe7fc1
Related: OS#6907
---
M bsc/BSC_Tests.ttcn
M library/BSSAP_CodecPort.ttcn
M library/RAN_Emulation.ttcnpp
M library/ranap/RANAP_CodecPort.ttcn
4 files changed, 138 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/68/41968/1

diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index db70bd5..f269654 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -1222,6 +1222,7 @@
                }
                connect(self:BSSAP, 
g_bssap[bssap_idx].sccpa.vc_SCCP:SCCP_SP_PORT);
                f_sccp_adapter_start(g_bssap[bssap_idx].sccpa);
+               f_bssap_wait_sccp_peer_available(BSSAP, 
bit2int(g_bssap[bssap_idx].sccpa.sccp_addr_peer.signPointCode));
                f_legacy_bssap_reset();
        }
 }
diff --git a/library/BSSAP_CodecPort.ttcn b/library/BSSAP_CodecPort.ttcn
index ce9248e..23000e2 100644
--- a/library/BSSAP_CodecPort.ttcn
+++ b/library/BSSAP_CodecPort.ttcn
@@ -406,7 +406,7 @@
           ASP_SCCP_N_RESET_ind -> ASP_SCCP_N_RESET_ind: simple;
           ASP_SCCP_N_RESET_cfm -> ASP_SCCP_N_RESET_cfm: simple;
           ASP_SCCP_N_STATE_ind -> ASP_SCCP_N_STATE_ind: simple;
-          ASP_SCCP_N_PCSTATE_ind -> -: discard)"
+          ASP_SCCP_N_PCSTATE_ind -> ASP_SCCP_N_PCSTATE_ind: simple)"
 }


diff --git a/library/RAN_Emulation.ttcnpp b/library/RAN_Emulation.ttcnpp
index 3b3e6bd..19ae324 100644
--- a/library/RAN_Emulation.ttcnpp
+++ b/library/RAN_Emulation.ttcnpp
@@ -961,6 +961,12 @@
                var BSSAP_N_CONNECT_cfm conn_cfm;
                var BSSAP_N_DATA_ind data_ind;
                var BSSAP_N_DISCONNECT_ind disc_ind;
+
+               var ASP_SCCP_N_RESET_ind n_reset_ind;
+               var ASP_SCCP_N_RESET_cfm n_reset_cfm;
+               var ASP_SCCP_N_STATE_ind n_state_ind;
+               var ASP_SCCP_N_PCSTATE_ind n_pcstate_ind;
+
                var BSSAP_Conn_Req creq;
                var PDU_BSSAP bssap;
                var BSSAP_N_UNITDATA_req bssap_ud;
@@ -1017,6 +1023,24 @@
                                f_handle_userData_BSSAP(vc_conn, 
conn_cfm.userData);
                        }
                        }
+
+               /* SCCP -> Client: N-RESET.ind */
+               [] BSSAP.receive(ASP_SCCP_N_RESET_ind:?) -> value n_reset_ind {
+                       log("Discard ", n_reset_ind)
+                       }
+               /* SCCP -> Client: N-RESET.cfm */
+               [] BSSAP.receive(ASP_SCCP_N_RESET_cfm:?) -> value n_reset_cfm {
+                       log("Discard ", n_reset_cfm)
+                       }
+               /* SCCP -> Client: N-STATE.ind */
+               [] BSSAP.receive(ASP_SCCP_N_STATE_ind:?) -> value n_state_ind {
+                       log("Discard ", n_state_ind)
+                       }
+               /* SCCP -> Client: N-PCSTATE.ind */
+               [] BSSAP.receive(ASP_SCCP_N_PCSTATE_ind:?) -> value 
n_pcstate_ind {
+                       log("Discard ", n_pcstate_ind)
+                       }
+
                [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn {
                        var integer conn_id := f_conn_id_by_comp(vc_conn);
                        /* send it to dispatcher */
@@ -1087,6 +1111,12 @@
                var RANAP_N_CONNECT_cfm rconn_cfm;
                var RANAP_N_DATA_ind rdata_ind;
                var RANAP_N_DISCONNECT_ind rdisc_ind;
+
+               var ASP_SCCP_N_RESET_ind n_reset_ind;
+               var ASP_SCCP_N_RESET_cfm n_reset_cfm;
+               var ASP_SCCP_N_STATE_ind n_state_ind;
+               var ASP_SCCP_N_PCSTATE_ind n_pcstate_ind;
+
                var RANAP_Conn_Req creq;
                var RANAP_PDU ranap;
                var RANAP_N_UNITDATA_req ranap_ud;
@@ -1152,6 +1182,23 @@
                        }
                        }

+               /* SCCP -> Client: N-RESET.ind */
+               [] RANAP.receive(ASP_SCCP_N_RESET_ind:?) -> value n_reset_ind {
+                       log("Discard ", n_reset_ind)
+                       }
+               /* SCCP -> Client: N-RESET.cfm */
+               [] RANAP.receive(ASP_SCCP_N_RESET_cfm:?) -> value n_reset_cfm {
+                       log("Discard ", n_reset_cfm)
+                       }
+               /* SCCP -> Client: N-STATE.ind */
+               [] RANAP.receive(ASP_SCCP_N_STATE_ind:?) -> value n_state_ind {
+                       log("Discard ", n_state_ind)
+                       }
+               /* SCCP -> Client: N-PCSTATE.ind */
+               [] RANAP.receive(ASP_SCCP_N_PCSTATE_ind:?) -> value 
n_pcstate_ind {
+                       log("Discard ", n_pcstate_ind)
+                       }
+
                [] CLIENT.receive(RANAP_PDU:?) -> value ranap sender vc_conn {
                        var integer conn_id := f_conn_id_by_comp(vc_conn);
                        /* send it to dispatcher */
@@ -1339,6 +1386,88 @@
        }
 }

+#ifdef RAN_EMULATION_BSSAP
+function f_bssap_wait_sccp_peer_available(BSSAP_CODEC_PT pt, integer peer_pc, 
float timeout_sec := 3.0)
+{
+       timer T;
+       var ASP_SCCP_N_PCSTATE_ind n_pcstate_ind;
+       var boolean rx_explicit_down := false;
+
+       log("Waiting for SCCP peer PC=", peer_pc, " to become available");
+       T.start(timeout_sec);
+
+       alt {
+       [] pt.receive(t_ASP_N_PCSTATE_ind(?, ?, *, *)) -> value n_pcstate_ind {
+               var integer aff_pc := bit2int(n_pcstate_ind.affectedSP);
+               if (aff_pc != peer_pc) {
+                       log("Waiting for SCCP peer PC=", peer_pc, ": Rx 
N-PCSTATE.ind for another peer PC=", aff_pc, ", ",n_pcstate_ind);
+                       repeat;
+               }
+               if (n_pcstate_ind.spStatus == SCCP_PAR_SP_Status_accessible and
+                       n_pcstate_ind.remSCCPStatus == 
SCCP_PAR_Remote_SCCP_Status_available) {
+                       log("SCCP peer PC=", aff_pc," is now available");
+                       /* All peer is available, we are done */
+                       T.stop;
+                       return;
+               }
+               log("SCCP peer PC=", aff_pc," is NOT available: ", 
n_pcstate_ind);
+               rx_explicit_down := true;
+               repeat;
+               }
+       [] T.timeout {
+               if (rx_explicit_down) {
+                       /* explicitly unavailable:*/
+                       Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+                                               log2str("Timeout waiting for 
SCCP peer PC=", peer_pc));
+               }
+               /* Done, assume PCs for which we didn't receive an explicit 
"unavailable" are actually available. */
+               }
+       }
+       log("Done waiting for SCCP peer PC=", peer_pc);
+}
+#endif
+
+#ifdef RAN_EMULATION_RANAP
+function f_ranap_wait_sccp_peer_available(RANAP_CODEC_PT pt, integer peer_pc, 
float timeout_sec := 3.0)
+{
+       timer T;
+       var ASP_SCCP_N_PCSTATE_ind n_pcstate_ind;
+       var boolean rx_explicit_down := false;
+
+       log("Waiting for SCCP peer PC=", peer_pc, " to become available");
+       T.start(timeout_sec);
+
+       alt {
+       [] pt.receive(t_ASP_N_PCSTATE_ind(?, ?, *, *)) -> value n_pcstate_ind {
+               var integer aff_pc := bit2int(n_pcstate_ind.affectedSP);
+               if (aff_pc != peer_pc) {
+                       log("Waiting for SCCP peer PC=", peer_pc, ": Rx 
N-PCSTATE.ind for another peer PC=", aff_pc, ", ",n_pcstate_ind);
+                       repeat;
+               }
+               if (n_pcstate_ind.spStatus == SCCP_PAR_SP_Status_accessible and
+                       n_pcstate_ind.remSCCPStatus == 
SCCP_PAR_Remote_SCCP_Status_available) {
+                       log("SCCP peer PC=", aff_pc," is now available");
+                       /* All peer is available, we are done */
+                       T.stop;
+                       return;
+               }
+               log("SCCP peer PC=", aff_pc," is NOT available: ", 
n_pcstate_ind);
+               rx_explicit_down := true;
+               repeat;
+               }
+       [] T.timeout {
+               if (rx_explicit_down) {
+                       /* explicitly unavailable:*/
+                       Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+                                               log2str("Timeout waiting for 
SCCP peer PC=", peer_pc));
+               }
+               /* Done, assume PCs for which we didn't receive an explicit 
"unavailable" are actually available. */
+               }
+       }
+       log("Done waiting for SCCP peer PC=", peer_pc);
+}
+#endif
+
 function main(RanOps ops, charstring id) runs on RAN_Emulation_CT {

        g_ran_id := id;
@@ -1350,11 +1479,17 @@
                select (g_ran_ops.protocol) {
 #ifdef RAN_EMULATION_BSSAP
                case (RAN_PROTOCOL_BSSAP) {
+                       if (ispresent(ops.sccp_addr_peer.signPointCode)) {
+                               f_bssap_wait_sccp_peer_available(BSSAP, 
bit2int(ops.sccp_addr_peer.signPointCode));
+                       }
                        f_bssap_reset(ops.sccp_addr_peer, ops.sccp_addr_local);
                        }
 #endif
 #ifdef RAN_EMULATION_RANAP
                case (RAN_PROTOCOL_RANAP) {
+                       if (ispresent(ops.sccp_addr_peer.signPointCode)) {
+                               f_ranap_wait_sccp_peer_available(RANAP, 
bit2int(ops.sccp_addr_peer.signPointCode));
+                       }
                        f_ranap_reset(ops.sccp_addr_peer, ops.sccp_addr_local, 
ops.grnc_id);
                        }
 #endif
diff --git a/library/ranap/RANAP_CodecPort.ttcn 
b/library/ranap/RANAP_CodecPort.ttcn
index 084d1cf..8d8ead5 100644
--- a/library/ranap/RANAP_CodecPort.ttcn
+++ b/library/ranap/RANAP_CodecPort.ttcn
@@ -405,7 +405,7 @@
           ASP_SCCP_N_RESET_ind -> ASP_SCCP_N_RESET_ind: simple;
           ASP_SCCP_N_RESET_cfm -> ASP_SCCP_N_RESET_cfm: simple;
           ASP_SCCP_N_STATE_ind -> ASP_SCCP_N_STATE_ind: simple;
-          ASP_SCCP_N_PCSTATE_ind -> -: discard)"
+          ASP_SCCP_N_PCSTATE_ind -> ASP_SCCP_N_PCSTATE_ind: simple)"
 }



--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41968?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I86b481fca9b7be84f3cda9fbce83e60820fe7fc1
Gerrit-Change-Number: 41968
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to