# SIP Trunk Routing by DID

Incoming SIP calls are addressed to a SIP username, commonly a Direct Inward Dialing (DID) telephone number. MBG can be configured to map the username (or portion of the username) to a specific ICP (MiVoice Business, MiVoice Office 250, MiVoice MX-One or MiVoice Office 400). Usernames can be obtained from URLs found in the "Request", "From", and "To" header fields of incoming SIP messages.

Example

A central data center (CenData) has three geographically remote locations that each have one ICP.

CenData programs their MBG server to perform call routing based on the called number, caller number and original target number:

- Called Number: When a match is made on the called number contained in the "Request" header, the call is routed to the appropriate ICP. In this example, ICP1 in Ottawa handles calls destined for area code 613. ICP2 in Vancouver handles calls for 604, and ICP3 in New York handles calls for 212. Their trunk service provider, SipCo, provides the DID numbers.
- Caller Number: When a match is made on the caller's number contained in the "From" header, the call is routed accordingly. In this example, the service provider routes calls from mobile phones originating in area code 819 to ICP1. This is useful when the service provider wants to route customer calls though a PBX, enabling the customers to dial office extensions from their mobile phones. It can also be used to route callers based on their anticipated language needs. For example, you create a rule that routes Puerto Rican callers to an ICP with Spanish-speaking call center agents.
- Original Target Number: When a match is made on the address-of-record contained in the "To" header, the call is routed accordingly. This enables you to direct calls based on the original called number, before call forwarding has been applied. For example, you have two data centers, A and B, where B is the backup for A and both data centers have their own DID number. If A goes offline, the service provider will reroute A's calls to B and modify the "Request" header so that it contains B's DID number and a different ICP. Provided that the service provider has left "To" header untouched, you can employ a routing rule to direct the call to its originally intended destination in data center A.

Using MBG Routing Rule configuration, calls for SIP usernames that begin with 613 or from SIP usernames that begin with 819 are routed to ICP1 in Ottawa. Calls for SIP usernames that begin with 604 are routed to ICP2 in New York, and calls for SIP usernames that begin with 212 are routed to ICP3 in Vancouver.Calls that do not match any of the first four rules will use rule 5 which directs all non-matching calls to ICP4. There is no secondary ICP for this rule.

## Managing DID Routing Rules for a SIP Trunk

Adding a Rule

You can add DID routing rules at the same time that you create a new SIP trunk, or you can add them to existing trunks.

To add a DID routing rule:

1. On the MBG main page, click the SIP trunkingtab and click Configuration.
2. In the trunk list, click to modify an existing trunk or to add a new trunk.
3. In the lower section of the screen, locate the place where you wish to add the new rule. Use the following tools to sort through the list:
   - Rules per page: Specify the number of rules displayed on the page, from 10 to 1000.
   - Jump to page: If there are multiple pages of rules, select the page you wish to view.

     Note: If the SIP Trunk does not yet have any rules, a single unprogrammed rule will be listed by default.

4. To add the new rule, click beside an existing rule. A new rule will be added directly below the existing rule.
5. Specify the rule parameters:
   - Match: Select the match criteria: Request URI, From header URI, or To header URI.
   - Rule: Enter the rule, making sure to adhere to the format outlined below.
   - Primary: Select the primary ICP to route the call.
   - Secondary: Select the secondary ICP to route the call (if applicable).
   - Description: Type a description of the rule (optional entry).
6. After you have specified the rule parameters, you can do the following:
   - To move the rule up the list, click .
   - To move the rule down the list, click .
7. Click Save.

Editing a Rule

You can move a DID routing rule forward or backward in order to adjust its precedence in the list. You can also modify the rule parameters or delete it altogether.

To edit a DID routing rule:

1. On the MBG main page, click the SIP trunking tab and click Configuration.
2. In the trunk list, locate the trunk you wish to edit and click .
3. In the lower section of the screen, use the following tools to sort through the list of rules:
   - Rules per page:Specify the number of rules displayed on the page, from 10 to 1000.
   - Jump to page: If there are multiple pages of rules, select the page you wish to view.

4. After locating the rule you wish to edit, you can do the following:

   1. To modify the rule parameters, select and change any of the following: Match, Rule, Primary, Secondary, Description.
   2. To move the rule up the list, click .
   3. To move the rule down the list, click .
   4. To delete the rule, click .

5. Click Save.

Rule Format

The routing rule format is a case-sensitive string of 0-9, +, -, _, *, N, or X characters. In effect, you are programming a "mask" to apply to the username in the SIP request to check for a match. If the SIP request is successfully matched with a routing rule, the call follows the corresponding ICP routing. SIP requests with unsuccessful matches continue through the list of rules until a match is found.

Pattern matching is exact. The rule and the dialed number must be the same length and each character in the dialed number must match the character in the rule. (For example, 6135925660" does not match "613 5925660" or "613-592-5660".) An "X" in the pattern will match any single character at that position in the dialed number. An "N" will match any single character at that position from 2-9.

Rule Characters

- X refers to any character from 0 through 9
- N refers to any character from 2 through 9
- + refers to the literal "plus" character that may be used in European telephone numbers
- - a routing rule consisting of a single "-" character allows the selected ICPs to make outgoing trunk calls, but since this pattern will never match an actual call, no incoming calls will be routed to those ICPs. When used in conjunction with other digits to make a pattern, "-" refers to the literal "dash" character.
- _ refers to the literal underscore character
- * a routing rule consisting of a single "*" character allows any pattern to match. Note: For effective pattern matching, make sure this type of rule is the final rule in your list, otherwise some patterns will never be checked. When used in conjunction with other digits to make a pattern, it refers to the literal "star" character.

Rule Examples

- A routing rule of "613NXXXXXX" matches any 10-digit phone number that starts with "613". When a call is received with a DID number (or SIP username) that matches this pattern, it is sent to the ICP that is configured in this rule.
- A routing rule of "613592XXXX" narrows the matches to any 10-digit phone number that begins with "613592".
- A routing rule of "613-592-XXXX" matches any 10-digit number that begins with "613-592-".
- A routing rule of "*" matches any number.