blob: 04848cee1a49bbd393e2da71c843c0d1489c3977 [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 { }
Harald Welte95a47812017-12-09 14:19:03 +010018 [] pt.receive(tr_CtrlMsgTrap) { repeat; }
Harald Welte03c0e562017-12-09 02:55:12 +010019 [] pt.receive(tr_CtrlMsgError) -> value rx {
20 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
21 }
22 [] T.timeout {
23 setverdict(fail, "Timeout waiting for CTRL GET REPLY ", variable);
24 }
25 }
26 return rx.resp.val;
27 }
28
29 /* perform a given SET Operation */
30 function f_ctrl_set(IPA_CTRL_PT pt, CtrlVariable variable, CtrlValue val) {
31 timer T := 2.0;
32 var CtrlMessage rx;
33 var CtrlId id := f_gen_rand_id();
34 pt.send(ts_CtrlMsgSet(id, variable, val));
35 T.start;
36 alt {
37 [] pt.receive(tr_CtrlMsgSetRepl(id, variable, val)) { }
Harald Welte95a47812017-12-09 14:19:03 +010038 [] pt.receive(tr_CtrlMsgTrap) { repeat; }
Harald Welte03c0e562017-12-09 02:55:12 +010039 [] pt.receive(tr_CtrlMsgError) -> value rx {
40 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
41 }
42 [] T.timeout {
43 setverdict(fail, "Timeout waiting for CTRL SET REPLY ", variable);
44 }
45 }
46 }
47
48 /* Expect a matching TRAP */
49 function f_ctrl_exp_trap(IPA_CTRL_PT pt, template CtrlVariable variable,
50 template CtrlValue val := ?) return CtrlValue {
51 timer T := 2.0;
52 var CtrlMessage rx;
53 T.start;
54 alt {
55 [] pt.receive(tr_CtrlMsgTrap(variable, val)) -> value rx {}
56 [] T.timeout {
57 setverdict(fail, "Timeout waiting for TRAP ", variable);
58 }
59 }
60 return rx.trap.val;
61 }
62}