Community discussions

MikroTik App
 
User avatar
Barones
just joined
Topic Author
Posts: 3
Joined: Tue Apr 17, 2018 11:07 pm

Packet loss Script to GRE Tunnels

Mon Sep 20, 2021 8:17 pm

Guys,

I do connect sites over GRE tunnels in a Spine Leaf topology, each site has 2 GRE Tunnels connection to a Tunnel Concentrator each, RSTP deal with looping

I made a script to test the WAN connection to each Concentrator and disable the GRE Tunnel if it has packet loss over X %

I'm making it avaiable so other people could use it as well
Any comments is appreciated
#VARIABLES
:local totalpings 25
:local ipdest [interface pptp-client get <interface-name> connect-to]

#IF GRE TUNNEL 2 IS WORKING - RUN SCRIPT
:if ([/interface pptp-client get <interfac2-name> running]=true) do={
    :local pings ([/ping count=$totalpings $ipdest interval=600ms] * 100 / $totalpings)
    :put $pings
    :log info ("Packet Loss:". (100 - $pings). "%")
 #IF PING > 80%
    :if ($pings > 80) do={
        :if ([/interface pptp-client get <interface-name> running]=true) do={} else={
            :interface pptp-client enable <interface-name>;
            :log info ("<interface-name> Enabled");}
    }
#IF PING < 80% 
    :if ($pings < 80) do={
        interface pptp-client disable <interface-name>;
        :log info ("<interface-name> Disabled");
    }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Packet loss Script to GRE Tunnels

Mon Sep 20, 2021 8:38 pm

Not tested, only fixed syntax and logic errors
# VARIABLES
:local interface  <interface-name>
:local interface2 <interface2-name>
:local totalpings 25
:local ipdest [/interface pptp-client get $interface connect-to]

# IF GRE TUNNEL 2 IS WORKING - RUN SCRIPT
:if ([/interface pptp-client get $interface2 running]) do={
    :local pings ([/ping count=$totalpings $ipdest interval=600ms] * 100 / $totalpings)
    :log info "Packet Loss: $(100 - $pings)%"
# IF PING > 80%
    :if ($pings > 80) do={
        :if ([/interface pptp-client get $interface running]!=true) do={
            /interface pptp-client enable $interface
            :log info "$interface Enabled"
        }
    }
#IF PING < 80% 
    :if ($pings < 80) do={
        /interface pptp-client disable $interface
        :log info "$interface Disabled"
    }
}

Who is online

Users browsing this forum: No registered users and 31 guests