S1AP_Emulation: delete UE association on S1AP_UeContextReleaseCmd

When a S1AP_UeContextReleaseCmd is received, the UE association should
be deleted.

Related: OS#5760
Change-Id: I8c6f7a780945ce34dabdc794aabab5d16a3a73aa
diff --git a/library/S1AP_Emulation.ttcn b/library/S1AP_Emulation.ttcn
index 0671d08..1f23b66 100644
--- a/library/S1AP_Emulation.ttcn
+++ b/library/S1AP_Emulation.ttcn
@@ -342,6 +342,29 @@
 }
 */
 
+function handle_S1AP_UeContextReleaseCmd(template (present) S1AP_PDU rel_cmd) runs on S1AP_Emulation_CT {
+	if (ispresent(rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair)) {
+		var template MME_UE_S1AP_ID mme_ue_id;
+		var template ENB_UE_S1AP_ID enb_ue_id;
+		var integer assoc_id;
+		var S1AP_ConnHdlr vc_conn
+
+		mme_ue_id := rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.mME_UE_S1AP_ID;
+		enb_ue_id := rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.eNB_UE_S1AP_ID;
+
+		assoc_id := f_assoc_id_by_s1ap_ids(mme_ue_id, enb_ue_id);
+		vc_conn := S1apAssociationTable[assoc_id].comp_ref;
+
+		f_s1ap_id_table_del(vc_conn, valueof(enb_ue_id));
+	} else {
+		/* TODO: The UE CONTEXT RELEASE COMMAND (see also: 3GPP TS 36.413, section 9.1.4.6), may identify the
+		 * context by either an uE_S1AP_ID_pair (MME_UE_S1AP_ID and ENB_UE_S1AP_ID) or an MME_UE_S1AP_ID alone.
+		 * The latter case is not implemented here yet. */
+		setverdict(fail, "complete implementation of UeContextReleaseCmd handling");
+		mtc.stop;
+	}
+}
+
 function main(S1APOps ops, S1AP_conn_parameters p, charstring id) runs on S1AP_Emulation_CT {
 	var Result res;
 	g_pars := p;
@@ -427,9 +450,7 @@
 					S1AP.send(t_S1AP_Send(g_s1ap_conn_id, valueof(resp)));
 				}
 			} else if (match(mrf.msg, tr_S1AP_UeContextReleaseCmd)) {
-				/* TODO: special handling, as it contains multiple eNB or MME IDs */
-				setverdict(fail, "implement UeContextReleaseCmd handling");
-				mtc.stop;
+				handle_S1AP_UeContextReleaseCmd(mrf.msg);
 			} else {
 				/* Ue-related S1AP message */
 				/* obtain MME + ENB UE S1AP ID */