laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/20123 )

Change subject: NS_Emulation: Refactor if/elseif/... clause to altsteps with 
guard
......................................................................

NS_Emulation: Refactor if/elseif/... clause to altsteps with guard

This makes for much more readable code, and we can even do without
activating any default altsteps.

Change-Id: I4c38dd55b7c27899735f5730851d36c1410d96a8
---
M library/NS_Emulation.ttcnpp
1 file changed, 69 insertions(+), 71 deletions(-)

Approvals:
  fixeria: Looks good to me, approved
  lynxis lazus: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/NS_Emulation.ttcnpp b/library/NS_Emulation.ttcnpp
index 5872b00..dcc0e17 100644
--- a/library/NS_Emulation.ttcnpp
+++ b/library/NS_Emulation.ttcnpp
@@ -203,7 +203,7 @@
                Tns_block.start;
        }

-       altstep as_allstate() runs on NS_CT {
+       private altstep as_allstate() runs on NS_CT {
                var PDU_NS rf;
                var ASP_Event evt;

@@ -266,7 +266,7 @@

        /* simple IP Sub-Network Service responder for the SGSN side. This is 
not a full implementation
         * of the protocol, merely sufficient to make the PCU/BSS side happy to 
proceed */
-       altstep as_sns_sgsn() runs on NS_CT {
+       private altstep as_sns_sgsn() runs on NS_CT {
                var PDU_NS rf;
                [] NSCP.receive(tr_SNS_SIZE(config.nsei)) -> value rf {
                        /* blindly acknowledge whatever the PCU sends */
@@ -305,82 +305,80 @@
                }
        }

-       private function f_ScanEvents() runs on NS_CT {
+       private altstep as_alive_blocked() runs on NS_CT {
+               var PDU_NS rf;
+               /* bogus block, just respond with ACK */
+               [] NSCP.receive(tr_NS_BLOCK(?, config.nsvci)) -> value rf {
+                       NSCP.send(ts_NS_BLOCK_ACK(config.nsvci));
+               }
+               /* Respond to UNBLOCK with UNBLOCK-ACK + change state */
+               [] NSCP.receive(t_NS_UNBLOCK) -> value rf {
+                       NSCP.send(t_NS_UNBLOCK_ACK);
+                       Tns_block.stop;
+                       f_change_state(NSE_S_ALIVE_UNBLOCKED);
+               }
+               [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf {
+                       Tns_block.stop;
+                       f_change_state(NSE_S_ALIVE_UNBLOCKED);
+               }
+               [] Tns_block.timeout {
+                       /* repeat unblock transmission */
+                       f_sendUnblock();
+               }
+       }
+
+       private altstep as_alive_unblocked() runs on NS_CT {
                var NsUnitdataRequest ud_req;
                var PDU_NS rf;
-               var default d;
+               /* bogus unblock, just respond with ACK */
+               [] NSCP.receive(t_NS_UNBLOCK) -> value rf {
+                       NSCP.send(t_NS_UNBLOCK_ACK);
+               }
+               /* Respond to BLOCK with BLOCK-ACK + change state */
+               [] NSCP.receive(tr_NS_BLOCK(?, config.nsvci)) -> value rf {
+                       NSCP.send(ts_NS_BLOCK_ACK(config.nsvci));
+                       Tns_block.stop;
+                       f_change_state(NSE_S_ALIVE_BLOCKED);
+               }
+               [] NSCP.receive(tr_NS_BLOCK_ACK(config.nsvci)) -> value rf {
+                       Tns_block.stop;
+               }
+               /* NS-UNITDATA PDU from network to NS-UNITDATA.ind to user */
+               [] NSCP.receive(tr_NS_UNITDATA(?, ?, ?)) -> value rf {
+                       NS_SP.send(t_NsUdInd(config.nsei,
+                                            oct2int(rf.pDU_NS_Unitdata.bVCI),
+                                            rf.pDU_NS_Unitdata.nS_SDU));
+               }
+               /* NS-UNITDATA.req from user to NS-UNITDATA PDU on network */
+               [] NS_SP.receive(t_NsUdReq(config.nsei, ?, ?, omit)) -> value 
ud_req {
+                       /* using raw octetstring PDU */
+                       NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, 
ud_req.sdu));
+               }
+               [] NS_SP.receive(t_NsUdReq(config.nsei, ?, omit, ?)) -> value 
ud_req {
+                       /* using decoded BSSGP PDU that we need to encode first 
*/
+                       var octetstring enc := enc_PDU_BSSGP(ud_req.bssgp);
+                       NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, enc));
+               }
+       }

-               d := activate(as_allstate());
+       private altstep as_wait_reset() runs on NS_CT {
+               var PDU_NS rf;
+               [] NSCP.receive(tr_NS_RESET_ACK(config.nsvci, config.nsei)) -> 
value rf {
+                       f_change_state(NSE_S_ALIVE_BLOCKED);
+                       f_sendAlive();
+                       f_sendUnblock();
+               }
+       }

+       private function f_ScanEvents() runs on NS_CT {
+               var PDU_NS rf;
                while (true) {
-               if (g_state == NSE_S_DEAD_BLOCKED) {
                        alt {
-                               [false] any timer.timeout {}
-                       }
-               } else if (g_state == NSE_S_WAIT_RESET) {
-                       alt {
-                               [] NSCP.receive(tr_NS_RESET_ACK(config.nsvci, 
config.nsei)) -> value rf {
-                                       f_change_state(NSE_S_ALIVE_BLOCKED);
-                                       f_sendAlive();
-                                       f_sendUnblock();
-                               }
-                       }
-               } else if (g_state == NSE_S_ALIVE_BLOCKED) {
-                       alt {
-                               /* bogus block, just respond with ACK */
-                               [] NSCP.receive(tr_NS_BLOCK(?, config.nsvci)) 
-> value rf {
-                                       
NSCP.send(ts_NS_BLOCK_ACK(config.nsvci));
-                               }
-                               /* Respond to UNBLOCK with UNBLOCK-ACK + change 
state */
-                               [] NSCP.receive(t_NS_UNBLOCK) -> value rf {
-                                       NSCP.send(t_NS_UNBLOCK_ACK);
-                                       Tns_block.stop;
-                                       f_change_state(NSE_S_ALIVE_UNBLOCKED);
-                               }
-                               [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf {
-                                       Tns_block.stop;
-                                       f_change_state(NSE_S_ALIVE_UNBLOCKED);
-                               }
-                               [] Tns_block.timeout {
-                                       /* repeat unblock transmission */
-                                       f_sendUnblock();
-                               }
-                       }
-               } else if (g_state == NSE_S_ALIVE_UNBLOCKED) {
-                       alt {
-                               /* bogus unblock, just respond with ACK */
-                               [] NSCP.receive(t_NS_UNBLOCK) -> value rf {
-                                       NSCP.send(t_NS_UNBLOCK_ACK);
-                               }
-                               /* Respond to BLOCK with BLOCK-ACK + change 
state */
-                               [] NSCP.receive(tr_NS_BLOCK(?, config.nsvci)) 
-> value rf {
-                                       
NSCP.send(ts_NS_BLOCK_ACK(config.nsvci));
-                                       Tns_block.stop;
-                                       f_change_state(NSE_S_ALIVE_BLOCKED);
-                               }
-                               [] NSCP.receive(tr_NS_BLOCK_ACK(config.nsvci)) 
-> value rf {
-                                       Tns_block.stop;
-                               }
-                               /* NS-UNITDATA PDU from network to 
NS-UNITDATA.ind to user */
-                               [] NSCP.receive(tr_NS_UNITDATA(?, ?, ?)) -> 
value rf {
-                                       NS_SP.send(t_NsUdInd(config.nsei,
-                                                            
oct2int(rf.pDU_NS_Unitdata.bVCI),
-                                                            
rf.pDU_NS_Unitdata.nS_SDU));
-                               }
-                               /* NS-UNITDATA.req from user to NS-UNITDATA PDU 
on network */
-                               [] NS_SP.receive(t_NsUdReq(config.nsei, ?, ?, 
omit)) -> value ud_req {
-                                       /* using raw octetstring PDU */
-                                       NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, 
ud_req.bvci, ud_req.sdu));
-                               }
-                               [] NS_SP.receive(t_NsUdReq(config.nsei, ?, 
omit, ?)) -> value ud_req {
-                                       /* using decoded BSSGP PDU that we need 
to encode first */
-                                       var octetstring enc := 
enc_PDU_BSSGP(ud_req.bssgp);
-                                       NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, 
ud_req.bvci, enc));
-                               }
+                       [g_state == NSE_S_WAIT_RESET] as_wait_reset();
+                       [g_state == NSE_S_ALIVE_BLOCKED] as_alive_blocked();
+                       [g_state == NSE_S_ALIVE_UNBLOCKED] as_alive_unblocked();
+                       [] as_allstate();
                        }
                }
-
-               } /* while */
-               //deactivate(d);
        }
 }

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

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I4c38dd55b7c27899735f5730851d36c1410d96a8
Gerrit-Change-Number: 20123
Gerrit-PatchSet: 12
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-MessageType: merged

Reply via email to