epdg: Introduce test TC_hss_initiated_update_user_profile(_unknown)

This test so far only validates the SWx interface during the procedure.
It can be extended at a later time when implementing propagation of the
procedure to other interfaces in osmo-epdg.

Related: OS#6042
Change-Id: Ic7c19a3fe7b2b1411414fb6b78ab9a665a1aa42b
diff --git a/epdg/EPDG_Tests.ttcn b/epdg/EPDG_Tests.ttcn
index bc4219b..1742fd7 100644
--- a/epdg/EPDG_Tests.ttcn
+++ b/epdg/EPDG_Tests.ttcn
@@ -471,6 +471,32 @@
 	}
 }
 
+/* Send PPR as HSS to AAA server, expect back PPA */
+private function f_DIA_SWx_PP(template (present) GenericAVP exp_result_tmpl := tr_AVP_ResultCode(DIAMETER_SUCCESS)) runs on EPDG_ConnHdlr {
+	var PDU_DIAMETER rx_dia;
+	var UINT32 hbh_id := f_rnd_octstring(4);
+	var UINT32 ete_id := f_rnd_octstring(4);
+	var octetstring reason_info := char2oct("test");
+
+	/* Unlike PPR, PPA contains no IMSI. Register ete_id in DIAMETER_Emulation,
+	 * so PPA is forwarded back to us in DIAMETER port instead of MTC_CT.DIAMETER_UNIT.
+	 */
+	f_epdg_connhldr_SWx_expect_eteid(ete_id);
+
+	SWx.send(ts_DIA_SWx_PPR(g_pars.imsi,
+				IPv4,
+				g_pars.apn,
+				hbh_id := hbh_id,
+				ete_id := ete_id));
+
+	alt {
+	[] SWx.receive(tr_DIA_SWx_PPA(exp_result_tmpl, hbh_id := hbh_id, ete_id := ete_id)) -> value rx_dia {}
+	[] SWx.receive(PDU_DIAMETER:?) -> value rx_dia {
+		Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter SWx msg rx: ", rx_dia));
+		}
+	}
+}
+
 /* Send RTR as HSS to AAA server, expect back RTA */
 private function f_DIA_SWx_RT(template (value) CxDx_3GPP_Reason_Code reason_code,
 			      template (present) GenericAVP exp_result_tmpl := tr_AVP_ResultCode(DIAMETER_SUCCESS),
@@ -1138,6 +1164,41 @@
 	setverdict(pass);
 }
 
+/*
+ * 3GPP TS 29.273 8.1.2.3 HSS Initiated Update of User Profile
+ * 3GPP TS 29.273 8.2.2.2 HSS Initiated Update of User Profile Procedure
+ */
+private function f_TC_hss_initiated_update_user_profile(charstring id) runs on EPDG_ConnHdlr {
+	f_initial_attach();
+	/* Procedure should be performed properly: */
+	f_DIA_SWx_PP(tr_AVP_ResultCode(DIAMETER_SUCCESS));
+}
+testcase TC_hss_initiated_update_user_profile() runs on MTC_CT {
+	var EPDG_ConnHdlrPars pars := f_init_pars();
+	var EPDG_ConnHdlr vc_conn;
+	f_init();
+	vc_conn := f_start_handler(refers(f_TC_hss_initiated_update_user_profile), pars);
+	vc_conn.done;
+	setverdict(pass);
+}
+
+/*
+ * Same as TC_hss_initiated_update_user_profile_unknown, but without registering
+ * subscriber first, so expect DIAMETER_ERROR_USER_UNKNOWN in answer.
+ */
+private function f_TC_hss_initiated_update_user_profile_unknown(charstring id) runs on EPDG_ConnHdlr {
+	var DIAMETER_ts29_229_ExperimentalResultcode erc := DIAMETER_ERROR_USER_UNKNOWN;
+	f_DIA_SWx_PP(tr_AVP_ExperimentalResult(vendor_id_3GPP, int2oct(enum2int(erc), 4)));
+}
+testcase TC_hss_initiated_update_user_profile_unknown() runs on MTC_CT {
+	var EPDG_ConnHdlrPars pars := f_init_pars();
+	var EPDG_ConnHdlr vc_conn;
+	f_init();
+	vc_conn := f_start_handler(refers(f_TC_hss_initiated_update_user_profile_unknown), pars);
+	vc_conn.done;
+	setverdict(pass);
+}
+
 private function f_TC_concurrent_ues(charstring id) runs on EPDG_ConnHdlr {
 	COORD.send(COORD_CMD_READY);
 	COORD.receive(COORD_CMD_START);
@@ -1236,6 +1297,8 @@
 	execute ( TC_s2b_CreateSession_rejected() );
 	execute ( TC_hss_initiated_deregister_new_server_assigned() );
 	execute ( TC_hss_initiated_deregister_permanent_termination() );
+	execute ( TC_hss_initiated_update_user_profile() );
+	execute ( TC_hss_initiated_update_user_profile_unknown() );
 	execute ( TC_concurrent_ues2() );
 	execute ( TC_concurrent_ues100() );
 	execute ( TC_upf_echo_req() );
diff --git a/epdg/expected-results.xml b/epdg/expected-results.xml
index ccc69cb..83155cd 100644
--- a/epdg/expected-results.xml
+++ b/epdg/expected-results.xml
@@ -9,6 +9,8 @@
   <testcase classname='EPDG_Tests' name='TC_s2b_CreateSession_rejected' time='MASKED'/>
   <testcase classname='EPDG_Tests' name='TC_hss_initiated_deregister_new_server_assigned' time='MASKED'/>
   <testcase classname='EPDG_Tests' name='TC_hss_initiated_deregister_permanent_termination' time='MASKED'/>
+  <testcase classname='EPDG_Tests' name='TC_hss_initiated_update_user_profile' time='MASKED'/>
+  <testcase classname='EPDG_Tests' name='TC_hss_initiated_update_user_profile_unknown' time='MASKED'/>
   <testcase classname='EPDG_Tests' name='TC_concurrent_ues2' time='MASKED'/>
   <testcase classname='EPDG_Tests' name='TC_concurrent_ues100' time='MASKED'/>
   <testcase classname='EPDG_Tests' name='TC_upf_echo_req' time='MASKED'/>
diff --git a/library/DIAMETER_ts29_273_Templates.ttcn b/library/DIAMETER_ts29_273_Templates.ttcn
index e1a0700..dcb5a31 100644
--- a/library/DIAMETER_ts29_273_Templates.ttcn
+++ b/library/DIAMETER_ts29_273_Templates.ttcn
@@ -205,6 +205,74 @@
 			ts_AVP_UserNameImsi(valueof(imsi))
 	});
 
+/* Push-Profile-Request,
+ * 3GPP TS 29.273 8.1.2.3 HSS Initiated Update of User Profile
+ * 3GPP TS 29.273 8.2.2.2 HSS Initiated Update of User Profile Procedure
+ */
+template (value) PDU_DIAMETER
+ts_DIA_SWx_PPR(template (value) hexstring imsi,
+	       template (value) AAA_3GPP_PDN_Type pdn_type,
+	       template (value) charstring apn,
+	       template (value) uint32_t vendor_app_id := c_DIAMETER_3GPP_SWx_AID,
+	       template (value) octetstring sess_id := c_def_sess_id,
+	       template (value) charstring orig_host := "hss.localdomain",
+	       template (value) charstring orig_realm := "localdomain",
+	       template (value) charstring dest_host := "aaa.localdomain",
+	       template (value) charstring dest_realm := "localdomain",
+	       template (value) UINT32 hbh_id := '00000000'O,
+	       template (value) UINT32 ete_id := '00000000'O) :=
+	ts_DIAMETER(flags := '11000000'B,
+		    cmd_code := Push_Profile,
+		    app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
+		    hbh_id := hbh_id,
+		    ete_id := ete_id,
+		    avps := {
+			ts_AVP_SessionId(sess_id),
+			ts_AVP_VendorSpecAppId(vendor_id_3GPP, valueof(vendor_app_id)),
+			ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
+			ts_AVP_OriginHost(orig_host),
+			ts_AVP_OriginRealm(orig_realm),
+			ts_AVP_DestinationHost(dest_host),
+			ts_AVP_DestinationRealm(dest_realm),
+			ts_AVP_UserNameImsi(imsi),
+			ts_AVP_3GPP_Non_3GPP_User_Data(pdn_type, apn)
+			/* Optional: PPR-Flags */
+			/* TODO:
+			 * *[ Supported-Features ]
+			 */
+	});
+
+/*  Push-Profile-Answer,
+ * 3GPP TS 29.273 8.1.2.3 HSS Initiated Update of User Profile
+ * 3GPP TS 29.273 8.2.2.2 HSS Initiated Update of User Profile Procedure
+ */
+template (present) PDU_DIAMETER
+tr_DIA_SWx_PPA(template (present) GenericAVP tmpl_result := ?,
+	       template (present) octetstring sess_id := ?,
+	       template (present) charstring orig_host :=  ?,
+	       template (present) charstring orig_realm := ?,
+	       template (present) charstring dest_host := ?,
+	       template (present) charstring dest_realm := ?,
+	       template (present) UINT32 hbh_id := ?,
+	       template (present) UINT32 ete_id := ?) :=
+	tr_DIAMETER(flags := '0???????'B,
+		    cmd_code := Push_Profile,
+		    app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
+		    hbh_id := hbh_id, ete_id := ete_id,
+		    avps := superset(
+			tr_AVP_SessionId(sess_id),
+			tr_AVP_VendorSpecAppId(?, ?),
+			tmpl_result,
+			tr_AVP_AuthSessionState(NO_STATE_MAINTAINED),
+			tr_AVP_OriginHost(orig_host),
+			tr_AVP_OriginRealm(orig_realm)
+			/* Optional:
+			* [ Access-Network-Info ]
+			* [ Local-Time-Zone ]
+			* *[ Supported-Features ]
+			*/
+	));
+
 /* Server-Assignment-Request,
  * 3GPP TS 29.273 8.1.2.2.2 UE/PDN Registration/DeRegistration Notification
  * 3GPP TS 29.273 8.2.2.3 Non-3GPP IP Access Registration Procedure */