Browse Source

work on transfer tracking, change the default freeswitch port, and include it in the dispatcher list

3.12
karl anderson 13 years ago
parent
commit
db8a0fb24e
3 changed files with 151 additions and 339 deletions
  1. +1
    -1
      freeswitch/sip_profiles/sipinterface_1.xml
  2. +1
    -0
      kamailio/dispatcher.list
  3. +149
    -338
      kamailio/kamailio.cfg

+ 1
- 1
freeswitch/sip_profiles/sipinterface_1.xml View File

@ -43,7 +43,7 @@
<!-- SIP -->
<param name="sip-ip" value="$${local_ip_v4}"/>
<param name="ext-sip-ip" value="auto"/>
<param name="sip-port" value="5060"/>
<param name="sip-port" value="11000"/>
<!--<param name="outbound-proxy" value="127.0.0.1"/>-->
<!--<param name="sip-domain" value="sip.2600hz.com"/>-->
<!--<param name="contact-user" value="sip.2600hz.com"/>-->


+ 1
- 0
kamailio/dispatcher.list View File

@ -1 +1,2 @@
# setit(integer) destination(sip uri) flags (integer, optional)
1 sip:127.0.0.1:11000 0

+ 149
- 338
kamailio/kamailio.cfg View File

@ -48,9 +48,6 @@ listen = tcp:127.0.0.1:5080
listen = udp:127.0.0.1:5080
listen = tcp:127.0.0.1:7000
listen = udp:127.0.0.1:7000
#listen = tcp:127.0.0.1:5065
#listen = udp:127.0.0.1:5065
tos = IPTOS_LOWDELAY
####### TCP Parameters #########
@ -106,18 +103,16 @@ disable_sctp = yes
####### Modules Section ########
mpath="/usr/lib64/kamailio/modules/"
####### Flags #######
flags
FLAG_INTERNALLY_SOURCED: 1,
# FLAG_ITSP_SOURCED: 2,
FLAG_ASSOCIATE_SERVER: 3,
FLAG_SKIP_NAT_CORRECTION: 4;
FLAG_ASSOCIATE_SERVER: 2,
FLAG_SKIP_NAT_CORRECTION: 3,
FLAG_ASSOCIATE_USER: 4;
#!define FLB_NATB 6
#!define FLB_NATSIPPING 7
######## Kamailio core extensions module ########
loadmodule "kex.so"
@ -163,19 +158,10 @@ modparam("path", "use_received", 0)
######## Generic Hash Table container in shared memory ########
loadmodule "htable.so"
#modparam("htable", "htable", "associations=>size=14;")
modparam("htable", "htable", "associations=>size=14;")
modparam("htable", "htable", "a=>size=10;")
/*
######## Memcached connector module ########
loadmodule "memcached.so"
modparam("memcached", "servers", "localhost:11211")
modparam("memcached", "expire", 10800)
modparam("memcached", "mode", 0)
modparam("memcached", "timeout", 10000)
*/
######## Module holding Pseudo-Variables ########
######## Pseudo-Variables module ########
loadmodule "pv.so"
######## Advanced logger module ########
@ -185,12 +171,9 @@ loadmodule "xlog.so"
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
####### Different config utilities ########
loadmodule "cfgutils.so"
####### Dispatcher Module Parameters ########
####### Dispatcher module ########
loadmodule "dispatcher.so"
modparam("dispatcher", "list_file", "/etc/kazoo/kamailio/dispatcher.list")
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "use_default", 0)
modparam("dispatcher", "force_dst", 1)
@ -208,35 +191,36 @@ modparam("dispatcher", "ds_probing_threshhold", 3)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "ds_ping_reply_codes", "501,403,404,400,200")
######## Uac_redirect ########
######## UAC Redirection module ########
loadmodule "uac_redirect.so"
####### db_kazoo registrar modules ##########
####### Kazoo Integration module ##########
loadmodule "db_kazoo.so"
# FIXME: uncomment the next line and set the correct hostname that should be advertised to Kazoo
#modparam("db_kazoo", "node_hostname", "kamailio.kazoo.com")
# If you want a certain fs_path to be sent Kazoo, uncomment the next line and set the right value
#modparam("db_kazoo", "register_fs_path", "IP:PORT")
####### Authentication Interface module ##########
loadmodule "auth.so"
loadmodule "auth_db.so"
# ----- registrar modules -----
loadmodule "usrloc.so"
loadmodule "registrar.so"
modparam("auth_db|usrloc", "db_url", "kazoo://guest:guest@127.0.0.1:5672/callmgr")
modparam("auth_db", "use_domain", 1)
modparam("auth_db", "version_table", 0)
modparam("auth_db", "calculate_ha1", 1)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "load_credentials", "$avp(password)=password")
/* enable DB persistency for location entries */
####### User Location Implementation module ##########
loadmodule "usrloc.so"
modparam("usrloc", "db_mode", 1)
modparam("usrloc", "db_update_as_insert", 1)
modparam("usrloc", "use_domain", 1)
modparam("usrloc", "nat_bflag", FLB_NATB)
####### SIP Registrar implementation module ##########
loadmodule "registrar.so"
######## NAT traversal module - signaling functions ########
######## NAT Traversal module - signaling functions ########
loadmodule "nathelper.so"
modparam("nathelper|registrar", "received_avp", "$avp(AVP_RECV_PARAM)")
modparam("nathelper", "natping_interval", 30)
@ -246,6 +230,9 @@ modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:sipcheck@127.0.0.1")
#modparam("nathelper", "natping_socket", "127.0.0.1:5060")
####### Common Module Parameters ##########
modparam("auth_db|usrloc", "db_url", "kazoo://guest:guest@127.0.0.1:5672/callmgr")
####### Routing Logic ########
route {
@ -311,24 +298,6 @@ route[CLASSIFY_SOURCE]
}
}
/*
route[CLASSIFY_SOURCE] {
switch($mct($si)) {
case "itsp":
xlog("L_INFO", "$ci|log|message is from ITSP");
setflag(FLAG_ITSP_SOURCED);
break;
case "kazoo":
xlog("L_INFO", "$ci|log|message is from KAZOO");
setflag(FLAG_INTERNALLY_SOURCED);
break;
default:
xlog("L_INFO", "$ci|log|message is from an unknown source");
break;
}
}
*/
route[HANDLE_OPTIONS] {
if (is_method("OPTIONS")) {
if (isflagset(FLAG_INTERNALLY_SOURCED)) {
@ -345,13 +314,10 @@ route[HANDLE_OPTIONS] {
# associate the contact with the media server
route[MAYBE_ASSOCIATE_USER] {
# if Invite for on hold, we need to associate the contact URI with the next hop
if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) {
$var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
xlog("L_INFO", "$ci|log|associate user $var(contact_uri):$si:$sp with media server $du\n");
$sht(associations=>$var(contact_uri))= $du;
setflag(FLAG_ASSOCIATE_USER);
}
}
route[HANDLE_IN_DIALOG_REQUESTS] {
@ -402,73 +368,60 @@ route[HANDLE_IN_DIALOG_REQUESTS] {
}
if (is_method("REGISTER")) {
if (nat_uac_test("3")) {
xlog("L_INFO", "Nated contact\n");
# setflag(FLB_NATSIPPING);
force_rport();
setbflag(FLB_NATB);
setbflag(FLB_NATSIPPING);
fix_nated_register();
}
# authenticate requests
# check iif we have the password in cache
if ( is_present_hf("Authorization") ) {
if ( $sht(a=>$Au) != $null ) {
xlog("L_INFO", "Found stored password for $Au, $sht(a=>$Au)\n");
if (!pv_auth_check("$fd", "$sht(a=>$Au)", "0", "0")) {
xlog("L_INFO", "Authentication did not work with stored password\n");
## RABBITMQ - Credentials fetch
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
} else {
xlog("Credential fetch $avp(password)\n");
# xlog("au=$au, ad = $ad, aU=$aU, Au= $Au\n");
$sht(a=>$Au) = $avp(password);
}
}
} else {
## RABBITMQ - Credentials fetch
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
} else {
xlog("L_INFO", "Credential fetch $avp(password)\n");
# xlog("au=$Au, ad = $ad, aU=$aU, Au= $Au\n");
$sht(a=>$Au) = $avp(password);
}
}
} else {
auth_challenge("$fd", "0");
exit;
}
# user authenticated - remove auth header
consume_credentials();
# if (!add_path_received()) {
# sl_send_reply("503", "Internal path befuddlement");
# # route(CLEANUP_DIALOG);
# exit();
# }
save("location");
exit;
/*
if (is_method("REGISTER")) {
if (!add_path_received()) {
sl_send_reply("503", "Internal path befuddlement");
# route(CLEANUP_DIALOG);
exit();
if (nat_uac_test("3")) {
xlog("L_INFO", "Nated contact\n");
#setflag(FLB_NATSIPPING);
force_rport();
setbflag(FLB_NATB);
setbflag(FLB_NATSIPPING);
fix_nated_register();
}
*/
# authenticate requests
# check iif we have the password in cache
if ( is_present_hf("Authorization") ) {
if ( $sht(a=>$Au) != $null ) {
xlog("L_INFO", "Found stored password for $Au, $sht(a=>$Au)\n");
if (!pv_auth_check("$fd", "$sht(a=>$Au)", "0", "0")) {
xlog("L_INFO", "Authentication did not work with stored password\n");
## RABBITMQ - Credentials fetch
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
} else {
xlog("Credential fetch $avp(password)\n");
# xlog("au=$au, ad = $ad, aU=$aU, Au= $Au\n");
$sht(a=>$Au) = $avp(password);
}
}
} else {
## RABBITMQ - Credentials fetch
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
} else {
xlog("L_INFO", "Credential fetch $avp(password)\n");
# xlog("au=$Au, ad = $ad, aU=$aU, Au= $Au\n");
$sht(a=>$Au) = $avp(password);
}
}
} else {
auth_challenge("$fd", "0");
exit;
}
# user authenticated - remove auth header
consume_credentials();
save("location");
exit;
} else {
if (!is_method("MESSAGE"))
record_route();
if (!is_method("MESSAGE")) {
record_route();
}
}
}
@ -476,127 +429,101 @@ route[HANDLE_IN_DIALOG_REQUESTS] {
# If prefered route defined, reorder the destionations
route[FIND_ROUTES]
{
if (is_method("REGISTER"))
# alg 0 = hash(Callid)
if (!ds_select_dst("1", "0"))
{
# alg 2 = hash(To URI)
# To URI is actually AOR - to help with nounce reusage at reRegister
if (!ds_select_dst("3", "2") && !ds_select_dst("1", "2"))
{
xlog("L_ERR", "$ci|end|no servers avaliable");
xlog("L_ERR", "$ci|end|no servers avaliable");
sl_send_reply("480", "All servers busy");
sl_send_reply("480", "All servers busy");
exit;
}
exit;
}
else
{
# alg 0 = hash(Callid)
if (!ds_select_dst("1", "0"))
{
xlog("L_ERR", "$ci|end|no servers avaliable");
sl_send_reply("480", "All servers busy");
# Handle the case when a prefered route is set
$var(contact_uri) = @from.uri.user + "@" + @from.uri.host;
exit;
}
# Handle the case when a prefered route is set
$var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
if ($sht(associations=>$var(contact_uri)) != $null)
{
$var(prefered_route) = $sht(associations=>$var(contact_uri));
xlog("L_INFO", "$ci|log|should route to $var(prefered_route)");
if ($sht(associations=>$var(contact_uri)) != $null)
{
$var(prefered_route) = $sht(associations=>$var(contact_uri));
route(REORDER_ROUTES);
}
xlog("L_INFO", "$ci|log|should route to $var(prefered_route)");
route(REORDER_ROUTES);
}
}
route[REORDER_ROUTES] {
# if the dispatcher list does not start with
# the the prefered route, reorder the list so that it does
if ($(avp(ds_dst)[0]) != $var(prefered_route))
$var(i) = 0;
$var(found) = 0;
while($(avp(ds_dst)[$var(i)]) != $null)
{
# create a index var for our loop (arrays are start at 0 and this is a count)
$var(i) = $avp(ds_cnt) - 1;
xlog("L_INFO", "$ci|log|IN $var(i): $(avp(ds_dst)[$var(i)])");
# loop over the dispatcher list
while($var(i) > 0)
{
# if this element in the dispatch list is the same
# as the call destination
if($(avp(ds_dst)[$var(i)]) == $var(prefered_route))
{
# replace it with the first element of the list
$(avp(ds_dst)[$(var(i))]) = $(avp(ds_dst)[0]);
# break out of the loop
$var(i) = -1;
}
$var(i) = $var(i) - 1;
if($(avp(ds_dst)[$var(i)]) != $var(prefered_route)) {
$avp(tmp_ds_dst) = $(avp(ds_dst)[$var(i)]);
} else {
$var(found) = 1;
}
# handles the case were we only have two servers
# and the one that we are locked to has failed
if ($var(i) >= 0)
{
xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd");
$var(i) = $var(i) + 1;
}
if ($var(found)) {
xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first");
$sht(associations=>$var(contact_uri)) = "sip:$rd:$rp";
$(avp(ds_dst)[*]) = $null;
xlog("L_INFO", "$ci|log|associated contact $var(contact_uri) with media server sip:$rd:$rp");
}
# the server we are locked to is in the active server list from then
# dispatcher so re-arrange the list to try it first
else
$var(i) = 0;
while($(avp(tmp_ds_dst)[$var(i)]) != $null)
{
xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first");
$avp(ds_dst) = $(avp(tmp_ds_dst)[$var(i)]);
# set the first element of the list to the destination
$(avp(ds_dst)[0]) = $var(prefered_route);
$var(i) = $var(i) + 1;
}
$avp(ds_dst) = $var(prefered_route);
$du = $var(prefered_route);
# set the domain for this request (server IP to route to)
$rd = $(var(prefered_route){uri.host});
$(avp(tmp_ds_dst)[*]) = $null;
} else {
xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd");
# set the port for this request (server IP to route to)
$rp = $(var(prefered_route){uri.port});
}
$sht(associations=>$var(contact_uri)) = $null;
}
}
$var(i) = 0;
while($(avp(ds_dst)[$var(i)]) != $null)
{
xlog("L_INFO", "$ci|log|OUT $var(i): $(avp(ds_dst)[$var(i)])");
$var(i) = $var(i) + 1;
}
}
route[HANDLE_MOVE_REQUEST]
{
if (is_method("INVITE") && $rU == "*6683*" && $sht(associations=>$var(contact_uri)) != $null )
if (is_method("INVITE") && $rU == "*6683*")
{
$var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
$var(contact_uri) = @from.uri.user + "@" + @from.uri.host;
xlog("L_INFO", "$ci|log|remove association for user $var(contact_uri):$si:$sp
with media server $sht(associations=>$var(contact_uri))\n");
if ($sht(associations=>$var(contact_uri)) != $null)
{
xlog("L_INFO", "$ci|log|remove association for user $var(contact_uri)
with media server $sht(associations=>$var(contact_uri))\n");
$sht(associations=>$var(contact_uri))= $null;
$sht(associations=>$var(contact_uri)) = $null;
}
# TODO - does the test expect smth like $rd:$rp as reason?
send_reply("503", "Removed association");
xlog("L_INFO", "$ci|log|removed association for user $var(contact_uri)
with media server $sht(associations=>$var(contact_uri))\n");
exit;
}
}
route[RELAY] {
# if (is_method("CANCEL") || is_method("BYE")) {
# route(CLEANUP_DIALOG);
# }
if (isflagset(FLAG_INTERNALLY_SOURCED)) {
route(INTERNAL_TO_EXTERNAL_RELAY);
} else {
@ -613,11 +540,6 @@ route[INTERNAL_TO_EXTERNAL_RELAY] {
t_set_fr(0, 10000);
route(LOG_DESTINATION);
# xlog("L_INFO", "$ci|log|associate call-id $ci with sip:$sip:$sp");
# $sht(associations=>$ci) = "sip:" + $si + ":" + $sp;
t_relay();
}
@ -634,13 +556,9 @@ route[EXTERNAL_TO_INTERNAL_RELAY] {
t_set_fr(0, 1000);
route(LOG_DESTINATION);
t_relay();
}
route[LOG_DESTINATION] {
if (isdsturiset()) {
$var(port) = $dp;
@ -689,16 +607,8 @@ onreply_route[EXTERNAL_REPLY] {
xlog("L_INFO", "$ci|log|external reply $T_reply_code");
route(NAT_TEST_AND_CORRECT);
# if (is_method("INVITE") && t_check_status("200")) {
# $var(user) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
# xlog("L_INFO", "$ci|log|associate user $var(user):$si:$sp with media server");
# $sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER);
# }
}
onreply_route[INTERNAL_REPLY]
{
# this route handles replies that are comming from our media server
@ -801,24 +711,26 @@ failure_route[INTERNAL_FAULT]
else if (t_check_status("302"))
{
## TODO - test this
get_redirects("*");
## get_redirects("*");
/*
if(@msg.header["X-Redirect-Server"] != $null)
{
$var(test) = @msg.header["X-Redirect-Server"].value;
xlog("L_INFO", "$ci|log|X-Redirect-Server $var(test)");
route(EXTERNAL_TO_INTERNAL_RELAY);
$var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
/*
if( $(<reply>hdr(X-Redirect-Server)) && $(<reply>ct.fields(uri)) )
{
$var(redirect_host) = $(<reply>hdr(X-Redirect-Server){uri.host});
$var(redirect_host) = $(hdr(X-Redirect-Server){uri.host});
$var(redirect_port) = $(<reply>hdr(X-Redirect-Server){uri.port});
$var(redirect_port) = $(hdr(X-Redirect-Server){uri.port});
cache_store("local", "$(<reply>ct.fields(uri))", "sip:$var(redirect_host):$var(redirect_port)", 60);
$sht(associations=>$var(contact_uri))= "sip:$var(redirect_host):$var(redirect_port)";
xlog("L_INFO", "$ci|log|stored redirect mapping for $(<reply>ct.fields(uri)) to sip:$var(redirect_host):$var(redirect_port)");
xlog("L_INFO", "$ci|log|stored redirect mapping for $var(contact_uri) to sip:$var(redirect_host):$var(redirect_port)");
remove_hf("X-Redirect-Server");
}
*/
*/
}
else
{
@ -831,114 +743,13 @@ failure_route[INTERNAL_FAULT]
}
onsend_route {
xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)");
}
## Not used routes
/*
# Take the routes from memcached
# Write them in an AVP
# Randomize
route[LOAD_KAZOO_ROUTES] {
$var(routes) = $mct(available_kazoo_routes);
route(LOAD_ROUTES);
$var(randomizer_pos) = $avp(AVP_ROUTE_CNT);
route(RANDOMIZE_ROUTES);
if (!isflagset(FLAG_ITSP_SOURCED) && is_method("REGISTER|INVITE|SUBSCRIBE")) {
setflag(FLAG_ASSOCIATE_SERVER);
}
}
route[LOAD_ROUTES] {
if ($var(routes) == $null) {
return(-1);
}
$var(i) = 0;
$var(route) = $(var(routes){s.select,$var(i),;});
while($(var(route){s.len}) > 0) {
$var(i) = $var(i) + 1;
$avp($var(i)) = $var(route);
$var(route) = $(var(routes){s.select,$var(i),;});
}
$avp(AVP_ROUTE_CNT) = $var(i);
return(1);
}
# No longer used
route[NEXT_ROUTE] {
if ($avp(AVP_ROUTE_CNT) <= 0) {
return(-1);
}
$var(domain) = $(avp($avp(AVP_ROUTE_CNT)){uri.host});
$var(port) = $(avp($avp(AVP_ROUTE_CNT)){uri.port});
$avp(AVP_ROUTE_CNT) = $avp(AVP_ROUTE_CNT) - 1;
if ($(var(domain){s.len}) <= 0) {
route(NEXT_ROUTE);
if (isflagset(FLAG_ASSOCIATE_USER)) {
$var(contact_uri) = @from.uri.user + "@" + @from.uri.host;
xlog("L_INFO", "$ci|log|associate user $var(contact_uri) with media server sip:$sndto(ip):$sndto(port)\n");
$sht(associations=>$var(contact_uri))= "sip:" + $sndto(ip) + ":" + $sndto(port);
}
if ($(var(port){s.len}) <= 4) {
$var(port) = "5060";
}
$du = "sip:" + $var(domain) + ":" + $var(port);
xlog("L_INFO", "$ci|log|associate call-id $ci with $du");
$sht(associations=>$ci) = $du;
return(1);
}
route[RANDOMIZE_ROUTES] {
if ($var(randomizer_pos) <= 0) {
return();
}
$var(random_pos) = ($RANDOM mod $var(randomizer_pos) + 1);
if ($var(random_pos) != $var(randomizer_pos)) {
$var(route) = $avp($var(randomizer_pos));
$avp($var(randomizer_pos)) = $avp($var(random_pos));
$avp($var(random_pos)) = $var(route);
}
$var(randomizer_pos) = $var(randomizer_pos) - 1;
route(RANDOMIZE_ROUTES);
}
route[LOG_ROUTES] {
$var(i) = $avp(AVP_ROUTE_CNT);
while($var(i) > 0) {
$var(value) = $avp($var(i));
xlog("L_INFO", "$ci|log|route $var(i): $var(value)");
$var(i) = $var(i) - 1;
}
}
route[CLEANUP_DIALOG] {
xlog("L_INFO", "$ci|log|remove any association for $ci");
sht_rm_name_re("associations=>$ci");
return();
xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)");
}
route[MAYBE_ASSOCIATE_SERVER] {
if (isflagset(FLAG_ASSOCIATE_SERVER) && defined $avp(AVP_ASSOCIATED_SERVER)) {
xlog("L_INFO", "$ci|log|associate call-id $ci with $avp(AVP_ASSOCIATED_SERVER)");
$sht(associations=>$ci) = $avp(AVP_ASSOCIATED_SERVER);
if (is_method("INVITE")) {
$var(user) = $(ct{tobody.user}) + "@" + $si;
xlog("L_INFO", "$ci|log|associate user $var(user) with $avp(AVP_ASSOCIATED_SERVER)");
$sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER);
}
}
}
*/
## vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab

Loading…
Cancel
Save