This shows you the differences between two versions of the page.
— | freeswitch:kamailio-3.0.x-freeswitch-1.0.6d-ms [2010/10/26 09:48] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Kamailio 3.0.x and FreeSWITCH 1.0.6+ for Media Services ====== | ||
+ | < | ||
+ | Author: | ||
+ | Daniel-Constantin Mierla | ||
+ | </ | ||
+ | |||
+ | ===== Overview ===== | ||
+ | |||
+ | The scope of this tutorial is to show how you can use [[http:// | ||
+ | |||
+ | Kamailio is an open source SIP server, forked from SIP Express Router (SER) in 2005 under the name OpenSER. In July 2008, OpenSER was renamed to Kamailio because of trademark issues. Starting with November 2008, Kamailio and SER teams restarted development collaboration, | ||
+ | |||
+ | One of outstanding features of Kamailio is ability of hosting large number of active users in a single instance (depending of hardware it can be 100 000+). Long development life ensures the stability required in real-time tele-comunications and a broad set of features in handling SIP signaling. | ||
+ | |||
+ | FreeSWITCH is an open source multi-protocol softswitch, supporting SIP as well. It is a very attractive project from features and extensibility point of view. Its media processing capabilities makes FreeSWITCH a perfect fit for providing media services to Kamailio based platforms. | ||
+ | |||
+ | Any Kamailio version 3.0.x can be used (right now last released is 3.0.1). For FreeSWITCH I used the development version from GIT after release 1.0.6, but before any other official release (no 1.0.7 or what is going to be next). | ||
+ | |||
+ | Following services are handled in the scenario built within document: | ||
+ | * kamailio | ||
+ | * user authentication | ||
+ | * user registration | ||
+ | * user location | ||
+ | * call routing | ||
+ | * instant messaging and presence | ||
+ | * freeswitch | ||
+ | * voicemail | ||
+ | * conference | ||
+ | * other media services (announcement, | ||
+ | |||
+ | Local users have 3 digit IDs (we will use users 101 102, and 103 for testing). Voice box ID is the same as user ID. Extensions for media services start with 4. | ||
+ | |||
+ | Kamailio and FreeSWITCH are installed on the same physical server (ip 192.168.178.23), | ||
+ | * kamailio: port 5060 | ||
+ | * freeswitch: port 5090 for internal profile and 5092 for external profile | ||
+ | |||
+ | ===== Kamailio Configuration ===== | ||
+ | |||
+ | ==== Installation ==== | ||
+ | |||
+ | A step by step installation tutorial for Kamailio 3.0.x is available at: | ||
+ | * [[http:// | ||
+ | |||
+ | It is no special tunning needed for this tutorial, just install it as usual. You can use MySQL or your preferred database server, has no relevance here. But if you choose another database type, be sure you update the Kamailio config file, the one provided here uses MySQL. | ||
+ | |||
+ | We try to keep FreeSWITCH and Kamailio installations as much as possible independent one from the other. | ||
+ | |||
+ | ==== Config File ==== | ||
+ | |||
+ | Kamailio has one config file by default, named kamailio.cfg. Starting with 3.0.0, you can split it in several files and use include_file to merge the pieces in main config file. | ||
+ | |||
+ | Another important features brought by 3.0.x are ' | ||
+ | |||
+ | <code c> | ||
+ | #!KAMAILIO | ||
+ | |||
+ | #!define WITH_MYSQL | ||
+ | #!define WITH_AUTH | ||
+ | #!define WITH_USRLOCDB | ||
+ | #!define WITH_FREESWITCH | ||
+ | |||
+ | # | ||
+ | # $Id$ | ||
+ | # | ||
+ | # Kamailio (OpenSER) SIP Server v3.0 - basic configuration script | ||
+ | # - web: http:// | ||
+ | # - git: http:// | ||
+ | # | ||
+ | # Direct your questions about this file to: < | ||
+ | # | ||
+ | # Refer to the Core CookBook at http:// | ||
+ | # for an explanation of possible statements, functions and parameters. | ||
+ | # | ||
+ | # Several features can be enabled using '# | ||
+ | # | ||
+ | # *** To run in debug mode: | ||
+ | # - define WITH_DEBUG | ||
+ | # | ||
+ | # *** To enable mysql: | ||
+ | # - define WITH_MYSQL | ||
+ | # | ||
+ | # *** To enable authentication execute: | ||
+ | # - enable mysql | ||
+ | # - define WITH_AUTH | ||
+ | # - add users using ' | ||
+ | # | ||
+ | # *** To enable persistent user location execute: | ||
+ | # - enable mysql | ||
+ | # - define WITH_USRLOCDB | ||
+ | # | ||
+ | # *** To enable presence server execute: | ||
+ | # - enable mysql | ||
+ | # - define WITH_PRESENCE | ||
+ | # | ||
+ | # *** To enable nat traversal execute: | ||
+ | # - define WITH_NAT | ||
+ | # - install RTPProxy: http:// | ||
+ | # - start RTPProxy: | ||
+ | # rtpproxy -l _your_public_ip_ -s udp: | ||
+ | # | ||
+ | # *** To enable PSTN gateway routing execute: | ||
+ | # - define WITH_PSTN | ||
+ | # - set the value of pstn.gw_ip | ||
+ | # - check route[PSTN] for regexp routing condition | ||
+ | # | ||
+ | # *** To enhance accounting execute: | ||
+ | # - enable mysql | ||
+ | # - define WITH_ACCDB | ||
+ | # - add following columns to database | ||
+ | #!ifdef ACCDB_COMMENT | ||
+ | ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; | ||
+ | ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; | ||
+ | #!endif | ||
+ | |||
+ | |||
+ | ####### Global Parameters ######### | ||
+ | |||
+ | #!ifdef WITH_DEBUG | ||
+ | debug=4 | ||
+ | log_stderror=yes | ||
+ | #!else | ||
+ | debug=2 | ||
+ | log_stderror=no | ||
+ | #!endif | ||
+ | |||
+ | memdbg=5 | ||
+ | memlog=5 | ||
+ | |||
+ | log_facility=LOG_LOCAL0 | ||
+ | |||
+ | fork=yes | ||
+ | children=4 | ||
+ | |||
+ | /* uncomment the next line to disable TCP (default on) */ | ||
+ | # | ||
+ | |||
+ | /* uncomment the next line to disable the auto discovery of local aliases | ||
+ | based on revers DNS on IPs (default on) */ | ||
+ | # | ||
+ | |||
+ | port=5060 | ||
+ | |||
+ | /* uncomment and configure the following line if you want Kamailio to | ||
+ | bind on a specific interface/ | ||
+ | # | ||
+ | |||
+ | |||
+ | ####### Custom Parameters ######### | ||
+ | |||
+ | # These parameters can be modified runtime via RPC interface | ||
+ | # - see the documentation of ' | ||
+ | # | ||
+ | # Format: group.id = value ' | ||
+ | # Access: $sel(cfg_get.group.id) or @cfg_get.group.id | ||
+ | # | ||
+ | |||
+ | #!ifdef WITH_PSTN | ||
+ | # PSTN GW Routing | ||
+ | # | ||
+ | # - pstn.gw_ip: valid IP or hostname as string value, example: | ||
+ | # pstn.gw_ip = " | ||
+ | # | ||
+ | # - by default is empty to avoid misrouting | ||
+ | pstn.gw_ip = "" | ||
+ | #!endif | ||
+ | |||
+ | #!ifdef WITH_FREESWITCH | ||
+ | freeswitch.bindip = " | ||
+ | freeswitch.bindport = " | ||
+ | #!endif | ||
+ | |||
+ | |||
+ | ####### Modules Section ######## | ||
+ | |||
+ | #set module path | ||
+ | mpath="/ | ||
+ | |||
+ | /* uncomment next line for MySQL DB support */ | ||
+ | #!ifdef WITH_MYSQL | ||
+ | loadmodule " | ||
+ | #!endif | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | #!ifdef WITH_AUTH | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | #!endif | ||
+ | /* uncomment next line for aliases support | ||
+ | NOTE: a DB (like db_mysql) module must be also loaded */ | ||
+ | #loadmodule " | ||
+ | /* uncomment next line for multi-domain support | ||
+ | NOTE: a DB (like db_mysql) module must be also loaded | ||
+ | NOTE: be sure and enable multi-domain support in all used modules | ||
+ | (see " | ||
+ | #loadmodule " | ||
+ | #!ifdef WITH_PRESENCE | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | #!endif | ||
+ | |||
+ | #!ifdef WITH_NAT | ||
+ | loadmodule " | ||
+ | #!endif | ||
+ | |||
+ | # ----------------- setting module-specific parameters --------------- | ||
+ | |||
+ | |||
+ | # ----- mi_fifo params ----- | ||
+ | modparam(" | ||
+ | |||
+ | |||
+ | # ----- rr params ----- | ||
+ | # add value to ;lr param to cope with most of the UAs | ||
+ | modparam(" | ||
+ | # do not append from tag to the RR (no need for this script) | ||
+ | modparam(" | ||
+ | |||
+ | |||
+ | # ----- rr params ----- | ||
+ | modparam(" | ||
+ | /* uncomment the next line to disable parallel forking via location */ | ||
+ | # modparam(" | ||
+ | /* uncomment the next line not to allow more than 10 contacts per AOR */ | ||
+ | # | ||
+ | |||
+ | |||
+ | # ----- uri_db params ----- | ||
+ | /* by default we disable the DB support in the module as we do not need it | ||
+ | in this configuration */ | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | |||
+ | |||
+ | # ----- acc params ----- | ||
+ | /* what sepcial events should be accounted ? */ | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | /* by default ww do not adjust the direct of the sequential requests. | ||
+ | if you enable this parameter, be sure the enable " | ||
+ | in " | ||
+ | modparam(" | ||
+ | /* account triggers (flags) */ | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | " | ||
+ | /* enhanced DB accounting */ | ||
+ | #!ifdef WITH_ACCDB | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | " | ||
+ | modparam(" | ||
+ | " | ||
+ | #!endif | ||
+ | |||
+ | # ----- usrloc params ----- | ||
+ | /* enable DB persistency for location entries */ | ||
+ | #!ifdef WITH_USRLOCDB | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | " | ||
+ | #!endif | ||
+ | |||
+ | # ----- auth_db params ----- | ||
+ | /* enable the DB based authentication */ | ||
+ | #!ifdef WITH_AUTH | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | " | ||
+ | modparam(" | ||
+ | #!endif | ||
+ | |||
+ | # ----- alias_db params ----- | ||
+ | /* uncomment the following lines if you want to enable the DB based | ||
+ | | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | # ----- domain params ----- | ||
+ | /* uncomment the following lines to enable multi-domain detection | ||
+ | | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | # ----- multi-module params ----- | ||
+ | /* uncomment the following line if you want to enable multi-domain support | ||
+ | in the modules (dafault off) */ | ||
+ | # | ||
+ | |||
+ | |||
+ | # ----- presence params ----- | ||
+ | /* enable presence server support */ | ||
+ | #!ifdef WITH_PRESENCE | ||
+ | modparam(" | ||
+ | " | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | #!endif | ||
+ | |||
+ | # ----- nathelper ----- | ||
+ | #!ifdef WITH_NAT | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | modparam(" | ||
+ | #!endif | ||
+ | |||
+ | ####### Routing Logic ######## | ||
+ | |||
+ | |||
+ | # main request routing logic | ||
+ | |||
+ | route{ | ||
+ | |||
+ | if (!mf_process_maxfwd_header(" | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | if(!sanity_check(" | ||
+ | { | ||
+ | xlog(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | # NAT detection | ||
+ | route(NAT); | ||
+ | |||
+ | if (has_totag()) { | ||
+ | # sequential request withing a dialog should | ||
+ | # take the path determined by record-routing | ||
+ | if (loose_route()) { | ||
+ | if (is_method(" | ||
+ | setflag(1); | ||
+ | setflag(3); | ||
+ | } | ||
+ | route(RELAY); | ||
+ | } else { | ||
+ | if (is_method(" | ||
+ | # in-dialog subscribe requests | ||
+ | route(PRESENCE); | ||
+ | exit; | ||
+ | } | ||
+ | if ( is_method(" | ||
+ | if ( t_check_trans() ) { | ||
+ | # non loose-route, | ||
+ | # or e.g. 404 from upstream server | ||
+ | t_relay(); | ||
+ | exit; | ||
+ | } else { | ||
+ | # ACK without matching transaction ... ignore and discard.\n" | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | #initial requests | ||
+ | |||
+ | # CANCEL processing | ||
+ | if (is_method(" | ||
+ | { | ||
+ | if (t_check_trans()) | ||
+ | t_relay(); | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | t_check_trans(); | ||
+ | |||
+ | # authentication | ||
+ | route(AUTH); | ||
+ | |||
+ | # record routing for dialog forming requests (in case they are routed) | ||
+ | # - remove preloaded route headers | ||
+ | remove_hf(" | ||
+ | if (is_method(" | ||
+ | record_route(); | ||
+ | |||
+ | # account only INVITEs | ||
+ | if (is_method(" | ||
+ | setflag(1); | ||
+ | } | ||
+ | if (!uri==myself) | ||
+ | /* replace with following line if multi-domain support is used */ | ||
+ | ##if (!is_uri_host_local()) | ||
+ | { | ||
+ | append_hf(" | ||
+ | route(RELAY); | ||
+ | } | ||
+ | |||
+ | # requests for my domain | ||
+ | |||
+ | if( is_method(" | ||
+ | route(PRESENCE); | ||
+ | |||
+ | if (is_method(" | ||
+ | { | ||
+ | if(isflagset(5)) | ||
+ | { | ||
+ | setbflag(" | ||
+ | # uncomment next line to do SIP NAT pinging | ||
+ | ## setbflag(" | ||
+ | } | ||
+ | if (!save(" | ||
+ | sl_reply_error(); | ||
+ | |||
+ | exit; | ||
+ | } | ||
+ | |||
+ | if ($rU==$null) { | ||
+ | # request with no Username in RURI | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | route(PSTN); | ||
+ | |||
+ | #!ifdef WITH_FREESWITCH | ||
+ | route(FSDISPATCH); | ||
+ | # save callee ID | ||
+ | $avp(callee) = $rU; | ||
+ | #!endif | ||
+ | |||
+ | # apply DB based aliases (uncomment to enable) | ||
+ | ## | ||
+ | |||
+ | if (!lookup(" | ||
+ | #!ifdef WITH_FREESWITCH | ||
+ | # offline - send to FreeSWITCH VoiceMail | ||
+ | route(FSVBOX); | ||
+ | #!endif | ||
+ | switch ($rc) { | ||
+ | case -1: | ||
+ | case -3: | ||
+ | t_newtran(); | ||
+ | t_reply(" | ||
+ | exit; | ||
+ | case -2: | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # when routing via usrloc, log the missed calls also | ||
+ | setflag(2); | ||
+ | #!ifdef WITH_FREESWITCH | ||
+ | if(is_method(" | ||
+ | { | ||
+ | # in case of failure -re-route to FreeSWITCH VoiceMail | ||
+ | t_on_failure(" | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | route(RELAY); | ||
+ | } | ||
+ | |||
+ | |||
+ | route[RELAY] { | ||
+ | #!ifdef WITH_NAT | ||
+ | if (check_route_param(" | ||
+ | setbflag(" | ||
+ | } | ||
+ | if (isflagset(5) || isbflagset(" | ||
+ | route(RTPPROXY); | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | #!ifdef WITH_CFGSAMPLES | ||
+ | /* example how to enable some additional event routes */ | ||
+ | if (is_method(" | ||
+ | # | ||
+ | t_on_reply(" | ||
+ | t_on_failure(" | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | if (!t_relay()) { | ||
+ | sl_reply_error(); | ||
+ | } | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | |||
+ | # Presence server route | ||
+ | route[PRESENCE] | ||
+ | { | ||
+ | #!ifdef WITH_PRESENCE | ||
+ | if (!t_newtran()) | ||
+ | { | ||
+ | sl_reply_error(); | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | if(is_method(" | ||
+ | { | ||
+ | handle_publish(); | ||
+ | t_release(); | ||
+ | } | ||
+ | else | ||
+ | if( is_method(" | ||
+ | { | ||
+ | handle_subscribe(); | ||
+ | t_release(); | ||
+ | } | ||
+ | exit; | ||
+ | #!endif | ||
+ | |||
+ | # if presence enabled, this part will not be executed | ||
+ | if (is_method(" | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | # Authentication route | ||
+ | route[AUTH] { | ||
+ | #!ifdef WITH_AUTH | ||
+ | if (is_method(" | ||
+ | { | ||
+ | # authenticate the REGISTER requests (uncomment to enable auth) | ||
+ | if (!www_authorize("", | ||
+ | { | ||
+ | www_challenge("", | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | if ($au!=$tU) | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | } else { | ||
+ | # authenticate if from local subscriber (uncomment to enable auth) | ||
+ | if (from_uri==myself) | ||
+ | { | ||
+ | if (!proxy_authorize("", | ||
+ | proxy_challenge("", | ||
+ | exit; | ||
+ | } | ||
+ | if (is_method(" | ||
+ | { | ||
+ | if ($au!=$tU) { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | } else { | ||
+ | if ($au!=$fU) { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | consume_credentials(); | ||
+ | # caller authenticated | ||
+ | } | ||
+ | } | ||
+ | #!endif | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | # Caller NAT detection route | ||
+ | route[NAT]{ | ||
+ | #!ifdef WITH_NAT | ||
+ | force_rport(); | ||
+ | if (nat_uac_test(" | ||
+ | if (method==" | ||
+ | fix_nated_register(); | ||
+ | } else { | ||
+ | fix_nated_contact(); | ||
+ | } | ||
+ | setflag(5); | ||
+ | } | ||
+ | #!endif | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | # RTPProxy control | ||
+ | route[RTPPROXY] { | ||
+ | #!ifdef WITH_NAT | ||
+ | if (is_method(" | ||
+ | unforce_rtp_proxy(); | ||
+ | } else if (is_method(" | ||
+ | force_rtp_proxy(); | ||
+ | } | ||
+ | if (!has_totag()) add_rr_param("; | ||
+ | #!endif | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | # PSTN GW routing | ||
+ | route[PSTN] { | ||
+ | #!ifdef WITH_PSTN | ||
+ | # check if PSTN GW IP is defined | ||
+ | if (strempty($sel(cfg_get.pstn.gw_ip))) { | ||
+ | xlog(" | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | # route to PSTN dialed numbers starting with ' | ||
+ | # | ||
+ | # - update the condition to match your dialing rules for PSTN routing | ||
+ | if(!($rU=~" | ||
+ | return; | ||
+ | |||
+ | # only local users allowed to call | ||
+ | if(from_uri!=myself) { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | $ru = " | ||
+ | |||
+ | route(RELAY); | ||
+ | exit; | ||
+ | #!endif | ||
+ | |||
+ | return; | ||
+ | } | ||
+ | |||
+ | #!ifdef WITH_FREESWITCH | ||
+ | # FreeSWITCH routing blocks | ||
+ | route[FSDISPATCH] { | ||
+ | if(!is_method(" | ||
+ | return; | ||
+ | if(!($rU=~" | ||
+ | return; | ||
+ | # dial number selection | ||
+ | |||
+ | switch($rU) { | ||
+ | case /" | ||
+ | # 41 - voicebox menu | ||
+ | # allow only authenticated users | ||
+ | if($au==$null) | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | $rU = " | ||
+ | break; | ||
+ | case /" | ||
+ | # starting with 44 folowed by 1XY - direct call to voice box | ||
+ | strip(2); | ||
+ | route(FSVBOX); | ||
+ | break; | ||
+ | case /" | ||
+ | # starting with 433 folowed by (0|1)XY - conference | ||
+ | strip(2); | ||
+ | break; | ||
+ | case /" | ||
+ | strip(2); | ||
+ | break; | ||
+ | default: | ||
+ | return; | ||
+ | } | ||
+ | route(FSRELAY); | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | route[FSVBOX] { | ||
+ | if(!($rU=~" | ||
+ | return; | ||
+ | prefix(" | ||
+ | route(FSRELAY); | ||
+ | } | ||
+ | |||
+ | # Send to FreeSWITCH | ||
+ | route[FSRELAY] { | ||
+ | $du = " | ||
+ | + $sel(cfg_get.freeswitch.bindport); | ||
+ | if($var(newbranch)==1) | ||
+ | { | ||
+ | append_branch(); | ||
+ | $var(newbranch) = 0; | ||
+ | } | ||
+ | route(RELAY); | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | #!endif | ||
+ | |||
+ | # Sample branch router | ||
+ | branch_route[BRANCH_ONE] { | ||
+ | xdbg(" | ||
+ | } | ||
+ | |||
+ | # Sample onreply route | ||
+ | onreply_route[REPLY_ONE] { | ||
+ | xdbg(" | ||
+ | #!ifdef WITH_NAT | ||
+ | if ((isflagset(5) || isbflagset(" | ||
+ | force_rtp_proxy(); | ||
+ | } | ||
+ | if (isbflagset(" | ||
+ | fix_nated_contact(); | ||
+ | } | ||
+ | #!endif | ||
+ | } | ||
+ | |||
+ | # Sample failure route | ||
+ | failure_route[FAIL_ONE] { | ||
+ | #!ifdef WITH_NAT | ||
+ | if (is_method(" | ||
+ | && | ||
+ | unforce_rtp_proxy(); | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | if (t_is_canceled()) { | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | # uncomment the following lines if you want to block client | ||
+ | # redirect based on 3xx replies. | ||
+ | ##if (t_check_status(" | ||
+ | ## | ||
+ | ## exit; | ||
+ | ##} | ||
+ | |||
+ | # uncomment the following lines if you want to redirect the failed | ||
+ | # calls to a different new destination | ||
+ | ##if (t_check_status(" | ||
+ | ## | ||
+ | ## | ||
+ | ## # do not set the missed call flag again | ||
+ | ## | ||
+ | ##} | ||
+ | } | ||
+ | |||
+ | #!ifdef WITH_FREESWITCH | ||
+ | failure_route[FAIL_FSVBOX] { | ||
+ | #!ifdef WITH_NAT | ||
+ | if (is_method(" | ||
+ | && | ||
+ | unforce_rtp_proxy(); | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | if (t_is_canceled()) { | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | if (t_check_status(" | ||
+ | # re-route to FreeSWITCH VoiceMail | ||
+ | $rU = $avp(callee); | ||
+ | $var(newbranch) = 1; | ||
+ | route(FSVBOX); | ||
+ | } | ||
+ | } | ||
+ | #!endif | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== SIP Users ==== | ||
+ | |||
+ | Be sure you updated **/ | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | SIP_DOMAIN=192.168.178.23 | ||
+ | ... | ||
+ | DBENGINE=MYSQL | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Create some test users in Kamailio with kamctl: | ||
+ | |||
+ | < | ||
+ | kamctl add userid password email | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | kamctl add 101 101 101@mysipserver.com | ||
+ | kamctl add 102 102 102@mysipserver.com | ||
+ | kamctl add 103 103 103@mysipserver.com | ||
+ | </ | ||
+ | |||
+ | ==== Config Remarks ==== | ||
+ | |||
+ | Routing to FreeSWITCH: | ||
+ | * dial 41 to listen to your voice mail service | ||
+ | * dial 44XYZ (e.g., 44101) to leave a message for user XYZ | ||
+ | * dial 4330XY or 4331XY to dial in 30XY or 31XY conference rooms on FreeSWITCH | ||
+ | * dial 45EXTEN to call extension EXTEN on FreeSWITCH (e.g., 459995 calls to 9995 on FreeSWITCH, which is echo service in default dialplan) | ||
+ | * if dialed user is offline, call is sent to callee' | ||
+ | * if callee does not answer or sends back busy, call is sent to callee' | ||
+ | |||
+ | To define the IP address and port, update the custom global parameters in class **freeswitch**: | ||
+ | |||
+ | <code c> | ||
+ | #!ifdef WITH_FREESWITCH | ||
+ | freeswitch.bindip = " | ||
+ | freeswitch.bindport = " | ||
+ | #!endif | ||
+ | </ | ||
+ | |||
+ | ===== FreeSWITCH Configuration ===== | ||
+ | |||
+ | ==== Installation ==== | ||
+ | |||
+ | Just do the standard FreeSWITCH installation, | ||
+ | * [[http:// | ||
+ | |||
+ | ==== Config Files ==== | ||
+ | |||
+ | === SIP === | ||
+ | |||
+ | Since this tutorial uses same IP but different ports, update your SIP profiles setting, setting the port accordingly. | ||
+ | |||
+ | Internal profiles: | ||
+ | <code xml> | ||
+ | <param name=" | ||
+ | </ | ||
+ | |||
+ | External profile: | ||
+ | <code xml> | ||
+ | <param name=" | ||
+ | </ | ||
+ | |||
+ | Also, for internal profile, disable call authentication. SIP traffic from Kamailio will be trusted and verified by ACL. | ||
+ | |||
+ | <code xml> | ||
+ | <param name=" | ||
+ | </ | ||
+ | |||
+ | === ACL === | ||
+ | |||
+ | Update ACL to allow traffic from Kamailio IP, edit **conf/ | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | After that should look like: | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | === Dialplan === | ||
+ | |||
+ | First direct the SIP traffic sent by Kamailio from public to default, edit **conf/ | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <action application=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Then in **conf/ | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | <action application=" | ||
+ | <action application=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <action application=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | First extension is to leave a voice message to callee. Second is to listen to caller' | ||
+ | |||
+ | === User Directory === | ||
+ | |||
+ | You have to create some file that hold the user profiles to provide voicemail services. Here we put the XML files on the local file system. | ||
+ | |||
+ | However, with freeswitch is easy to get them dynamically, | ||
+ | |||
+ | For now, add three files in **directory/ | ||
+ | |||
+ | * 101.xml | ||
+ | <code xml> | ||
+ | < | ||
+ | <user id=" | ||
+ | < | ||
+ | <param name=" | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | * 102.xml | ||
+ | <code xml> | ||
+ | < | ||
+ | <user id=" | ||
+ | < | ||
+ | <param name=" | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | * 103.xml | ||
+ | <code xml> | ||
+ | < | ||
+ | <user id=" | ||
+ | < | ||
+ | <param name=" | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Since we use them for voicemail, the important field is **vm-password** which represents the voicemail PIN. You can omit other files if you don't need them. | ||
+ | |||
+ | ===== Testing ===== | ||
+ | |||
+ | Once you have installed and configured kamailio and freeswitch, configure some phones with users 101, 102 and 103 to register with Kamailio. | ||
+ | |||
+ | The start calling between them: | ||
+ | |||
+ | * if you answer, call is connected, you should have voice | ||
+ | * if you reject, caller should get to callee' | ||
+ | * if you don't answer, caller should get to callee' | ||
+ | |||
+ | Call into a conference: dial 433001 from your phones. | ||
+ | |||
+ | Leave a voice message to user 101: dial 44101 | ||
+ | |||
+ | Listen your voice messages: dial 41 | ||
+ | |||
+ | ===== See Also ===== | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | {{tag> | ||
+ | |||
+ | |||
+ | <box 100% round red|Kamailio Advanced Training, November 22-25, 2010, Berlin, Germany> | ||
+ | < | ||
+ | </ |