Debian Codegraph @

src/modules/cnxcc/README

raw
1 cnxcc Module
2
3 Carlos Ruiz Díaz
4
5 ConexionGroup S.A.
6
7 Copyright © 2013 Carlos Ruiz Díaz, [email protected]
8
9 Copyright © 2014 Carlos Ruiz Díaz, [email protected]
10 __________________________________________________________________
11
12 Table of Contents
13
14 1. Admin Guide
15
16 1. Overview
17 2. Dependencies
18
19 2.1. Modules
20 2.2. Libraries
21
22 3. Parameters
23
24 3.1. redis (integer)
25 3.2. credit_check_period (integer)
26
27 4. Functions
28
29 4.1. cnxcc_set_max_credit(customer, maxcredit, connect, cps,
30 ipulse, fpulse)
31
32 4.2. cnxcc_set_max_time(customer, maxtime)
33 4.3. cnxcc_update_max_time(customer, maxtime)
34 4.4. cnxcc_set_max_channel(customer, maxchan)
35 4.5. cnxcc_terminate_all(customer)
36
37 5. RPC Commands
38
39 5.1. cnxcc.active_clients
40 5.2. cnxcc.check_client
41 5.3. cnxcc.kill_call
42 5.4. cnxcc.stats
43
44 6. Events
45 7. Web Interface
46 8. Sample Config
47
48 List of Examples
49
50 1.1. redis parameter
51 1.2. credit_check_period parameter
52 1.3. cnxcc_set_max_credit()
53 1.4. cnxcc_set_max_time()
54 1.5. cnxcc_update_max_time()
55 1.6. cnxcc_set_max_channels()
56 1.7. cnxcc_set_max_time()
57 1.8. kamailio-cnxcc.cfg
58
59 Chapter 1. Admin Guide
60
61 Table of Contents
62
63 1. Overview
64 2. Dependencies
65
66 2.1. Modules
67 2.2. Libraries
68
69 3. Parameters
70
71 3.1. redis (integer)
72 3.2. credit_check_period (integer)
73
74 4. Functions
75
76 4.1. cnxcc_set_max_credit(customer, maxcredit, connect, cps,
77 ipulse, fpulse)
78
79 4.2. cnxcc_set_max_time(customer, maxtime)
80 4.3. cnxcc_update_max_time(customer, maxtime)
81 4.4. cnxcc_set_max_channel(customer, maxchan)
82 4.5. cnxcc_terminate_all(customer)
83
84 5. RPC Commands
85
86 5.1. cnxcc.active_clients
87 5.2. cnxcc.check_client
88 5.3. cnxcc.kill_call
89 5.4. cnxcc.stats
90
91 6. Events
92 7. Web Interface
93 8. Sample Config
94
95 1. Overview
96
97 This module was designed to act as a mechanism to limit call duration
98 based on credit information parameters. After getting the credit
99 information of the call being set up, you can instruct the module to
100 start monitoring the consumed credit to shutdown a single call or a
101 group of calls in case of credit exhaustion.
102
103 Every call is associated to an unique client/customer identifier. If a
104 credit event occurs, all calls hooked to this identifier are
105 automatically shutdown.
106
107 Cnxcc is dialog-aware so there's no need to explicitly
108 allocate/deallocate the monitoring. The dlg_manage() function must be
109 called in the configuration file for the dialog to be tracked.
110
111 The credit discount rate is proportional to the number of calls grouped
112 inside an identifier. Once the setup of the first call is done, the
113 information remains while the call is active. If the customer starts a
114 new call with the same routing criteria, it will land in the same
115 monitoring bag and it will consume the same pool of credit in rates
116 that are equal to the cost per second of both calls.
117
118 If your accounting program does not maintain the state of the call in
119 real time, this module can provide you with that ability.
120
121 Cnxcc can also provide more common means of monitoring, i.e., by time
122 limit or by maximum simultaneous calls.
123
124 2. Dependencies
125
126 2.1. Modules
127 2.2. Libraries
128
129 2.1. Modules
130
131 The following module must be loaded before this module:
132 * dialog
133
134 2.2. Libraries
135
136 The following module must be loaded before this module:
137 * hiredis-devel >= 0.11.0
138 * libevent-devel >= 2.0.18-2
139
140 3. Parameters
141
142 3.1. redis (integer)
143 3.2. credit_check_period (integer)
144
145 3.1. redis (integer)
146
147 Redis datasource connection information
148
149 Example 1.1. redis parameter
150 ...
151 modparam("cnxcc", "redis", "addr=127.0.0.1;port=6379;db=1")
152 ...
153
154 3.2. credit_check_period (integer)
155
156 Indicates how often the credit checking function should be called. It
157 is directly related to the precision of the module. The maximum
158 precision is 1, which means that every call is checked every one
159 second.
160
161 Values greater than 1 leads to precision lost but less CPU consumption.
162
163 Example 1.2. credit_check_period parameter
164 ...
165 modparam("cnxcc", "credit_check_period", 1)
166 ...
167
168 4. Functions
169
170 4.1. cnxcc_set_max_credit(customer, maxcredit, connect, cps, ipulse,
171 fpulse)
172
173 4.2. cnxcc_set_max_time(customer, maxtime)
174 4.3. cnxcc_update_max_time(customer, maxtime)
175 4.4. cnxcc_set_max_channel(customer, maxchan)
176 4.5. cnxcc_terminate_all(customer)
177
178 4.1. cnxcc_set_max_credit(customer, maxcredit, connect, cps, ipulse, fpulse)
179
180 Note
181
182 The dlg_manage() function must be called in the configuration file to
183 ensure dialog is tracked.
184
185 Associates the call with a customer id and sets the max credit, connect
186 cost, cost per second, initial pulse and final pulse. The discount is
187 calculated in pulses (1/1, 60/1, etc) and subtracted from the pool of
188 credit.
189
190 The customer value can be provided as a string or a variable holding a
191 string. This value identifies all calls from the same customer.
192
193 The maxcredit (float) value is the maximum credit available for the
194 current call.
195
196 The connect (float) value is the connect cost for the current call.
197
198 The cps (float) value is the cost per second for the current call.
199
200 The ipuse (integer) value is the initial pulse and establishes the
201 minimum time to be charged. For example, value 1 establishes a charge
202 per second and value 60 sets a charge per minute. If it is taken as
203 value 60, even if the duration is 5 seconds, 1 minute will be charged.
204
205 The fpulse (integer) value is the final pulse and establishes, from the
206 initial pulse, the time range to be charged. For example, the value 1
207 establishes a charge per second, 5 sets a charge in blocks of 5
208 seconds, 60 sets a full minute charge.
209
210 1/1 will make a charge per seconds for the entire call. 60/1 will make
211 a charge per seconds with the first full minute. 60/60 always perform a
212 full minute charge.
213
214 Return code:
215 * 1 - successful
216 * -1 - failed, error logged
217 * -4 - call-id already present for this client
218
219 Example 1.3. cnxcc_set_max_credit()
220 ...
221 cnxcc_set_max_credit("john-doe", "100", "3.0", "0.5", 60, 1);
222 ...
223 $var(customer) = "john-doe"; # customer id
224 $var(credit) = "100"; # max credit for all calls with the same
225 # customer id
226 $var(connect) = "3.0"; # connect cost or initial cost for the call
227 $var(cps) = "0.5"; # cost per second
228 $var(initial_p) = 60; # initial pulse (60 = the first minute will be
229 # charged even if the call is shorter)
230 $var(final_p) = 1; # final pulse (after the first minute, it will
231 # be charge in ranges of 1 second)
232 cnxcc_set_max_credit("$var(customer)", "$var(credit)", "$var(connect)",
233 "$var(cps)", "$var(initial_p)", "$var(final_p)");
234 ...
235
236 4.2. cnxcc_set_max_time(customer, maxtime)
237
238 Note
239
240 The dlg_manage() function must be called in the configuration file to
241 ensure dialog is tracked.
242
243 Specifies the amount of time the call should last at most.
244
245 The customer value can be provided as a string or a variable holding a
246 string.
247
248 The maxtime value is an integer values, it can be also given via a
249 variable holding an integer.
250
251 Return code:
252 * 1 - successful
253 * -1 - failed, error logged
254 * -4 - call-id already present for this client
255
256 Example 1.4. cnxcc_set_max_time()
257 ...
258 $var(customer) = "john-doe-basic";
259 $var(max_time) = 120;
260 cnxcc_set_max_time("$var(customer)", "$var(max_time)");
261 ...
262
263 4.3. cnxcc_update_max_time(customer, maxtime)
264
265 Note
266
267 The dlg_manage() function must be called in the configuration file to
268 ensure dialog is tracked.
269
270 Updates max-time of an established and monitored call. This can be used
271 to grant minimum values and to update them every short periods on time
272 as a mean to prevent frauds and/or to mimic requested/granted units of
273 time of Credit Control Application behavior.
274
275 The customer value can be provided as a string or a variable holding a
276 string.
277
278 The maxtime value is an integer values, it can be also given via a
279 variable holding an integer.
280
281 Return code:
282 * 1 - successful
283 * -1 - failed, error logged
284
285 Example 1.5. cnxcc_update_max_time()
286 ...
287 $var(client) = "john-doe-basic";
288 $var(update_time) = 5;
289
290 if (!cnxcc_update_max_time("$var(client)", "$var(update_time)")) {
291 xlog("Error updating max-time");
292 return;
293 }
294 ...
295
296 4.4. cnxcc_set_max_channel(customer, maxchan)
297
298 Note
299
300 The dlg_manage() function must be called in the configuration file to
301 ensure dialog is tracked.
302
303 Specifies a limit for the number of simultaneous calls.
304
305 The customer value can be provided as a string or a variable holding a
306 string.
307
308 The maxchan value is an integer values, it can be also given via a
309 variable holding an integer.
310
311 Return code:
312 * 1 - successful
313 * -1 - failed, error logged
314 * -2 - failed, calls established plus calls being established result
315 in more than the limit you specified
316 * -3 - failed, number of calls established is more than the limit you
317 specified
318 * -4 - call-id already present for this client
319
320 Example 1.6. cnxcc_set_max_channels()
321 ...
322 $var(customer) = "john-doe-123-basic";
323 $var(max_chan) = 2;
324 $var(retcode) = cnxcc_set_max_channels("$var(customer)", "$var(max_chan)");
325
326 if ($var(retcode) == -1) {
327 xlog("Error setting up credit control");
328 return;
329 }
330
331 if ($var(retcode) < -1) {
332 xlog("Too many channels for customer");
333 sl_send_reply(403, "Forbidden");
334
335 if (!cnxcc_terminate_all("$var(customer)")) {
336 xlog("Error terminating customer's calls");
337 }
338
339 exit;
340 }
341 ...
342
343 4.5. cnxcc_terminate_all(customer)
344
345 Terminates all calls of the specified customer/profile.
346
347 The customer value can be provided as a string or a variable holding a
348 string.
349
350 Return code:
351 * 1 - successful
352 * -1 - failed, error logged
353
354 Example 1.7. cnxcc_set_max_time()
355 ...
356 $var(customer) = "john-doe-123-basic";
357
358 if (!cnxcc_terminate_all("$var(customer)")) {
359 xlog("Error terminating customer's calls");
360 }
361 ...
362
363 5. RPC Commands
364
365 5.1. cnxcc.active_clients
366 5.2. cnxcc.check_client
367 5.3. cnxcc.kill_call
368 5.4. cnxcc.stats
369
370 5.1. cnxcc.active_clients
371
372 Retrieves all calls grouped by their identifiers.
373
374 Parameters: none
375
376 Example:
377 ...
378 kamcmd cnxcc.active_clients
379 ...
380
381 5.2. cnxcc.check_client
382
383 Retrieves all calls from a particular identifier.
384
385 Parameters: client/customer identifier
386
387 Example:
388 ...
389 kamcmd cnxcc.check_client john-doe-premium
390 ...
391
392 5.3. cnxcc.kill_call
393
394 Kills an active call using its call ID.
395
396 Parameters: Call-ID
397
398 Example:
399 ....
400 kamcmd cnxcc.kill_call [email protected]
401 ...
402
403 5.4. cnxcc.stats
404
405 List credit control stats.
406
407 Parameters: none
408
409 Example:
410 ...
411 kamcmd cnxcc.stats
412 ...
413
414 6. Events
415
416 When a call is forced to end an event route is automatically invoked.
417 This route is suited with a fake OPTIONS message containing the call
418 ID, ftag and ttag of the original call so it can be located somehow in
419 the accounting database.
420
421 Example:
422 ...
423 event_route[cnxcc:call-shutdown]
424 {
425 xlog("L_INFO", "[$ci]: call killed");
426
427 # perform some kind of notification, database update, email sending, etc
428 .
429 }
430 ...
431
432 7. Web Interface
433
434 The module contains a web management interface completely optional.
435 With it, you can review your calls in real time and hang them up if
436 necessary.
437
438 Link: https://github.com/caruizdiaz/cnxcc-web
439
440 8. Sample Config
441
442 Example 1.8. kamailio-cnxcc.cfg
443 ...
444 route[CNXCC]
445 {
446 $var(client) = "test-client";
447 $var(credit) = "50";
448 $var(connect_cost) = "3.0";
449 $var(cost_per_sec) = "0.5";
450 $var(i_pulse) = 30;
451 $var(f_pulse) = 6;
452
453
454 cnxcc_set_max_credit("$var(client)",
455 "$var(credit)",
456 "$var(connect_cost)",
457 "$var(cost_per_sec)",
458 "$var(i_pulse)",
459 "$var(f_pulse)");
460
461 switch ($?) {
462 case -1:
463 xerr("Error setting up credit control");
464 sl_send_reply("503", "Internal Server Error");
465 case -4:
466 xwarn("$ci already present for client $var(client)");
467 };
468 }
469
470 event_route[cnxcc:call-shutdown]
471 {
472 xlog("L_INFO", "[$ci]: call killed");
473 }
474 ...