RAN_Emulation: Add RANAP support

So far, RAN_Emulation only handled BSSAP and hence could be used
to emulate BSCs towards the MSC.  Let's extend it with RANAP support
so we can also emulate RNCs towards the MSC.

We try to share as much code and logic as possible betweeb the two.

Related: OS#2856, OS#2857
Change-Id: Ie79bda764162e5c5a42608bde5c5f486ea531f33
diff --git a/library/RAN_Adapter.ttcnpp b/library/RAN_Adapter.ttcnpp
index ae7934e..53c8bac 100644
--- a/library/RAN_Adapter.ttcnpp
+++ b/library/RAN_Adapter.ttcnpp
@@ -45,7 +45,8 @@
 type enumerated RAN_Transport {
 	BSSAP_TRANSPORT_AoIP,	/* 3GPP AoIP: SCCP over M3UA over SCTP */
 	BSSAP_TRANSPORT_SCCPlite_SERVER, /* SCCPlite: SCCP over IPA over TCP */
-	BSSAP_TRANSPORT_SCCPlite_CLIENT  /* SCCPlite: SCCP over IPA over TCP */
+	BSSAP_TRANSPORT_SCCPlite_CLIENT, /* SCCPlite: SCCP over IPA over TCP */
+	RANAP_TRANSPORT_IuCS	/* 3GPP IuCS: SCCP over M3UA over SCTP */
 };
 
 type record RAN_Configuration {
@@ -90,8 +91,7 @@
 		ba.vc_RAN := RAN_Emulation_CT.create(id & "-RAN");
 	}
 	select (cfg.transport) {
-#ifdef RAN_EMULATION_BSSAP
-	case (BSSAP_TRANSPORT_AoIP) {
+	case (BSSAP_TRANSPORT_AoIP, RANAP_TRANSPORT_IuCS) {
 		ba.vc_M3UA := M3UA_CT.create(id & "-M3UA");
 		map(ba.vc_M3UA:SCTP_PORT, system:sctp);
 		/* connect MTP3 service provider (M3UA) to lower side of SCCP */
@@ -133,7 +133,6 @@
 		disconnect(ba.vc_IPA:IPA_SP_PORT, ba.vc_WAIT:IPA_SP_PORT);
 		}
 #endif /* SCCP */
-#endif /* BSSAP */
 	case else {
 		setverdict(fail, "Unsuppored RAN_Transport");
 		mtc.stop;
@@ -145,10 +144,17 @@
 		T.start;
 		//T.timeout;
 		log("Connecting BSSMAP Emulation to SCCP_SP_PORT and starting emulation");
-#if RAN_EMULATION_BSSAP
 		/* connect BSSNAP component to upper side of SCCP */
-		connect(ba.vc_RAN:BSSAP, ba.vc_SCCP:SCCP_SP_PORT);
+		if (cfg.transport == RANAP_TRANSPORT_IuCS) {
+#ifdef RAN_EMULATION_RANAP
+			ops.protocol := RAN_PROTOCOL_RANAP
+			connect(ba.vc_RAN:RANAP, ba.vc_SCCP:SCCP_SP_PORT);
 #endif
+		} else {
+#ifdef RAN_EMULATION_BSSAP
+			connect(ba.vc_RAN:BSSAP, ba.vc_SCCP:SCCP_SP_PORT);
+#endif
+		}
 		if (cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER or
 		    cfg.transport == BSSAP_TRANSPORT_SCCPlite_CLIENT) {
 #ifdef IPA_EMULATION_MGCP
@@ -156,7 +162,6 @@
 			connect(ba.vc_IPA:IPA_MGCP_PORT, ba.vc_RAN:MGCP);
 #endif
 		}
-		/* start the BSSMAP emulation */
 		ba.vc_RAN.start(RAN_Emulation.main(valueof(ops), ""));
 	}