Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[asterisk-users] How to setup redundant SIP peers


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users
View previous topic :: View next topic  
Author Message
asteriskusers at dovid...
Guest





PostPosted: Wed Jan 02, 2008 8:01 am    Post subject: [asterisk-users] How to setup redundant SIP peers Reply with quote

Do you mind sharing that script with us ?

----- Original Message -----
From: "Matt Riddell" <matt at venturevoip.com>
To: "Thomas Balsfulland" <tbals at ctrl-c.de>; "Asterisk Users Mailing List -
Non-Commercial Discussion" <asterisk-users at lists.digium.com>
Sent: Monday, December 24, 2007 2:06 AM
Subject: Re: [asterisk-users] How to setup redundant SIP peers
Quote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thomas Balsfulland wrote:
Quote:
this is not the right way, because it takes 30 sec before asterisk try
dialout over peer2. the dial-timer (.... at peer1,30) is normaly set for
the time to wait of "200 OK", but it is also active when peer1 is
down or not answering.

1st off use qualify to check that peers are up.

We also use a script that checks qualify status, and changes a flag in
the routing database so that if a provider is down or lagged, they won't
be considered in the LCR.

- --
Kind Regards,

Matt Riddell
Director
_______________________________________________

http://www.venturevoip.com (Great new VoIP end to end solution)
http://www.venturevoip.com/news.php (Daily Asterisk News - html)
http://www.venturevoip.com/newrssfeed.php (Daily Asterisk News - rss)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHbvgJDQNt8rg0Kp4RAggUAKC9ujWPzE2iemsMHA4hqyB100McsQCfTJ3+
sZCDlhBzXx+nAuwtAViRRcY=
=gQJe
-----END PGP SIGNATURE-----


_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
nicholas at blasgen.com
Guest





PostPosted: Wed Jan 02, 2008 4:13 pm    Post subject: [asterisk-users] How to setup redundant SIP peers Reply with quote

Some email asked for some examples. He's an example system that
will use ViaTalk lines (which allow 2 concurrent calls on a channel,
so I use GroupCount to check for a value of 2). It isn't round-robin
and actually I'd pay someone good money to make a revised Dial()
function that would do round robbin on a defined set of SIP trunks. I
solve the Round Robbin issue right now by periodicly changing
where SIP/trunk0 ... SIP/trunkN point to and then reloading the
configurations. Periodic for me is midnight each night. So every night the
order in priority order is reset.

*Again, just in case someone from Asterisk-Dev or Asterisk-Bus is reading
this: I will donate/pay to have a Round Robbin outbound trunk balancing
scheme developed. Should be able to use any Asterisk supported trunk type
(SIP, IAX2, etc). No need to care about maximum concurrent connections
since if it fails then we're out of lines anyways.*

[globals]
TRY1=SIP/trunk0
TRY2=SIP/trunk1
TRY3=SIP/trunk2
TRY4=SIP/trunk3
TRY5=SIP/trunk4
TRY6=SIP/trunk5
TRY7=SIP/trunk6
TRY8=SIP/trunk7
TRY9=SIP/trunk8
TRY10=SIP/trunk9
TRY11=SIP/trunk10

[macro-which-line]
exten => s,1,set(TRIES=0)
exten => s,n(nextone),set(TRIES=$[${TRIES} + 1]) ; increment TRIES by 1
exten => s,n,set(DIALSTRING=${TRY${TRIES}}) ; assign TRYn to DIALSTRING
exten => s,n,gotoif($["${DIALSTRING}" = ""]?donehere) ; see if we've run out
of things to try
exten => s,n,ChanIsAvail(${DIALSTRING}) ; it will be up or down, no need for
this to be exclusive
exten => s,n,gotoif($[${AVAILSTATUS} = 0]?:nextone)
exten => s,n,gotoif($[${GROUP_COUNT(${DIALSTRING})} >= 2]?nextone) ; have we
used up the allowed calls on this channel
exten => s,n,set(GROUP()=${DIALSTRING}) ; Lock the line! Yay...
exten => s,n,Dial(${DIALSTRING}/1${ARG1}) ; dial the phone
exten => s,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?donehere) ; Don't keep
dialing
exten => s,n,NoOp("Moving to the next one...");
exten => s,n,goto(nextone) ; TEMP
exten => s,n(donehere),MacroExit() ; we only get here if everything failed
=================

Okay, that's one example. Your simple two line thing might be better done
another way. Let's say we try this:

1) Place a call two two phone lines at once, but have a single line delayed
by 3 seconds.

Something to this effect:

Quote:
Quote:
Dial(SIP/trunk0&Local/delayed_trunk1)

Where Delayed_Trunk1 is a macro which calls SLEEP(3) and then Dial(Trunk1).
I could go into more detail, but I'm going to assume you can figure out how
to do this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20080102/06d936f7/attachment-0001.htm
Back to top
matt at venturevoip.com
Guest





PostPosted: Sat Jan 05, 2008 2:02 am    Post subject: [asterisk-users] How to setup redundant SIP peers Reply with quote

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dovid B wrote:
Quote:
Do you mind sharing that script with us ?

Thomas Balsfulland wrote:
Quote:
Quote:
Quote:
this is not the right way, because it takes 30 sec before asterisk try
dialout over peer2. the dial-timer (.... at peer1,30) is normaly set for
the time to wait of "200 OK", but it is also active when peer1 is
down or not answering.
1st off use qualify to check that peers are up.

We also use a script that checks qualify status, and changes a flag in
the routing database so that if a provider is down or lagged, they won't
be considered in the LCR.

It kinda wouldn't work unless you have the same routing and billing, but
here goes:

#!/usr/bin/php -q
<?php

function is_alive($server, $type){
if($server == NULL || $type == NULL)
return false;
$ping = "/usr/sbin/asterisk -rx '".$type." show peer ".$server."' |
grep -a Status";
$output;
$retval = 0;
exec($ping,$output,$retval);
return is_string(strstr($output[0], "OK"));
}

$db_name="cdr";
$db_user="xxx";
$db_pass="xxx";
$connection = mysql_connect("data.venturevoip.com",$db_user, $db_pass);
mysql_select_db($db_name, $connection);

$result = mysql_query("select * from providers where active<>0");

while($row = mysql_fetch_row($result)){
if($row[7] != NULL){
$server = $row[5];
if($row[8] != NULL)
$server = $row[8];
$alive = is_alive(str_replace(" ", '', strtolower($server)),$row[7]);

if($alive === TRUE && $row[2] === "2"){
echo "Changing provider ".$row[1]." to avaliable\n";
$query = "update providers set active = 1 where providerid like
".$row[0];
mysql_query($query) or die(mysql_error());
}else if ($alive === FALSE && $row[2] === "1"){
echo "Changing provider ".$row[1]." to unavaliable\n";
$query = "update providers set active = 2 where providerid like
".$row[0];
mysql_query($query) or die(mysql_error());
}else{
echo "Nothing to change for ".$row[1]." ($row[0]) - ALIVE: $alive\n";

}
}
}
?>

Sorry about the word wrapping!

Basically we have a few tables:

sellrates - price each destination is sold for to the customer - one
entry per destination

rates - every provider's destination and price (including profit and
exchange rates where applicable). Each rate also has a weight (for
reducing or increasing the likelihood that a particular rate will be
chosen).

providers - the provider table specifies the contact details for each
provider, the type of peer (iax or sip), and the peer name that they are
shown as. It also contains a status flag (0 for leave off we don't want
to use this provider at this time, 1 for active but check them once a
minute and 2 for active but because they are currently unreachable don't
use them).

We then run two scripts, one for routing and one for billing. The
routing script first finds the price from sellrates and saves it to a
channel variable. This is the price the customer will be charged for
the call (no matter how much it costs us).

We then look through the providers and find which are active (status=1).

We then get the longest match on the phone number from each provider
(i.e. if I dial 6434742112 <http://www.snapanumber.com/> a New Zealand
provider may be able to match 6434 whereas a US based provider will
probably only match 64).

Once we have this collection of rates from each provider we first remove
any which have a weight higher than the lowest rate we found.

So for example:

Provider 1: weight 80 cost $2
Provider 2: weight 80 cost $3
Provider 3: weight 90 cost $0.01

So, we are then left with just Provider 1 and Provider 2 (even though
Provider 3 is cheaper, we know they are not good at providing that rate
- - either because the ping time is too high or there is packet loss/echo).

Final step is to chose the actual provider to use. Since we just have a
rate at $2 and a rate at $3 we would chose the $2 rate.

The call is made via Provider 1.

In the h extension we run deadagi with the billing script.

It takes the channel variable that was set for pricing at the beginning,
works out how the channel ended and charges the customer's account.

That's the basics of it, there is also call length limiting and realtime
updating of customer balances but I won't go in to that.

Hope that makes a bit of sense!

Smile

Oh, and each of our customers is connected to each server, and each
server is running this script every minute, so even if one of our
servers is unable to complete the call, chances are another will.

Final fall back is that each server has PRI. Obviously we would prefer
not to be using the PRI for international calls as we lose money on that
but the call has to go through whether our providers have problems or not.

- --
Kind Regards,

Matt Riddell
Director
_______________________________________________

http://www.venturevoip.com (Great new VoIP end to end solution)
http://www.venturevoip.com/news.php (Daily Asterisk News - html)
http://www.venturevoip.com/newrssfeed.php (Daily Asterisk News - rss)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHfyuhDQNt8rg0Kp4RApxdAKCc1832mOfQ862Ig1GmEssf8caPIACgtIH5
nNDv98i2hZnKmGzC3iQ+P2k=
=EOQk
-----END PGP SIGNATURE-----
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services