blob: b8e68e3f8a74cfabd0d46f90663cdef7802934e7 [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 {
Harald Weltefdfa0462017-12-10 18:09:40 +010017 [] pt.receive(tr_CtrlMsgGetRepl(id, variable)) -> value rx {
18 }
Harald Welte95a47812017-12-09 14:19:03 +010019 [] pt.receive(tr_CtrlMsgTrap) { repeat; }
Harald Welte03c0e562017-12-09 02:55:12 +010020 [] pt.receive(tr_CtrlMsgError) -> value rx {
21 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
Harald Weltefdfa0462017-12-10 18:09:40 +010022 return "FAIL";
Harald Welte03c0e562017-12-09 02:55:12 +010023 }
24 [] T.timeout {
25 setverdict(fail, "Timeout waiting for CTRL GET REPLY ", variable);
Harald Weltefdfa0462017-12-10 18:09:40 +010026 return "TIMEOUT";
Harald Welte03c0e562017-12-09 02:55:12 +010027 }
28 }
29 return rx.resp.val;
30 }
31
32 /* perform a given SET Operation */
33 function f_ctrl_set(IPA_CTRL_PT pt, CtrlVariable variable, CtrlValue val) {
34 timer T := 2.0;
35 var CtrlMessage rx;
36 var CtrlId id := f_gen_rand_id();
37 pt.send(ts_CtrlMsgSet(id, variable, val));
38 T.start;
39 alt {
40 [] pt.receive(tr_CtrlMsgSetRepl(id, variable, val)) { }
Harald Welte95a47812017-12-09 14:19:03 +010041 [] pt.receive(tr_CtrlMsgTrap) { repeat; }
Harald Welte03c0e562017-12-09 02:55:12 +010042 [] pt.receive(tr_CtrlMsgError) -> value rx {
43 setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason);
44 }
45 [] T.timeout {
46 setverdict(fail, "Timeout waiting for CTRL SET REPLY ", variable);
47 }
48 }
49 }
50
51 /* Expect a matching TRAP */
52 function f_ctrl_exp_trap(IPA_CTRL_PT pt, template CtrlVariable variable,
53 template CtrlValue val := ?) return CtrlValue {
54 timer T := 2.0;
55 var CtrlMessage rx;
56 T.start;
57 alt {
Harald Weltefdfa0462017-12-10 18:09:40 +010058 [] pt.receive(tr_CtrlMsgTrap(variable, val)) -> value rx {
59 }
Harald Welte03c0e562017-12-09 02:55:12 +010060 [] T.timeout {
61 setverdict(fail, "Timeout waiting for TRAP ", variable);
Harald Weltefdfa0462017-12-10 18:09:40 +010062 return "TIMEOUT";
Harald Welte03c0e562017-12-09 02:55:12 +010063 }
64 }
65 return rx.trap.val;
66 }
Harald Welte852a3842017-12-09 14:19:36 +010067
68 /* Expect a matching GET result */
69 function f_ctrl_get_exp(IPA_CTRL_PT pt, CtrlVariable variable, template CtrlValue exp) {
70 var charstring ctrl_resp;
71 ctrl_resp := f_ctrl_get(pt, variable);
72 if (not match(ctrl_resp, exp)) {
73 setverdict(fail, "Unexpected " & variable & ":" & ctrl_resp);
74 }
75 }
76
Harald Welte3ec493f2017-12-09 16:25:29 +010077 template charstring ts_ctrl_ratectr(CtrlVariable grp, integer instance, CtrlVariable name,
78 CtrlVariable kind := "abs") :=
79 "rate_ctr." & kind & "." & grp & "." & int2str(instance) & "." & name;
80
81 function f_ctrl_get_ratectr_abs(IPA_CTRL_PT pt, CtrlVariable grp, integer instance,
82 CtrlVariable name) return integer {
83 return str2int(f_ctrl_get(pt, valueof(ts_ctrl_ratectr(grp, instance, name))));
84 }
85
86 function f_ctrl_get_exp_ratectr_abs(IPA_CTRL_PT pt, CtrlVariable grp, integer instance,
87 CtrlVariable name, template integer exp) {
88 var charstring ctrl_resp;
89 var CtrlVariable variable := valueof(ts_ctrl_ratectr(grp, instance, name));
90 ctrl_resp := f_ctrl_get(pt, variable);
91 if (not match(str2int(ctrl_resp), exp)) {
92 setverdict(fail, variable & " value " & ctrl_resp & " didn't match ", exp);
93 }
94 }
95
Harald Welte852a3842017-12-09 14:19:36 +010096
Harald Welte03c0e562017-12-09 02:55:12 +010097}