Page 1 of 1

Failover with SIP trunk

Posted: Wed Dec 05, 2012 1:52 am
by garyscholten
Hi,

I am trying to get our Panasonic NCP1000 Phone system to work with a failover Internet connection.

After many hours a Telco company told me it won't work because the SIP connection table needs to be flushed (clear out all connections) before the phonesystem will route all traffic over the second Internet connection.

I configured RB750 with Dual WAN ports (static IP) from Telus and Shaw IP providers and default all goes thru Shaw. When Shaw fails all traffic should go to Telus, but apparently the SIP connection table needs to be flushed first.

I found scripts on this forum to clear out connection on: http://forum.mikrotik.com/viewtopic.php?f=9&t=42318
:foreach ENTRY in=[/ip firewall address-list find list="abuse"] do={
 :local IP [/ip firewall address-list get number=$ENTRY address ]; 
  :foreach CONN in=[/ip firewall connection find src-address~"^$IP:"] do={
   /ip firewall connection remove $CONN;
 }
}
But how do I trigger this script to run when my Shaw connection fails and how do I add all existing connections in an "abuse" list or is this already taken care off by the script. I am a newby!

Thx in advance!
Gary

Re: Failover with SIP trunk

Posted: Wed Dec 05, 2012 3:27 pm
by pchaxor
This is how we do failover on our Mikrotik routers... we had an in house person write it and it works well. (thanks Andrew!)

You will need to edit this to fit your upstream Gateway IP [replace xx.xx.xx.xx with your primary ISP gateway] and change the comment to whatever your label is on the default route. We used Google DNS as the secondary ping but you can use whatever external IP you see fit. (We need both IP's to fail before it fails over."else=")
:if ([/ping xx.xx.xx.xx interval=.1 count=10]<5 && [/ping 8.8.4.4 interval=.1 count=10]<5 && [/ip route get [find comment="Primary"] disabled]=false) do={
    :log info "Disabling Primary"; /ip route set [find comment="Primary"] disabled=yes
} else= {
    :if ([/ip route get [find comment="Primary"] disabled]=true) do={
    :log info "Enabling Primary"; /ip route set [find comment="Primary"] disabled=no
   /delay 5
   /system reboot
    }
}
Then schedule this script to run and check how often you wish... we run ours every 2 minutes.
The reboot is put in there because we also run a PBX and NAT related services and this clears the tables.

Re: Failover with SIP trunk

Posted: Thu Dec 06, 2012 1:34 am
by garyscholten
Thx a lot for this script!

Question: Do I need to make more changes?

1. I changed my ip address to the fixed ip of the IP-provider (SHAW)

In the scheduler, I added the sctipt and set it to run the script every minute.

In the ethernet connections, for my SHAW connection (ether5), I need to add a comment called "Primary"

Is that All?

Question 2:
The router will reboot when the primary connection fails? And when the primary connection is up again, it will reboot again?

Seemed pretty easy!

Re: Failover with SIP trunk

Posted: Thu Dec 06, 2012 10:16 pm
by pchaxor
Thx a lot for this script!
Question: Do I need to make more changes?
1. I changed my ip address to the fixed ip of the IP-provider (SHAW)
In the scheduler, I added the sctipt and set it to run the script every minute.
In the ethernet connections, for my SHAW connection (ether5), I need to add a comment called "Primary"
Is that All?
Question 2:
The router will reboot when the primary connection fails? And when the primary connection is up again, it will reboot again?
Seemed pretty easy!
That should be all... Just make sure the comments and upstream gateway match the script is all.
I tested this initially with Asterisks but should work just the same for any IP phone system.

There may also be a better way to flush the tables rather than a reboot, but the reboot is so fast and cleans it all out so its a sure thing.

I also use a more modified version that sends me notices on another router...
:global strDate [/system clock get date]
:global strTime [/system clock get time]
:global strSystemName [/system identity get name]

:if ([/ping xx.xx.xx.xx interval=.1 count=10]<5 && [/ping 8.8.4.4 interval=.1 count=10]<5 && [/ip route get [find comment="Default Route"] disabled]=false) do={
    :log info "Disabling Primary"; /ip route set [find comment="Primary"] disabled=yes
    /tool e-mail send from="noreply@routerdomain.com" to="alert@emaildomain.com" server="MAILSERVERIPHERE" subject="Route Failover - $strDate $strTime - $strSystemName" body="Failover to ISPNAME occurred at $strDate $strTime on $strSystemName"
} else= {
    :if ([/ip route get [find comment="Primary"] disabled]=true) do={
        :log info "Enabling Primary"; /ip route set [find comment="Primary"] disabled=no
    /delay 5
    /system reboot
    }
}
This was was written also by the same guy... but he was also trying to add email notices to notify.
We have control of the mail server so we were able to add smtp bypass to the sending mail server. Auth will need to be added to the script if you want to add it.

Re: Failover with SIP trunk

Posted: Wed Dec 12, 2012 5:14 pm
by garyscholten
Hi,

Thx so much. I like the reboot as that way I am 100% sure that it cleans out everything.

I added an auto-emailer already in almost the same way, this way I keep track of the connections.

The comment Primary needed to be added to the route list and not to the ethernet interfaces.

Regards, Gary

Re: Failover with SIP trunk

Posted: Mon Dec 28, 2015 7:29 pm
by SeanR
Hi

If the route is disabled how will the router know if it up again?