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 { |
| 17 | [] pt.receive(tr_CtrlMsgGetRepl(id, variable)) -> value rx { } |
Harald Welte | 95a4781 | 2017-12-09 14:19:03 +0100 | [diff] [blame] | 18 | [] pt.receive(tr_CtrlMsgTrap) { repeat; } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 19 | [] 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 Welte | 95a4781 | 2017-12-09 14:19:03 +0100 | [diff] [blame] | 38 | [] pt.receive(tr_CtrlMsgTrap) { repeat; } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 39 | [] 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 | } |
Harald Welte | 852a384 | 2017-12-09 14:19:36 +0100 | [diff] [blame] | 62 | |
| 63 | /* Expect a matching GET result */ |
| 64 | function f_ctrl_get_exp(IPA_CTRL_PT pt, CtrlVariable variable, template CtrlValue exp) { |
| 65 | var charstring ctrl_resp; |
| 66 | ctrl_resp := f_ctrl_get(pt, variable); |
| 67 | if (not match(ctrl_resp, exp)) { |
| 68 | setverdict(fail, "Unexpected " & variable & ":" & ctrl_resp); |
| 69 | } |
| 70 | } |
| 71 | |
Harald Welte | 3ec493f | 2017-12-09 16:25:29 +0100 | [diff] [blame^] | 72 | template charstring ts_ctrl_ratectr(CtrlVariable grp, integer instance, CtrlVariable name, |
| 73 | CtrlVariable kind := "abs") := |
| 74 | "rate_ctr." & kind & "." & grp & "." & int2str(instance) & "." & name; |
| 75 | |
| 76 | function f_ctrl_get_ratectr_abs(IPA_CTRL_PT pt, CtrlVariable grp, integer instance, |
| 77 | CtrlVariable name) return integer { |
| 78 | return str2int(f_ctrl_get(pt, valueof(ts_ctrl_ratectr(grp, instance, name)))); |
| 79 | } |
| 80 | |
| 81 | function f_ctrl_get_exp_ratectr_abs(IPA_CTRL_PT pt, CtrlVariable grp, integer instance, |
| 82 | CtrlVariable name, template integer exp) { |
| 83 | var charstring ctrl_resp; |
| 84 | var CtrlVariable variable := valueof(ts_ctrl_ratectr(grp, instance, name)); |
| 85 | ctrl_resp := f_ctrl_get(pt, variable); |
| 86 | if (not match(str2int(ctrl_resp), exp)) { |
| 87 | setverdict(fail, variable & " value " & ctrl_resp & " didn't match ", exp); |
| 88 | } |
| 89 | } |
| 90 | |
Harald Welte | 852a384 | 2017-12-09 14:19:36 +0100 | [diff] [blame] | 91 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 92 | } |