Table of Contents
List of Examples
ping_interval
parameterdestination
parameterdelete_counter
parameterping_from
parameterka_is_alive()
usageka_add_destination(sip_uri, ownder)
usageka_del_destination(sip_uri, owner)
usagekeepalive.list
RPC examplekeepalive.add
RPC examplekeepalive.del
RPC examplekeepalive.get
RPC examplekeepalive.flush
RPC exampleTable of Contents
This module performs destinations monitoring either for itself, or on the behalf of other modules. The monitoring is done by sending SIP OPTIONS requests, more or less in the same fashion as the dispatcher module (which was the initial source for this module).
As an example of usage by other modules, see drouting, which was enhanced to use this module to monitor its gateways.
The following modules must be loaded before this module:
tm - Transaction module
The following libraries or applications must be installed before running Kamailio with this module loaded:
none
Define the interval (in seconds) ping requests are sent to destinations
Default value is 30 seconds.
Allows to statically define destinations you want to monitor
Example 1.2. Set destination
parameter
... modparam("keepalive", "destination", "192.168.10.20") modparam("keepalive", "destination", "sip.provider.com") ...
Unsuccessful attempts increase delete_counter. After passing it, keepalive module doesn't try to send options requests. Ignored if it's set to 0.
Default value is 5 .
Get destination status.
The parameter destination is destination you want to check status
Returned value:
This function can be used from ANY_ROUTE.
Adds SIP URI in the memory destinations list to perform keep alive to it.
Meaning of the parameters:
Returned value:
This function can be used from REQUEST_ROUTE,BRANCH_ROUTE,ONREPLY_ROUTE.
Example 1.6. ka_add_destination(sip_uri, ownder)
usage
... $avp(duri1)="sip:192.168.1.10:5060;transport=tcp"; $avp(duri2)="sip:192.168.1.11:5061"; $avp(duri3)="sip:192.168.1.12" ka_add_destination("$avp(duri3)", "config"); ka_add_destination("sip:192.168.1.10:5060;transport=tcp", "config"); ...
Deletes the SIP URI from the memory destinations list used for monitoring.
Meaning of the parameters:
Returned value:
This function can be used from ANY_ROUTE.
Example 1.7. ka_del_destination(sip_uri, owner)
usage
... $avp(duri1)="sip:192.168.1.10:5060;transport=tcp"; $avp(duri2)="sip:192.168.1.11:5061"; $avp(duri3)="sip:192.168.1.12" ka_del_destination("$avp(duri3)", "config"); ka_del_destination("sip:192.168.1.10:5060;transport=tcp", "config"); ...
Lists destinations in memory.
Name: keepalive.list
Parameters: none
Adds destination in memory.
Name: keepalive.add
Parameters: sip_uri listname
Deletes destination in memory.
Name: keepalive.del
Parameters: sip_uri listname
Gets destination in memory.
Name: keepalive.get
Parameters: sip_uri listname
Table of Contents
The KeepAlive module provides an internal API to be used by other Kamailio modules. This API offers support for destinations monitoring.
For internal (non-script) usage, the KeepAlive module offers to other module the possibility to register callback functions to be executed for each destination's status change.
This function registers a new destination to monitor. Monitoring of the destination starts as soon as it returns with success (0 value).
Meaning of the parameters is as follows:
uri (string) - address of destination to monitor. Valid format is [proto:]ip[:port], with:
owner (string) - module name “owning” the destination (for information purpose)
flags (integer) - destination flags (unused for now, use 0 value)
ping_interval (integer) - Pinging interval in seconds for this destination
statechanged_clb (ka_statechanged_f, optional) - callback function, executed on destination's state change.
The callback function is of type void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
. Use NULL to set no callback.
destination's state value is one of:
response_clb (ka_response_f, optional) - callback function, executed on destination's response provided.
The callback function is of type void (*ka_response_f)(str *uri, struct tmcb_params *ps, void *user_attr);
. Use NULL to set no callback.
ps is a pack structure with all params passed to callback function. Defined in t_hooks.h
user_attr (void * pointer, optional) - If any callback function is setup, this parameter will be forwarded to it (or both callbacks in both are defined), as last parameter. Use NULL to set no user_attr parameter.
Returned values:
Example 2.1. Loading KeepAlive module's API from another module, adding a destination to monitor & registering a callback
... #include "../keepalive/api.h" ... keepalive_api_t ka_api; ... ... /* loading keepalive API */ if (bind_keepalive( &ka_api ) != 0) { LM_ERR("can't load KeepAlive API\n"); goto error; } ... ... /* callback function (on state changed) */ void my_state_changed_clb(str uri, int state, void *user_attr) { printf("%.*s new state is: %d\n", uri.len, uri.str, state) } /* callback function (on each response received) */ void my_response_clb(str *uri, struct tmcb_params *ps, void *user_attr) { printf("response [%d] from %.*s\n", ps->code, uri.len, uri.str) } if (ka_api.add_destination(dest, owner, 0, 60, my_state_changed_clb, my_response_clb, NULL) != 0) { LM_ERR("can't add destination\n"); goto error; } ...