
Installation
------------

For Debian testing or unstable there is an official public repository
provided by AG Projects. Install the AG Projects debian software signing
key:

wget http://download.ag-projects.com/agp-debian-gpg.key apt-key add
agp-debian-gpg.key

Add these lines in etc/apt/sources.list

# AG Projects software
deb http://ag-projects.com/debian unstable main
deb-src http://ag-projects.com/debian unstable main

After that, run:

apt-get update
apt-get install callcontrol

For non Debian installations, you must install the following dependencies:

python-application (>= 1.2.8)
python-twisted-core
python-sqlobject

Call Control software is available as a tar archive at:

http://download.ag-projects.com/CallControl/

Extract it using tar xzvf callcontrol-version.tar.gz and change directory to
the newly created callcontrol directory.

The source code is managed using darcs version control tool. The darcs
repository can be fetched with:

darcs get http://devel.ag-projects.com/repositories/callcontrol

To obtain the incremental changes after the initial get:

cd callcontrol
darcs pull -a

Install the software:

cd callcontrol
python setup.py install


You may run the software from its own directory or install it in a directory
anywhere in the system.


Configuration
-------------

You must setup the following components:

1. OpenSIPS configuration
2. Call Control (this application)
3. CDRTool rating engine


1. OpenSIPS configuration

loadmodule "mi_fifo.so"
loadmodule "mi_datagram.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "dialog.so"
loadmodule "call_control.so"

modparam("call_control", "disable", 0)

route {
...
    if ((method=="INVITE" && !has_totag())) {
       # you need to call this function at the first INVITE
        call_control();
        switch ($retcode) {
        case 2:
            # Call with no limit
        case 1:
            # Call with a limit under callcontrol management (either prepaid
            # or postpaid)
            break;
        case -1:
            # Not enough credit (prepaid call)
            xlog("L_INFO", "Call control: not enough credit for prepaid call\n");
            acc_rad_request("402");
            sl_send_reply("402", "Not enough credit");
            exit;
            break;
        case -2:
            # Locked by call in progress (prepaid call)
            xlog("L_INFO", "Call control: prepaid call locked by another call in progress\n");
            acc_rad_request("403");
            sl_send_reply("403", "Call locked by another call in progress");
            exit;
            break;
        case -3:
            # Duplicated CallID
            xlog("L_INFO", "Call control: duplicated CallID\n");
            acc_rad_request("400");
            sl_send_reply("400", "Duplicated CallID");
            exit;
            break;
        default:
            # Internal error (message parsing, communication, ...)
            xlog("L_INFO", "Call control: internal server error\n");
            acc_rad_request("500");
            sl_send_reply("500", "Internal server error");
            exit;
        }
    }
...
}

For more information see the documentation that comes with the OpenSIPS
callcontrol module.


2. Call Control configuration (this application)

The application is searching for its configuration file config.ini in its current
directory and in /etc/callcontrol/config.ini

[CDRTool]
; connection to cdrtool rating engine for MaxSessionTime() and DebitBalance()
address = cdrtool.hostname:9024

[RadiusDatabase]
; user = radius
; password = password
; host = db
; database = radius
; table = radacct%%Y%%m

[OpenSIPS]
; Connection to OpenSIPS' MI
; socket_path = /run/opensips/socket

A more detailed sample configuration file is available in config.ini.sample.


3. CDRTool rating engine

Please see the documentation of CDRTool project to setup the rating engine.


Logging
-------

Call Control logs all activity to syslog. You may grep for call-control in
syslog. The requests can be correlated by call-id with the syslog entries
generated by CDRTool rating engine.


Control commands
----------------

Monitoring active sessions:

/etc/init.d/callcontrol sessions

Displaying information about an active session:

/etc/init.d/callcontrol session id

Terminating a session:

/etc/init.d/callcontrol terminate id

