asterisk: Implement support to handle 2nd REGISTER through ipsec

This patch implements the necessary infra to set up ipsec tunnel towards
the asterisk IMS client, and receive the 2nd REGISTER through the ipsec
tun plus answer it acking the registration successfully.

Change-Id: Ic042422788ee406f5b71ca3878bc5617e5455579
diff --git a/library/PIPEasp_Templates.ttcn b/library/PIPEasp_Templates.ttcn
index af4e434..0775a5e 100644
--- a/library/PIPEasp_Templates.ttcn
+++ b/library/PIPEasp_Templates.ttcn
@@ -3,6 +3,20 @@
 import from PIPEasp_PortType all;
 import from PIPEasp_Types all;
 
+template (value) ASP_PExecute ts_PExecute(template (value) charstring command,
+					  template (value) charstring stdin) := {
+	command := command,
+	stdin := stdin
+}
+
+template (present) ASP_PResult tr_PResult(template (present) charstring stdout,
+					  template (present) charstring stderr,
+					  template (present) integer code) := {
+	stdout := stdout,
+	stderr := stderr,
+	code   := code
+}
+
 template (value) ASP_PExecuteBackground ts_ExecBg(charstring cmd) := {
 	command := cmd
 }
@@ -24,4 +38,36 @@
 [] pt.receive(tr_Stderr(?)) { repeat; }
 }
 
+/* User should map(component_name:PIPE, system:PIPE) before using this function. */
+function f_PIPEasp_exec_sync_PResult(PIPEasp_PT pt,
+				    charstring cmdline,
+				    template (present) ASP_PResult res_exp := tr_PResult(?,?,0),
+				    float time_out := 10.0) return ASP_PResult {
+	var ASP_PResult res;
+	timer t;
+
+	if (time_out > 0.0) {
+		t.start(time_out);
+	}
+
+	log ("Executing: ", cmdline);
+	pt.send(ts_PExecute(cmdline, ""));
+
+	alt {
+	[] pt.receive(res_exp) -> value res;
+	[time_out > 0.0] t.timeout {
+		setverdict(fail, "Timeout: ", cmdline);
+		mtc.stop;
+	}
+	}
+	log ("Result: ", res);
+	return res;
+}
+
+function f_PIPEasp_exec_sync(PIPEasp_PT pt,
+			     charstring cmdline,
+			     template (present) integer rc := 0) return ASP_PResult {
+	return f_PIPEasp_exec_sync_PResult(pt, cmdline, tr_PResult(?, ?, rc));
+}
+
 }