hnbgw: Introduce tests about UE registration

We didn't have any test coverage for HNBAP UE registration so far.

Let's start with two basic tests:
* normal / successful case
* abnormal case: UE Register without prior HNB Register

Change-Id: Ice2743d376ab8041646259fa25117d6fd0e8c2fd
diff --git a/hnbgw/HNBGW_Tests.ttcn b/hnbgw/HNBGW_Tests.ttcn
index 91677b1..cfdf923 100644
--- a/hnbgw/HNBGW_Tests.ttcn
+++ b/hnbgw/HNBGW_Tests.ttcn
@@ -33,6 +33,7 @@
 import from TELNETasp_PortType all;
 
 import from HNBAP_Templates all;
+import from HNBAP_IEs all;
 import from HNBAP_PDU_Descriptions all;
 
 import from RUA_IEs all;
@@ -923,6 +924,38 @@
 	}
 }
 
+function f_hnbap_ue_register(integer hnb_idx := 0, template (present) UE_Identity ue_id, boolean expect_reject := false) runs on test_CT
+{
+	timer T := 2.0;
+
+	HNBAP[hnb_idx].send(ts_HNBAP_UERegisterRequest(ue_id));
+
+	T.start;
+	alt {
+	[] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterAccept(ue_id)) {
+		if (expect_reject) {
+			setverdict(fail, "Rx UE Register Accept while expecting reject");
+		} else {
+			setverdict(pass);
+		}
+	}
+	[] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterReject(ue_id, ?)) {
+		if (expect_reject) {
+			setverdict(pass);
+		} else {
+			setverdict(fail, "Rx UE Register Reject while expecting accept");
+		}
+	}
+	[] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
+		repeat;
+	}
+	[] T.timeout {
+		setverdict(fail, "Timeout waiting for UE Register response");
+	}
+	}
+}
+
+
 testcase TC_hnb_register() runs on test_CT {
 	g_num_hnbs := 1;
 	f_init(start_hnb := false);
@@ -965,6 +998,24 @@
 	f_shutdown_helper();
 }
 
+/* regular UE registration */
+testcase TC_ue_register() runs on test_CT {
+	var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
+	g_num_hnbs := 1;
+	f_init(start_hnb := true);
+	f_hnbap_ue_register(0, ue_id);
+	f_shutdown_helper();
+}
+
+/* UE registration from unregistered HNB */
+testcase TC_ue_register_before_hnb_register() runs on test_CT {
+	var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
+	g_num_hnbs := 1;
+	f_init(start_hnb := false);
+	f_hnbap_ue_register(0, ue_id, expect_reject := true);
+	f_shutdown_helper();
+}
+
 /***********************************************************************
  * RUA / RANAP Testing
  ***********************************************************************/
@@ -2715,6 +2766,8 @@
 	execute(TC_hnb_register());
 	execute(TC_hnb_register_duplicate());
 	execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
+	execute(TC_ue_register());
+	execute(TC_ue_register_before_hnb_register());
 	execute(TC_ranap_cs_initial_ue());
 	execute(TC_ranap_ps_initial_ue());
 	execute(TC_ranap_cs_initial_ue_empty_cr());
diff --git a/library/hnbap/HNBAP_Templates.ttcn b/library/hnbap/HNBAP_Templates.ttcn
index 2576d17..7a86e0c 100644
--- a/library/hnbap/HNBAP_Templates.ttcn
+++ b/library/hnbap/HNBAP_Templates.ttcn
@@ -232,6 +232,172 @@
 	}
 }
 
+/* 9.1.6 UE REGISTER REQUEST */
+template (present) HNBAP_PDU
+tr_HNBAP_UERegisterRequest(template (present) UE_Identity ue_id) := {
+	initiatingMessage := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterRequest := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Registration_Cause,
+						criticality := ignore,
+						value_ := { Registration_Cause := normal }
+					}, {
+						id := HNBAP_Constants.id_UE_Capabilities,
+						criticality := ignore,
+						value_ := {
+							UE_Capabilities := {
+								access_stratum_release_indicator := ?,
+								csg_capability := ?
+							}
+						}
+					}
+				},
+				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+
+template (value) HNBAP_PDU
+ts_HNBAP_UERegisterRequest(template (value) UE_Identity ue_id) := {
+	initiatingMessage := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterRequest := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Registration_Cause,
+						criticality := ignore,
+						value_ := { Registration_Cause := normal }
+					}, {
+						id := HNBAP_Constants.id_UE_Capabilities,
+						criticality := ignore,
+						value_ := {
+							UE_Capabilities := {
+								access_stratum_release_indicator := rel_8_and_beyond,
+								csg_capability := not_csg_capable,
+								iE_Extensions := omit
+							}
+						}
+					}
+				},
+				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+
+/* 9.1.7 UE REGISTER ACCEPT */
+template (present) HNBAP_PDU
+tr_HNBAP_UERegisterAccept(template (present) UE_Identity ue_id) := {
+	successfulOutcome := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterAccept := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Context_ID,
+						criticality := reject,
+						value_ := { Context_ID := ? }
+					}, *
+				},
+				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+
+template (value) HNBAP_PDU
+ts_HNBAP_UERegisterAccept(template (value) UE_Identity ue_id,
+			  template (value) BIT24 context_id) := {
+	successfulOutcome := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterAccept := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Context_ID,
+						criticality := reject,
+						value_ := { Context_ID := context_id }
+					}
+				},
+				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+
+/* 9.1.8 UE REGISTER REJECT */
+template (present) HNBAP_PDU
+tr_HNBAP_UERegisterReject(template (present) UE_Identity ue_id, template (present) Cause cause := ?) := {
+	unsuccessfulOutcome := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterReject := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Cause,
+						criticality := ignore,
+						value_ := { Cause := cause }
+					}, *
+				},
+				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+template (value) HNBAP_PDU
+ts_HNBAP_UERegisterReject(template (value) UE_Identity ue_id, template (value) Cause cause) := {
+	unsuccessfulOutcome := {
+		procedureCode := id_UERegister,
+		criticality := reject,
+		value_ := {
+			uERegisterReject := {
+				protocolIEs := {
+					{
+						id := HNBAP_Constants.id_UE_Identity,
+						criticality := reject,
+						value_ := { UE_Identity := ue_id }
+					}, {
+						id := HNBAP_Constants.id_Cause,
+						criticality := ignore,
+						value_ := { Cause := cause }
+					}
+				},
+				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
+			}
+		}
+	}
+}
+
 /* 9.1.9 HNB DE-REGISTER */
 template (value) HNBAP_PDU
 ts_HNBAP_HNBDe_Register(template (value) Cause cause) := {