Chapter 10: Digit Manipulation

Cisco Press

1 2 3 4 Page 2
Page 2 of 4

Using Regular Expressions When Rerouting a Call over the PSTN

The real power of regular expressions comes from using them in more complex ways. One common use is when intrasite calls that would normally traverse an IP WAN must be rerouted over the PSTN. You must remove any private numbering, such as site codes, from the called number and format it for use on the PSTN.

In Example 10-4, a company has two locations in Maryland, USA. One has a site code of 758, and the other has a site code of 759. The remainder of intrasite the number is the last seven digits of the actual phone number. In the national numbering plan, the area code for both locations is 410. To route intraoffice calls to these locations over the PSTN, you must substitute the long-distance code and area code for the site code. In this example, the first four numbers are translated to 1410, but the rest of the number is left untouched.

Example 10-4 Using Regular Expressions: Replacing Digits

Boise(config)#voice translation-rule 2
Boise(cfg-translation-rule)#rule 1 /^75[89]\(.*\)/ /1410\1/
Boise#
Boise#test voice translation-rule 2 7591234567
Matched with rule 1
Original number: 7591234567  Translated number: 14101234567

To understand a regular expression, break it into its component parts and decipher each part individually. Breaking the match portion of Rule 1 into its component parts:

  • ^75 are literal characters. The caret (^) designates the beginning of a string. This only matches a string that begins with a 7 and is followed by a 5.

  • [89] matches a literal character 8 or 9. The brackets tell the router to match just one of the numbers that the expression contains.

  • In \(.*\), the backslashes change the parentheses from literal characters to set-delimiters. The characters within the set are .*, which matches any character that is repeated zero or more times.

The following list breaks down the replacement portion of the rule into its component parts:

  • 1410 replaces the initial literal characters.

  • In the \1 part of the expression, the backslash changes the meaning of the digit 1. It is no longer a literal number—instead, it points to the first set in the matching part of the rule. The first set is (.*). Thus, any digits matching that set are inserted after 1410.

Instead of replacing site codes, your gateway might need to add digits when it reroutes an intrasite call to the PSTN. One way it can do this is to create multiple dial peers, each with a destination pattern of a remote site, and then prefix digits. If PSTN calls to multiple locations will go out the same PRI, the gateway can accomplish this more efficiently by using a set of voice translation rules grouped under one translation profile. For instance, suppose that your company uses seven-digit dialing between three internal sites over your MPLS WAN. One site is local to you, but your phone company uses ten-digit dialing locally. The other two sites are long distance. You would need to add three additional digits to the called number for the local site, and the appropriate long-distance and area codes for the other sites. The original seven digits must remain unchanged.

Example 10-5 shows the voice translation rules to accomplish this for three sites in the United States. Numbers in the local site begin with 789, with an area code of 410. Numbers in one remote site begin with 123, with an area code of 212, and the other site begins with 456 with an area code of 617. The long-distance code is 1. Also shown in the example is the translation rules grouped under a voice translation profile; this could then be applied to the POTS dial peer pointing to the PRI. The section "Creating Voice Translation Profiles," later in this chapter, covers voice translation profiles in greater detail.

Example 10-5 Using Regular Expressions: Prefixing Digits

VoiceGW(config)#voice translation-rule 15
VoiceGW(cfg-translation-rule)#rule 1 /^789/ /410&/
VoiceGW(cfg-translation-rule)#rule 2 /^123/ /1212&/
VoiceGW(cfg-translation-rule)#rule 3 /^456/ /1617&/
!
VoiceGW(config)#voice translation-profile TO-PSTN
VoiceGW(cfg-translation-profile)#translate called 15
!
VoiceGW#test voice translation-rule 15 7891234
Matched with rule 1
Original number: 7891234    Translated number: 4107891234
Original number type: none   Translated number type: none
Original number plan: none   Translated number plan: none

VoiceGW#test voice translation-rule 15 1234567
Matched with rule 2
Original number: 1234567    Translated number: 12121234567
Original number type: none   Translated number type: none
Original number plan: none   Translated number plan: none

VoiceGW#test voice translation-rule 15 4561111
Matched with rule 3
Original number: 4561111    Translated number: 16174561111
Original number type: none   Translated number type: none
Original number plan: none   Translated number plan: none

Breaking the match portion of Rule 1 into its component parts:

  • ^789 designates the literal characters 789 at the beginning of the string. This matches any string, of any number of digits, that begins with 789 so it will match the entire seven-digit called number.

Breaking the replacement portion of Rule 1 into its component parts:

  • 410 tells the router to place the digits 410 at the beginning of the replacement string.

  • & (ampersand) pulls all the matched digits into the replacement string.

The logic behind the other two rules is the same as Rule 1.

Using Regular Expressions to Delete Specific Digits

One of the company locations in Maryland, USA has a legacy PBX with a few users connected to it. Users in other company sites dial a site code of 758 to reach this location, and then a seven-digit number. The seven-digit number for PBX users begins with 4445. The PBX was programmed to expect to receive an incoming called number consisting of the site code and the last four digits of the phone number. So you must keep the site code, remove the next three digits (444), and keep the last four digits.

In Example 10-6, voice translation rule 3 accomplishes this by making the site code one set, and the last four numbers another set, but leaving the middle string of 444 out of any sets. It then tells the router to create a string consisting only of the two sets.

Example 10-6 Using Regular Expressions: Deleting Digits

Boise(config)#voice translation-rule 3
Boise(cfg-translation-rule)#rule 1 /^\(758\)444\(5...\)$/ /\1\2/
!
Boise#test voice translation-rule 1 7584445111
Matched with rule 1
Original number: 7584445111   Translated number: 7585111

Breaking the match portion of this rule into its component parts

  • ^\(758\) creates a set that contains the string 758 at the beginning of the digit string. The caret designates the beginning of a string, and the backslashes change the meaning of the parenthesis from literal characters to set delimiters.

  • 444 designates three literal number fours

  • The last four digits are grouped into a second set with \(5...\). This set matches any four digits at the end of the string, if they begin with the number 5. The end of the string is designated with the character $.

Breaking the replacement part of the rule into its component parts

  • In the expression \1, the backslash changes the number 1 from a literal character. In the translated number, it is replaced with the contents of the first set—758.

  • The expression \2 points to the second set. In the translated number, it is replaced with the contents of the second set—in this example, the string 5111.

Using Regular Expressions with Sets and Replacement Digits

Notice that in Example 10-6, the middle string of 444 is not included in the replacement pattern. Suppose that the rule is changed to include a replacement for that string, as shown in Example 10-7. Now the translated number matches those three fours and replaces them with three sevens.

Example 10-7 Using Regular Expressions: Digit Replacement Using Sets

Boise(config)#voice translation-rule 4
Boise(cfg-translation-rule)#rule 1 /^\(758\)444\(5...\)$/ /\1777\2/
Boise#test voice translation-rule 4 7584445111
Matched with rule 1
Original number: 7584445111   Translated number: 7587775111

Breaking the match portion of this rule into its component parts

  • ^\(758\) creates a set that contains the string 758 at the beginning of the digit string. The caret designates the beginning of a string, and the backslashes change the meaning of the parenthesis from literal characters to set delimiters.

  • 444 designates three literal number fours.

  • The last four digits are grouped into a second set with \(5...\). This set matches any four digits at the end of the string, if they begin with the number 5. The end of the string is designated with the character $.

The replacement part of this equation can look confusing because there is no visual break between its three components, so it is important to understand how the router interprets it. Breaking the replacement part of the rule into its component parts

  • In the expression \1, the backslash changes the number 1 from a literal character. In the translated number, it is replaced with the contents of the first set—758.

  • The next three digits, 777, are a literal replacement for 444.

  • The expression \2 points to the second set. In the translated number, it is replaced with the contents of the second set—in this example, the string 5111.

Using Regular Expressions to Change the Call Type or Numbering Plan

You can also match and replace the type of call, such as national or international, and the numbering plan, such as ISDN or national. For instance, the commands in Example 10-8 replace the string 011 with 1 and change the call type from international to national.

Example 10-8 Using Regular Expressions: Changing the Call Type and Numbering Plan

Boise(config)#voice translation-rule 4
Boise(cfg-translation-rule)#rule 1 /^011/ /1/ type international national plan isdn national
!
Boise#test voice translation-rule 4 0115551212 type international plan isdn 
Matched with rule 1
Original number: 0115551212   Translated number: 15551212
Original number type: international   Translated number type: national
Original number plan: isdn   Translated number plan: national

In this example, the match and replacement expressions follow a slightly different pattern. This expression has three components:

  • In the first component, /^011/ /1/, the number 011 at the beginning of the string is replaced with the number 1.

  • The second component, type international national, replaces the numbering type international with national.

  • The third component, plan isdn national, replaces a numbering plan of isdn with a national numbering plan.

For a call to be matched by a rule, it must fulfill all the conditions. In this case, the call must begin with 011, have a type value of international, and have a plan value of isdn. If any of these values is not matched, this rule will not process the call.

Creating Voice Translation Profiles

Voice translation rules are associated with voice translation profiles. Using a voice translation profile gives you flexibility and scalability by allowing the use of multiple voice translation rules. You can apply voice translation rules to called numbers, calling numbers, and redirected numbers in the same profile. A voice translation profile is typically associated with a dial peer, a voice port, a trunk group, or all VoIP calls globally.

Create a translation profile and enter profile configuration mode with the command voice translation-profile name. Then specify what type of number will be translated, and the rule to apply to that number. Example 10-9 shows a sample translation profile.

Example 10-9 Creating a Translation Profile

Boise(config)#voice translation-profile TEST
Boise(cfg-translation-profile)#translate ?
 called      Translation rule for the called-number
 calling     Translation rule for the calling-number
 redirect-called Translation rule for the redirect-number 
!
Boise(cfg-translation-profile)#translate called 2 
Boise(cfg-translation-profile)#translate calling 3
Boise(cfg-translation-profile)#translate redirect-called 1

In Example 10-9, translation Rule 2 is applied to called numbers, translation Rule 3 is applied to calling numbers, and translation Rule 1 is applied to redirecting numbers. You can apply the same translation rule to each type of number, if appropriate.

Applying Voice Translation Profiles

After you create a voice translation profile, you can assign it to a dial peer, a voice port, a trunk group, or all VoIP calls globally. Where the voice translation profile is applied affects the matching of inbound and outbound dial peers. A profile that is applied to a voice port is carried out before the inbound dial peer is matched. A profile that is applied to an inbound dial peer is carried out before the outbound dial peer is matched. A profile that is applied to an outbound dial peer is carried out before the call is transmitted. Be sure to take this into consideration when placing your voice profiles and configuring your dial peers.

Related:
1 2 3 4 Page 2
Page 2 of 4
The 10 most powerful companies in enterprise networking 2022