# &adminguide;

## Overview

This module tracks dialogs (active calls) in stateless mode and offers statistics about them.

The dialogs can be tagged and the number of dialogs with the same tag can be retrieved in configuration file.

The module aims to be a lightweight alternative to dialog module, to enable SIP server instances (such as an edge proxy or SBC) to know how many active calls they route, without being a call stateful proxy. The tracking of active calls is done without any dependency on other modules, in other words, it does not need the tm (transaction management) module.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- none.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- none

## Parameters

### `active_lifetime` (int)

The lifetime in seconds of an active dialog in memory. A dialog is considered active after the ACK of 200 OK for INVITE.

Default value is 10800 (3 hours).

#### Set `active_lifetime` parameter

    ...
    modparam("dlgs", "active_lifetime", 3600)
    ...

### `init_lifetime` (int)

The lifetime in seconds of an initial dialog in memory. A dialog is in initial state from the moment of creation until it gets to active state. If the dialog stays longer in the initial state, then it is destroyed by the next timer cleanup.

Default value is 180 (3 minutes).

#### Set `init_lifetime` parameter

    ...
    modparam("dlgs", "init_lifetime", 240)
    ...

### `finish_lifetime` (int)

The lifetime in seconds of a finished dialog in memory. A dialog is finished if the initial INVITE was not answered or the BYE was received. Once this lifetime passes, the dialog record is removed from memory by the next timer cleanup.

Default value is 10 (seconds).

#### Set `finish_lifetime` parameter

    ...
    modparam("dlgs", "finish_lifetime", 20)
    ...

### `timer_interval` (int)

The value in seconds to run the timer callback function for cleaning up dialogs past the lifetime limit.

Default value is 30.

#### Set `timer_interval` parameter

    ...
    modparam("dlgs", "timer_interval", 60)
    ...

### `hash_size` (integer)

The size of the hash table internally used to keep the dialogs. A larger table is much faster but consumes more memory. The hash size must be a power of two.

Default value is 9.

#### Set `hash_size` parameter

    ...
    modparam("dlgs", "hash_size", 5)
    ...

## Functions

### `dlgs_init(src, dst, data)`

Start track the dialog corresponding to the current SIP message. It has to be used for INVITE messages.

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, ONREPLY_ROUTE, ONSEND_ROUTE.

#### `dlgs_init` usage

    ...
    onsend_route {
        ...
        if(is_method("INVITE")) {
            dlgs_init("$fu", "$tu", "my data");
        }
        ...
    }
    ...

### `dlgs_update()`

Update dialog state. It has to be used for SIP requests only, the SIP responses are handled automatically.

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, ONSEND_ROUTE.

#### `dlgs_update` usage

    ...
    request_route {
        ...
        if(is_method("ACK|BYE|CANCEL")) {
            dlgs_update();
        }
        ...
    }
    ...

### `dlgs_count(field, op, data)`

Return the number of dialogs matching the filter specified by the parameters. It does not count the dialogs that are finished (not answered or terminated with BYE).

The field parameter can be: 'src', 'dst', 'data' to specify what dialog attribute has to be used for matching. It can be also 'any' to get the count of all ongoing dialogs.

The op parameter can be: 'eq' - equal; 'ne' - not equal; 're' - regex; 'sw' - start with; 'fm' - fnmatch.

In case of error or no dialog matched, it returns -1 or other negative (false) value.

This function can be used from ANY_ROUTE.

#### `dlgs_count` usage

    ...
    request_route {
        ...
        $var(count) = dlgs_count("src", "eq", "$fu");
        if($var(count) > 0) {
            # caller has ongoing dialogs
        }
        ...
        $var(allcalls) = dlgs_count("any", "eq", "*");
        if($var(allcalls) > 0) {
            # there are ongoing dialogs
        }
        ...
    }
    ...

### `dlgs_tags_add(vtag)`

Add a tag to current dialog.

This function can be used from ANY_ROUTE.

#### `dlgs_tags_add` usage

    ...
    request_route {
        ...
        dlgs_tags_add("$si");
        ...
    }
    ...

### `dlgs_tags_rm(vtag)`

Remove a tag from current dialog.

This function can be used from ANY_ROUTE.

#### `dlgs_tags_rm` usage

    ...
    request_route {
        ...
        dlgs_tags_rm("$si");
        ...
    }
    ...

### `dlgs_tags_count(vtag)`

Count all tags for ongoing dialogs matching the parameter.

It returns -1 if no tag for ongoing dialogs is matched or there was an error.

This function can be used from ANY_ROUTE.

#### `dlgs_tags_count` usage

    ...
    request_route {
        ...
        $var(tcount) = dlgs_tags_count("$si");
        ...
    }
    ...

## RPC Commands

### `dlgs.list`

List dialog records.

#### `dlgs.list` usage

    ...
    &kamctl; rpc dlgs.list
    ...

### `dlgs.briefing`

List dialog records with fewer attributes per record.

#### `dlgs.briefing` usage

    ...
    &kamctl; rpc dlgs.briefing
    ...

### `dlgs.get`

Prototype: dlgs.get field op data

List first dialog record matching the filter. The parameters have the same meaning like those for dlgs_count(...).

#### `dlgs.get` usage

    ...
    &kamctl; rpc dlgs.get src eq sip:alice@sipserver.com
    ...

### `dlgs.getall`

Prototype: dlgs.getall field op data

List all dialog records matching the filter. The parameters have the same meaning like those for dlgs_count(...).

#### `dlgs.getall` usage

    ...
    &kamctl; rpc dlgs.getall src eq sip:alice@sipserver.com
    ...

### `dlgs.stats`

Return dialog statistics.

#### `dlgs.stats` usage

    ...
    &kamctl; rpc dlgs.stats
    ...