Inbound Calls on Trunk

From Pbxnsip Wiki

Jump to: navigation, search

Contents

How the PBX identifies the trunk

When a new call is requested from the PBX, it must find out if the call is being initiated from a known extension or from a trunk. It does this in the following way:

  • If the Request-URI contains the line parameter, it is clear which trunk is called. The line parameter is set by the PBX when the trunk is registered. The support of the line parameter must be supported by RFC-compliant components. Most SIP devices today are RFC compliant, so that you usually do not have a problem if the parameter is present. However, for gateways and proxies this method is not possible, therefore the PBX must continue searching the trunk if the line parameter is not present.
  • The PBX determines to which IP addresses and ports a trunk may send requests. This is done by a recursive DNS-resolution of the outbound proxy of that trunk. The outbound proxy is used as "inbound proxy" as well. The PBX then tries to find trunks with the following priority:
    • The incoming call matches a domain name of the trunk and a IP address and port of the outbound proxy of that trunk
    • The incoming call matches a domain name of the trunk and a IP address of the outbound proxy of that trunk
    • The incoming call matches a IP address and port of the outbound proxy of that trunk
    • The incoming call matches a IP address of the outbound proxy of that trunk
    • The incoming call matches a domain name of the trunk

The domain name "localhost" matches any domain name presented in the Request-URI, as usual.

If the From-header identifies a extension on the PBX, the trunk identification will be cancelled and the PBX assumes that the call comes from that extension, no matter if the extension is registered on the perceived IP address or not.

Please note that this way of "inbound proxy" is a kind of IP-based authentication of requests. If you are using UDP, there is a inherent risk that someone is spoofing the IP address of the PSTN gateway. In order to avoid this, you can use TCP or even TLS transport layer.

How the PBX identifies the extension

After the trunk has been identified, the PBX must determine where to send the call inside the domain. For this purpose, the PBX uses the setting "Extension" in the trunk. The PBX writes a log with the message "Trunk sends call to ..." into the log file (log level 5). There are two modes for this job. The simple mode just looks the extension up and the extended mode uses patterns to identify the destination.

Simple Mode

In the simple mode, the extension is just the user-part of the Request-URI. For example, if you want to send all calls on this trunk to a specific auto attendant, just put the name of the account into the extension setting.

If you set tel: alias to an account, you can easily set up the necessary information to map an extension to a DID. For example, an extension might have a primary name of "123" and an alias name of "tel:8124353423".

Extended Mode

In the extended mode, the extension setting must consist of the following four parts in the form <delimiter> <pattern> <delimiter> <replacement> [ <delimiter> [ <flag> [ <delimiter> [ <default> ]]]] (for example, ![0-9]{7}([0-9]{3})!\1!). The parts must be separated by any unique character which is not used elsewhere in the setting string (for example, an exclamation mark).

  • The "pattern" is an extended regular expression which is matched against the user part of the Request-URI (or the To-header if you use the t flag below). This pattern uses the same mechanism as the dial plan.
  • The "replacement" tells the PBX which extension to dial. It also uses the same mechanism as the dial plan. Typically it will reference matches from the pattern with \1.
  • The flag tells the PBX weather to look into the Request-URI ("u") or into the To-header ("t"). The default is "u". Some Internet service providers provide the destination information in the To-header, although SIP recommends to use the Request-URI. Please note that you cannot just put two delimiters without anything in between, therefore if you want to specify a default you must use either the "u" or the "t".
  • If the PBX cannot find the extension, you may specify a default extension. This extension must exist and it will be chosen in case that the replacement pattern does not produce an existing extension.

Please note that you may have more than one expression. The PBX will try to match the expressions until it finds a match. If no match is being found, the default extension of the last pattern will be used.

Locating Global Extensions

After the extension was identified, the PBX might find out that the extension is actually in a different domain that the trunk is. This can happen if the extension has a tel: name. In this case the call will be taken into the destination's extensions domain.

Examples

  • The first example is common in Europe. You want to strip the main number of the PBX and use the remaining numbers to identify the extension. If the extension is not found, you send it to the auto attendant. The example assumes that the number starts with 7 digits (e.g. 0228123) and that the auto attendant is located at 100: "![0-9]{7}([0-9]*)!\1!t!100".
  • The second example always uses the last 4 digits of the number, no matter how long it is: "!([0-9]{4}$)!\1!t!100". This example assumes that the number of digits is always the same.
  • In a typical US office, you send all calls to an auto attendant. Then the value for the extension is very simple: Just use the string "100" if the auto attendant is located on account 100.
  • If you are using tel: alias names for accounts, you can leave the Extension field just empty and just match the DID number to a tel: alias.
  • To strip the first digit from a DID number, you can use the pattern "!1([0-9]*)!\1!u!100" (default destination would be 100).
Personal tools
Getting Help