/**
*    @author   ETSI / TTF033
*    @version  $URL$
*              $Id$
*    @desc     This module provides ATS specific steps used by the test cases for NGAP 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 NGAP_Steps {

    // LibNGAP
    import from LibNGAP_Steps  all;
    import from LibNGAP_Interface all;
    import from LibNGAP_Pixits all;
    import from LibNGAP_Templates all;

    // NGAP_Ats
    import from NGAP_Pixits all;
  

    group GlobalSteps {

        /**
         * @desc    This is a test step that init global variables
         *          This procedure will be use when the Test System acts as AMF (SUT is gNB)
         */
        function f_NGAP_amf_init()
        runs on NGAPComponent {

            // Defaults
            vc_default_ngap := activate (a_defaultNGAP());

            // Base LibNGAP init function if there will be any base initialisation
            f_NGAP_Init_Component();

            vc_ETS_address := PX_NGAP_ETS_IPADDR;
            vc_ETS_port    := PX_NGAP_ETS_PORT;
            vc_SUT_address := PX_NGAP_SUT_IPADDR;
            vc_SUT_port    := PX_NGAP_SUT_PORT;

        } // End of function f_NGAP_amf_init

        /**
         * @desc    This is a test step that init global variables
         *          This procedure will be use when the Test System acts as gNB (SUT is AMF)
         */
        function f_NGAP_gnb_init()
        runs on NGAPComponent {

            // Defaults
            vc_default_ngap := activate (a_defaultNGAP());

            // Base LibNGAP init function if there will be any base initialisation
            f_NGAP_Init_Component();

            vc_ETS_address := PX_NGAP_ETS_IPADDR;
            vc_ETS_port    := PX_NGAP_ETS_PORT;
            vc_SUT_address := PX_NGAP_SUT_IPADDR;
            vc_SUT_port    := PX_NGAP_SUT_PORT;

            f_send_NGAP_PDU(
                m_ngap_initMsg(
                    m_n2_NGSetupRequest(
                            m_globalRANNodeID_globalGNB_ID(
                                m_ie_globalGnbId(
                                PX_PLMN_IDENTITY,
                                PX_GNB_ID,//'0000000000000000000000'B,//in template (value) bitstring p_gnbId,
                                -//in template (omit) GlobalGNB_ID.iE_Extensions p_iE_Extensions := omit
                        )),
                        {
                            m_supportedTAItem(
                                PX_TACode,
                                {
                                    m_ie_broadcastPLMNItem(
                                        PX_PLMN_IDENTITY,//m_ie_pLMNIdentity('00f110'O),
                                        {
                                            m_sliceSupportItem(
                                                    m_s_NSSAI(
                                                        PX_SST,
                                                        PX_SD,//      in template (omit) SD p_sD := omit,
                                                        -//      in template (omit) S_NSSAI.iE_Extensions p_iE_Extensions := omit
                                                    ),
                                                    -//in template (omit) SliceSupportItem.iE_Extensions p_iE_Extensions := omit
                                                )
                                        }
                                    )
                                },//in template (value) BroadcastPLMNList p_broadcastPLMNList,
                                -//in template (omit) SupportedTAItem.iE_Extensions p_iE_Extensions := omit
                            )
                        },
                        PX_PAGING_DRX
                    )
                )
            );               

            f_recv_NGAP_PDU(
                mw_ngap_succMsg(
                    mw_n2_NGSetupResponse(-,-,-,-)
                    )
            );
            // f_recv_NGAP_PDU(
            //     mw_ngap_succMsg(
            //         mw_n2_NGSetupResponse(
            //         ?,
            //         {
            //             mw_servedGUAMIItem(
            //             mw_gUAMI(
            //                 ?,//template (present) PLMNIdentity p_pLMNIdentity := ?,
            //                 ?,//template (present) AMFRegionID p_aMFRegionID := ?,
            //                 ?,//template (present) AMFSetID p_aMFSetID := ?,
            //                 ?,//template (present) AMFPointer p_aMFPointer := ?,
            //                 *//template GUAMI.iE_Extensions p_iE_Extensions := *
            //             ),//template (present) GUAMI p_gUAMI := ?,
            //             *,//template AMFName p_backupAMFName := *,
            //             *//template ServedGUAMIItem.iE_Extensions p_iE_Extensions := *
            //             )
            //         },//template (present) ServedGUAMIList p_servedGUAMIList := ?,
            //         ?,//template (present) RelativeAMFCapacity p_relativeAmfCap:= ?,
            //         {
            //             mw_pLMNSupportItem(
            //             ?,//template (present) PLMNIdentity p_pLMNIdentity := ?,
            //             {
            //                 mw_sliceSupportItem(
            //                 mw_s_NSSAI(
            //                     ?,//template (present) SST p_sST := ?,
            //                     *,//template SD p_sD := *,
            //                     *//template S_NSSAI.iE_Extensions p_iE_Extensions := *
            //                 ),//template (present) S_NSSAI p_s_NSSAI := ?,
            //                 ?//template SliceSupportItem.iE_Extensions p_iE_Extensions := *
            //                 )
            //             },//template (present) SliceSupportList p_sliceSupportList := ?,
            //             *//template PLMNSupportItem.iE_Extensions p_iE_Extensions := *
            //             )
            //         }//template (present) PLMNSupportList p_plmnSuppList := ?
            //         )
            //     )
            // );
        } // End of function f_NGAP_gnb_init

        /**
         * @desc    This is a test step that init global variables
         */
        function f_NGAP_gnb_init2()
        runs on NGAPComponent {

            // Defaults
            vc_default_ngap := activate (a_defaultNGAP());

            // Base LibNGAP init function if there will be any base initialisation
            f_NGAP_Init_Component();

            vc_ETS_address := PX_NGAP_ETS_IPADDR2;
            vc_ETS_port    := PX_NGAP_ETS_PORT2;
            vc_SUT_address := PX_NGAP_SUT_IPADDR;
            vc_SUT_port    := PX_NGAP_SUT_PORT;

        } // End of function f_NGAP_gnb_init2

    } // End of group GlobalSteps

    group Preambles{

        /**
         * @desc
         */
        function f_preamble_NGAP_AMF() runs on NGAPComponent {
            var default     v_def_ngap_;

            f_NGAP_amf_init();
            //f_preambleNGAPClient();
        } // End of function f_preamble_NGAP_AMF

        /**
         * @desc
         */
        function f_preamble_NGAP_gNB() runs on NGAPComponent {
            var default     v_def_ngap_;

            f_NGAP_gnb_init();
            //f_preambleNGAPServer();
        } // End of function f_preamble_NGAP_gNB

        /**
         * @desc
         */
        function f_preamble_NGAP_gNB2() runs on NGAPComponent {
            var default     v_def_ngap_;

            f_NGAP_gnb_init2();
            //f_preambleNGAPServer();
        } // End of function f_preamble_NGAP_gNB2

    } // End of group Preambles

    group Postambles {

        /**
         * @desc
         */
        function f_postamble_NGAP_AMF() runs on NGAPComponent {
            f_postambleNGAP_AMF();

            // Deactivate defaults
            deactivate;
        } // End of function f_postamble_NGAP_AMF

        /**
         * @desc
         */
        function f_postamble_NGAP_gNB() runs on NGAPComponent {
            f_postambleNGAP_gNB();

            //Deactivate defaults
            deactivate;
        } // End of function f_postamble_NGAP_gNB

        /**
         * @desc
         */
        function f_postamble_NGAP_gNB2() runs on NGAPComponent {
            f_postambleNGAP_gNB();

            // Deactivate defaults
            deactivate;
        } // End of function f_postamble_NGAP_gNB2

    } // End of group Postambles

    group CheckFunctions {

    } // End of group CheckFunctions

    group DefaultTestStep{

    }//end group DefaultTestStep

    group BehaviorFunctions{

        /**
         * @desc
         */
        function f_NGAP_amf_UE_Register() runs on NGAPComponent {
        //FIXME: Implementation of UE registration
        } // End of function f_NGAP_amf_UE_Register

        /**
         * @desc
         */
        function f_NGAP_amf_UE_PDU_ResourceSetup() runs on NGAPComponent {
        //FIXME: Implementation of PDU session resource setup
        } // End of function f_NGAP_amf_UE_PDU_ResourceSetup

        /**
         * @desc
         */
        function f_NGAP_amf_UE_NoLongerAvailable() runs on NGAPComponent {
        //FIXME: Implementation of PDU not longer available
        } // End of function f_NGAP_amf_UE_NoLongerAvailable

        /**
         * @desc The IUT entity indicate the initiation "of a Handover Required procedure"
         */
        function f_NGAP_amf_UE_MMP_Initiate_Handover() runs on NGAPComponent {
        //FIXME: Implementation of Handover init
        } // End of function f_NGAP_amf_UE_MMP_Initiate_Handover

        /**
         * @desc
         */
        function f_NGAP_amf_UE_MMP_Initiate_Handover_Completed() runs on NGAPComponent {
        //FIXME: Implementation of Handover init completed
        } // End of function f_NGAP_amf_UE_MMP_Initiate_Handover_Completed

        /**
         * @desc
         */
        function f_NGAP_amf_UE_MMP_Handover_Completed() runs on NGAPComponent {
        //FIXME: Implementation of Handover completed
        } // End of function f_NGAP_amf_UE_MMP_Handover_Completed

        /**
         * @desc
         */
        function f_NGAP_amf_UE_MMP_Cancel_Initiated_Handover() runs on NGAPComponent {
        //FIXME: Implementation of Handover init cancelled
        } // End of function f_NGAP_amf_UE_MMP_Cancel_Initiated_Handover

        /**
         * @desc
         */
        function f_NGAP_amf_UE_MMP_Initiate_UE_Uplink_RAN_Status_Transfer() runs on NGAPComponent {
        //FIXME: Implementation of initiate uplink RAN xfer
        } // End of function f_NGAP_amf_UE_MMP_Initiate_UE_Uplink_RAN_Status_Transfer

        /**
         * @desc
         */
        function f_NGAP_amf_UE_MMP_Initiate_UE_Uplink_RAN_Early_Status_Transfer() runs on NGAPComponent {
        //FIXME: Implementation of initiate an early uplink RAN xfer
        } // End of function f_NGAP_amf_UE_MMP_Initiate_UE_Uplink_RAN_Early_Status_Transfer

        /**
         * @desc
         */
        function f_NGAP_amf_UE_NAS_Initiate() runs on NGAPComponent {
        //FIXME: Implementation of a NAS procedure
        } // End of function f_NGAP_amf_UE_NAS_Initiate

        /**
         * @desc
         */
        function f_NGAP_amf_UE_RRC_UL_Message() runs on NGAPComponent {
        //FIXME: Implementation of an RRC UL message delivery
        } // End of function f_NGAP_amf_UE_RRC_UL_Message

        /**
         * @desc
         */
        function f_NGAP_amf_UE_RRC_UL_Message_Failure() runs on NGAPComponent {
        //FIXME: Implementation of an RRC UL message delivery failure
        } // End of function f_NGAP_amf_UE_RRC_UL_Message_Failure
        
        /**
         * @desc
         */
        function f_NGAP_amf_isTransitioningTo_RRC_INACTIVE() runs on NGAPComponent {
        //FIXME: Implementation of an UE transitioning into the RRC_INACTIVE state
        } // End of function f_NGAP_amf_isTransitioningTo_RRC_INACTIVE

        /******************************************************************/

        /**
         * @desc
         */
        function f_NGAP_gnb_UE_Register() runs on NGAPComponent {
        //FIXME: Implementation of UE registration
        } // End of function f_NGAP_gnb_UE_Register

        /**
         * @desc
         */
        function f_NGAP_gnb_UE_Not_Available() runs on NGAPComponent {
        //FIXME: Implementation of UE not available
        } // End of function f_NGAP_gnb_UE_Not_Available

        /**
         * @desc
         */
        function f_NGAP_gnb_UE_Handover_Required() runs on NGAPComponent {
        //FIXME: Implementation of UE handover required
        } // End of function f_NGAP_gnb_UE_Handover_Required

        /**
         * @desc
         */
        function f_NGAP_gnb_UE_EstablishedInitialContext() runs on NGAPComponent {
        //FIXME: Implementation of UE handover required
        } // End of function f_NGAP_gnb_UE_EstablishedInitialContext
        
        /**
         * @desc
         */
        function f_NGAP_gnb_UE_Has_EstablishedContextInproperly() runs on NGAPComponent {
        //FIXME: Implementation of UE handover required
        } // End of function f_NGAP_gnb_UE_Has_EstablishedContextInproperly
        
        /**
         * @desc
         */
        function f_NGAP_gnb_UE_HasPendingDataTransmission() runs on NGAPComponent {
        //FIXME: Implementation of UE has pending data transmission leading to failed context suspension
        } // End of function f_NGAP_gnb_UE_HasPendingDataTransmission

        /**
         * @desc
         */
        function f_NGAP_gnb_UE_PDU_ResourceSetup() runs on NGAPComponent {
        //FIXME: Implementation of PDU session resource setup
        } // End of function f_NGAP_gnb_UE_PDU_ResourceSetup
        
        /**
         * @desc
         */
        function f_NGAP_gnb_UE_Has_Suspended_Context() runs on NGAPComponent {
        //FIXME: Implementation of UE has suspended context
        } // End of function f_NGAP_amf_UE_hasSuspendedContext
        
        /**
         * @desc
         */
        function f_NGAP_gnb_UE_alreadyPreparedHandover() runs on NGAPComponent {
        //FIXME: Implementation of UE halready prepared Handover
        } // End of function f_NGAP_amf_UE_hasSuspendedContext
        

    }//end group BehaviorFunctions

} // End of module NGAP_Steps
