Page MenuHomePhabricator

Routes: PBX or Trunk
AG Projects RTC Platforms (Routing Guides)

This guide describes SIP routing for calls from and to a PBX or a SIP trunk.

The terms PBX and SIP trunk are interchangeable and are further called as PBX.

The platform uses internally the term Trusted peer. So a Trusted Peer defined in the platform represents a remote PBX or a Trunk.

PBX to PBX

book-general-sip-platform-flow-pbx-a-pbx-b (387×637 px, 37 KB)

The PBX has its own accounts and connected devices. Requests originating from a PBX cannot be therefore authorized based on username/password combinations as they are not provisioned in the platform's subscriber database, they are locally managed by the PBX owner. The traffic generated by the PBX can be only identified by its source IP address(es) or its MS Teams domain, when originating from Microsoft gateways.

To allow traffic from a PBX, the platform uses the concept of trusted peers.

A trusted peer is an entity that is allowed to route SIP calls through the platform without digest authorization, that is used for local users belonging to local domains. Beware that, no checks are done by the proxy related to the incoming caller identity, as long as the SIP sessions originate from a trusted peer. Once you trust a peer, you trust all traffic generated by it. Optionally, you can perform various checks for trusted peers by adding confitions to the custom configuration handle-incoming-pstn.m4 (described later in this document)

AuthenticationNone
AuthorizationTrusted peer A
Caller IdSupplied by trusted peer A
Billing partyTrusted peer A
AccountingPostpaid
Number formatsE.164, 00.., 0.
Media typesRTP (audio, video), T.38 Fax, SIP MESSAGE
Address resolutionENUM
From headerMust contain a non-local SIP domain
Fraud ControlSimultaneous call limit
  • The domain name used by the PBX in the From field must be different than any domain served by the SIP Proxy otherwise the Proxy will challenge the session for credentials as it does for any other locally registered SIP account.
  • To route incoming traffic for a number block assigned to the PBX, create ENUM entries that point to the hostname (or IP address) of the PBX.

PBX to PSTN

book-general-sip-platform-flow-pbx-a-pstn (387×637 px, 47 KB)

To allow high call per second ratios for call centers or other high density traffic, many checks related to individual accounts are disabled when using trusted peers. Access Lists, Pike flood detection, quota checks are disabled.

AuthenticationBased on source IP address
AuthorizationPSTN transit
Caller IdSupplied by trusted peer
Billing partyIP address
AccountingPostpaid only
Number formatsE.164, 00., 0.
Media typesRTP (audio, video), T.38 Fax
Address resolutionENUM, LCR, Custom SIP Proxy logic
From headerMust contain a non-local SIP domain
Request URIMust contain a local SIP domain
Fraud controlSimultaneous call limit

Routing

To allow transiting the proxy, handle-incoming-pstn.m4 configuration file is configured by default with this logic (your particular platform configuration may differ):

sample-handle-incoming-pstn.m4
if (FROM_TRUSTED_PARTY) {
    DINFO("Call from trusted party");

    $var(need_transit) = 0;
    if (uri =~ "^sip:PSTN_REGEXP@.*") {
        $rd = "SERVER_DOMAIN";
        strip(2);
        prefix("+");
        set_billing_party();
        DINFO("Performing ENUM lookup");
        route(__ENUM_LOOKUP);
        if ($retcode==-1) {
            DINFO("ENUM number not found. PSTN transit");
            revert_uri();
            $var(need_transit) = 1;
        }
    } else if (uri =~ "^sip:LOCAL_PSTN_REGEXP@.*") {
        $rd = "SERVER_DOMAIN";
        strip(1);
        prefix("+COUNTRY_CODE");
        set_billing_party();
        DINFO("Performing ENUM lookup");
        route(__ENUM_LOOKUP);
        if ($retcode==-1) {
            DINFO("ENUM number not found. PSTN transit");
            revert_uri();
            $var(need_transit) = 1;
        }
    } else if (uri =~ "^sip:COUNTRY_CODE[1-9][0-9]{4,}@.*") {
        $rd = "SERVER_DOMAIN";
        prefix("+");
        set_billing_party();
        DINFO("Performing ENUM lookup");
        route(__ENUM_LOOKUP);
        if ($retcode==-1) {
            DINFO("ENUM number not found. PSTN transit");
            revert_uri();
            $var(need_transit) = 1;
        }
    } else if (uri =~ "^sip:\+[0-9]{7,}@.*") {
        $rd = "SERVER_DOMAIN";
        set_billing_party();
        DINFO("Performing ENUM lookup");
        route(__ENUM_LOOKUP);
        if ($retcode==-1) {
            DINFO("ENUM number not found. PSTN transit");
            strip(1);
            prefix("00");
            $var(need_transit) = 1;
        }
    }

    if ($var(need_transit) == 1 && !FROM_PSTN_GATEWAY) {
        DINFO("Transit call from trusted peer $si");
        route(__PSTN_TRANSIT);
        exit;
    }

    # Check if it's a local user
    if (!is_uri_host_local()) {
        set_billing_party();
        setflag(ACCOUNTING_FLAG);
        $avp(can_uri) = $ru;
        t_on_reply("__INVITE_REPLY");
        if (!isflagset(NO_MEDIAPROXY_FLAG)) {
            DINFO("Engaging mediaproxy for SIP transit call");
            engage_media_proxy();
        }
        $avp(invite_timeout) = OUTGOING_TIMEOUT;
        DINFO("Set timeout to OUTGOING_TIMEOUT");
        route(__SEND_OUT);
        exit;
    }
}

Provisioning

The IP address(es) of the PBX must be added in the trusted table using the SOAP/XML provisioning API. See Provisioning: Trusted Peers

The domain name used by the PBX in the From field must be different than any domain served by the SIP Proxy otherwise the Proxy will challenge the session for credentials as it does for any other local served SIP account.

Phone Numbers

ENUM can be used to assign phone numbers to a particular PBX. The proxy queries two ENUM Top Level Domains. The second ENUM Top Level Domain is used for MS Teams interconnect.

See Provisioning: ENUM chapter for how to map telephone numbers to SIP addresses.

Rating

To rate the traffic generated by trusted peers identified by IP address you must add a rating plan in CDRTool rating engine by using the source IP address of the PBX as the gateway field in the rating customers table.

See Rating: Assignment

Beware that no automatic quota can be imposed on the traffic generated by a trusted peer.

Caller Id

Traffic generated by the trusted peers and any header thereof containing caller id indication is also trusted. When allowing traffic to transit from PBXs to PSTN gateways connected to the proxy, make sure that the way caller ID indication is provided by the trusted party is compatible with what the PSTN gateway expects.

Trusted peers, as their name imply, are allowed to set Caller Id information and Privacy headers, by default the SIP Proxy will not check nor enforce them from Trusted peers. If such checks are desired one must modify handle-incoming-pstn.m4 configuration file.

Number formats

To avoid adding specific rewriting rules, that require the restart of the SIP Proxy, ask the PBX owner to send the numbers formated in E.164 format or starting with 00 prefix insetad of +. If properly configured, local numbers starting with one 0 may also work.

E.164 format: [+][country code][area code][local phone number]

Next Steps

Continue by: