Osmocom_VTY_Functions: Make prompt configurable

We want to use this code also for OsmoMSC testing, so let's make the
prefix configurable as module parameter.

Change-Id: Iec846227e88b3dc0d3be9474b8b926719161c9ee
This commit is contained in:
Harald Welte 2018-01-24 18:50:53 +01:00
parent d5b91409bc
commit 553f655035
1 changed files with 42 additions and 33 deletions

View File

@ -1,58 +1,67 @@
module Osmocom_VTY_Functions {
import from TELNETasp_PortType all;
/* permitted prompts on VTY */
const charstring NORMAL_PROMPT := "OpenBSC> ";
const charstring ENABLE_PROMPT := "OpenBSC# ";
const charstring CONFIG_PROMPT := "OpenBSC(*)\#";
template charstring t_vty_unknown := pattern "*% Unknown command.";
modulepar {
charstring mp_prompt_prefix := "OpenBSC";
}
const ASP_TelnetDynamicConfig vty_prompt[3] := {
{
prompt := {
id := 1,
prompt := NORMAL_PROMPT,
has_wildcards := false
}
}, {
prompt := {
id := 2,
prompt := ENABLE_PROMPT,
has_wildcards := false
}
}, {
prompt := {
id := 3,
prompt := CONFIG_PROMPT,
has_wildcards := true
}
}
};
const charstring VTY_VIEW_SUFFIX := "> ";
const charstring VTY_ENABLE_SUFFIX := "# ";
const charstring VTY_CFG_SUFFIX := "(*)";
template charstring t_vty_unknown := pattern "*% Unknown command.";
/* configure prompts in TELNETasp module */
function f_vty_set_prompts(TELNETasp_PT pt) {
var ASP_TelnetDynamicConfig vty_prompt[3] := {
{
prompt := {
id := 1,
prompt := mp_prompt_prefix & VTY_VIEW_SUFFIX,
has_wildcards := false
}
}, {
prompt := {
id := 2,
prompt := mp_prompt_prefix & VTY_ENABLE_SUFFIX,
has_wildcards := false
}
}, {
prompt := {
id := 3,
prompt := mp_prompt_prefix & VTY_CFG_SUFFIX,
has_wildcards := true
}
}
};
/* set some configuration that isn't possible to express
* in the config file due to syntactic restrictions (Who invents config
* files that don't permit regular expressions? */
for (var integer i := 0; i < sizeof(vty_prompt); i:= i + 1) {
pt.send(vty_prompt[i])
log(vty_prompt[i]);
pt.send(vty_prompt[i]);
}
}
/* wait for any of the permitted prompts; buffer + return all intermediate output */
function f_vty_wait_for_prompt(TELNETasp_PT pt) return charstring {
template charstring config_pattern := pattern CONFIG_PROMPT;
var charstring rx, buf := "";
timer T := 2.0;
T.start;
alt {
[] pt.receive(NORMAL_PROMPT) { };
[] pt.receive(ENABLE_PROMPT) { };
[] pt.receive(config_pattern) { };
[] pt.receive(t_vty_unknown) { testcase.stop(fail, "VTY: Unknown Command") };
[] pt.receive(mp_prompt_prefix & VTY_VIEW_SUFFIX) { };
[] pt.receive(mp_prompt_prefix & VTY_ENABLE_SUFFIX) { };
[] pt.receive(pattern mp_prompt_prefix & VTY_CFG_SUFFIX) { };
[] pt.receive(t_vty_unknown) {
testcase.stop(fail, "VTY: Unknown Command");
};
[] pt.receive(charstring:?) -> value rx { buf := buf & rx; repeat };
[] T.timeout { setverdict(fail, "VTY Timeout for prompt"); return ""};
[] T.timeout {
setverdict(fail, "VTY Timeout for prompt");
self.stop;
};
}
T.stop;
return buf;