Routing guide

Version 26 (Tijmen de Mes, 07/04/2013 04:31 pm)

1 5 Tijmen de Mes
h1. Routing Guide
2 5 Tijmen de Mes
3 20 Adrian Georgescu
MSP and SIP Thor platforms are based on a SIP Proxy/Registrar/Presence Agent design. Each SIP server node maintains transaction and dialog state for each session and is able to terminate each of them based on various criteria. The platform handles and controls the RTP and MSRP media planes and is able to take decisions related to authorization, authentication, accounting, NAT traversal and session termination based on the media flow behavior. The design eliminates the need of separate session border controller elements which just add costs, hurt scalability and add no end-user features.  
4 1 Tijmen de Mes
5 12 Adrian Georgescu
The platform has rich telephony functions equivalent with traditional Class 4 switches (routing inter-carrier calls) and Class 5 switches (routing last-mile calls to end-users).
6 1 Tijmen de Mes
7 12 Adrian Georgescu
The platform can be equally used to perform SIP services that include and are not limited to Residential VoIP, Prepaid Cards, Video Calling, Presence and IM, Trunking, Least Cost Routing and ENUM Peering.
8 1 Tijmen de Mes
9 4 Tijmen de Mes
h2. Logical Architecture
10 2 Tijmen de Mes
11 6 Tijmen de Mes
!msp-interconnect.png!
12 2 Tijmen de Mes
13 1 Tijmen de Mes
h2. SIP Entities
14 1 Tijmen de Mes
15 2 Tijmen de Mes
This document describes routing logic between several SIP entities defined as follows:
16 2 Tijmen de Mes
17 4 Tijmen de Mes
# SIP Proxy: the platform core that performs the logic described in this document
18 4 Tijmen de Mes
# End-Point: a SIP end-user device that is configured with the credentials of a SIP account for which the platform is responsable
19 4 Tijmen de Mes
# PBX: a SIP end-point or intermediary that is configured under a foreign SIP domain not handled by the platform
20 4 Tijmen de Mes
# PSTN gateway: a SIP end-point or intermediary that is handling the translation between IP (using SIP protocol) and PSTN networks
21 1 Tijmen de Mes
22 4 Tijmen de Mes
h2. Supported Signaling
23 3 Tijmen de Mes
24 20 Adrian Georgescu
The platform supports SIP protocol over UDP/TCP/TLS transports. Additional, a gateway to and from XMPP remote domains can be configured. 
25 2 Tijmen de Mes
26 3 Tijmen de Mes
h2. Supported Media
27 2 Tijmen de Mes
28 2 Tijmen de Mes
The platform supports sessions containing the following media types:
29 1 Tijmen de Mes
30 4 Tijmen de Mes
* Audio (RTP and sRTP)
31 4 Tijmen de Mes
* Video (RTP and sRTP)
32 4 Tijmen de Mes
* FAX (RTP and T.38)
33 4 Tijmen de Mes
* Instant messaging (MSRP and its relay extension)
34 4 Tijmen de Mes
* File transfer (MSRP and its relay extension)
35 4 Tijmen de Mes
* Page mode messaging (SIP MESSAGE method)
36 22 Adrian Georgescu
* Presence (PIDF XML)
37 2 Tijmen de Mes
38 4 Tijmen de Mes
The platform is codec agnostic, the negotiation of the codecs depends entirely on the end-points. The MediaProxy component that relays the RTP media between the end-points, for NAT traversal and accounting purposes, relays all packets at IP layer 3 (UDP protocol that encapsulates the RTP/RTCP streams). The actual payload with the particular codecs used inside the RTP streams is transparently passed between end-points without interference from MediaProxy.
39 2 Tijmen de Mes
40 1 Tijmen de Mes
Other payloads are supported as long as they are embedded into a supported stream, for example any payload that is embedded within the RTP streams (zRTP, DTMF tones) or MSRP streams (file transfer, multy-party chat service, desktop sharing).
41 1 Tijmen de Mes
42 2 Tijmen de Mes
h2. Primitives
43 2 Tijmen de Mes
44 3 Tijmen de Mes
The routing of SIP sessions is governed by two main protocols:
45 2 Tijmen de Mes
46 4 Tijmen de Mes
# Domain based SIP routing based on RFC3261 and RFC3263
47 4 Tijmen de Mes
# ENUM lookups based on RFC3761
48 2 Tijmen de Mes
49 2 Tijmen de Mes
The routing logic of the platform can be configured by changing its database tables and configuration files. The primitives used for routing are:
50 2 Tijmen de Mes
51 2 Tijmen de Mes
52 4 Tijmen de Mes
|Registrar database|Used to translate a SIP address into a SIP contact address|
53 4 Tijmen de Mes
|ENUM|Used to translate an E.164 telephone number into a SIP address|
54 4 Tijmen de Mes
|SIP alias|Used for adding aliases to existing SIP accounts|
55 4 Tijmen de Mes
|Emergency numbers|Translation between 911 and 112 into closest emergency access points|
56 4 Tijmen de Mes
|Call diversion|Translate a SIP address into another based on signaling conditions or end-user preferences|
57 1 Tijmen de Mes
|DNS lookups|Translate a SIP domain/hostname into an protocol:IP:port combination|
58 22 Adrian Georgescu
|LCR|Used for selection of outgoing PSTN gateway|
59 2 Tijmen de Mes
60 2 Tijmen de Mes
61 4 Tijmen de Mes
h2. Server Location
62 1 Tijmen de Mes
63 4 Tijmen de Mes
To locate the SIP Proxy/Registrar for a domain, SIP endpoints must perform DNS lookups based on RFC3263 that return the IP:port combination for which the server is configured.
64 1 Tijmen de Mes
65 4 Tijmen de Mes
h2. Configuration Files
66 1 Tijmen de Mes
67 4 Tijmen de Mes
Index of SIP Proxy configuration files located in/etc/opensips/:
68 2 Tijmen de Mes
69 4 Tijmen de Mes
70 4 Tijmen de Mes
|config/settings.m4|Contains the settings that can customize the routing logic|
71 4 Tijmen de Mes
|config/opensips.m4|Contains the proxy routing logic (should not be modified)|
72 4 Tijmen de Mes
|config/siteconfig/handle-incoming-pstn.m4|Used to customize routing logic for incoming PSTN calls|
73 4 Tijmen de Mes
|config/siteconfig/handle-local-extensions.m4|Used to define installation specific custom local extensions|
74 4 Tijmen de Mes
|config/siteconfig/handle-outgoing-peers.m4|Used to customize routing for outgoing calls to non-local domains|
75 4 Tijmen de Mes
|config/siteconfig/postprocess-request.m4|Used to customize outgoing requests before they leave the proxy|
76 4 Tijmen de Mes
|config/siteconfig/preprocess-pstn.m4|Used to customize outgoing PSTN requests before applying LCR routing|
77 4 Tijmen de Mes
|config/siteconfig/preprocess-request.m4|Used to apply custom pre-processing to a request before anything else|
78 4 Tijmen de Mes
|config/siteconfig/preprocess-uri.m4|Used to apply custom pre-processing to the request URI before converting to E164|
79 4 Tijmen de Mes
80 4 Tijmen de Mes
81 4 Tijmen de Mes
The settings.m4 file is used to customize the existing routing logic defined in opensips.m4 using the predefined routing options. 
82 4 Tijmen de Mes
 The files under the siteconfig/ directory can contain installation specific routing logic, which will be included by opensips.m4 and will allow for the routing logic to be adapted to the specific requirements of a given installation. The opensips.m4 file will always be overwritten on upgrades, so it should never be modified, while the files under the siteconfig/ directory will never be overwritten and can be modified without restrictions.
83 4 Tijmen de Mes
84 2 Tijmen de Mes
h2. NAT Traversal
85 1 Tijmen de Mes
86 4 Tijmen de Mes
NAT traversal methods encountered in the field and their properties:
87 1 Tijmen de Mes
88 4 Tijmen de Mes
* SIP server based (Relay) - reliable server side technology that works with all SIP clients, this method is used by the platform
89 4 Tijmen de Mes
* SIP client based (ICE) - client and server technology where client may negotiate media paths, is supported by the platform
90 4 Tijmen de Mes
* Intermediates based:
91 4 Tijmen de Mes
** NAT routers with SIP Application Level Gateway (SIP ALG) - located in customer premises network and the most *unreliable* technique
92 4 Tijmen de Mes
** Sessions Border Controllers (SBC) - located in service provider network - reliable with high cost and high complexity
93 1 Tijmen de Mes
94 4 Tijmen de Mes
The most reliable way to solve NAT issues with SIP is server based, by relaying packets using servers visible by both end-points. A new methodology under development is ICE, which relies partially on the SIP clients. NAT traversal applied in intermediates only introduce problems and SBCs add costs without adding value to the SIP service.
95 2 Tijmen de Mes
96 2 Tijmen de Mes
Below is a display of all possible NAT traversal techinques used for SIP and related media.
97 2 Tijmen de Mes
98 6 Tijmen de Mes
!nat-traversal-techniques.png!
99 1 Tijmen de Mes
100 4 Tijmen de Mes
The platform handles the NAT traversal for all its end-points by relaying all traffic, signaling and media through its servers that have public IP address and are visible for both end-points involved in a call flow.
101 2 Tijmen de Mes
102 4 Tijmen de Mes
Optional, "ICE can be deployed":http://mediaproxy-ng.org/wiki/ICE when supported by the end-points. The media relay acts like a TURN candidate and the operator may choose on a per call basis when and how this relay is to be used. When using ICE, SIP sessions that do not have a BYE cannot be accounted for.
103 2 Tijmen de Mes
104 4 Tijmen de Mes
NAT traversal is not the same thing as Firewall traversal. A firewall has an administrative policy, which must be set to support SIP and associated media traffic.
105 2 Tijmen de Mes
106 1 Tijmen de Mes
h3. Platform Ports
107 1 Tijmen de Mes
108 4 Tijmen de Mes
See the Firewall Setup section for a list of ports used by the platform software.
109 1 Tijmen de Mes
110 4 Tijmen de Mes
bq. Make sure that NAT traversal functions related to SIP known as SIP ALG functionality in the NAT routers are disabled.
111 1 Tijmen de Mes
112 4 Tijmen de Mes
113 4 Tijmen de Mes
114 1 Tijmen de Mes
h2. AAA
115 1 Tijmen de Mes
116 1 Tijmen de Mes
Authentication, Authorization and Accounting are performed depending on particular call flows as follows:
117 1 Tijmen de Mes
118 4 Tijmen de Mes
h3. Authentication
119 1 Tijmen de Mes
120 4 Tijmen de Mes
The trust relationship between SIP subscribers and SIP Proxy is based on DIGEST algorithm, both have a database with shared credentials.
121 1 Tijmen de Mes
122 4 Tijmen de Mes
h4. Sessions
123 4 Tijmen de Mes
124 1 Tijmen de Mes
Authentication for INVITE requests based on two methods:
125 2 Tijmen de Mes
126 4 Tijmen de Mes
# *SIP credentials*, when the From header contains a domain served by the platform. The From header presented by the device must match the credentials used for authentication.
127 4 Tijmen de Mes
# *Trusted peer* identified by IP address, used when the From header contains a remote domain and the request URI is not a local SIP address.
128 1 Tijmen de Mes
129 4 Tijmen de Mes
By default, incoming SIP sessions from remote domains to local SIP accounts served by the platform are not authenticated and always authorized.
130 1 Tijmen de Mes
131 1 Tijmen de Mes
For Instant Messaging and File transfers, MSRP relay reservations are authenticated using the same credentials for each SIP account.
132 1 Tijmen de Mes
133 4 Tijmen de Mes
h4. Register
134 1 Tijmen de Mes
135 1 Tijmen de Mes
Authentication for REGISTER methods is based on SIP credentials, this method can be used only by local SIP accounts and will not be relayed outside the platform. The From header presented by the SIP device must match the credentials used for authentication.
136 2 Tijmen de Mes
137 2 Tijmen de Mes
h4. Presence
138 1 Tijmen de Mes
139 1 Tijmen de Mes
The platform provides a Presence Agent that handles PUBLISH, SUBSCRIBE and NOTIFY methods based on SIP SIMPLE standards. The following event packages are supported:
140 1 Tijmen de Mes
141 4 Tijmen de Mes
* presence
142 4 Tijmen de Mes
* presence.winfo
143 19 Adrian Georgescu
* xcap-diff
144 1 Tijmen de Mes
145 4 Tijmen de Mes
Authentication for PUBLISH is based on SIP credentials, this methods can be used only by local SIP accounts and will not be relayed outside the platform. The From header presented by the SIP device must match the credentials used for authentication. Authentication for SUBSCRIBE requests are based on SIP credentials, when the From header contains a domain served by the SIP Proxy.
146 1 Tijmen de Mes
147 4 Tijmen de Mes
SUBSCRIBE requests from remote domains are allowed without authentication when the request URI is a local SIP address served by the platform.
148 1 Tijmen de Mes
149 1 Tijmen de Mes
SUBSCRIBE for the events message-summary and presence.winfo are allowed only for local users.
150 1 Tijmen de Mes
151 2 Tijmen de Mes
XCAP requests are authenticated using the same credentials for each SIP account.
152 1 Tijmen de Mes
153 1 Tijmen de Mes
The following XCAP documents are supported:
154 1 Tijmen de Mes
155 13 Adrian Georgescu
http://www.openxcap.org/projects/openxcap/wiki/Features
156 2 Tijmen de Mes
157 4 Tijmen de Mes
h3. Authorization
158 1 Tijmen de Mes
159 4 Tijmen de Mes
h4. Sessions
160 2 Tijmen de Mes
161 2 Tijmen de Mes
Authorization for outgoing SIP sessions can be performed for local SIP accounts based on:
162 1 Tijmen de Mes
163 4 Tijmen de Mes
# Access to PSTN
164 4 Tijmen de Mes
# Administrative blocking
165 4 Tijmen de Mes
# Monthly quota usage
166 4 Tijmen de Mes
# Prepaid balance
167 14 Adrian Georgescu
# Concurrent number of calls
168 4 Tijmen de Mes
# Call barring (user driven)
169 4 Tijmen de Mes
# Custom SIP Proxy logic
170 1 Tijmen de Mes
171 2 Tijmen de Mes
Authorization for incoming SIP sessions can be performed for local SIP accounts based on:
172 2 Tijmen de Mes
173 14 Adrian Georgescu
# Source IP address
174 4 Tijmen de Mes
# Administrative blocking
175 4 Tijmen de Mes
# Accept based on caller
176 4 Tijmen de Mes
# Accept based on time of day
177 4 Tijmen de Mes
# Reject based on caller id
178 4 Tijmen de Mes
# Custom SIP Proxy logic
179 1 Tijmen de Mes
180 1 Tijmen de Mes
Automatic session cut-off
181 1 Tijmen de Mes
182 1 Tijmen de Mes
SIP sessions can be terminated forcefully by the platform based on the following conditions:
183 1 Tijmen de Mes
184 4 Tijmen de Mes
# Prepaid balance exceeded (in real time)
185 4 Tijmen de Mes
# Monthly quota exceeded (on the next call)
186 4 Tijmen de Mes
# Maximum call duration exceeded
187 4 Tijmen de Mes
# RTP media timeout
188 14 Adrian Georgescu
# Signaling path lost
189 14 Adrian Georgescu
190 1 Tijmen de Mes
191 4 Tijmen de Mes
h4. Presence
192 1 Tijmen de Mes
193 2 Tijmen de Mes
Authorization for SUBSCRIBE for the presence event can be performed for local SIP accounts based on:
194 2 Tijmen de Mes
195 4 Tijmen de Mes
# XCAP pres-rules document
196 4 Tijmen de Mes
# Trusted peers
197 2 Tijmen de Mes
198 2 Tijmen de Mes
199 2 Tijmen de Mes
200 4 Tijmen de Mes
h3. Accounting
201 2 Tijmen de Mes
202 4 Tijmen de Mes
All SIP and RTP sessions are accounted by using RADIUS requests. See "accounting guide for more information":/wiki/AccountingGuide.
203 1 Tijmen de Mes
204 4 Tijmen de Mes
h2. End-Point to End-Point
205 1 Tijmen de Mes
206 7 Tijmen de Mes
!flow-sip-phone-a-b.png!
207 4 Tijmen de Mes
208 4 Tijmen de Mes
209 4 Tijmen de Mes
|Authentication|SIP account A|
210 4 Tijmen de Mes
|Authorization|SIP account A|
211 4 Tijmen de Mes
|Billing party|SIP account A|
212 4 Tijmen de Mes
|Accounting|Postpaid, Prepaid|
213 4 Tijmen de Mes
|Media types|RTP (audio and video), Presence, MSRP (Instant messaging and file transfers)|
214 4 Tijmen de Mes
|Address resolution|SIP address, SIP alias, Quickdial, ENUM|
215 4 Tijmen de Mes
|From header|Must contain a local SIP domain|
216 25 Tijmen de Mes
|Fraud Control | PIKE, ACL | 
217 4 Tijmen de Mes
218 4 Tijmen de Mes
h3. Quick Dial
219 4 Tijmen de Mes
220 1 Tijmen de Mes
Quick dial is a per SIP account feature that allows to dial short numbers to match other SIP accounts in the same number range. The SIP Proxy will try to autocomplete the number to form a full address. To use this feature:
221 1 Tijmen de Mes
222 4 Tijmen de Mes
# The username part of the SIP account must be numeric (example "31208005169@ag-projects.com":mailto:31208005169@ag-projects.com)
223 4 Tijmen de Mes
# The *quickdial* attribute of the SIP account must be set to a substring matching the beginning of the username (e.g. 312080051).
224 4 Tijmen de Mes
# When user dials 60 the example above, the SIP Proxy will concatenate the quickdial set to 312080051 with the dialed number 60 and try "31208005160@ag-projects.com":mailto:31208005160@ag-projects.com as destination.
225 1 Tijmen de Mes
226 4 Tijmen de Mes
h2. End-Point to PBX
227 1 Tijmen de Mes
228 7 Tijmen de Mes
!flow-sip-phone-a-pbx-b.png!
229 1 Tijmen de Mes
230 1 Tijmen de Mes
231 4 Tijmen de Mes
|Authentication|SIP account A|
232 4 Tijmen de Mes
|Authorization|SIP account A|
233 4 Tijmen de Mes
|Caller Id|Asserted by the platform|
234 4 Tijmen de Mes
|Billing party|SIP account A|
235 4 Tijmen de Mes
|Accounting|Postpaid, Prepaid|
236 4 Tijmen de Mes
|Media types|RTP (audio)|
237 4 Tijmen de Mes
|Address resolution|ENUM|
238 4 Tijmen de Mes
|From header|Must contain a local SIP domain|
239 26 Tijmen de Mes
|Fraud Control | PIKE, ACL | 
240 1 Tijmen de Mes
241 4 Tijmen de Mes
h2. PBX to PBX
242 4 Tijmen de Mes
243 7 Tijmen de Mes
!flow-pbx-a-pbx-b.png!
244 4 Tijmen de Mes
245 1 Tijmen de Mes
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 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). To allow traffic from a PBX, the platform uses the concept of trusted peers. A trusted peer is an IP address that is allowed to route SIP calls through the platform without digest authorization. Beware that, no checks are done by the proxy related to the incoming caller identity, as long as the SIP sessions originate from the trusted IP address. Once you trust an IP address, you trust all traffic generated by it.
246 1 Tijmen de Mes
247 1 Tijmen de Mes
248 4 Tijmen de Mes
|Authentication|None|
249 4 Tijmen de Mes
|Authorization|Trusted peer A|
250 4 Tijmen de Mes
|Caller Id|Supplied by trusted peer A|
251 4 Tijmen de Mes
|Billing party|Trusted peer A|
252 4 Tijmen de Mes
|Accounting|Postpaid|
253 4 Tijmen de Mes
|Media types|RTP (audio)|
254 4 Tijmen de Mes
|Address resolution|ENUM|
255 4 Tijmen de Mes
|From header|Must contain a non-local SIP domain|
256 1 Tijmen de Mes
257 2 Tijmen de Mes
258 4 Tijmen de Mes
* 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.
259 4 Tijmen de Mes
* 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.
260 4 Tijmen de Mes
261 4 Tijmen de Mes
h2. End-Point to PSTN
262 4 Tijmen de Mes
263 1 Tijmen de Mes
For interconnection with PSTN, a SIP trunking service must be setup between the SIP Proxy and the PSTN gateway provider. The authorization of SIP requests is based on transitive trust. The SIP Proxy has a trust relationship with each SIP subscriber and the PSTN gateway has a trust relation with the SIP Proxy. The trust relation between the SIP Proxy and the PSTN gateway is based on the IP addresses. The PSTN gateway cannot use DIGEST authentication in the relation with the SIP Proxy because it does not have access to the SIP accounts database of the SIP Proxy.
264 1 Tijmen de Mes
265 4 Tijmen de Mes
h3. PSTN Gateway Requirements
266 2 Tijmen de Mes
267 2 Tijmen de Mes
Must have:
268 2 Tijmen de Mes
269 4 Tijmen de Mes
* SIP signaling based on RFC 3261
270 4 Tijmen de Mes
* DNS lookups based on RFC 3263
271 4 Tijmen de Mes
* Support for SIP extensions for caller id and privacy (P headers)
272 4 Tijmen de Mes
* RTP active mode (send RTP data as soon as call setup is completed)
273 4 Tijmen de Mes
* Use public routable IP addresses for both signaling and media
274 2 Tijmen de Mes
275 2 Tijmen de Mes
Recommended:
276 2 Tijmen de Mes
277 4 Tijmen de Mes
* ENUM lookups based on RFC 3761
278 2 Tijmen de Mes
279 2 Tijmen de Mes
Routing to PSTN destinations is realized by provisioning the PSTN carriers, gateways and routes (also known as Least Cost Routing engine or LCR). The structure of the PSTN provisioning is as follows:
280 2 Tijmen de Mes
281 9 Tijmen de Mes
  Route ->  Carriers -> Gateways -> Rules
282 2 Tijmen de Mes
283 2 Tijmen de Mes
284 4 Tijmen de Mes
For each PSTN prefix (called a PSTN route) a set of carriers can be assigned with an optional priority. Each carrier can have one or more gateways and each gateway can have optional rules for converting the number. For more information see the "provisioning guide":/wiki/ProvisioningGuide.
285 4 Tijmen de Mes
286 2 Tijmen de Mes
Once the SIP request is authenticated, the SIP Proxy authorizes the request based on the rights associated with the subscriber account and decides whether a SIP session to the PSTN gateway is allowed or not. If the session is allowed, the SIP Proxy asserts an identity associated to the SIP account, which can be the telephone number presented as caller ID to the destination, locates a PSTN gateway for the dialed number (by using least cost routing or other configured logic) and forwards the request to the PSTN gateways inserting itself in the path of subsequent messages.
287 2 Tijmen de Mes
288 7 Tijmen de Mes
!flow-sip-phone-a-pstn.png!
289 2 Tijmen de Mes
290 2 Tijmen de Mes
291 4 Tijmen de Mes
|Authentication|SIP account A|
292 4 Tijmen de Mes
|Authorization|SIP account A|
293 4 Tijmen de Mes
|Caller Id|Asserted by the platform|
294 4 Tijmen de Mes
|Billing party|SIP account A|
295 4 Tijmen de Mes
|Accounting|Postpaid, Prepaid|
296 4 Tijmen de Mes
|Media types|RTP (audio)|
297 4 Tijmen de Mes
|Address resolution|ENUM, LCR|
298 2 Tijmen de Mes
|From header|Must contain a local SIP domain|
299 24 Tijmen de Mes
|Fraud Coontrol | PIKE, ACL, Call limit | 
300 2 Tijmen de Mes
301 4 Tijmen de Mes
h3. Caller id indication
302 2 Tijmen de Mes
303 4 Tijmen de Mes
The platform generates a Caller ID indication by appending Remote-Party-Id or P-Asserted identity headers, depending on its configuration. The content of the headers is generated with the SipAccount->rpid attribute associated with the SIP account.
304 2 Tijmen de Mes
305 4 Tijmen de Mes
h2. PSTN to End-Point
306 2 Tijmen de Mes
307 4 Tijmen de Mes
The platform is designed to accept traffic from outside SIP end-points (this includes remote PSTN gateways) to any local user. This means that a PSTN gateway that initiates a session to a correct SIP address user@domain belonging to the platform will be accepted and routed to the SIP devices belonging to the user with no extra configurations. When a SIP session originates from the PSTN, only the dialed telephone (a.k.a. E.164) number is known. For routing sessions from the PSTN to the SIP Proxy of the platform the gateway must translate the telephone number into a valid SIP address.
308 2 Tijmen de Mes
309 4 Tijmen de Mes
h4. ENUM Routing
310 4 Tijmen de Mes
311 7 Tijmen de Mes
!msp-enum-lookup.png!
312 4 Tijmen de Mes
313 2 Tijmen de Mes
The ideal way to achieve this number translation with minimum configuration is for the PSTN gateway to perform an ENUM lookup (RFC 3761). All popular open source software gateways like Asterisk and OpenSIPS are able to perform ENUM lookups and commercial gateways have started adding this support into their commercial products.
314 2 Tijmen de Mes
315 2 Tijmen de Mes
The ENUM look-up queries the DNS server provisioned with E.164 numbers by the operator, which is always kept up to date by the operator. The result of a successful ENUM lookup is a SIP address. Once the ENUM lookup is complete, the PSTN gateway can initiate the SIP session to the SIP address returned by the ENUM lookups.
316 2 Tijmen de Mes
317 2 Tijmen de Mes
The only setting required in the PSTN gateway for this setup is the top level domain used to perform ENUM lookups. The ENUM top level domain must be the same used by the SIP Proxy lookup and NGNPro provisioning.
318 2 Tijmen de Mes
319 4 Tijmen de Mes
h4. Manual Routing
320 2 Tijmen de Mes
321 4 Tijmen de Mes
For PSTN gateways that are not able to perform ENUM lookups and from which we need to accept incoming sessions, the SIP Proxy can be configured to accept any traffic, manipulate the number format based on custom rules and help performing the ENUM lookup in the behalf of the gateway.
322 2 Tijmen de Mes
323 2 Tijmen de Mes
The PSTN gateway must be configured for the E.164 number ranges to be routed to the MSP platform and the hostname of the SIP Proxy machine (e.g. sip.example.com). Do not use static IP addresses in the PSTN configuration, use the DNS name configured by the operator so that when the IP addresses of the SIP Proxy change or when multiple SIP Proxies are used by default (like in SIP Thor) the gateway does not need to be re-configured.
324 2 Tijmen de Mes
325 2 Tijmen de Mes
You must setup the following SIP Proxy configuration file:
326 2 Tijmen de Mes
327 8 Tijmen de Mes
  sipproxy:/etc/opensips/config/siteconfig/handle-incoming-pstn.m4
328 2 Tijmen de Mes
329 2 Tijmen de Mes
330 4 Tijmen de Mes
Example:
331 4 Tijmen de Mes
332 4 Tijmen de Mes
<pre class="wiki">
333 2 Tijmen de Mes
if (allow_trusted()) {
334 10 Tijmen de Mes
    DINFO('Incoming PSTN call');
335 10 Tijmen de Mes
    if (uri=~'^sip:0[1-9][0-9]{4,}@.*') {
336 2 Tijmen de Mes
        strip(1);
337 10 Tijmen de Mes
        prefix('+31');
338 10 Tijmen de Mes
        DINFO('Converted to ENUM number $ru');
339 10 Tijmen de Mes
    } else if (uri=~'^sip:0031[1-9][0-9]{4,}@.*') {
340 2 Tijmen de Mes
        strip(2);
341 10 Tijmen de Mes
        prefix('+');
342 10 Tijmen de Mes
        DINFO('Converted to ENUM number $ru');
343 2 Tijmen de Mes
    } else {
344 10 Tijmen de Mes
        ERROR('Invalid destination');
345 10 Tijmen de Mes
        sl_send_reply('403', 'Invalid destination');
346 10 Tijmen de Mes
        LOG_MISSED_CALL('403');
347 2 Tijmen de Mes
        exit;
348 2 Tijmen de Mes
    }
349 2 Tijmen de Mes
350 10 Tijmen de Mes
    rewritehostport('example.com');
351 2 Tijmen de Mes
352 2 Tijmen de Mes
    route(__ENUM_LOOKUP);
353 2 Tijmen de Mes
354 2 Tijmen de Mes
    if (retcode==-1) {
355 10 Tijmen de Mes
        DINFO('User not found');
356 10 Tijmen de Mes
        sl_send_reply('404', 'User not found');
357 10 Tijmen de Mes
        LOG_MISSED_CALL('404');
358 2 Tijmen de Mes
        exit;
359 2 Tijmen de Mes
    } else if (!is_uri_host_local()) {
360 10 Tijmen de Mes
        DINFO('Call to non local user');
361 10 Tijmen de Mes
        sl_send_reply('403', 'Invalid destination');
362 10 Tijmen de Mes
        LOG_MISSED_CALL('403');
363 2 Tijmen de Mes
        exit;
364 2 Tijmen de Mes
    }
365 2 Tijmen de Mes
}
366 4 Tijmen de Mes
</pre>
367 2 Tijmen de Mes
368 2 Tijmen de Mes
369 4 Tijmen de Mes
|Authentication|None|
370 4 Tijmen de Mes
|Authorization|Custom SIP Proxy logic|
371 4 Tijmen de Mes
|Billing party|Trusted peer|
372 4 Tijmen de Mes
|Accounting|Postpaid|
373 4 Tijmen de Mes
|Media types|RTP (audio)|
374 4 Tijmen de Mes
|From header|Must contain a non-local SIP domain|
375 2 Tijmen de Mes
|Address resolution|ENUM, Custom SIP Proxy logic|
376 2 Tijmen de Mes
377 4 Tijmen de Mes
h2. PBX to PSTN
378 4 Tijmen de Mes
379 7 Tijmen de Mes
!flow-pbx-a-pstn.png!
380 4 Tijmen de Mes
381 2 Tijmen de Mes
The IP address(es) of the PBX must be added in the trusted table using the SOAP/XML provisioning API. To allow trusted parties to transit your SIP Proxy edit sip:/etc/opensips/config/siteconfig/handle-incoming-pstn.m4 and add to it:
382 2 Tijmen de Mes
383 11 Tijmen de Mes
<pre>
384 11 Tijmen de Mes
if (allow_trusted()) {
385 2 Tijmen de Mes
    if (uri=~"^sip:0[1-9]*@.*") {
386 2 Tijmen de Mes
        # National calls must be formated as 00XX
387 2 Tijmen de Mes
        strip(1);
388 2 Tijmen de Mes
        prefix("0031");
389 2 Tijmen de Mes
        route(__PSTN_TRANSIT);
390 2 Tijmen de Mes
        exit;
391 2 Tijmen de Mes
    } else if (uri=~"^sip:00[1-9]*@.*") {
392 2 Tijmen de Mes
        # International calls
393 2 Tijmen de Mes
        route(__PSTN_TRANSIT);
394 2 Tijmen de Mes
        exit;
395 2 Tijmen de Mes
    } else {
396 2 Tijmen de Mes
        ERROR("Invalid destination");
397 2 Tijmen de Mes
        sl_send_reply("403", "Invalid destination");
398 2 Tijmen de Mes
        LOG_MISSED_CALL("403");
399 2 Tijmen de Mes
        exit;
400 1 Tijmen de Mes
    }
401 2 Tijmen de Mes
}
402 11 Tijmen de Mes
</pre>
403 2 Tijmen de Mes
404 4 Tijmen de Mes
405 4 Tijmen de Mes
|Authentication|None|
406 4 Tijmen de Mes
|Authorization|Trusted peer A|
407 4 Tijmen de Mes
|Caller Id|Supplied by trusted peer A|
408 4 Tijmen de Mes
|Billing party|Trusted peer A|
409 4 Tijmen de Mes
|Accounting|Postpaid|
410 4 Tijmen de Mes
|Media types|RTP (audio)|
411 4 Tijmen de Mes
|Address resolution|ENUM, LCR, Custom SIP Proxy logic|
412 4 Tijmen de Mes
|From header|Must contain a non-local SIP domain|
413 4 Tijmen de Mes
414 4 Tijmen de Mes
415 2 Tijmen de Mes
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.
416 2 Tijmen de Mes
417 4 Tijmen de Mes
h3. Rating
418 2 Tijmen de Mes
419 2 Tijmen de Mes
To rate the traffic generated by trusted peers you must add a rating plan in CDRTool rating engine based on the source IP address (the gateway field in rating customers table). Beware that no quota can be imposed on the traffic of a trusted peer.
420 2 Tijmen de Mes
421 4 Tijmen de Mes
h3. Caller Id Indication
422 2 Tijmen de Mes
423 4 Tijmen de Mes
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, make sure that the way caller ID indication is provided by the trusted party is compatible with what the PSTN gateway expects.
424 2 Tijmen de Mes
425 4 Tijmen de Mes
h2. PSTN to PBX
426 2 Tijmen de Mes
427 7 Tijmen de Mes
!flow-pbx-a-pstn.png!
428 2 Tijmen de Mes
429 2 Tijmen de Mes
430 4 Tijmen de Mes
|Authentication|None|
431 4 Tijmen de Mes
|Authorization|Trusted peer PSTN gateway|
432 4 Tijmen de Mes
|Caller Id|Supplied by PSTN gateway|
433 4 Tijmen de Mes
|Billing party|Trusted peer PSTN gateway|
434 4 Tijmen de Mes
|Accounting|Postpaid|
435 4 Tijmen de Mes
|Media types|RTP (audio)|
436 4 Tijmen de Mes
|From header|Must contain a non-local SIP domain|
437 4 Tijmen de Mes
|Address resolution|ENUM, Custom SIP Proxy logic|
438 2 Tijmen de Mes
439 2 Tijmen de Mes
440 4 Tijmen de Mes
h2. Call Diversion
441 4 Tijmen de Mes
442 7 Tijmen de Mes
!flow-sip-phone-a-b-diverted.png!
443 4 Tijmen de Mes
444 2 Tijmen de Mes
A user may chose to divert his/her calls based on various conditions (like unconditional, busy or not online) to another SIP address including PSTN destinations. Diverted calls are always charged to the user who enabled them. For every call diversion, a new Diversion header is appended to the original SIP request.
445 2 Tijmen de Mes
446 2 Tijmen de Mes
447 4 Tijmen de Mes
|Authentication|SIP account A|
448 4 Tijmen de Mes
|Authorization|SIP account A|
449 4 Tijmen de Mes
|Billing party|SIP account B|
450 4 Tijmen de Mes
|Accounting|Postpaid, Prepaid|
451 4 Tijmen de Mes
|Address resolution|SIP address, SIP alias, Quickdial, ENUM, LCR|
452 2 Tijmen de Mes
453 4 Tijmen de Mes
454 4 Tijmen de Mes
h2. Presence
455 4 Tijmen de Mes
456 7 Tijmen de Mes
!flow-presence.png!
457 4 Tijmen de Mes
458 2 Tijmen de Mes
Multiple watchers are subscribed to a publisher. The Publisher authorizes the watchers to subscriber to presence notifications by updating pres-rules XCAP document. The Publisher must subscribe to event presence.winfo to receive notifications from the Presence Agent about the watcher list.
459 2 Tijmen de Mes
460 2 Tijmen de Mes
461 4 Tijmen de Mes
|Authorization|XCAP pres-rules|
462 4 Tijmen de Mes
|Address resolution|SIP address, SIP alias, Quickdial, ENUM|
463 4 Tijmen de Mes
|Accounting|None|
464 2 Tijmen de Mes
465 18 Adrian Georgescu
h2. Presence using RLS
466 4 Tijmen de Mes
467 7 Tijmen de Mes
!flow-rls-services.png!
468 4 Tijmen de Mes
469 2 Tijmen de Mes
A subscriber uploads to the XCAP server a resource list. Then it subscribes to the list by sending a SUBSCRIBE for event presence with extra header Supported: eventlist, the Presence agent then subscribes to all recipients from the resource lists and returns consolidated NOTIFY with the state of all lists.
470 2 Tijmen de Mes
471 1 Tijmen de Mes
472 15 Adrian Georgescu
|Authorization|XCAP org.openmobilealliance.pres-rules|
473 15 Adrian Georgescu
|Contacts Storage| XCAP rls-services and resource-lists|
474 15 Adrian Georgescu
|Signaling|RLS SUBSCRIBE RFC4662 and RLMI NOTIFY RFC4662|
475 4 Tijmen de Mes
|Address resolution|SIP address, SIP alias, Quickdial, ENUM|
476 1 Tijmen de Mes
|Accounting|None|
477 1 Tijmen de Mes
478 4 Tijmen de Mes
h2. IM using MSRP Relay
479 4 Tijmen de Mes
480 7 Tijmen de Mes
!flow-msrp-relay.png!
481 4 Tijmen de Mes
482 1 Tijmen de Mes
Instant Messaging based on MSRP protocol is similar to a regular SIP audio session. Instead of RTP media , MSRP is used for establishing a media channel. Instead of MediaProxy, A MSRP relay is used to traverse the NAT. The called party reserves a session in the MSRP relay and offeres it in the response to the SIP INVITE. The calling party the initiates a TCP/TLS connection to the relay reserved address and the called party does the same. By using the relay both parties can establish a TCP flow from behind their NAT routers.
483 1 Tijmen de Mes
484 4 Tijmen de Mes
h2. IM using MSRP ACM
485 1 Tijmen de Mes
486 7 Tijmen de Mes
!flow-msrp-acm.png!
487 1 Tijmen de Mes
488 4 Tijmen de Mes
MSRP ACM is an alternative method for traversing NAT that is standardized by 3GPP that is interoperable with the IETF MSRP relay specification. The SBC mangles the SDP and stays in the SIP signaling and MSRP media path and forces the end-points to be both active (that is starting the outbound MSRP connection) when behind NAT.
489 1 Tijmen de Mes
490 4 Tijmen de Mes
h2. IM using MSRP ACM and Relay
491 1 Tijmen de Mes
492 7 Tijmen de Mes
!flow-msrp-acm-relay.png!
493 1 Tijmen de Mes
494 1 Tijmen de Mes
MSRP ACM and Relay methodologies can interoperate.
495 1 Tijmen de Mes
496 4 Tijmen de Mes
h2. File Transfer
497 4 Tijmen de Mes
498 1 Tijmen de Mes
File transfer based on MSRP protocol is similar to a regular SIP audio session. Instead of RTP media , MSRP is used for establishing a media channel. A MSRP relay is used to traverse the NAT.
499 1 Tijmen de Mes
500 4 Tijmen de Mes
h2. Emergency Calls
501 1 Tijmen de Mes
502 4 Tijmen de Mes
Emergency calls refer to dialing short numbers usually associated with emergency services like police or fire-brigade (e.g. 112 or 911). When a session is setup to a short number designated as an emergency number (in the SIP Proxy configuration), a database lookup is performed by the proxy in the emergency&#95;mapping table. Based on the *region* attribute provisioned with the SIP account, the final destination corresponding with the emergency number is looked up. Only local users can dial an emergency number.
503 1 Tijmen de Mes
504 21 Tijmen de Mes
See [[Provisioning_guide#Emergency-Numbers|"Provisioning the emergency numbers"]] section for more information.
505 1 Tijmen de Mes
506 16 Adrian Georgescu
h2. XMMP gateway
507 16 Adrian Georgescu
508 16 Adrian Georgescu
The platform can be setup to federate with remote XMPP domains using a gateway function. The functionality is described at:
509 16 Adrian Georgescu
510 16 Adrian Georgescu
http://sylkserver.ag-projects.com/projects/sylkserver/wiki/DesignXMPP
511 16 Adrian Georgescu
512 17 Adrian Georgescu
h2. PBX Media Functions
513 1 Tijmen de Mes
514 1 Tijmen de Mes
Functions involving playing media in the middle of a call setup are not possible by the design of a SIP Proxy. Features like:
515 1 Tijmen de Mes
516 4 Tijmen de Mes
* IVR
517 4 Tijmen de Mes
* Auto-attendant
518 4 Tijmen de Mes
* Call queues and ACD
519 4 Tijmen de Mes
* Listen-in and barge-in
520 4 Tijmen de Mes
* Call parking
521 4 Tijmen de Mes
* Music on hold (MoH)
522 1 Tijmen de Mes
523 4 Tijmen de Mes
are not performed by a SIP Proxy. Such functions can be implemented only by dedicated IP-PBX added to the platform. The platform is used to route calls between such PBXs, from the MSP perspective these PBX are seen as SIP trunks connected to the platform.