/**
 *    @author   ETSI / TTF041
 *    @version  $URL$
 *              $Id$
 *    @desc     This module provides testcases for NG_NAS tests.
 *    @copyright   ETSI Copyright Notification
 *                 No part may be reproduced except as authorized by written permission.
 *                 The copyright and the foregoing restriction extend to reproduction in all media.
 *                 All rights reserved.
 *    @see      ETSI TS 
 */

module NG_NAS_TestCases {

    // LibCommon
    import from LibCommon_Sync all ;

    // NG_NAS
    import from Lib_NG_NAS_Interface all;
    import from NG_NAS_TCFunctions all;
    import from NG_NAS_Pics all;
    import from NG_NAS_TestConfiguration all;
    import from NG_NAS_TestSystem all;

    // LibNGAP
    import  from  NGAP_Constants  language  "ASN.1:2002"  all;
    import  from  NGAP_CommonDataTypes  language  "ASN.1:2002"  all;
    import  from  NGAP_IEs  language  "ASN.1:2002"  all;
    import  from  NGAP_PDU_Contents  language  "ASN.1:2002"  all;
    import  from  NGAP_PDU_Descriptions  language  "ASN.1:2002"  all;
    import  from  NGAP_Containers  language  "ASN.1:2002"  all;

    //import  from  LibNGAP_TypesAndValues all;
    //import  from  LibNGAP_Templates all;
    //import  from  LibNGAP_Pixits all;

    // NGAP_Ats
    //import from LibNGAP_TypesAndValues all;
    //import from NGAP_TestConfiguration all;
    import from NGAP_TestSystem all;
    //import from NGAP_TCFunctions all;
    //import from NGAP_Pics all;

    group TC_AMF {

        group /*5_4_*/fiveGMM_Common_Procedures {

            group /*5_4_1_*/fiveGMM_Common_ProceduresPrimary_authentication_and_key_agreement_procedure {

                /**
                 * @desc Verify that the IUT sends an AUTHENTICATION REQUEST message correctly upon receipt of a NAS Registration without an active security context
                 * @see ETSI TS 124 501 [1], Clauses 5.4.1.3.2 and 8.2.1
                 */
                testcase TC_5GNAS_AMF_AUT_REQ_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_REQ_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_REQ_01

                /**
                 * @desc Verify that the IUT sends an AUTHENTICATION REQUEST message correctly upon receipt of a NAS Registration without an active security context
                 * @see ETSI TS 124 501 [1], Clause 5.4.1.3.5 and 8.2.5
                 */
                testcase TC_5GNAS_AMF_AUT_REQ_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_REQ_02());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_REQ_02

                /**
                 * @desc Verify that the IUT stops re-sending an AUTHENTICATION REQUEST message if no AUTHENTICATION RESPONSE message is received on the fifth expiry of timer T3560
                 * @see ETSI TS 124 501 [1], Clauses 5.4.1.3.7 b) and Table 10.3.1
                 */
                testcase TC_5GNAS_AMF_AUT_REQ_03() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_REQ_03());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_REQ_03

                /**
                 * @desc Verify that the IUT sends an IDENTITY REQUEST message correctly upon receipt of an AUTHENTICATION FAILURE message indicating a 5GMM cause value #20 - MAC failure
                 * @see ETSI TS 124 501 [1], Clauses 5.4.1.3.7 c) and 8.2.4
                 */
                testcase TC_5GNAS_AMF_AUT_REQ_04() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_REQ_04());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_REQ_04

                /**
                 * @desc Verify that the IUT sends a new AUTHENTICATION REQUEST message with new ngKSI value to re-initiate the 5G AKA based primary authentication upon receipt of an AUTHENTICATION FAILURE message indicating a 5GMM cause value #71 - ngKSI already in use
                 * @see ETSI TS 124 501 [1], Clauses 5.4.1.3.7 e) and 8.2.4
                 */
                testcase TC_5GNAS_AMF_AUT_REQ_05() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_REQ_05());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_REQ_05

                /**
                 * @desc Verify that the IUT sends a new IDENTITY REQUEST message to obtain the SUCI from the UE upon receipt of an AUTHENTICATION FAILURE message indicating a 5GMM cause value #26 - non-5G authentication unacceptable
                 * @see ETSI TS 124 501 [1], Clauses 5.4.1.3.7 and 8.2.4
                 */
                testcase TC_5GNAS_AMF_AUT_ABN_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_AUT_ABN_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_AUT_ABN_01

            } // End of group /*5_4_1_*/fiveGMM_Common_ProceduresPrimary_authentication_and_key_agreement_procedure

            group /*5_4_2_*/Security_mode_control_procedure {
                
                /**
                 * @desc Verify that the IUT sends a SECURITY MODE COMMAND message correctly to indicate NAS security mode procedure upon receipt of a NAS AUTHENTICATION RESPONSE
                 * @see ETSI TS 124 501 [1], Clause 5.4.1.2
                 */
                testcase TC_NGNAS_AMF_AUT_SEQ_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_NGNAS_AMF_AUT_SEQ_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_NGNAS_AMF_AUT_SEQ_01

                /**
                 * @desc Verify that the IUT, upon receiving the NAS SECURITY MODE COMPLETE message after completing the NAS Authentication and Security procedure, successfully completes the registration process by accepting the registration
                 * @see ETSI TS 124 501 [1], Clause 5.4.2 and 8.2.25
                 */
                testcase TC_5GNAS_AMF_SEC_ACC_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_SEC_ACC_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_SEC_ACC_01

                /**
                 * @desc Verify that the IUT, upon receiving the NAS SECURITY MODE REJECT Message after a failed NAS Authentication and security procedure, successfully aborts the registration process by rejecting the registration
                 * @see ETSI TS 124 501 [1], Clause 5.4.2 and 8.2.25
                 */
                testcase TC_5GNAS_AMF_SEC_REJ_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_SEC_REJ_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_SEC_REJ_01

            } // End of group /*5_4_2_*/Security_mode_control_procedure

            group /*5_4_5_*/NAS_transport_procedure {

                /**
                 * @desc Verify that the IUT correctly handles a UL NAS transport message containing a PDU SESSION ESTABLISHMENT REQUEST from the UE and responds with a DL NAS transport message containing a PDU SESSION ESTABLISHMENT ACCEPT
                 * @see ETSI TS 124 501 [1], Clause 5.4.5 and 8.2.10, 8.2.11
                 */
                testcase TC_5GNAS_AMF_DLN_ACC_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                    // Local variables
                    var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                    // Test control
                    if (not PICS_NGNAS) {
                        log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                        stop;
                    }

                    // Test component configuration
                    f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                    // Start
                    v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DLN_ACC_01());

                    // synchronize PTC on 1 sychronization points
                    f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                    //f_cf_Down/*gNBoraMF*/();

                } // End of testcase TC_5GNAS_AMF_DLN_ACC_01

            } // End of group /*5_4_5_*/NAS_transport_procedure

        } // End of group /*5_4_*/fiveGMM_Common_Procedures

        group /*5_5_1_2_*/Registration_Procedure_for_initial_registration {
            
            /**
             * @desc Verify that the IUT sends a REGISTRATION ACCEPT message containing the 5GS registration result, TAI list, 5G-GUTI and T3512 when initial registration is accepted by the network
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.4 and 8.2.7
             */
            testcase TC_5GNAS_AMF_REG_ACC_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_ACC_01());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase _5GNAS_AMF_REG_ACC_01

            /**
             * @desc Verify that the IUT sends a REGISTRATION ACCEPT message indicating SMS over NAS allowed when initial registration with SMS over NAS is requested and network allows SMS service
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.4 and 8.2.7
             */
            testcase TC_5GNAS_AMF_REG_ACC_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_ACC_02());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase _5GNAS_AMF_REG_ACC_02

            /**
             * @desc Verify that the IUT sends a REGISTRATION ACCEPT message indicating SMS over NAS not allowed when initial registration with SMS over NAS is requested and network does not support SMS service
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.4 and 8.2.7
             */
            testcase TC_5GNAS_AMF_REG_ACC_03() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_ACC_03());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase _5GNAS_AMF_REG_ACC_03

            /**
             * @desc Verify that the IUT includes the allowed NSSAI in the REGISTRATION ACCEPT message when the UE includes a requested NSSAI in the REGISTRATION REQUEST message and the network allows one or more S-NSSAIs from the requested NSSAI
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.4 and 8.2.7
             */
            testcase TC_5GNAS_AMF_REG_ACC_04() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_ACC_04());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_REG_ACC_04

            /**
             * @desc Verify that the IUT optionally includes rejected NSSAI in the REGISTRATION ACCEPT message when the network rejects one or more S-NSSAIs from the requested NSSAI
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.4 and 8.2.7
             */
            testcase TC_5GNAS_AMF_REG_ACC_05() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_ACC_05());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_REG_ACC_05

            /**
             * @desc Verify that the IUT rejects initial registration request due to general NAS level mobility management congestion control with 5GMM cause value #22 - congestion and assign a value for back-off timer T3346
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.5 and 8.2.9
             */
            testcase TC_5GNAS_AMF_REG_REJ_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_REJ_01());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_REG_REJ_01

            /**
             * @desc Verify that the IUT rejects initial registration request because all the S-NSSAI(s) included in the requested NSSAI are either rejected for current PLMN, rejected for the current registration area or rejected due to failed or revoked NSSAIs
             * @see ETSI TS 124 501 [1], Clauses 5.5.1.2.5 and 8.2.9
             */
            testcase TC_5GNAS_AMF_REG_REJ_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_REG_REJ_02());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_REG_REJ_02

        } // End of group /*5_5_1_2_*/Registration_Procedure_for_initial_registration

        group /*5_5_2_2_3*/UE_initiated_de_registration_procedure_completion {

            /**
             * @desc Verify that the IUT, upon receiving a DEREGISTRATION REQUEST message containing the De-registration type IE with Normal de-registration from the UE, sends a DEREGISTRATION ACCEPT message
             * @see ETSI TS 124 501 [1], Clauses 5.5.2.2.3, 8.2.12 and 8.2.13
             */
            testcase TC_5GNAS_AMF_DRG_ACC_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DRG_ACC_01());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_DRG_ACC_01 

            /**
             * @desc Verify that the IUT, upon receiving a DEREGISTRATION REQUEST message containing the De-registration type IE with Switch-off from the UE, does not send a DEREGISTRATION ACCEPT message and IUT completes de-registration procedure
             * @see ETSI TS 124 501 [1], Clauses 5.5.2.2.3, 8.2.12 and 8.2.13
             */
            testcase TC_5GNAS_AMF_DRG_ACC_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DRG_ACC_02());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_DRG_ACC_02

        } // End of group /*5_5_2_2_3*/UE_initiated_de_registration_procedure_completion

        group /*5_5_2_3_1*/Network_initiated_de_registration_procedure_initiation {

            /**
             * @desc Verify that the IUT initiates network de-registration by sending a DEREGISTRATION REQUEST message containing De-registration type IE with re-registration not required and the access type based on the UE’s registration status (3GPP access only). **NOTE:** explicit network deregistration triggered by O&M - deactivation of UE
             * @see ETSI TS 124 501 [1], Clauses 5.5.2.3.1 and 8.2.14
             */
            testcase TC_5GNAS_AMF_DRG_REQ_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DRG_REQ_01());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_DRG_REQ_01

            /**
             * @desc Verify that the IUT initiates network de-registration by sending a DEREGISTRATION REQUEST message and if UE does not send DEREGISTRATION ACCEPT then IUT retransmits DEREGISTRATION REQUEST message after timer T3522 expiration. **NOTE:** explicit network deregistration triggered by O&M - UE deregistration
             * @see ETSI TS 124 501 [1], Clauses 5.5.2.3.1 and 8.2.14
             */
            testcase TC_5GNAS_AMF_DRG_REQ_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DRG_REQ_02());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_DRG_REQ_02

            /**
             * @desc Verify that the IUT initiates network de-registration by sending DEREGISTRATION REQUEST message containing De-registration type IE with re-registration required and the access type based on the UE’s registration status (3GPP access only). **NOTE 1:** UE sends DEREGISTRATION ACCEPT and starts with re-registration procedure.(also used ref 5.5.2.3.2 1st paragraph) **NOTE 2:** explicit network deregistration triggered by O&M - UE deregistration"
             * @see ETSI TS 124 501 [1], Clauses 5.5.2.3.1, 5.5.2.3.2 and 8.2.14
             */
            testcase TC_5GNAS_AMF_DRG_REQ_03() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
            
                // Local variables
                var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

                // Test control
                if (not PICS_NGNAS) {
                    log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                    stop;
                }

                // Test component configuration
                f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

                // Start
                v_ngnas_ngap_gnb.start(f_TC_5GNAS_AMF_DRG_REQ_03());

                // synchronize PTC on 1 sychronization points
                f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

                //f_cf_Down/*gNBoraMF*/();

            } // End of testcase TC_5GNAS_AMF_DRG_REQ_03

        } // End of group /*5_5_2_3_1*/Network_initiated_de_registration_procedure_initiation

    } // End of group TC_AMF

    group TC_AMF_NGAP {

        /**
         * @desc The IUT is able to receive an INITIAL_UE_MESSAGE to indicate a NAS transport procedure and reply with INITIAL_CONTEXT_SETUP_REQUEST
         * @see ETSI TS 138 413 [1], Clauses 8.3.1.2, 8.6.1.2, 9.2.5.1 and 9.2.2.1
         */
        testcase TC_5GAP_ICS_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
            // Local variables
            var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

            // Test control
            if (not PICS_NGNAS) {
                log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                stop;
            }

            // Test component configuration
            f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

            // Start
            v_ngnas_ngap_gnb.start(f_TC_5GAP_ICS_01());

            // synchronize PTC on 1 sychronization points
            f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

            //f_cf_Down/*gNBoraMF*/();

        } // End of testcase TC_5GAP_ICS_01

        /**
         * @desc The IUT is able to receive an UPLINK_NAS_TRANSPORT to indicate a NAS transport procedure and reply with INITIAL_CONTEXT_SETUP_REQUEST
         * @see ETSI TS 138 413 [1], Clauses 8.3.1.2, 8.6.3.2, 9.2.2.1 and 9.2.5.3
         */
        testcase TC_5GAP_ICS_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
            // Local variables
            var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

            // Test control
            if (not PICS_NGNAS) {
                log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                stop;
            }

            // Test component configuration
            f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

            // Start
            v_ngnas_ngap_gnb.start(f_TC_5GAP_ICS_02());

            // synchronize PTC on 1 sychronization points
            f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

            //f_cf_Down/*gNBoraMF*/();

        } // End of testcase TC_5GAP_ICS_02

        /**
         * @desc The IUT is able to receive an INITIAL_UE_MESSAGE to indicate a NAS transport procedure and reply with DOWNLINK_NAS_TRANSPORT
         * @see ETSI TS 138 413 [1], Clauses 8.6.1.2, 8.6.2.2, 9.2.5.1 and 9.2.5.2
         */
        testcase TC_5GAP_DNA_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
            // Local variables
            var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

            // Test control
            if (not PICS_NGNAS) {
                log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                stop;
            }

            // Test component configuration
            f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

            // Start
            v_ngnas_ngap_gnb.start(f_TC_5GAP_DNA_01());

            // synchronize PTC on 1 sychronization points
            f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

            //f_cf_Down/*gNBoraMF*/();

        } // End of testcase TC_5GAP_DNA_01

        /**
         * @desc The IUT is able to receive an INITIAL_UE_MESSAGE to indicate a NAS transport procedure and reply with DOWNLINK_NAS_TRANSPORT
         * @see ETSI TS 138 413 [1], Clauses 8.6.1.2, 8.6.2.2, 9.2.5.1 and 9.2.5.2
         */
        testcase TC_5GAP_DNA_02() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
            // Local variables
            var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

            // Test control
            if (not PICS_NGNAS) {
                log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                stop;
            }

            // Test component configuration
            f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

            // Start
            v_ngnas_ngap_gnb.start(f_TC_5GAP_DNA_02());

            // synchronize PTC on 1 sychronization points
            f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

            //f_cf_Down/*gNBoraMF*/();

        } // End of testcase TC_5GAP_DNA_02

        /**
         * @desc The IUT is able to receive an UPLINK_NAS_TRANSPORT to indicate a NAS transport procedure and reply with DOWNLINK_NAS_TRANSPORT
         * @see ETSI TS 138 413 [1], Clauses 8.2.1.2, 8.6.3.2, 9.2.1.1 and 9.2.5.3
         */
        testcase TC_5GAP_PDU_01() runs on gNB_NGNAS_NGAPComponent system TestAdapter {
        
            // Local variables
            var gNB_NGNAS_NGAPComponent v_ngnas_ngap_gnb;

            // Test control
            if (not PICS_NGNAS) {
                log("*** " & __SCOPE__ & ": ERROR: 'PICS_NGNAS' shall be set to true for executing the TC. ***");
                stop;
            }

            // Test component configuration
            f_cf_NGNAS_gNB_Up(v_ngnas_ngap_gnb);

            // Start
            v_ngnas_ngap_gnb.start(f_TC_5GAP_PDU_01());

            // synchronize PTC on 1 sychronization points
            f_serverSyncNClientsAndStop(1, {c_prDone, c_tbDone, c_poDone});

            //f_cf_Down/*gNBoraMF*/();

        } // End of testcase TC_5GAP_PDU_01

    } // End of group TC_AMF_NGAP

}// End of module NG_NAS_TestCases
