call_control_admin.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section id="call_control.overview">
  12. <title>Overview</title>
  13. <para>
  14. This module allows one to limit the duration of calls and automatically
  15. end them when they exceed the imposed limit. Its main use case is to
  16. implement a prepaid system, but it can also be used to impose a global
  17. limit on all calls processed by the proxy.
  18. </para>
  19. </section>
  20. <section>
  21. <title>Description</title>
  22. <para>
  23. Callcontrol consists of 3 components:
  24. <itemizedlist>
  25. <listitem>
  26. <para>The &kamailio; call_control module</para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. An external application called callcontrol which keeps track of
  31. the calls that have a time limit and automatically ends them when
  32. they exceed it. This application receives requests from &kamailio;
  33. and makes requests to a rating engine (see below) to find out if
  34. a call needs to be limited or not. When a call ends (or is ended)
  35. it will also instruct the rating engine to debit the balance for
  36. the caller with the consumed amount. The callcontrol application
  37. is available from http://callcontrol.ag-projects.com/
  38. </para>
  39. </listitem>
  40. <listitem>
  41. <para>
  42. A rating engine that is used to calculate the time limit based on
  43. the caller's credit and the destination price and to debit the
  44. caller's balance after a call ends. This is available as part of
  45. CDRTool from http://cdrtool.ag-projects.com/
  46. </para>
  47. </listitem>
  48. </itemizedlist>
  49. </para>
  50. <para>
  51. The callcontrol application runs on the same machine as &kamailio; and they
  52. communicate over a filesystem socket, while the rating engine can run on
  53. a different host and communicates with the callcontrol application using
  54. a TCP connection.
  55. </para>
  56. <para>
  57. Callcontrol is invoked by calling the call_control() function for the
  58. initial INVITE of every call we want to apply a limit to. This will end
  59. up as a request to the callcontrol application, which will interogate
  60. the rating engine for a time limit for the given caller and destination.
  61. The rating engine will determine if the destination has any associated
  62. cost and if the caller has any credit limit and if so will return the
  63. amount of time he is allowed to call that destination. Otherwise it will
  64. indicate that there is no limit associated with the call. If there is a
  65. limit, the callcontrol application will retain the session and attach
  66. a timer to it that will expire after the given time causing it to call
  67. back to &kamailio; with a request to end the dialog. If the rating engine
  68. returns that there is no limit for the call, the session is discarded
  69. by the callcontrol application and it will allow it to go proceed any
  70. limit. An appropriate response is returned to the call_control module
  71. that is then returned by the call_control() function call and allows
  72. the script to make a decision based on the answer.
  73. </para>
  74. </section>
  75. <section>
  76. <title>Features</title>
  77. <para>
  78. <itemizedlist>
  79. <listitem>
  80. <para>
  81. Very simple API consisting of a single function that needs to be
  82. called once for the first INVITE of every call. The rest is done
  83. automatically in the background using dialog callbacks.
  84. </para>
  85. </listitem>
  86. <listitem>
  87. <para>
  88. Gracefully end dialogs when they exceed their time by triggering
  89. a dlg_end_dlg request into the dialog module, that will generate
  90. two BYE messages towards each endpoint, ending the call cleanly.
  91. </para>
  92. </listitem>
  93. <listitem>
  94. <para>
  95. Allow parallel sessions using one balance per subscriber
  96. </para>
  97. </listitem>
  98. <listitem>
  99. <para>
  100. Integrates with mediaproxy's ability to detect when a call does
  101. timeout sending media and is closed. In this case the dlg_end_dlg
  102. that is triggered by mediaproxy will end the callcontrol session
  103. before it reaches the limit and consumes all the credit for a call
  104. that died and didn't actually take place. For this mediaproxy has
  105. to be used and it has to be started by engage_media_proxy() to be
  106. able to keep track of the call's dialog and end it on timeout.
  107. </para>
  108. <para>
  109. Even when mediaproxy is unable to end the dialog because it was
  110. not started with engage_media_proxy(), the callcantrol application
  111. is still able to detect calls that did timeout sending media, by
  112. looking in the radius accounting records for entries recorded by
  113. mediaproxy for calls that did timeout. These calls will also be
  114. ended gracefully by the callcontrol application itself.
  115. </para>
  116. </listitem>
  117. </itemizedlist>
  118. </para>
  119. </section>
  120. <section>
  121. <title>Dependencies</title>
  122. <section>
  123. <title>&kamailio; Modules</title>
  124. <para>
  125. The following modules must be loaded before this module:
  126. <itemizedlist>
  127. <listitem>
  128. <para>
  129. <emphasis>dialog</emphasis> module
  130. </para>
  131. </listitem>
  132. </itemizedlist>
  133. </para>
  134. </section>
  135. <section>
  136. <title>External Libraries or Applications</title>
  137. <para>
  138. The following libraries or applications must be installed before
  139. running &kamailio; with this module loaded:
  140. <itemizedlist>
  141. <listitem>
  142. <para>
  143. <emphasis>None</emphasis>.
  144. </para>
  145. </listitem>
  146. </itemizedlist>
  147. </para>
  148. </section>
  149. </section>
  150. <section>
  151. <title>Exported parameters</title>
  152. <section id="call_control.p.disable">
  153. <title><varname>disable</varname> (int)</title>
  154. <para>
  155. Boolean flag that specifies if callcontrol should be disabled. This
  156. is useful when you want to use the same &kamailio; configuration in
  157. two different contexts, one using callcontrol, the other not. In the
  158. case callcontrol is disabled, calls to the call_control() function
  159. will return a code indicating that there is no limit associated with
  160. the call, allowing the use of the same configuration without changes.
  161. </para>
  162. <para>
  163. <emphasis>
  164. Default value is <quote>0</quote>.
  165. </emphasis>
  166. </para>
  167. <example>
  168. <title>Setting the <varname>disable</varname> parameter</title>
  169. <programlisting format="linespecific">
  170. ...
  171. modparam("call_control", "disable", 1)
  172. ...
  173. </programlisting>
  174. </example>
  175. </section>
  176. <section id="call_control.p.socket_name">
  177. <title><varname>socket_name</varname> (string)</title>
  178. <para>
  179. The path to the filesystem socket where the callcontrol
  180. application listens for commands from the module.
  181. </para>
  182. <para>
  183. <emphasis>
  184. Default value is
  185. <quote>/var/run/callcontrol/socket</quote>.
  186. </emphasis>
  187. </para>
  188. <example>
  189. <title>Setting the <varname>socket_name</varname> parameter</title>
  190. <programlisting format="linespecific">
  191. ...
  192. modparam("call_control", "socket_name", "/var/run/callcontrol/socket")
  193. ...
  194. </programlisting>
  195. </example>
  196. </section>
  197. <section id="call_control.p.socket_time">
  198. <title><varname>socket_timeout</varname> (int)</title>
  199. <para>
  200. How long time (in milliseconds) to wait for an answer from the
  201. callcontrol application.
  202. </para>
  203. <para>
  204. <emphasis>
  205. Default value is <quote>500</quote> ms.
  206. </emphasis>
  207. </para>
  208. <example>
  209. <title>Setting the <varname>socket_timeout</varname> parameter</title>
  210. <programlisting format="linespecific">
  211. ...
  212. modparam("call_control", "socket_timeout", 500)
  213. ...
  214. </programlisting>
  215. </example>
  216. </section>
  217. <section id="call_control.p.signaling_ip_avp">
  218. <title><varname>signaling_ip_avp</varname> (string)</title>
  219. <para>
  220. Specification of the AVP which holds the IP address from where
  221. the SIP signaling originated. If this AVP is set it will be used
  222. to get the signaling IP address, else the source IP address
  223. from where the SIP message was received will be used.
  224. This AVP is meant to be used in cases where there are more than
  225. one proxy in the call setup path and the proxy that actually
  226. starts callcontrol doesn't receive the SIP messages directly
  227. from the UA and it cannot determine the NAT IP address from
  228. where the signaling originated. In such a case attaching a
  229. SIP header at the first proxy and then copying that header's
  230. value into the signaling_ip_avp on the proxy that starts
  231. callcontrol will allow it to get the correct NAT IP address
  232. from where the SIP signaling originated.
  233. </para>
  234. <para>
  235. This is used by the rating engine which finds the rates to apply to a
  236. call based on caller's SIP URI, caller's SIP domain or caller's IP
  237. address (whichever yields a rate forst, in this order).
  238. </para>
  239. <para>
  240. <emphasis>
  241. Default value is <quote>$avp(s:signaling_ip)</quote>.
  242. </emphasis>
  243. </para>
  244. <example>
  245. <title>Setting the <varname>signaling_ip_avp</varname> parameter</title>
  246. <programlisting format="linespecific">
  247. ...
  248. modparam("call_control", "signaling_ip_avp", "$avp(s:signaling_ip)")
  249. ...
  250. </programlisting>
  251. </example>
  252. </section>
  253. <section id="call_control.p.canonical_uri_avp">
  254. <title><varname>canonical_uri_avp</varname> (string)</title>
  255. <para>
  256. Specification of the AVP which holds an optional application defined
  257. canonical request URI. When this is set, it will be used as the
  258. destination when computing the call price, otherwise the request URI
  259. will be used. This is useful when the username of the ruri needs to
  260. have a different, canonical form in the rating engine computation
  261. than it has in the ruri.
  262. </para>
  263. <para>
  264. <emphasis>
  265. Default value is <quote>$avp(s:can_uri)</quote>.
  266. </emphasis>
  267. </para>
  268. <example>
  269. <title>Setting the <varname>canonical_uri_avp</varname> parameter</title>
  270. <programlisting format="linespecific">
  271. ...
  272. modparam("call_control", "canonical_uri_avp", "$avp(s:can_uri)")
  273. ...
  274. </programlisting>
  275. </example>
  276. </section>
  277. <section id="call_control.p.diverter_avp_id">
  278. <title><varname>diverter_avp_id</varname> (string)</title>
  279. <para>
  280. Specification of the id of an integer AVP which holds an optional
  281. application defined diverter SIP URI. When this is set, it will be
  282. used by the rating engine as the billing party when finding the rates
  283. to apply to a given call, otherwise, the caller's URI taken from the
  284. From field will be used. When set, this AVP should contain a value in
  285. the form <quote>user@domain</quote> (no sip: prefix should be used).
  286. </para>
  287. <para>
  288. This is useful when a destination diverts a call, thus becoming the
  289. new caller. In this case the billing party is the diverter and this
  290. AVP should be set to it, to allow the rating engine to pick the right
  291. rates for the call. For example, if A calls B and B diverts all its
  292. calls unconditionally to C, then the diverter AVP should the set to
  293. B's URI, because B is the billing party in the call not A after the
  294. call was diverted.
  295. </para>
  296. <para>
  297. <emphasis>
  298. Default value is <quote>805</quote>.
  299. </emphasis>
  300. </para>
  301. <example>
  302. <title>Setting the <varname>diverter_avp_id</varname> parameter</title>
  303. <programlisting format="linespecific">
  304. ...
  305. modparam("call_control", "diverter_avp_id", 805)
  306. route {
  307. ...
  308. # [email protected] is paying for this call
  309. $avp(i:805) = "sip:[email protected]";
  310. ...
  311. }
  312. ...
  313. </programlisting>
  314. </example>
  315. </section>
  316. </section>
  317. <section>
  318. <title>Functions</title>
  319. <section id="call_control.f.call_control">
  320. <title><function moreinfo="none">call_control()</function></title>
  321. <para>
  322. Trigger the use of callcontrol for the dialog started by the INVITE
  323. for which this function is called (the function should only be called
  324. for the first INVITE of a call). Further in-dialog requests will be
  325. processed automatically using internal bindings into the dialog state
  326. machine, allowing callcontrol to update its internal state as the
  327. dialog progresses, without any other intervention from the script.
  328. </para>
  329. <para>
  330. This function should be called right before the message is sent out
  331. using t_relay(), when all the request uri modifications are over and
  332. a final destination has been determined.
  333. </para>
  334. <para>This function has the following return codes:</para>
  335. <para>
  336. <itemizedlist>
  337. <listitem><para>
  338. +2 - call has no limit
  339. </para></listitem>
  340. <listitem><para>
  341. +1 - call has limit and is traced by callcontrol
  342. </para></listitem>
  343. <listitem><para>
  344. -1 - not enough credit to make the call
  345. </para></listitem>
  346. <listitem><para>
  347. -2 - call is locked by another call in progress
  348. </para></listitem>
  349. <listitem><para>
  350. -5 - internal error (message parsing, communication, ...)
  351. </para></listitem>
  352. </itemizedlist>
  353. </para>
  354. <para>
  355. This function can be used from REQUEST_ROUTE.
  356. </para>
  357. <example>
  358. <title>Using the <function>call_control</function> function</title>
  359. <programlisting format="linespecific">
  360. ...
  361. if (is_avp_set("$avp(i:805)")) {
  362. # the diverter AVP is set, use it as billing party
  363. $avp(s:billing_party_domain) = $(avp(i:805){uri.domain});
  364. } else {
  365. $avp(s:billing_party_domain) = $fd;
  366. }
  367. if (method==INVITE &amp;&amp; !has_totag() &amp;&amp;
  368. is_domain_local("$avp(s:billing_party_domain)")) {
  369. call_control();
  370. switch ($retcode) {
  371. case 2:
  372. # Call with no limit
  373. case 1:
  374. # Call has limit and is under callcontrol management
  375. break;
  376. case -1:
  377. # Not enough credit (prepaid call)
  378. sl_send_reply("402", "Not enough credit");
  379. exit;
  380. break;
  381. case -2:
  382. # Locked by another call in progress (prepaid call)
  383. sl_send_reply("403", "Call locked by another call in progress");
  384. exit;
  385. break;
  386. default:
  387. # Internal error (message parsing, communication, ...)
  388. if (PREPAID_ACCOUNT) {
  389. xlog("Call control: internal server error\n");
  390. sl_send_reply("500", "Internal server error");
  391. exit;
  392. } else {
  393. xlog("L_WARN", "Cannot set time limit for postpaid call\n");
  394. }
  395. }
  396. }
  397. t_relay();
  398. ...
  399. </programlisting>
  400. </example>
  401. </section>
  402. </section>
  403. </chapter>