From 67f8c9228114349ecece0e462d8b73fd76d8e78a Mon Sep 17 00:00:00 2001
From: Yann Garcia <yann.garcia@fscom.fr>
Date: Thu, 1 Jun 2023 11:13:34 +0200
Subject: [PATCH] Finalyze test cases TD_VoLTE_ECO_INT_REL_01_01/02

---
 ttcn/AtsImsIot/AtsImsIot_Emergency.ttcn      | 184 +++++++++++++++-
 ttcn/AtsImsIot/AtsImsIot_PIXITS.ttcn         |   5 +
 ttcn/AtsImsIot/AtsImsIot_TP_behavior_MM.ttcn | 204 +++++++++++++++---
 ttcn/AtsImsIot/AtsImsIot_Templates_MM.ttcn   | 212 +++++++++++--------
 4 files changed, 474 insertions(+), 131 deletions(-)

diff --git a/ttcn/AtsImsIot/AtsImsIot_Emergency.ttcn b/ttcn/AtsImsIot/AtsImsIot_Emergency.ttcn
index 03c8ec3..093c65e 100644
--- a/ttcn/AtsImsIot/AtsImsIot_Emergency.ttcn
+++ b/ttcn/AtsImsIot/AtsImsIot_Emergency.ttcn
@@ -285,7 +285,6 @@ module AtsImsIot_Emergency {
                     var IotEquipmentUser v_ueA  := f_cf_create_IotEquipmentUser ( c_userUE_A_emergency );
                     var IotEquipmentUser v_psap := f_cf_create_IotEquipmentUser ( c_psap );
                     var ImsUserInfo v_userInfoA := f_getImUser ( PX_EUT_A_EMERGENCY );
-                    var ImsUserInfo v_infoPsap  := f_getImUser ( PX_PSAP ); 
         
                     f_setVxLteMonIterfacesAvailability();
                     //Check required monitor interfaces due to TD
@@ -308,8 +307,8 @@ module AtsImsIot_Emergency {
                         f_cf_VxLteMonitor_Up();
                 
                         // Preamble
-                        f_mtc_userRegistration(v_ueA, v_userInfoA); 
-                        f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        f_mtc_userRegistration(v_ueA, v_userInfoA);
+                        // PSAP is not known from the IMS A
                         f_mtc_check_precond_TD_VoLTE_ECO_INT_INI_01_01();
                         
                         // Test body
@@ -434,7 +433,11 @@ module AtsImsIot_Emergency {
                 
                         // Preamble
                         f_mtc_userRegistration(v_ueA, v_userInfoA); 
-                        f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        if (PX_PSAP_REGISTERED) {
+                            f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        } else {
+                            // TODO Check OPTIONS from PSAP to E-CSCF
+                        }
                         f_mtc_check_precond_TD_VoLTE_ECO_INT_INI_01_02();
                         
                         // Test body
@@ -542,7 +545,6 @@ module AtsImsIot_Emergency {
                     var IotEquipmentUser v_ueA  := f_cf_create_IotEquipmentUser ( c_userUE_A_emergency );
                     var IotEquipmentUser v_psap := f_cf_create_IotEquipmentUser ( c_psap );
                     var ImsUserInfo v_userInfoA := f_getImUser ( PX_EUT_A_EMERGENCY );
-                    var ImsUserInfo v_infoPsap  := f_getImUser ( PX_PSAP ); 
         
                     f_setVxLteMonIterfacesAvailability();
                     //Check required monitor interfaces due to TD
@@ -551,7 +553,7 @@ module AtsImsIot_Emergency {
                                                               PX_DIAMETER_RX_INTERFACENAME,
                                                               PX_SIP_MW_PE_INTERFACENAME,
                                                               PX_SIP_EB_INTERFACENAME, // E-CSCF -> IBCF
-                                                              PX_SIP_MM_PSAP_INTERFACENAME // IBCF -> PSAP
+                                                              PX_SIP_PSTN_INTERFACENAME // IBCF -> PSTN -> PSAP
                                                               }))
                     {
                         var SipMessage v_sip;
@@ -566,7 +568,7 @@ module AtsImsIot_Emergency {
                 
                         // Preamble
                         f_mtc_userRegistration(v_ueA, v_userInfoA); 
-                        f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        // PSAP is not known from the IMS A
                         f_mtc_check_precond_TD_VoLTE_ECO_INT_INI_01_03();
                         
                         // Test body
@@ -1010,6 +1012,97 @@ module AtsImsIot_Emergency {
 
             group EmergencySessionRelease {
 
+                /**
+                 * @desc    To perform originating UE session release and the tear down of related dedicated bearers.
+                 *          On call release, the P-CSCF A should trigger the removal of all relevant previously created bearers
+                 * @see ETSI TS 103 795-2 Clause 5.3.3.1	UE Initiated Emergency Session Release
+                 * @remark This is option1: IBCF is connected to the PSAP, the interface IBCF and the PSAP is the Mm interface
+                 */
+                testcase TD_VoLTE_ECO_INT_REL_01_01() runs on ImsTestCoordinator system IotSystemInterface {
+
+                    var IotEquipmentUser v_ueA  := f_cf_create_IotEquipmentUser ( c_userUE_A_emergency );
+                    var IotEquipmentUser v_psap := f_cf_create_IotEquipmentUser ( c_psap );
+                    var ImsUserInfo v_userInfoA := f_getImUser ( PX_EUT_A_EMERGENCY );
+                    var ImsUserInfo v_infoPsap  := f_getImUser ( PX_PSAP ); 
+        
+                    f_setVxLteMonIterfacesAvailability();
+                    //Check required monitor interfaces due to TD
+                    if (f_checkVxLteRequiredMonitorInterface({PX_SIP_GMA_INTERFACENAME,
+                                                              PX_DIAMETER_GX_INTERFACENAME,
+                                                              PX_DIAMETER_RX_INTERFACENAME,
+                                                              PX_SIP_MW_PE_INTERFACENAME,
+                                                              PX_SIP_EB_INTERFACENAME, // E-CSCF -> IBCF
+                                                              PX_SIP_MM_PSAP_INTERFACENAME // IBCF -> PSAP
+                                                              }))
+                    {
+                        var SipMessage v_sip;
+                        
+                        f_cf_createVxLteMonitor();
+                
+                        // map/connect component ports
+                        f_cf_adapter_up ( );
+                        f_cf_user_up ( v_ueA );
+                        f_cf_user_up ( v_psap );
+                        f_cf_VxLteMonitor_Up();
+                
+                        // Preamble
+                        f_mtc_userRegistration(v_ueA, v_userInfoA); 
+                        f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        f_mtc_userInitiateCall (v_ueA, v_infoPsap);
+                        f_mtc_userCheckRinging(v_psap);
+                        f_mtc_userCheckPeerIsRinging(v_ueA);
+                        f_mtc_userAnswerCall(v_psap);
+                        f_mtc_userCheckCallEstablished(v_ueA); // Event 1
+                        f_mtc_userCheckCallEstablished(v_psap); // Event 1
+                        f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_01();
+                        
+                        // Test body
+                        //f_mtc_userInitiateCall (v_ueA, v_userTelInfoB);
+
+                        f_mtc_check_TP_GM_PCSCF_BYE_01(vc_vxlte_monitor_components.gmA, -, v_sip); // Event 2
+                        f_mtc_check_TP_MW_ECSCF_BYE_01(vc_vxlte_monitor_components.mwPE, -, v_sip); // Event 3
+                        f_mtc_check_TP_MW_IBCF_BYE_01(vc_vxlte_monitor_components.mwBE, -, v_sip); // Event 3
+                        f_mtc_check_TP_MM_PSAP_BYE_01(vc_vxlte_monitor_components.mwB_PSAP); // Event 6
+
+                        //Rx/Gx exchange after BYE was received at P-CSCF
+                        f_mtc_check_TP_RX_PCSCF_STR_01(vc_vxlte_monitor_components.rx); // (STR – Event 10
+                        f_mtc_check_TP_GX_PCRF_RAR_02(vc_vxlte_monitor_components.gx, true); // (RAR – Event 11)
+                        f_mtc_check_TP_GX_PGW_RAA_03(vc_vxlte_monitor_components.gx); // (RAA – Event 12)
+                        f_mtc_check_TP_RX_PCRF_STA_01(vc_vxlte_monitor_components.rx); // (STA – Event 13)                        
+                        
+                        
+                        f_mtc_check_TP_MW_IBCF_200OK_01(vc_vxlte_monitor_components.mwBE, -, v_sip); // Event 15
+                        f_mtc_check_TP_MW_ECSCF_200OK_01(vc_vxlte_monitor_components.mwPE, -, v_sip); // Event 20
+                        f_mtc_check_TP_GM_PCSCF_200OK_02(vc_vxlte_monitor_components.gmA, -, v_sip); // Event 21
+                        
+                        f_mtc_userCheckCallTerminated(v_ueA); // Event 22
+                        f_mtc_userCheckCallCancelled(v_ueB); // Event 23
+                        
+                        // Postamble
+                        f_PO_user_home_deregistration(v_ueA);
+                        f_PO_user_home_deregistration(v_ueB);
+            
+                        //unmap/disconnect component ports
+                        f_cf_user_down ( v_ueB );
+                        f_cf_user_down ( v_ueA );
+                        f_cf_VxLteMonitor_Down();
+                        f_cf_adapter_down ( );
+                    }else{
+                        //log...
+                        setverdict (inconc,"At least one required monitor interface SHALL be selected! Check PIXITs")
+                    }
+                    f_cf_adapter_down ( );
+                } // End of TC TD_VoLTE_ECO_INT_REL_01_01
+                
+                group f_TD_VoLTE_ECO_INT_REL_01_01 {
+                    
+                    function f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_01() runs on ImsTestCoordinator {
+                        log("If the test case fails, please check the preconditions");
+                        // TODO Add real code to check pre-conditions
+                     } // End of function f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_01
+                     
+                } // End of group f_TD_VoLTE_ECO_INT_REL_01_01
+
                 /**
                  * @desc    To perform originating UE session release and the tear down of related dedicated bearers.
                  *          On call release, the P-CSCF A should trigger the removal of all relevant previously created bearers
@@ -1100,6 +1193,83 @@ module AtsImsIot_Emergency {
                      
                 } // End of f_TD_VoLTE_ECO_INT_REL_01_02
 
+               /**
+                 * @desc    To perform originating UE session release and the tear down of related dedicated bearers.
+                 *          On call release, the P-CSCF A should trigger the removal of all relevant previously created bearers
+                 * @see ETSI TS 103 795-2 Clause 5.3.3.1	UE Initiated Emergency Session Release
+                 * @remark This is option3: IBCF is connected to the PSTN network
+                 */
+                testcase TD_VoLTE_ECO_INT_REL_01_03() runs on ImsTestCoordinator system IotSystemInterface {
+
+                    var IotEquipmentUser v_ueA  := f_cf_create_IotEquipmentUser ( c_userUE_A_emergency );
+                    var IotEquipmentUser v_psap := f_cf_create_IotEquipmentUser ( c_psap );
+                    var ImsUserInfo v_userInfoA := f_getImUser ( PX_EUT_A_EMERGENCY );
+                    var ImsUserInfo v_infoPsap  := f_getImUser ( PX_PSAP ); 
+        
+                    f_setVxLteMonIterfacesAvailability();
+                    //Check required monitor interfaces due to TD
+                    if (f_checkVxLteRequiredMonitorInterface({PX_SIP_GMA_INTERFACENAME,
+                                                              PX_DIAMETER_GX_INTERFACENAME,
+                                                              PX_DIAMETER_RX_INTERFACENAME,
+                                                              PX_SIP_MW_PE_INTERFACENAME,
+                                                              PX_SIP_EB_INTERFACENAME, // E-CSCF -> IBCF
+                                                              PX_SIP_PSTN_INTERFACENAME // IBCF -> PSTN -> PSAP
+                                                              }))
+                    {
+                        var SipMessage v_sip;
+                        
+                        f_cf_createVxLteMonitor();
+                
+                        // map/connect component ports
+                        f_cf_adapter_up ( );
+                        f_cf_user_up ( v_ueA );
+                        f_cf_user_up ( v_psap );
+                        f_cf_VxLteMonitor_Up();
+                
+                        // Preamble
+                        f_mtc_userRegistration(v_ueA, v_userInfoA); 
+                        f_mtc_userRegistration(v_psap, v_infoPsap); 
+                        f_mtc_userInitiateCall (v_ueA, v_infoPsap);
+                        f_mtc_userCheckRinging(v_psap);
+                        f_mtc_userCheckPeerIsRinging(v_ueA);
+                        f_mtc_userAnswerCall(v_psap);
+                        f_mtc_userCheckCallEstablished(v_ueA); // Event 1
+                        f_mtc_userCheckCallEstablished(v_psap); // Event 1
+                        f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_03();
+                        
+                        // Test body
+                        //f_mtc_userInitiateCall (v_ueA, v_userTelInfoB);
+
+                        // TODO
+                        
+                        f_mtc_userCheckCallTerminated(v_ueA); // Event 22
+                        f_mtc_userCheckCallCancelled(v_ueB); // Event 23
+                        
+                        // Postamble
+                        f_PO_user_home_deregistration(v_ueA);
+                        f_PO_user_home_deregistration(v_ueB);
+            
+                        //unmap/disconnect component ports
+                        f_cf_user_down ( v_ueB );
+                        f_cf_user_down ( v_ueA );
+                        f_cf_VxLteMonitor_Down();
+                        f_cf_adapter_down ( );
+                    }else{
+                        //log...
+                        setverdict (inconc,"At least one required monitor interface SHALL be selected! Check PIXITs")
+                    }
+                    f_cf_adapter_down ( );
+                } // End of TC TD_VoLTE_ECO_INT_REL_01_03
+                
+                group f_TD_VoLTE_ECO_INT_REL_01_03 {
+                    
+                    function f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_03() runs on ImsTestCoordinator {
+                        log("If the test case fails, please check the preconditions");
+                        // TODO Add real code to check pre-conditions
+                     } // End of function f_mtc_check_precond_TD_VoLTE_ECO_INT_REL_01_03
+                     
+                } // End of group f_TD_VoLTE_ECO_INT_REL_01_03
+
             } // End of group EmergencySessionRelease
 
             group EmergencySessionAbortOrReject {
diff --git a/ttcn/AtsImsIot/AtsImsIot_PIXITS.ttcn b/ttcn/AtsImsIot/AtsImsIot_PIXITS.ttcn
index b8bd9b0..02bda0b 100644
--- a/ttcn/AtsImsIot/AtsImsIot_PIXITS.ttcn
+++ b/ttcn/AtsImsIot/AtsImsIot_PIXITS.ttcn
@@ -22,6 +22,11 @@ group SUT_CONF {
 		 * @desc charstring for PChargingVector TP_IC_IBCF_INVITE_04
 		 */
 		modulepar charstring PX_IMS_A_ICID := "PX_IMS_A_ICID";
+
+		/**
+		 * @desc Set to true of PSAP shall be registered to the IMS 
+		 */
+		modulepar boolean PX_PSAP_REGISTERED := true;
 		
 } // end group SUT_CONF
 
diff --git a/ttcn/AtsImsIot/AtsImsIot_TP_behavior_MM.ttcn b/ttcn/AtsImsIot/AtsImsIot_TP_behavior_MM.ttcn
index 445028a..dc62386 100644
--- a/ttcn/AtsImsIot/AtsImsIot_TP_behavior_MM.ttcn
+++ b/ttcn/AtsImsIot/AtsImsIot_TP_behavior_MM.ttcn
@@ -32,7 +32,7 @@ module AtsImsIot_TP_behavior_MM {
     group imsInvite {
         
         /**
-         * @desc Verify that the IBCF successfully processes an initial INVITE (Originating Leg)..
+         * @desc Verify that the E-CSCF successfully processes an initial INVITE (Originating Leg)..
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -43,7 +43,7 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives an INVITE containing
+         *         the IMS_E_CSCF_A entity receives an INVITE containing
          *             From indicating value PX_UE_A_SIP_URI,
          *             To indicating value PX_PSAP_SIP_URI,
          *             CallId indicating value PX_UE_A_CALLID,
@@ -53,9 +53,7 @@ module AtsImsIot_TP_behavior_MM {
          *             MessageBody containing
          *                 SDP containing
          *                     Version indicating value "0" 
-         *                         ;
-         *             ;;
-         *         from the IMS_E_CSCF_A entity
+         *         from the IMS_P_CSCF_A entity
          *     }
          *     then {
          *         the IMS_IBCF_A entity sends an INVITE containing
@@ -67,9 +65,7 @@ module AtsImsIot_TP_behavior_MM {
          *             PAccessNetworkInfo,
          *             MessageBody containing
          *                 SDP containing
-         *                     Version indicating value "0" 
-         *                         ;
-         *             ;;
+         *                     Version indicating value "0"
          *         to the PSAP entity
          *         }
          *     }
@@ -111,7 +107,7 @@ module AtsImsIot_TP_behavior_MM {
     group ims100Trying {
         
         /**
-         * @desc Verify that the IBCF successfully processes a 100 (Trying) provisional response on initial INVITE (Originating Leg).
+         * @desc Verify that the E-CSCF successfully processes a 100 (Trying) provisional response on initial INVITE (Originating Leg).
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -122,16 +118,16 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives a 100_Trying
+         *         the IMS_E_CSCF_A entity receives a 100_Trying
          *         from the PSAP entity
          *     }
          *     then {
-         *         the IMS_IBCF_A entity sends a 100_Trying
-         *         to the IMS_E_CSCF_A entity
+         *         the IMS_E_CSCF_A entity sends a 100_Trying
+         *         to the IMS_P_CSCF_A entity
          *         }
          *     }
          */
-        function f_mtc_check_TP_MW_IBSCF_100Trying_01(
+        function f_mtc_check_TP_MM_PSAP_100Trying_01(
                                                       in SipInterfaceMonitor p_monitorCompRef,
                                                       in boolean p_checkMessage := false,
                                                       in SipMessage p_sip
@@ -140,7 +136,7 @@ module AtsImsIot_TP_behavior_MM {
                 // Check the 100 TRYING
                 p_monitorCompRef.start(
                                        f_Iot_Sip_receive(
-                                                         { mw_SipResponse(mw_TP_MW_IBCF_100Trying_01(
+                                                         { mw_SipResponse(mw_TP_MM_PSAP_100Trying_01(
                                                                                                       p_sip.request.msgHeader.cSeq,
                                                                                                       p_sip.request.msgHeader.fromField,
                                                                                                       p_sip.request.msgHeader.toField
@@ -148,21 +144,21 @@ module AtsImsIot_TP_behavior_MM {
                                                          },
                                                          { mw_SipResponse(mw_100Trying_Base) },
                                                          { 0, omit },
-                                                         "TP_MW_IBCF_100Trying_01",
+                                                         "TP_MM_PSAP_100Trying_01",
                                                          false,
                                                          p_checkMessage
                                                          )
                                         );
                 p_monitorCompRef.done;
             }
-        } // End of function f_mtc_check_TP_MW_IBSCF_100Trying_01
+        } // End of function f_mtc_check_TP_MM_PSAP_100Trying_01
         
     } // End of group ims100Trying
 
     group ims180Ringing {
         
         /**
-         * @desc Verify that the IBCF successfully processes a 180 (Ringing) provisional response on initial INVITE (Originating Leg).
+         * @desc Verify that the IMS_E_CSCF_A successfully processes a 180 (Ringing) provisional response on initial INVITE (Originating Leg).
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -173,7 +169,7 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives a 180_Ringing containing
+         *         the IMS_E_CSCF_A entity receives a 180_Ringing containing
          *             From indicating value PX_PSAP_SIP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_PSAP_CALLID,
@@ -183,14 +179,14 @@ module AtsImsIot_TP_behavior_MM {
          *         from the PSAP entity
          *     }
          *     then {
-         *         the IMS_IBCF_A entity sends a 180_Ringing containing
+         *         the IMS_E_CSCF_A entity sends a 180_Ringing containing
          *             From indicating value PX_PSAP_SIP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_PSAP_CALLID,
          *             Via indicating value PX_PSAP_VIA,
          *             Route indicating value PX_PSAP_SERVICE_ROUTE
          *             ;
-         *         to the IMS_E_CSCF_A entity
+         *         to the IMS_P_CSCF_A entity
          *         }
          *     }
          */
@@ -227,7 +223,7 @@ module AtsImsIot_TP_behavior_MM {
     group ims183SessionProgress {
         
         /**
-         * @desc Verify that the IBCF successfully processes a 183 (Ringing) provisional response on initial INVITE (Originating Leg).
+         * @desc Verify that the IMS_E_CSCF_A successfully processes a 183 (Ringing) provisional response on initial INVITE (Originating Leg).
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -238,7 +234,7 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives a 183_SessionProgress containing
+         *         the IMS_E_CSCF_A entity receives a 183_SessionProgress containing
          *             From indicating value PX_SAP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_SAP_CALLID,
@@ -248,14 +244,14 @@ module AtsImsIot_TP_behavior_MM {
          *         from the PSAP entity
          *     }
          *     then {
-         *         the IMS_IBCF_A entity sends a 183_SessionProgress containing
+         *         the IMS_E_CSCF_A entity sends a 183_SessionProgress containing
          *             From indicating value PX_PSAP_SIP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_PSAP_CALLID,
          *             Via indicating value PX_PSAP_VIA,
          *             Route indicating value PX_PSAP_SERVICE_ROUTE
          *             ;
-         *         to the IMS_E_CSCF_A entity
+         *         to the IMS_P_CSCF_A entity
          *         }
          *     }
          */
@@ -290,7 +286,7 @@ module AtsImsIot_TP_behavior_MM {
     group ims200Ok {
         
         /**
-         * @desc Verify that the IBCF successfully processes a 200 (OK) provisional response on initial INVITE (Originating Leg).
+         * @desc Verify that the IMS_E_CSCF_A successfully processes a 200 (OK) provisional response on initial INVITE (Originating Leg).
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -301,7 +297,7 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives a 200_Ok containing
+         *         the IMS_E_CSCF_A entity receives a 200_Ok containing
          *             From indicating value PX_PSAP_SIP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_PSAP_CALLID,
@@ -314,7 +310,7 @@ module AtsImsIot_TP_behavior_MM {
          *         from the PSAP entity
          *     }
          *     then {
-         *         the IMS_IBCF_A entity sends a 200_Ok containing
+         *         the IMS_E_CSCF_A entity sends a 200_Ok containing
          *             From indicating value PX_PSAP_SIP_URI,
          *             To indicating value PX_UE_A_SIP_URI,
          *             CallId indicating value PX_PSAP_CALLID,
@@ -324,7 +320,7 @@ module AtsImsIot_TP_behavior_MM {
          *             PChargingFunctionAddresses,
          *             PPreferredIdentity
          *             ;
-         *         to the IMS_E_CSCF_A entity
+         *         to the IMS_P_CSCF_A entity
          *         }
          *     }
          */
@@ -367,7 +363,7 @@ module AtsImsIot_TP_behavior_MM {
     group imsAck {
         
         /**
-         * @desc Verify that the IBCF successfully processes a ACK provisional response on initial INVITE (Originating Leg).
+         * @desc Verify that the IMS_E_CSCF_A successfully processes a ACK provisional response on initial INVITE (Originating Leg).
          * Initial conditions with {
          *     the UE_A entity isAttachedTo the EPC_A and
          *     the PSAP entity isAttachedTo the EPC_B and
@@ -378,17 +374,17 @@ module AtsImsIot_TP_behavior_MM {
          * Expected behaviour
          * ensure that {
          *     when {
-         *         the IMS_IBCF_A entity receives an ACK containing
+         *         the IMS_E_CSCF_A entity receives an ACK containing
          *             From indicating value PX_UE_A_SIP_URI,
          *             To indicating value PX_PSAP_SIP_URI,
          *             CallId indicating value PX_UE_A_CALLID,
          *             Via indicating value PX_UE_A_VIA,
          *             Route indicating value PX_UE_A_SERVICE_ROUTE
          *             ;
-         *         from the IMS_E_CSCF_A entity
+         *         from the IMS_P_CSCF_A entity
          *     }
          *     then {
-         *         the IMS_IBCF_A entity sends an ACK containing
+         *         the IMS_E_CSCF_A entity sends an ACK containing
          *             From indicating value PX_UE_A_SIP_URI,
          *             To indicating value PX_PSAP_SIP_URI,
          *             CallId indicating value PX_UE_A_CALLID,
@@ -429,4 +425,148 @@ module AtsImsIot_TP_behavior_MM {
         
     } // End of group imsAck
     
+    group imsBye {
+        
+        /**
+         * @desc Verify that the E-CSCF successfully processes a BYE (Terminating Leg).
+         * Initial conditions with {
+         *     the UE_A entity isAttachedTo the EPC_A and
+         *     the UE_B entity isAttachedTo the EPC_B and
+         *     the UE_A entity isRegisteredTo the IMS_A and
+         *     the UE_B entity isRegisteredTo the IMS_B and
+         *     the UE_A entity previouslyEstablishedCallWith the UE_B
+         * }
+         * 
+         * Expected behaviour
+         * ensure that {
+         *     when {
+         *         the IMS_E_CSCF_A entity receives a BYE containing
+         *             From indicating value PX_UE_B_SIP_URI,
+         *             To indicating value PX_UE_A_SIP_URI,
+         *             CallId indicating value PX_UE_B_CALLID,
+         *             Via indicating value PX_UE_B_VIA,
+         *             Route indicating value PX_UE_B_SERVICE_ROUTE
+         *             ;
+         *         from the IMS_P_CSCF_A entity
+         *     }
+         *     then {
+         *         the IMS_E_CSCF_A entity sends a BYE containing
+         *             From indicating value PX_UE_B_SIP_URI,
+         *             To indicating value PX_UE_A_SIP_URI,
+         *             CallId indicating value PX_UE_B_CALLID,
+         *             Via indicating value PX_UE_B_VIA,
+         *             Route indicating value PX_UE_B_SERVICE_ROUTE
+         *             ;
+         *         from the PSAP entity
+         *         }
+         *     }
+         */
+        function f_mtc_check_TP_MM_PSAP_BYE_01(
+                                               in SipInterfaceMonitor p_monitorCompRef,
+                                               in boolean p_checkMessage := false,
+                                               inout SipMessage p_sip
+                                               ) runs on ImsTestCoordinator {
+            if (isvalue(p_monitorCompRef)) {
+                // Check the BYE
+                p_monitorCompRef.start(
+                                       f_Iot_Sip_receive(
+                                                         { mw_SipRequest(mw_TP_MM_PSAP_BYE_01(
+                                                                                               p_sip.request.msgHeader.callId,
+                                                                                               -, // New CSeq,
+                                                                                               -, // FIXME To be set
+                                                                                               {
+                                                                                                 fieldName := FROM_E,
+                                                                                                 addressField := p_sip.request.msgHeader.toField.addressField,
+                                                                                                 fromParams := *
+                                                                                               }, //p_sip.request.msgHeader.fromField,
+                                                                                               {
+                                                                                                 fieldName := TO_E,
+                                                                                                 addressField := p_sip.request.msgHeader.fromField.addressField,
+                                                                                                 toParams := *
+                                                                                               } //p_sip.request.msgHeader.toField
+                                                                                               )) 
+                                                         },
+                                                         { mw_SipRequest(mw_BYE_Request_Base) },
+                                                         { 0, omit },
+                                                         "TP_MM_PSAP_BYE_01 - Request",
+                                                         true,
+                                                         p_checkMessage
+                                                         )
+                                        );
+                p_monitorCompRef.done;
+                // Retrieve messge
+                f_getSipMsgFromMonitor(p_monitorCompRef, p_sip);
+            }
+        } // End of function f_mtc_check_TP_MM_PSAP_BYE_01
+
+    } // End of group imsBye
+    
+    group ims200OkBye {
+        
+        /**
+         * @desc Verify that the E-CSCF successfully processes a 200 (OK) BYE (Originating Leg).
+         * Initial conditions with {
+         *     the UE_A entity isAttachedTo the EPC_A and
+         *     the UE_B entity isAttachedTo the EPC_B and
+         *     the UE_A entity isRegisteredTo the IMS_A and
+         *     the UE_B entity isRegisteredTo the IMS_B
+         * }
+         * 
+         * Expected behaviour
+         * ensure that {
+         *     when {
+         *         the IMS_E_CSCF_A entity sends a 200_Ok containing
+         *             From indicating value PX_UE_A_SIP_URI,
+         *             To indicating value PX_UE_B_SIP_URI,
+         *             CallId indicating value PX_UE_A_CALLID,
+         *             Via indicating value PX_UE_A_VIA,
+         *             Route indicating value PX_UE_A_SERVICE_ROUTE,
+         *             not PChargingVector,
+         *             not PChargingFunctionAddresses,
+         *             not PPreferredIdentity
+         *         to the PSAP entity
+         *     }
+         *     then {
+         *         the IMS_E_CSCF_A entity sends a 200_Ok containing
+         *             From indicating value PX_UE_A_SIP_URI,
+         *             To indicating value PX_UE_B_SIP_URI,
+         *             CallId indicating value PX_UE_A_CALLID,
+         *             Via indicating value PX_UE_A_VIA,
+         *             Route indicating value PX_UE_A_SERVICE_ROUTE,
+         *             not PChargingVector,
+         *             not PChargingFunctionAddresses,
+         *             not PPreferredIdentity
+         *         to the IMS_P_CSCF_A entity
+         *         }
+         *     }
+         */
+        function f_mtc_check_TP_MM_PSAP_200OK_BYE_01(
+                                                      in SipInterfaceMonitor p_monitorCompRef,
+                                                      in boolean p_checkMessage := false,
+                                                      in SipMessage p_sip
+                                                      ) runs on ImsTestCoordinator {
+            if (isvalue(p_monitorCompRef)) {
+                // Check the 200 OK BYE
+                p_monitorCompRef.start(
+                                       f_Iot_Sip_receive(
+                                                         { mw_SipResponse(mw_200OK(
+                                                                                   p_sip.request.msgHeader.cSeq,
+                                                                                   p_sip.request.msgHeader.callId,
+                                                                                   p_sip.request.msgHeader.fromField,
+                                                                                   p_sip.request.msgHeader.toField
+                                                                                   )) 
+                                                         },
+                                                         { mw_SipResponse(mw_200OK_Base) },
+                                                         { 0, omit },
+                                                         "TP_MM_PSAP_200OK_BYE_01",
+                                                         false,
+                                                         p_checkMessage
+                                                         )
+                                        );
+                p_monitorCompRef.done;
+            }
+        } // End of function f_mtc_check_TP_MM_PSAP_200OK_BYE_01
+
+    } // End of group ims200OkBye
+
 } // End of module AtsImsIot_TP_behavior_MM
\ No newline at end of file
diff --git a/ttcn/AtsImsIot/AtsImsIot_Templates_MM.ttcn b/ttcn/AtsImsIot/AtsImsIot_Templates_MM.ttcn
index 4a48304..ddded2b 100644
--- a/ttcn/AtsImsIot/AtsImsIot_Templates_MM.ttcn
+++ b/ttcn/AtsImsIot/AtsImsIot_Templates_MM.ttcn
@@ -28,107 +28,135 @@ module AtsImsIot_Templates_MM {
     import from AtsImsIot_PIXITS all;
     import from AtsImsIot_Templates all;
     
-        /**
-          * @desc INVITE Request checking TP_MM_PSAP_INVITE_01
-          */
-         template(present)  INVITE_Request mdw_TP_MM_PSAP_INVITE_01 (template (present) SipUrl p_IBCF_SIP_URI := ?,
-                                                                     template (present) From p_from := ?,
-                                                                     template (present) To p_to := ?)
-          modifies mw_INVITE_Request_Base := {
-           msgHeader := {
-             fromField := p_from,
-             toField := p_to,
-             route := ({
-                 fieldName := ROUTE_E,
-                 routeBody := {
-                     *, 
-                     complement(mw_routeBody(p_IBCF_SIP_URI)),
-                     *
-                 }
-             }, omit),
-             recordRoute := {
-                 fieldName := RECORD_ROUTE_E,
-                 routeBody := {mw_routeBody(p_IBCF_SIP_URI), *}             
-             },        
-             pChargingVector := {
-                 fieldName := P_CHARGING_VECTOR_E,
-                 chargeParams := {
-                     *,
+    /**
+        * @desc INVITE Request checking TP_MM_PSAP_INVITE_01
+        */
+        template(present)  INVITE_Request mdw_TP_MM_PSAP_INVITE_01 (template (present) SipUrl p_IBCF_SIP_URI := ?,
+                                                                    template (present) From p_from := ?,
+                                                                    template (present) To p_to := ?)
+        modifies mw_INVITE_Request_Base := {
+        msgHeader := {
+            fromField := p_from,
+            toField := p_to,
+            route := ({
+                fieldName := ROUTE_E,
+                routeBody := {
+                    *, 
+                    complement(mw_routeBody(p_IBCF_SIP_URI)),
+                    *
+                }
+            }, omit),
+            recordRoute := {
+                fieldName := RECORD_ROUTE_E,
+                routeBody := {mw_routeBody(p_IBCF_SIP_URI), *}             
+            },        
+            pChargingVector := {
+                fieldName := P_CHARGING_VECTOR_E,
+                chargeParams := {
+                    *,
 //                     {id := "icid-value", paramValue := ?},
-                     *,
-                     {id := "orig-ioi", paramValue := ?},
-                     *,
+                    *,
+                    {id := "orig-ioi", paramValue := ?},
+                    *,
 //                     complement({id := "term-ioi", paramValue := ?}),
-                     *,
-                     complement({id := "access-network-charging-info", paramValue := ?}),
-                     *
-                 }
-             },
-            pAccessNetworkInfo := omit
-           }
-         }
+                    *,
+                    complement({id := "access-network-charging-info", paramValue := ?}),
+                    *
+                }
+            },
+        pAccessNetworkInfo := omit
+        }
+        }
 
-        template (present) Response mw_TP_MM_PSAP_100Trying_01(
+    template (present) Response mw_TP_MM_PSAP_100Trying_01(
+                                                            template (present) CSeq p_cSeq := ?,
+                                                            template (present) From p_from := ?,
+                                                            template (present) To p_to := ?
+                                                            ) modifies mw_100Trying_Base := {
+        msgHeader := {
+            cSeq      := p_cSeq,
+            fromField := p_from,
+            toField   := p_to
+        }
+    } // End of template mw_TP_MM_PSAP_100Trying_01
+    
+    template (present) Response mw_TP_MM_PSAP_180Ringing_01(
                                                                 template (present) CSeq p_cSeq := ?,
                                                                 template (present) From p_from := ?,
                                                                 template (present) To p_to := ?
-                                                                ) modifies mw_100Trying_Base := {
-            msgHeader := {
-                cSeq      := p_cSeq,
-                fromField := p_from,
-                toField   := p_to
-            }
-        } // End of template mw_TP_MM_PSAP_100Trying_01
-        
-        template (present) Response mw_TP_MM_PSAP_180Ringing_01(
-                                                                 template (present) CSeq p_cSeq := ?,
-                                                                 template (present) From p_from := ?,
-                                                                 template (present) To p_to := ?
-                                                                 ) modifies mw_180Ringing_Base := {
-            msgHeader := {
-                cSeq      := p_cSeq,
-                fromField := p_from,
-                toField   := p_to
-            }
-        } // End of template mw_TP_MM_PSAP_180Ringing_01
-        
-        template (present) Response mw_TP_MM_PSAP_183SessionProgress_01(
-                                                                 template (present) CSeq p_cSeq := ?,
-                                                                 template (present) From p_from := ?,
-                                                                 template (present) To p_to := ?
-                                                                 ) modifies mw_183SessionProgress_Base := {
-            msgHeader := {
-                cSeq      := p_cSeq,
-                fromField := p_from,
-                toField   := p_to
+                                                                ) modifies mw_180Ringing_Base := {
+        msgHeader := {
+            cSeq      := p_cSeq,
+            fromField := p_from,
+            toField   := p_to
+        }
+    } // End of template mw_TP_MM_PSAP_180Ringing_01
+    
+    template (present) Response mw_TP_MM_PSAP_183SessionProgress_01(
+                                                                template (present) CSeq p_cSeq := ?,
+                                                                template (present) From p_from := ?,
+                                                                template (present) To p_to := ?
+                                                                ) modifies mw_183SessionProgress_Base := {
+        msgHeader := {
+            cSeq      := p_cSeq,
+            fromField := p_from,
+            toField   := p_to
+        }
+    } // End of template mw_TP_MM_PSAP_183SessionProgress_01
+
+    template (present) ACK_Request mw_TP_MM_PSAP_ACK_01( // TODO To be enforced
+                                                            template (present) CallId p_callId := ?,
+                                                            template (present) CSeq p_cSeq := ?,
+                                                            template (present) SipUrl p_ack_uri := ?,
+                                                            template (present) From p_from := ?,
+                                                            template (present) To p_to := ?
+                                                            ) modifies mw_ACK_Request_Base := {
+        requestLine := {
+            method := ACK_E,
+            requestUri := p_ack_uri, // @TODO
+            sipVersion := c_sipNameVersion
+        },
+        msgHeader := {
+            callId := p_callId,
+            fromField := p_from,
+            toField := p_to,
+            route := {
+                fieldName := ROUTE_E,
+                routeBody := {
+                    *, 
+                    ?,
+                    *
+                }
             }
-        } // End of template mw_TP_MM_PSAP_183SessionProgress_01
+        }
+    } // End of template mw_TP_MM_PSAP_ACK_01
     
-        template (present) ACK_Request mw_TP_MM_PSAP_ACK_01( // TODO To be enforced
-                                                             template (present) CallId p_callId := ?,
-                                                             template (present) CSeq p_cSeq := ?,
-                                                             template (present) SipUrl p_ack_uri := ?,
-                                                             template (present) From p_from := ?,
-                                                             template (present) To p_to := ?
-                                                             ) modifies mw_ACK_Request_Base := {
-            requestLine := {
-                method := ACK_E,
-                requestUri := p_ack_uri, // @TODO
-                sipVersion := c_sipNameVersion
-            },
-            msgHeader := {
-                callId := p_callId,
-                fromField := p_from,
-                toField := p_to,
-                route := {
-                    fieldName := ROUTE_E,
-                    routeBody := {
-                        *, 
-                        ?,
-                        *
-                    }
+    template (present) BYE_Request mw_TP_MM_PSAP_BYE_01( // TODO To be enforced
+                                                            template (present) CallId p_callId := ?,
+                                                            template (present) CSeq p_cSeq := ?,
+                                                            template (present) SipUrl p_bye_uri := ?,
+                                                            template (present) From p_from := ?,
+                                                            template (present) To p_to := ?
+                                                            ) modifies mw_BYE_Request_Base := {
+        requestLine := {
+            method := BYE_E,
+            requestUri := p_bye_uri, // @TODO
+            sipVersion := c_sipNameVersion
+        },
+        msgHeader := {
+            callId := p_callId,
+            fromField := p_from,
+            toField := p_to,
+            route := {
+                fieldName := ROUTE_E,
+                routeBody := {
+                    *, 
+                    ?,
+                    *
                 }
             }
-        } // End of template mw_TP_MM_PSAP_ACK_01
+        }
+    } // End of template mw_TP_MW_PCSCF_BYE_01
         
+
 } // End of module AtsImsIot_Templates_MM
-- 
GitLab