一、概述
Translation-rule用于增加、移除和替换VoIP中dial-peer拨号对等体inbound和outbound号码。它有以下几种应用:
1、应用于所有inbound call legs。
2、应用于特定voice-port的所有inbound call legs。
3、应用于特定dial-peer的所有outbound call legs。
二、命令格式
Translation-rule在全局模式侠有以下两种命令配置方式:
1、(config)translation-rule rule_tag
(config-rule)rule <0-10> match pattern replacement pattern
应用translation-rule:
1) 所有inbound call legs
(config) voip-incoming translation-rule rule_tag {called/calling}
2) 特定voice-port的所有inbound call legs
(config)voice-port 0/0/0
(config-voiceport)translate {called/calling} rule_tag
3) 特定dial-peer的所有outbound call legs
(config)dial-peer voice 10 pots
(config-dial-peer)translate-outgoing {called/calling} rule_tag
2、(config)voice translation-rule rule_tag
(config-rule)rule <1-15> /match pattern/ /replacement pattern/
应用voice translation-rule:
1) 创建voice translation-profile
(config) voice translation?profile profile_name
(cfg-translation-profile) translate {called/calling} rule_tag
2) 特定的dial-peer所有incoming和outgoing call legs
(config)dial-peer voice 10 pots
(config-dial-peer)translation-profile {incoming/outgoing} profile_name
三、通配符
1、数字通配符
通配符号用途
.任意一个数字(0~9)。
[0-9] 区间范围内的一个数字,也可用[0,2-4,5,8-9]方式表示间断和连续数字。
* 0个或多个相同数字。
+ 1个或多个相同数字。
? 0个或1个相同数字。
.* 任意数字,可以为0个。
.+ 非0个任意数字。
2、其他符号:
符号用途
$ 无数字,相当于结束符。
^ 从此符号后的数字开始,相当于起始符。
^$ Null,即没有数字。
\ 在match pattern中,表示在此之前copy;在replace pattern中,表示在此之后paste。( ) 表示一个集合,用于copy数字时。
四、用法示例
1、将40开头的5位号码替换为号码"6666000":
voice translation?rule 1
rule 1 /^40.../ /6666000/
router#test voice translation?rule 1 40123
Matched with rule 1
Original number: 40123 Translated number: 6666000
2、将所有号码替换为"5554000":
voice translation?rule 2
rule 1 /.*/ /5554000/
router#test voice translation?rule 2 123
Matched with rule 1
Original number: 123 Translated number: 5554000
router#test voice translation?rule 2 86573
Matched with rule 1
Original number: 86573 Translated number: 5554000
router#test voice translation?rule 2 ""
Matched with rule 1
Original number: Translated number: 5554000
3、将所有非空号码替换为"5554000".
voice translation?rule 2
rule 1 /.+/ /5554000/
router#test voice translation?rule 2 123
Matched with rule 1
Original number: 123 Translated number: 5554000
router#test voice translation?rule 2 ""
Didn't match with any of rules
4、保留最后3位号码至5554开头的后3位:voice translation?rule 2
rule 1 /^....(...\)/ /5554\1/
router#test voice translation?rule 2 1234567 Matched with rule 1
Original number: 1234567 Translated number: 5554567 router#test voice translation?rule 2 123456
Didn't match with any of rules