1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,259 +0,0 @@ |
1 |
- |
|
2 |
-Least Cost Routing Module |
|
3 |
- |
|
4 |
-Juha Heinanen |
|
5 |
- |
|
6 |
-Edited by |
|
7 |
- |
|
8 |
-Juha Heinanen |
|
9 |
- |
|
10 |
- Copyright � 2005 Juha Heinanen |
|
11 |
- _________________________________________________________ |
|
12 |
- |
|
13 |
- Table of Contents |
|
14 |
- |
|
15 |
- 1. User's Guide |
|
16 |
- |
|
17 |
- 1.1. Overview |
|
18 |
- 1.2. Dependencies |
|
19 |
- 1.3. Exported Parameters |
|
20 |
- 1.4. Exported Functions |
|
21 |
- 1.5. FIFO Commands |
|
22 |
- 1.6. Known Limitations |
|
23 |
- |
|
24 |
- 2. TODO |
|
25 |
- _________________________________________________________ |
|
26 |
- |
|
27 |
-Chapter 1. User's Guide |
|
28 |
- |
|
29 |
-1.1. Overview |
|
30 |
- |
|
31 |
- Least cost routing (LCR) module implements two related capabilities: |
|
32 |
- |
|
33 |
- (1) sequential forwarding of a request to one or more gateways |
|
34 |
- (functions load_gws and next_gw), |
|
35 |
- |
|
36 |
- (2) sequential forwarding to contacts if they don't share the |
|
37 |
- the same qvalue (functions load_contacts and next_contacts). |
|
38 |
- |
|
39 |
- Gateway selection is based on caller's RPID URI (if available in |
|
40 |
- caller's RPID AVP after authentication) or From URI and user part of |
|
41 |
- Request-URI (telephone number). Gateway patterns matching RPID or |
|
42 |
- From URI and telephone number are ordered for forwarding purpose (1) |
|
43 |
- according to longest user part match, (2) according to priority, and |
|
44 |
- (3) randomly. |
|
45 |
- |
|
46 |
- Each gateway belongs to a gateway group either alone or among other |
|
47 |
- gateways. All gateways in a group share the same priority. |
|
48 |
- |
|
49 |
- Gateway and routing information is kept in two tables: gw and lcr. |
|
50 |
- |
|
51 |
- When a gateway is selected, Request-URI is rewritten with information |
|
52 |
- from gw table: URI scheme, prefix, IP address, port, and transport |
|
53 |
- protocol. Valid URI scheme values are NULL = sip, 1 = sip and 2 = |
|
54 |
- sips. Prefix is appended in front of Request-URI user part. |
|
55 |
- Currently valid transport protocol values are NULL = none, 1 = udp, 2 |
|
56 |
- = tcp, and 3 = tls. |
|
57 |
- |
|
58 |
- Table lcr contains prefix of user part of Request-URI, From URI, |
|
59 |
- gateway group id, and priority. From URI can contain special |
|
60 |
- characters % and _ matching any number of any characters and any one |
|
61 |
- character, respectively. |
|
62 |
- |
|
63 |
- In addition to gw and lcr tables there is third table gw_grp that is |
|
64 |
- used for administrative purposes only to associate names with gateway |
|
65 |
- group ids. |
|
66 |
- _________________________________________________________ |
|
67 |
- |
|
68 |
-1.2. Dependencies |
|
69 |
- |
|
70 |
- The module depends on the following modules (in the other |
|
71 |
- words the listed modules must be loaded before this module): |
|
72 |
- |
|
73 |
- * tm module |
|
74 |
- * mysql module |
|
75 |
- _________________________________________________________ |
|
76 |
- |
|
77 |
-1.3. Exported Parameters |
|
78 |
- |
|
79 |
- LCR module exports the following database related parameters that |
|
80 |
- have usual purpose: |
|
81 |
- |
|
82 |
- * db_url (default system default) |
|
83 |
- * gw_table (default "gw") |
|
84 |
- * gw_name_column (default "gw_name") |
|
85 |
- * ip_addr_column (default "ip_addr") |
|
86 |
- * port_column (default "port") |
|
87 |
- * uri_scheme_column (default "uri_scheme") |
|
88 |
- * transport_column (default "transport") |
|
89 |
- * grp_id_column (default "grp_id") |
|
90 |
- * lcr_table (default "lcr") |
|
91 |
- * prefix_column (default "prefix") |
|
92 |
- * from_uri_column (default "from_uri") |
|
93 |
- * priority_column (default "priority") |
|
94 |
- |
|
95 |
- In addition there are parameters that can be used to override names |
|
96 |
- of the AVPs used by LCR module: |
|
97 |
- |
|
98 |
- * gw_uri_avp (default "1400") |
|
99 |
- * contact_avp (default "1401") |
|
100 |
- * fr_inv_timer_avp (default "fr_inv_timer_avp") |
|
101 |
- * rpid_avp (default "rpid") |
|
102 |
- |
|
103 |
- If string value of an AVP parameter contains only digits, the name of |
|
104 |
- the AVP is int value of the string. |
|
105 |
- |
|
106 |
- Finally, the parameters used by sequential forwarding: |
|
107 |
- |
|
108 |
- * fr_inv_timer (default 90) |
|
109 |
- * fr_inv_timer_next (default 30) |
|
110 |
- * fr_inv_timer_param (default "") |
|
111 |
- * fr_inv_timer_next_param (default "") |
|
112 |
- |
|
113 |
- Function next_contacts() sets tm fr_inv_timer to fr_inv_timer_next |
|
114 |
- value if, after next contacts, there are still lower qvalue |
|
115 |
- contacts available, and to fr_inv_timer value if next contacts are |
|
116 |
- the last ones left. fr_inv_timer_param can define an AVP |
|
117 |
- overwriting fr_inv_timer value, and similarly, AVP defined by |
|
118 |
- fr_inv_timer_next_param can overwrite fr_inv_timer_next value. |
|
119 |
- _________________________________________________________ |
|
120 |
- |
|
121 |
-1.4. Exported Functions |
|
122 |
- |
|
123 |
-1.4.1. load_gws() |
|
124 |
- |
|
125 |
- Loads URIs of gateways matching RPID AVP (if available) or From URI |
|
126 |
- and user part of Request-URI to gw_uri_avp AVPs. Returns 1 or -1 |
|
127 |
- depending on success. |
|
128 |
- |
|
129 |
- Example: |
|
130 |
- |
|
131 |
- if (!load_gws()) { |
|
132 |
- sl_send_reply("500", "Server Internal Error - Cannot load gateways"); |
|
133 |
- break; |
|
134 |
- }; |
|
135 |
- |
|
136 |
-1.4.2. next_gw() |
|
137 |
- |
|
138 |
- If called from a route block, replaces Request-URI by the first |
|
139 |
- gw_uri_avp AVP value and destroys that AVP. |
|
140 |
- |
|
141 |
- If called from a failure route block, appends a new branch to request, |
|
142 |
- whose Request-URI is the first gw_uri_avp AVP value, and destroys that |
|
143 |
- AVP. |
|
144 |
- |
|
145 |
- Returns 1 on success and -1 if there were no gateways left or if an |
|
146 |
- error occurred (see syslog). |
|
147 |
- |
|
148 |
- Must be preceded by successful load_gws() call. |
|
149 |
- |
|
150 |
- Example from route block: |
|
151 |
- |
|
152 |
- if (!next_gw()) { |
|
153 |
- sl_send_reply("503", "Service not available - No gateways"); |
|
154 |
- break; |
|
155 |
- }; |
|
156 |
- |
|
157 |
- Example from failure route block: |
|
158 |
- |
|
159 |
- if (!next_gw()) { |
|
160 |
- t_reply("503", "Service not available - No more gateways"); |
|
161 |
- break; |
|
162 |
- }; |
|
163 |
- |
|
164 |
-1.4.3. from_gw() |
|
165 |
- |
|
166 |
- Checks if request came from IP address of a gateway. |
|
167 |
- |
|
168 |
- Example: |
|
169 |
- |
|
170 |
- if (from_gw()) { |
|
171 |
- ... |
|
172 |
- break; |
|
173 |
- }; |
|
174 |
- |
|
175 |
-1.4.4. to_gw() |
|
176 |
- |
|
177 |
- Checks if in-dialog request goes to a gateway. |
|
178 |
- |
|
179 |
- Example: |
|
180 |
- |
|
181 |
- if (to_gw()) { |
|
182 |
- ... |
|
183 |
- break; |
|
184 |
- }; |
|
185 |
- |
|
186 |
-1.4.5. load_contacts() |
|
187 |
- |
|
188 |
- Loads contacts in destination set in increasing qvalue order as |
|
189 |
- values of lcr_contact AVP. If all contacts in the destination set |
|
190 |
- have the same qvalue, load_contacts() does not do anything thus |
|
191 |
- minimizing performance impact of sequential forking capability when |
|
192 |
- it is not needed. Returns 1 if loading of contacts succeeded or |
|
193 |
- there was nothing to do. Returns -1 on error (see syslog). |
|
194 |
- |
|
195 |
- Example: |
|
196 |
- |
|
197 |
- if (!load_contacts()) { |
|
198 |
- sl_send_reply("500", "Server Internal Error - Cannot load contacts"); |
|
199 |
- break; |
|
200 |
- }; |
|
201 |
- |
|
202 |
-1.4.6. next_contacts() |
|
203 |
- |
|
204 |
- If called from a route block, replaces Request-URI with the first |
|
205 |
- lcr_contact AVP value, adds the remaining lcr_contact AVP values with |
|
206 |
- the same qvalue as branches, and destroys those AVPs. It does |
|
207 |
- nothing if there are no lcr_contact AVPs. Returns 1 if there were no |
|
208 |
- errors and -1 if an error occurred (see syslog). |
|
209 |
- |
|
210 |
- If called from a failure route block, adds the first lcr_contact AVP |
|
211 |
- value and all following lcr_contact AVP values with the same qvalue |
|
212 |
- as new branches to request and destroys those AVPs. Returns 1 if new |
|
213 |
- branches were successfully added and -1 on error (see syslog) or if |
|
214 |
- there were no more lcr_contact AVPs. |
|
215 |
- |
|
216 |
- Must be preceded by successful load_contacts() call. |
|
217 |
- |
|
218 |
- Example from route block: |
|
219 |
- |
|
220 |
- if (!next_contacts()) { |
|
221 |
- sl_send_reply("500", "Server Internal Error"); |
|
222 |
- break; |
|
223 |
- } else { |
|
224 |
- t_relay(); |
|
225 |
- }; |
|
226 |
- |
|
227 |
- Example from failure route block: |
|
228 |
- |
|
229 |
- if (next_contacts()) { |
|
230 |
- t_relay(); |
|
231 |
- }; |
|
232 |
- |
|
233 |
- |
|
234 |
-1.5. FIFO Commands |
|
235 |
- |
|
236 |
-1.5.1. lcr_reload |
|
237 |
- |
|
238 |
- Causes lcr module to re-read the contents of gateway table |
|
239 |
- into memory. |
|
240 |
- |
|
241 |
-1.5.2. lcr_dump |
|
242 |
- |
|
243 |
- Causes lcr module to dump the contents of its in-memory gateway |
|
244 |
- table. |
|
245 |
- |
|
246 |
-1.6. Known Limitations |
|
247 |
- |
|
248 |
- There is an unlikely race condition on lcr reload. If a process uses |
|
249 |
- in memory gw table, which is reloaded at the same time twice through |
|
250 |
- FIFO, the second reload will delete the original table still in use |
|
251 |
- by the process. |
|
252 |
- _________________________________________________________ |
|
253 |
- |
|
254 |
-2.0. TODO |
|
255 |
- |
|
256 |
- Function load_gws() currently makes an SQL query for the matching |
|
257 |
- gateways. In order to avoid the query, also lcr table should be |
|
258 |
- read into memory and the corresponding query should be rewritten in |
|
259 |
- C. |
This reverts commit a3f16850cd2a897710cb0a56174e9f64dcc77653.
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,259 @@ |
1 |
+ |
|
2 |
+Least Cost Routing Module |
|
3 |
+ |
|
4 |
+Juha Heinanen |
|
5 |
+ |
|
6 |
+Edited by |
|
7 |
+ |
|
8 |
+Juha Heinanen |
|
9 |
+ |
|
10 |
+ Copyright � 2005 Juha Heinanen |
|
11 |
+ _________________________________________________________ |
|
12 |
+ |
|
13 |
+ Table of Contents |
|
14 |
+ |
|
15 |
+ 1. User's Guide |
|
16 |
+ |
|
17 |
+ 1.1. Overview |
|
18 |
+ 1.2. Dependencies |
|
19 |
+ 1.3. Exported Parameters |
|
20 |
+ 1.4. Exported Functions |
|
21 |
+ 1.5. FIFO Commands |
|
22 |
+ 1.6. Known Limitations |
|
23 |
+ |
|
24 |
+ 2. TODO |
|
25 |
+ _________________________________________________________ |
|
26 |
+ |
|
27 |
+Chapter 1. User's Guide |
|
28 |
+ |
|
29 |
+1.1. Overview |
|
30 |
+ |
|
31 |
+ Least cost routing (LCR) module implements two related capabilities: |
|
32 |
+ |
|
33 |
+ (1) sequential forwarding of a request to one or more gateways |
|
34 |
+ (functions load_gws and next_gw), |
|
35 |
+ |
|
36 |
+ (2) sequential forwarding to contacts if they don't share the |
|
37 |
+ the same qvalue (functions load_contacts and next_contacts). |
|
38 |
+ |
|
39 |
+ Gateway selection is based on caller's RPID URI (if available in |
|
40 |
+ caller's RPID AVP after authentication) or From URI and user part of |
|
41 |
+ Request-URI (telephone number). Gateway patterns matching RPID or |
|
42 |
+ From URI and telephone number are ordered for forwarding purpose (1) |
|
43 |
+ according to longest user part match, (2) according to priority, and |
|
44 |
+ (3) randomly. |
|
45 |
+ |
|
46 |
+ Each gateway belongs to a gateway group either alone or among other |
|
47 |
+ gateways. All gateways in a group share the same priority. |
|
48 |
+ |
|
49 |
+ Gateway and routing information is kept in two tables: gw and lcr. |
|
50 |
+ |
|
51 |
+ When a gateway is selected, Request-URI is rewritten with information |
|
52 |
+ from gw table: URI scheme, prefix, IP address, port, and transport |
|
53 |
+ protocol. Valid URI scheme values are NULL = sip, 1 = sip and 2 = |
|
54 |
+ sips. Prefix is appended in front of Request-URI user part. |
|
55 |
+ Currently valid transport protocol values are NULL = none, 1 = udp, 2 |
|
56 |
+ = tcp, and 3 = tls. |
|
57 |
+ |
|
58 |
+ Table lcr contains prefix of user part of Request-URI, From URI, |
|
59 |
+ gateway group id, and priority. From URI can contain special |
|
60 |
+ characters % and _ matching any number of any characters and any one |
|
61 |
+ character, respectively. |
|
62 |
+ |
|
63 |
+ In addition to gw and lcr tables there is third table gw_grp that is |
|
64 |
+ used for administrative purposes only to associate names with gateway |
|
65 |
+ group ids. |
|
66 |
+ _________________________________________________________ |
|
67 |
+ |
|
68 |
+1.2. Dependencies |
|
69 |
+ |
|
70 |
+ The module depends on the following modules (in the other |
|
71 |
+ words the listed modules must be loaded before this module): |
|
72 |
+ |
|
73 |
+ * tm module |
|
74 |
+ * mysql module |
|
75 |
+ _________________________________________________________ |
|
76 |
+ |
|
77 |
+1.3. Exported Parameters |
|
78 |
+ |
|
79 |
+ LCR module exports the following database related parameters that |
|
80 |
+ have usual purpose: |
|
81 |
+ |
|
82 |
+ * db_url (default system default) |
|
83 |
+ * gw_table (default "gw") |
|
84 |
+ * gw_name_column (default "gw_name") |
|
85 |
+ * ip_addr_column (default "ip_addr") |
|
86 |
+ * port_column (default "port") |
|
87 |
+ * uri_scheme_column (default "uri_scheme") |
|
88 |
+ * transport_column (default "transport") |
|
89 |
+ * grp_id_column (default "grp_id") |
|
90 |
+ * lcr_table (default "lcr") |
|
91 |
+ * prefix_column (default "prefix") |
|
92 |
+ * from_uri_column (default "from_uri") |
|
93 |
+ * priority_column (default "priority") |
|
94 |
+ |
|
95 |
+ In addition there are parameters that can be used to override names |
|
96 |
+ of the AVPs used by LCR module: |
|
97 |
+ |
|
98 |
+ * gw_uri_avp (default "1400") |
|
99 |
+ * contact_avp (default "1401") |
|
100 |
+ * fr_inv_timer_avp (default "fr_inv_timer_avp") |
|
101 |
+ * rpid_avp (default "rpid") |
|
102 |
+ |
|
103 |
+ If string value of an AVP parameter contains only digits, the name of |
|
104 |
+ the AVP is int value of the string. |
|
105 |
+ |
|
106 |
+ Finally, the parameters used by sequential forwarding: |
|
107 |
+ |
|
108 |
+ * fr_inv_timer (default 90) |
|
109 |
+ * fr_inv_timer_next (default 30) |
|
110 |
+ * fr_inv_timer_param (default "") |
|
111 |
+ * fr_inv_timer_next_param (default "") |
|
112 |
+ |
|
113 |
+ Function next_contacts() sets tm fr_inv_timer to fr_inv_timer_next |
|
114 |
+ value if, after next contacts, there are still lower qvalue |
|
115 |
+ contacts available, and to fr_inv_timer value if next contacts are |
|
116 |
+ the last ones left. fr_inv_timer_param can define an AVP |
|
117 |
+ overwriting fr_inv_timer value, and similarly, AVP defined by |
|
118 |
+ fr_inv_timer_next_param can overwrite fr_inv_timer_next value. |
|
119 |
+ _________________________________________________________ |
|
120 |
+ |
|
121 |
+1.4. Exported Functions |
|
122 |
+ |
|
123 |
+1.4.1. load_gws() |
|
124 |
+ |
|
125 |
+ Loads URIs of gateways matching RPID AVP (if available) or From URI |
|
126 |
+ and user part of Request-URI to gw_uri_avp AVPs. Returns 1 or -1 |
|
127 |
+ depending on success. |
|
128 |
+ |
|
129 |
+ Example: |
|
130 |
+ |
|
131 |
+ if (!load_gws()) { |
|
132 |
+ sl_send_reply("500", "Server Internal Error - Cannot load gateways"); |
|
133 |
+ break; |
|
134 |
+ }; |
|
135 |
+ |
|
136 |
+1.4.2. next_gw() |
|
137 |
+ |
|
138 |
+ If called from a route block, replaces Request-URI by the first |
|
139 |
+ gw_uri_avp AVP value and destroys that AVP. |
|
140 |
+ |
|
141 |
+ If called from a failure route block, appends a new branch to request, |
|
142 |
+ whose Request-URI is the first gw_uri_avp AVP value, and destroys that |
|
143 |
+ AVP. |
|
144 |
+ |
|
145 |
+ Returns 1 on success and -1 if there were no gateways left or if an |
|
146 |
+ error occurred (see syslog). |
|
147 |
+ |
|
148 |
+ Must be preceded by successful load_gws() call. |
|
149 |
+ |
|
150 |
+ Example from route block: |
|
151 |
+ |
|
152 |
+ if (!next_gw()) { |
|
153 |
+ sl_send_reply("503", "Service not available - No gateways"); |
|
154 |
+ break; |
|
155 |
+ }; |
|
156 |
+ |
|
157 |
+ Example from failure route block: |
|
158 |
+ |
|
159 |
+ if (!next_gw()) { |
|
160 |
+ t_reply("503", "Service not available - No more gateways"); |
|
161 |
+ break; |
|
162 |
+ }; |
|
163 |
+ |
|
164 |
+1.4.3. from_gw() |
|
165 |
+ |
|
166 |
+ Checks if request came from IP address of a gateway. |
|
167 |
+ |
|
168 |
+ Example: |
|
169 |
+ |
|
170 |
+ if (from_gw()) { |
|
171 |
+ ... |
|
172 |
+ break; |
|
173 |
+ }; |
|
174 |
+ |
|
175 |
+1.4.4. to_gw() |
|
176 |
+ |
|
177 |
+ Checks if in-dialog request goes to a gateway. |
|
178 |
+ |
|
179 |
+ Example: |
|
180 |
+ |
|
181 |
+ if (to_gw()) { |
|
182 |
+ ... |
|
183 |
+ break; |
|
184 |
+ }; |
|
185 |
+ |
|
186 |
+1.4.5. load_contacts() |
|
187 |
+ |
|
188 |
+ Loads contacts in destination set in increasing qvalue order as |
|
189 |
+ values of lcr_contact AVP. If all contacts in the destination set |
|
190 |
+ have the same qvalue, load_contacts() does not do anything thus |
|
191 |
+ minimizing performance impact of sequential forking capability when |
|
192 |
+ it is not needed. Returns 1 if loading of contacts succeeded or |
|
193 |
+ there was nothing to do. Returns -1 on error (see syslog). |
|
194 |
+ |
|
195 |
+ Example: |
|
196 |
+ |
|
197 |
+ if (!load_contacts()) { |
|
198 |
+ sl_send_reply("500", "Server Internal Error - Cannot load contacts"); |
|
199 |
+ break; |
|
200 |
+ }; |
|
201 |
+ |
|
202 |
+1.4.6. next_contacts() |
|
203 |
+ |
|
204 |
+ If called from a route block, replaces Request-URI with the first |
|
205 |
+ lcr_contact AVP value, adds the remaining lcr_contact AVP values with |
|
206 |
+ the same qvalue as branches, and destroys those AVPs. It does |
|
207 |
+ nothing if there are no lcr_contact AVPs. Returns 1 if there were no |
|
208 |
+ errors and -1 if an error occurred (see syslog). |
|
209 |
+ |
|
210 |
+ If called from a failure route block, adds the first lcr_contact AVP |
|
211 |
+ value and all following lcr_contact AVP values with the same qvalue |
|
212 |
+ as new branches to request and destroys those AVPs. Returns 1 if new |
|
213 |
+ branches were successfully added and -1 on error (see syslog) or if |
|
214 |
+ there were no more lcr_contact AVPs. |
|
215 |
+ |
|
216 |
+ Must be preceded by successful load_contacts() call. |
|
217 |
+ |
|
218 |
+ Example from route block: |
|
219 |
+ |
|
220 |
+ if (!next_contacts()) { |
|
221 |
+ sl_send_reply("500", "Server Internal Error"); |
|
222 |
+ break; |
|
223 |
+ } else { |
|
224 |
+ t_relay(); |
|
225 |
+ }; |
|
226 |
+ |
|
227 |
+ Example from failure route block: |
|
228 |
+ |
|
229 |
+ if (next_contacts()) { |
|
230 |
+ t_relay(); |
|
231 |
+ }; |
|
232 |
+ |
|
233 |
+ |
|
234 |
+1.5. FIFO Commands |
|
235 |
+ |
|
236 |
+1.5.1. lcr_reload |
|
237 |
+ |
|
238 |
+ Causes lcr module to re-read the contents of gateway table |
|
239 |
+ into memory. |
|
240 |
+ |
|
241 |
+1.5.2. lcr_dump |
|
242 |
+ |
|
243 |
+ Causes lcr module to dump the contents of its in-memory gateway |
|
244 |
+ table. |
|
245 |
+ |
|
246 |
+1.6. Known Limitations |
|
247 |
+ |
|
248 |
+ There is an unlikely race condition on lcr reload. If a process uses |
|
249 |
+ in memory gw table, which is reloaded at the same time twice through |
|
250 |
+ FIFO, the second reload will delete the original table still in use |
|
251 |
+ by the process. |
|
252 |
+ _________________________________________________________ |
|
253 |
+ |
|
254 |
+2.0. TODO |
|
255 |
+ |
|
256 |
+ Function load_gws() currently makes an SQL query for the matching |
|
257 |
+ gateways. In order to avoid the query, also lcr table should be |
|
258 |
+ read into memory and the corresponding query should be rewritten in |
|
259 |
+ C. |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,259 +0,0 @@ |
1 |
- |
|
2 |
-Least Cost Routing Module |
|
3 |
- |
|
4 |
-Juha Heinanen |
|
5 |
- |
|
6 |
-Edited by |
|
7 |
- |
|
8 |
-Juha Heinanen |
|
9 |
- |
|
10 |
- Copyright � 2005 Juha Heinanen |
|
11 |
- _________________________________________________________ |
|
12 |
- |
|
13 |
- Table of Contents |
|
14 |
- |
|
15 |
- 1. User's Guide |
|
16 |
- |
|
17 |
- 1.1. Overview |
|
18 |
- 1.2. Dependencies |
|
19 |
- 1.3. Exported Parameters |
|
20 |
- 1.4. Exported Functions |
|
21 |
- 1.5. FIFO Commands |
|
22 |
- 1.6. Known Limitations |
|
23 |
- |
|
24 |
- 2. TODO |
|
25 |
- _________________________________________________________ |
|
26 |
- |
|
27 |
-Chapter 1. User's Guide |
|
28 |
- |
|
29 |
-1.1. Overview |
|
30 |
- |
|
31 |
- Least cost routing (LCR) module implements two related capabilities: |
|
32 |
- |
|
33 |
- (1) sequential forwarding of a request to one or more gateways |
|
34 |
- (functions load_gws and next_gw), |
|
35 |
- |
|
36 |
- (2) sequential forwarding to contacts if they don't share the |
|
37 |
- the same qvalue (functions load_contacts and next_contacts). |
|
38 |
- |
|
39 |
- Gateway selection is based on caller's RPID URI (if available in |
|
40 |
- caller's RPID AVP after authentication) or From URI and user part of |
|
41 |
- Request-URI (telephone number). Gateway patterns matching RPID or |
|
42 |
- From URI and telephone number are ordered for forwarding purpose (1) |
|
43 |
- according to longest user part match, (2) according to priority, and |
|
44 |
- (3) randomly. |
|
45 |
- |
|
46 |
- Each gateway belongs to a gateway group either alone or among other |
|
47 |
- gateways. All gateways in a group share the same priority. |
|
48 |
- |
|
49 |
- Gateway and routing information is kept in two tables: gw and lcr. |
|
50 |
- |
|
51 |
- When a gateway is selected, Request-URI is rewritten with information |
|
52 |
- from gw table: URI scheme, prefix, IP address, port, and transport |
|
53 |
- protocol. Valid URI scheme values are NULL = sip, 1 = sip and 2 = |
|
54 |
- sips. Prefix is appended in front of Request-URI user part. |
|
55 |
- Currently valid transport protocol values are NULL = none, 1 = udp, 2 |
|
56 |
- = tcp, and 3 = tls. |
|
57 |
- |
|
58 |
- Table lcr contains prefix of user part of Request-URI, From URI, |
|
59 |
- gateway group id, and priority. From URI can contain special |
|
60 |
- characters % and _ matching any number of any characters and any one |
|
61 |
- character, respectively. |
|
62 |
- |
|
63 |
- In addition to gw and lcr tables there is third table gw_grp that is |
|
64 |
- used for administrative purposes only to associate names with gateway |
|
65 |
- group ids. |
|
66 |
- _________________________________________________________ |
|
67 |
- |
|
68 |
-1.2. Dependencies |
|
69 |
- |
|
70 |
- The module depends on the following modules (in the other |
|
71 |
- words the listed modules must be loaded before this module): |
|
72 |
- |
|
73 |
- * tm module |
|
74 |
- * mysql module |
|
75 |
- _________________________________________________________ |
|
76 |
- |
|
77 |
-1.3. Exported Parameters |
|
78 |
- |
|
79 |
- LCR module exports the following database related parameters that |
|
80 |
- have usual purpose: |
|
81 |
- |
|
82 |
- * db_url (default system default) |
|
83 |
- * gw_table (default "gw") |
|
84 |
- * gw_name_column (default "gw_name") |
|
85 |
- * ip_addr_column (default "ip_addr") |
|
86 |
- * port_column (default "port") |
|
87 |
- * uri_scheme_column (default "uri_scheme") |
|
88 |
- * transport_column (default "transport") |
|
89 |
- * grp_id_column (default "grp_id") |
|
90 |
- * lcr_table (default "lcr") |
|
91 |
- * prefix_column (default "prefix") |
|
92 |
- * from_uri_column (default "from_uri") |
|
93 |
- * priority_column (default "priority") |
|
94 |
- |
|
95 |
- In addition there are parameters that can be used to override names |
|
96 |
- of the AVPs used by LCR module: |
|
97 |
- |
|
98 |
- * gw_uri_avp (default "1400") |
|
99 |
- * contact_avp (default "1401") |
|
100 |
- * fr_inv_timer_avp (default "fr_inv_timer_avp") |
|
101 |
- * rpid_avp (default "rpid") |
|
102 |
- |
|
103 |
- If string value of an AVP parameter contains only digits, the name of |
|
104 |
- the AVP is int value of the string. |
|
105 |
- |
|
106 |
- Finally, the parameters used by sequential forwarding: |
|
107 |
- |
|
108 |
- * fr_inv_timer (default 90) |
|
109 |
- * fr_inv_timer_next (default 30) |
|
110 |
- * fr_inv_timer_param (default "") |
|
111 |
- * fr_inv_timer_next_param (default "") |
|
112 |
- |
|
113 |
- Function next_contacts() sets tm fr_inv_timer to fr_inv_timer_next |
|
114 |
- value if, after next contacts, there are still lower qvalue |
|
115 |
- contacts available, and to fr_inv_timer value if next contacts are |
|
116 |
- the last ones left. fr_inv_timer_param can define an AVP |
|
117 |
- overwriting fr_inv_timer value, and similarly, AVP defined by |
|
118 |
- fr_inv_timer_next_param can overwrite fr_inv_timer_next value. |
|
119 |
- _________________________________________________________ |
|
120 |
- |
|
121 |
-1.4. Exported Functions |
|
122 |
- |
|
123 |
-1.4.1. load_gws() |
|
124 |
- |
|
125 |
- Loads URIs of gateways matching RPID AVP (if available) or From URI |
|
126 |
- and user part of Request-URI to gw_uri_avp AVPs. Returns 1 or -1 |
|
127 |
- depending on success. |
|
128 |
- |
|
129 |
- Example: |
|
130 |
- |
|
131 |
- if (!load_gws()) { |
|
132 |
- sl_send_reply("500", "Server Internal Error - Cannot load gateways"); |
|
133 |
- break; |
|
134 |
- }; |
|
135 |
- |
|
136 |
-1.4.2. next_gw() |
|
137 |
- |
|
138 |
- If called from a route block, replaces Request-URI by the first |
|
139 |
- gw_uri_avp AVP value and destroys that AVP. |
|
140 |
- |
|
141 |
- If called from a failure route block, appends a new branch to request, |
|
142 |
- whose Request-URI is the first gw_uri_avp AVP value, and destroys that |
|
143 |
- AVP. |
|
144 |
- |
|
145 |
- Returns 1 on success and -1 if there were no gateways left or if an |
|
146 |
- error occurred (see syslog). |
|
147 |
- |
|
148 |
- Must be preceded by successful load_gws() call. |
|
149 |
- |
|
150 |
- Example from route block: |
|
151 |
- |
|
152 |
- if (!next_gw()) { |
|
153 |
- sl_send_reply("503", "Service not available - No gateways"); |
|
154 |
- break; |
|
155 |
- }; |
|
156 |
- |
|
157 |
- Example from failure route block: |
|
158 |
- |
|
159 |
- if (!next_gw()) { |
|
160 |
- t_reply("503", "Service not available - No more gateways"); |
|
161 |
- break; |
|
162 |
- }; |
|
163 |
- |
|
164 |
-1.4.3. from_gw() |
|
165 |
- |
|
166 |
- Checks if request came from IP address of a gateway. |
|
167 |
- |
|
168 |
- Example: |
|
169 |
- |
|
170 |
- if (from_gw()) { |
|
171 |
- ... |
|
172 |
- break; |
|
173 |
- }; |
|
174 |
- |
|
175 |
-1.4.4. to_gw() |
|
176 |
- |
|
177 |
- Checks if in-dialog request goes to a gateway. |
|
178 |
- |
|
179 |
- Example: |
|
180 |
- |
|
181 |
- if (to_gw()) { |
|
182 |
- ... |
|
183 |
- break; |
|
184 |
- }; |
|
185 |
- |
|
186 |
-1.4.5. load_contacts() |
|
187 |
- |
|
188 |
- Loads contacts in destination set in increasing qvalue order as |
|
189 |
- values of lcr_contact AVP. If all contacts in the destination set |
|
190 |
- have the same qvalue, load_contacts() does not do anything thus |
|
191 |
- minimizing performance impact of sequential forking capability when |
|
192 |
- it is not needed. Returns 1 if loading of contacts succeeded or |
|
193 |
- there was nothing to do. Returns -1 on error (see syslog). |
|
194 |
- |
|
195 |
- Example: |
|
196 |
- |
|
197 |
- if (!load_contacts()) { |
|
198 |
- sl_send_reply("500", "Server Internal Error - Cannot load contacts"); |
|
199 |
- break; |
|
200 |
- }; |
|
201 |
- |
|
202 |
-1.4.6. next_contacts() |
|
203 |
- |
|
204 |
- If called from a route block, replaces Request-URI with the first |
|
205 |
- lcr_contact AVP value, adds the remaining lcr_contact AVP values with |
|
206 |
- the same qvalue as branches, and destroys those AVPs. It does |
|
207 |
- nothing if there are no lcr_contact AVPs. Returns 1 if there were no |
|
208 |
- errors and -1 if an error occurred (see syslog). |
|
209 |
- |
|
210 |
- If called from a failure route block, adds the first lcr_contact AVP |
|
211 |
- value and all following lcr_contact AVP values with the same qvalue |
|
212 |
- as new branches to request and destroys those AVPs. Returns 1 if new |
|
213 |
- branches were successfully added and -1 on error (see syslog) or if |
|
214 |
- there were no more lcr_contact AVPs. |
|
215 |
- |
|
216 |
- Must be preceded by successful load_contacts() call. |
|
217 |
- |
|
218 |
- Example from route block: |
|
219 |
- |
|
220 |
- if (!next_contacts()) { |
|
221 |
- sl_send_reply("500", "Server Internal Error"); |
|
222 |
- break; |
|
223 |
- } else { |
|
224 |
- t_relay(); |
|
225 |
- }; |
|
226 |
- |
|
227 |
- Example from failure route block: |
|
228 |
- |
|
229 |
- if (next_contacts()) { |
|
230 |
- t_relay(); |
|
231 |
- }; |
|
232 |
- |
|
233 |
- |
|
234 |
-1.5. FIFO Commands |
|
235 |
- |
|
236 |
-1.5.1. lcr_reload |
|
237 |
- |
|
238 |
- Causes lcr module to re-read the contents of gateway table |
|
239 |
- into memory. |
|
240 |
- |
|
241 |
-1.5.2. lcr_dump |
|
242 |
- |
|
243 |
- Causes lcr module to dump the contents of its in-memory gateway |
|
244 |
- table. |
|
245 |
- |
|
246 |
-1.6. Known Limitations |
|
247 |
- |
|
248 |
- There is an unlikely race condition on lcr reload. If a process uses |
|
249 |
- in memory gw table, which is reloaded at the same time twice through |
|
250 |
- FIFO, the second reload will delete the original table still in use |
|
251 |
- by the process. |
|
252 |
- _________________________________________________________ |
|
253 |
- |
|
254 |
-2.0. TODO |
|
255 |
- |
|
256 |
- Function load_gws() currently makes an SQL query for the matching |
|
257 |
- gateways. In order to avoid the query, also lcr table should be |
|
258 |
- read into memory and the corresponding query should be rewritten in |
|
259 |
- C. |
... | ... |
@@ -103,15 +103,19 @@ Chapter 1. User's Guide |
103 | 103 |
If string value of an AVP parameter contains only digits, the name of |
104 | 104 |
the AVP is int value of the string. |
105 | 105 |
|
106 |
- Finally, there are two parameters used by sequential forwarding: |
|
106 |
+ Finally, the parameters used by sequential forwarding: |
|
107 | 107 |
|
108 |
- * fr_inv_timer (default 90) |
|
109 |
- * fr_inv_timer_next (default 30) |
|
108 |
+ * fr_inv_timer (default 90) |
|
109 |
+ * fr_inv_timer_next (default 30) |
|
110 |
+ * fr_inv_timer_param (default "") |
|
111 |
+ * fr_inv_timer_next_param (default "") |
|
110 | 112 |
|
111 | 113 |
Function next_contacts() sets tm fr_inv_timer to fr_inv_timer_next |
112 | 114 |
value if, after next contacts, there are still lower qvalue |
113 | 115 |
contacts available, and to fr_inv_timer value if next contacts are |
114 |
- the last ones left. |
|
116 |
+ the last ones left. fr_inv_timer_param can define an AVP |
|
117 |
+ overwriting fr_inv_timer value, and similarly, AVP defined by |
|
118 |
+ fr_inv_timer_next_param can overwrite fr_inv_timer_next value. |
|
115 | 119 |
_________________________________________________________ |
116 | 120 |
|
117 | 121 |
1.4. Exported Functions |
... | ... |
@@ -46,19 +46,23 @@ Chapter 1. User's Guide |
46 | 46 |
Each gateway belongs to a gateway group either alone or among other |
47 | 47 |
gateways. All gateways in a group share the same priority. |
48 | 48 |
|
49 |
- Gateway selection operates on two database tables: gw and lcr. Table |
|
50 |
- gw contains gw's name, IP address, port, URI scheme, transport URI |
|
51 |
- parameter, and group id. IP address, URI scheme, and transport are |
|
52 |
- coded as unsigned integers. Valid URI scheme values are NULL = sip, |
|
53 |
- 1 = sip and 2 = sips. Currently valid transport values are NULL = |
|
54 |
- none, 1 = udp, 2 = tcp, and 3 = tls. |
|
49 |
+ Gateway and routing information is kept in two tables: gw and lcr. |
|
50 |
+ |
|
51 |
+ When a gateway is selected, Request-URI is rewritten with information |
|
52 |
+ from gw table: URI scheme, prefix, IP address, port, and transport |
|
53 |
+ protocol. Valid URI scheme values are NULL = sip, 1 = sip and 2 = |
|
54 |
+ sips. Prefix is appended in front of Request-URI user part. |
|
55 |
+ Currently valid transport protocol values are NULL = none, 1 = udp, 2 |
|
56 |
+ = tcp, and 3 = tls. |
|
55 | 57 |
|
56 | 58 |
Table lcr contains prefix of user part of Request-URI, From URI, |
57 | 59 |
gateway group id, and priority. From URI can contain special |
58 | 60 |
characters % and _ matching any number of any characters and any one |
59 |
- character, respectively. In addition to gw and lcr tables there is |
|
60 |
- third table gw_grp that is used for administrative purposes only to |
|
61 |
- associate names with gateway group ids. |
|
61 |
+ character, respectively. |
|
62 |
+ |
|
63 |
+ In addition to gw and lcr tables there is third table gw_grp that is |
|
64 |
+ used for administrative purposes only to associate names with gateway |
|
65 |
+ group ids. |
|
62 | 66 |
_________________________________________________________ |
63 | 67 |
|
64 | 68 |
1.2. Dependencies |
... | ... |
@@ -47,13 +47,18 @@ Chapter 1. User's Guide |
47 | 47 |
gateways. All gateways in a group share the same priority. |
48 | 48 |
|
49 | 49 |
Gateway selection operates on two database tables: gw and lcr. Table |
50 |
- gw contains gw's name, IP address, port, and group id. Table lcr |
|
51 |
- contains prefix of user part of Request-URI, From URI, gateway group |
|
52 |
- id, and priority. From URI can contain special characters % and _ |
|
53 |
- matching any number of any characters and any one character, |
|
54 |
- respectively. In addition to gw and lcr tables there is third table |
|
55 |
- gw_grp that is used for administrative purposes only to associate |
|
56 |
- names with gateway group ids. |
|
50 |
+ gw contains gw's name, IP address, port, URI scheme, transport URI |
|
51 |
+ parameter, and group id. IP address, URI scheme, and transport are |
|
52 |
+ coded as unsigned integers. Valid URI scheme values are NULL = sip, |
|
53 |
+ 1 = sip and 2 = sips. Currently valid transport values are NULL = |
|
54 |
+ none, 1 = udp, 2 = tcp, and 3 = tls. |
|
55 |
+ |
|
56 |
+ Table lcr contains prefix of user part of Request-URI, From URI, |
|
57 |
+ gateway group id, and priority. From URI can contain special |
|
58 |
+ characters % and _ matching any number of any characters and any one |
|
59 |
+ character, respectively. In addition to gw and lcr tables there is |
|
60 |
+ third table gw_grp that is used for administrative purposes only to |
|
61 |
+ associate names with gateway group ids. |
|
57 | 62 |
_________________________________________________________ |
58 | 63 |
|
59 | 64 |
1.2. Dependencies |
... | ... |
@@ -75,6 +80,8 @@ Chapter 1. User's Guide |
75 | 80 |
* gw_name_column (default "gw_name") |
76 | 81 |
* ip_addr_column (default "ip_addr") |
77 | 82 |
* port_column (default "port") |
83 |
+ * uri_scheme_column (default "uri_scheme") |
|
84 |
+ * transport_column (default "transport") |
|
78 | 85 |
* grp_id_column (default "grp_id") |
79 | 86 |
* lcr_table (default "lcr") |
80 | 87 |
* prefix_column (default "prefix") |
... | ... |
@@ -84,12 +91,13 @@ Chapter 1. User's Guide |
84 | 91 |
In addition there are parameters that can be used to override names |
85 | 92 |
of the AVPs used by LCR module: |
86 | 93 |
|
87 |
- * gw_addr_port_avp (default "1400") |
|
94 |
+ * gw_uri_avp (default "1400") |
|
88 | 95 |
* contact_avp (default "1401") |
89 | 96 |
* fr_inv_timer_avp (default "fr_inv_timer_avp") |
97 |
+ * rpid_avp (default "rpid") |
|
90 | 98 |
|
91 |
- If string value of gw_addr_port_avp or contact_avp contains only |
|
92 |
- digits, the name of the AVP is int value of the string. |
|
99 |
+ If string value of an AVP parameter contains only digits, the name of |
|
100 |
+ the AVP is int value of the string. |
|
93 | 101 |
|
94 | 102 |
Finally, there are two parameters used by sequential forwarding: |
95 | 103 |
|
... | ... |
@@ -106,9 +114,9 @@ Chapter 1. User's Guide |
106 | 114 |
|
107 | 115 |
1.4.1. load_gws() |
108 | 116 |
|
109 |
- Loads addresses and ports of gateways matching RPID AVP (if |
|
110 |
- available) or From URI and user part of Request-URI to |
|
111 |
- gw_addr_port_avp AVPs. Returns 1 or -1 depending on success. |
|
117 |