blob: 8bd6025a12f90d36f80cb8b2a8644d6186fc1b58 [file] [log] [blame]
Harald Welte03c0e562017-12-09 02:55:12 +01001module Osmocom_CTRL_Functions {
2 import from Osmocom_CTRL_Types all;
3 import from IPA_Emulation all;
4
5 private function f_gen_rand_id() return CtrlId {
6 return int2str(float2int(rnd()*999999999.0));
7 }
8
9 /* perform a given GET Operation */
10 function f_ctrl_get(IPA_CTRL_PT pt, CtrlVariable variable) return CtrlValue {
11 timer T := 2.0;
12 var CtrlMessage rx;
13 var CtrlId id := f_gen_rand_id();
14 pt.send(ts_CtrlMsgGet(id, variable));
15 T.start;
16 alt {
17 [] pt.receive(tr_CtrlMsgGetRepl(id, variable)) -> value rx { }
18 [] pt.receive(tr_CtrlMsgError) -> value rx {
19 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
20 }
21 [] T.timeout {
22 setverdict(fail, "Timeout waiting for CTRL GET REPLY ", variable);
23 }
24 }
25 return rx.resp.val;
26 }
27
28 /* perform a given SET Operation */
29 function f_ctrl_set(IPA_CTRL_PT pt, CtrlVariable variable, CtrlValue val) {
30 timer T := 2.0;
31 var CtrlMessage rx;
32 var CtrlId id := f_gen_rand_id();
33 pt.send(ts_CtrlMsgSet(id, variable, val));
34 T.start;
35 alt {
36 [] pt.receive(tr_CtrlMsgSetRepl(id, variable, val)) { }
37 [] pt.receive(tr_CtrlMsgError) -> value rx {
38 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
39 }
40 [] T.timeout {
41 setverdict(fail, "Timeout waiting for CTRL SET REPLY ", variable);
42 }
43 }
44 }
45
46 /* Expect a matching TRAP */
47 function f_ctrl_exp_trap(IPA_CTRL_PT pt, template CtrlVariable variable,
48 template CtrlValue val := ?) return CtrlValue {
49 timer T := 2.0;
50 var CtrlMessage rx;
51 T.start;
52 alt {
53 [] pt.receive(tr_CtrlMsgTrap(variable, val)) -> value rx {}
54 [] T.timeout {
55 setverdict(fail, "Timeout waiting for TRAP ", variable);
56 }
57 }
58 return rx.trap.val;
59 }
60}