Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 1 | module 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 Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 17 | [] pt.receive(tr_CtrlMsgGetRepl(id, variable)) -> value rx { |
| 18 | } |
Harald Welte | 95a4781 | 2017-12-09 14:19:03 +0100 | [diff] [blame] | 19 | [] pt.receive(tr_CtrlMsgTrap) { repeat; } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 20 | [] pt.receive(tr_CtrlMsgError) -> value rx { |
| 21 | setverdict(fail, "Error in CTRL GET ", variable, ": ", rx.err.reason); |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 22 | return "FAIL"; |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 23 | } |
| 24 | [] T.timeout { |
| 25 | setverdict(fail, "Timeout waiting for CTRL GET REPLY ", variable); |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 26 | return "TIMEOUT"; |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 27 | } |
| 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 Welte | 95a4781 | 2017-12-09 14:19:03 +0100 | [diff] [blame] | 41 | [] pt.receive(tr_CtrlMsgTrap) { repeat; } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 42 | [] 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 Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 58 | [] pt.receive(tr_CtrlMsgTrap(variable, val)) -> value rx { |
| 59 | } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 60 | [] T.timeout { |
| 61 | setverdict(fail, "Timeout waiting for TRAP ", variable); |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 62 | return "TIMEOUT"; |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | return rx.trap.val; |
| 66 | } |
Harald Welte | 852a384 | 2017-12-09 14:19:36 +0100 | [diff] [blame] | 67 | |
| 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 Welte | 3ec493f | 2017-12-09 16:25:29 +0100 | [diff] [blame] | 77 | 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 Welte | 852a384 | 2017-12-09 14:19:36 +0100 | [diff] [blame] | 96 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 97 | } |