NSN HLR simulator for provisioning in expect

电信设备中,HLR(Home Location Register)是非常昂贵的,通常不会有为provisioning开发而准备的HLR。因此,我们需要一个模拟器,能够简单地应答客户端发送过来的HLR指令。Expect是Unix/Linux下自动处理人机交互指令的脚步语言,用它来写一个HLR模拟器就最合适不过了。

 

一个最简单的NSN HLR模拟器是这样的,它可以

1. 模拟登录和退出

2. 模拟执行ZM开头的NSN HLR指令并回复“COMMAND EXECUTED”

3. 对于ZMIO、ZMNO等打印用户信息的指令,会读取预先设定好的文件并将其内容全部显示出来

4. 识别错误指令并返回错误信息

 

#! /bin/env expect set timeout 86400 proc handle_login {} { send_user "ENTER USERNAME < " expect -re ".*/n" {} send_user "ENTER PASSWORD < " expect -re ".*/n" {} send_user "/nWELCOME TO THE NSN HLR SIMULATOR/n/nMAIN LEVEL COMMAND <___>/n< /n" } proc handle_zmio {} { set file [open "/export/home/ilink/simulator/zmio_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmbo {} { set file [open "/export/home/ilink/simulator/zmbo_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmko {} { set file [open "/export/home/ilink/simulator/zmko_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmgo {} { set file [open "/export/home/ilink/simulator/zmgo_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmso {} { set file [open "/export/home/ilink/simulator/zmso_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmno {} { set file [open "/export/home/ilink/simulator/zmno_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_zmqo {} { set file [open "/export/home/ilink/simulator/zmqo_result.txt" "r"] while { [gets $file line] != -1 } { send_user "$line/n" } close $file send_user "COMMAND EXECUTED/n< /n" } proc handle_logout {} { send_user "END OF DIALOGUE SESSION/n" } proc handle_cmd {} { send_user "COMMAND EXECUTED/nXXX HANDLING COMMAND <MX_>/n< /n" } proc handle_dummy {} { send_user "MAIN LEVEL COMMAND <___>/n< /n" } proc handle_error {} { send_user "/*** UNKNOWN COMMAND CLASS ***//n/nMAIN LEVEL COMMAND <___>/n< /n" } handle_login expect { -re "Z;" { handle_logout } -re "ZMIO:.*;/n" { handle_zmio exp_continue } -re "ZMBO:.*;/n" { handle_zmbo exp_continue } -re "ZMKO:.*;/n" { handle_zmko exp_continue } -re "ZMGO:.*;/n" { handle_zmgo exp_continue } -re "ZMSO:.*;/n" { handle_zmso exp_continue } -re "ZMNO:.*;/n" { handle_zmno exp_continue } -re "ZMQO:.*;/n" { handle_zmqo exp_continue } -re "ZM.*;/n" { handle_cmd exp_continue } -re "^/[/r/n]" { handle_dummy exp_continue } -re "^/[^Z].*" { handle_error exp_continue } }

你可能感兴趣的:(command,user,File,Class,电信,login)