Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set local variables
- :local firstInterface "reachable ether8_to_vipNet_HW1000_01";
- :local secondInterface "reachable ether6_to_vipNet_HW1000_02";
- :local pingTo1 "172.16.9.11";
- :local pingTo2 "172.16.9.11";
- :local pingCount 5;
- :local stableConnectFrom 70;
- :local prefix ">>> ";
- # Local variables
- :local firstInterfaceName $firstInterface;
- :local secondInterfaceName $secondInterface;
- # Function to cleaning ARP table
- :local clearArp do={
- :local dumplist [/ip arp find]
- :foreach i in=$dumplist do={
- /ip arp remove $i
- }
- :log info ($prefix . "ARP cleaned");
- }
- # Function to reconnect PPPoE connection
- :local reconnectPPPoE do={
- /interface pppoe-client set $nameInterface disable=yes;
- :delay 1s;
- /interface pppoe-client set $nameInterface disable=no;
- }
- :log info ($prefix . "START PING to $pingTo1 & $pingTo2");
- # Check FIRST interface
- /interface pppoe-client {
- :if ( [get $firstInterface disable] = true) do={
- set $firstInterface disable=no;
- :delay 5s;
- }
- }
- # Check SECOND interface
- /interface ethernet {
- :if ( [get $secondInterface disable] = true) do={
- set $secondInterface disable=no;
- }
- }
- /ip route {
- # Set objects to variables
- :set firstInterface [find dst-address="172.16.0.0/18" gateway=$firstInterfaceName];
- :set secondInterface [find dst-address="172.16.0.0/18" gateway=$secondInterfaceName];
- # Check routes
- :if ( [get $firstInterface distance] != 2 ) do={
- set $firstInterface distance=2;
- :log info ($prefix . "Distance for " . $firstInterfaceName . " corrected");
- }
- :if ( [get $secondInterface distance] != 1 && [get $secondInterface distance] != 3) do={
- set $secondInterface distance=3;
- :log info ($prefix . "Distance for " . $secondInterfaceName . " corrected");
- }
- # Get ping successfully packets. In percent
- :local pingStatus \
- ((( [/ping $pingTo1 interface=$firstInterfaceName count=$pingCount] + \
- [/ping $pingTo2 interface=$firstInterfaceName count=$pingCount] ) / ($pingCount * 2)) * 100);
- # Check Internet
- :if ( [get $firstInterface active] = false or $pingStatus < $stableConnectFrom) do={
- :log info ($prefix . "FIRST NO INTERNET!!!");
- # Change distance
- :if ( [get $secondInterface distance] != 1 ) do={
- set $secondInterface distance=1;
- :log info ($prefix . "Distance for " . $secondInterfaceName . " changed");
- $clearArp;
- }
- $reconnectPPPoE nameInterface=$firstInterfaceName;
- } else={
- :log info ($prefix . "FIRST INTERNET CONNECTED");
- # Change distance
- :if ( [get $secondInterface distance] != 3 ) do={
- set $secondInterface distance=3;
- :log info ($prefix . "Distance for " . $secondInterfaceName . " changed");
- $clearArp;
- }
- }
- }
- :log info ($prefix . "END PING");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement