Enable - Disable BGP peer based on signal strength.

In the AWMN is common enough for a dish antenna to move from strong winds or for a feeder to fill with water after a storm. The link quality may drop drastically but the BGP session remains active. However, since the link quality is very poor many frames drop, the people using it suffer and the quality of the internet drops. Another as long or even longer but higher in quality route could be used instead. A script may monitor the signal strength of each link and close the appropriate BGP session if the link quality drops drastically.

The following is such a script written for RouterOS by George Katsimagklis aka SV1BDS (Ham Radio Cosign and awmn handle) inspired by an AWMN VoIP conversation we had. There is a thread in Greek about it the awmn forum.

The script

# monitor WLAN1 status
:global wlan1status
:global wlan1RSSI
:local interfacename "wlan1-xyz"
:local myemail "69xxxxxxxx@mycosmos.gr,zzzzz@yahoo.com"
:local RSSIlevel -75
:local SMTPserver "smtp.gmail.com"
:local peername "SV1XYZ"

# Local variables
:local int
:local mysubject
:local RSSIs "-1dB"
:local RSSI
:local statusnow "down"
:local s

:foreach int in=[/interface wireless registration-table find interface=$interfacename] do={
    :set statusnow "up"
    :set RSSIs [/interface wireless registration-table get $int signal-strength]}

:set RSSI [:tonum [:pick $RSSIs 0 [:find $RSSIs "d" 0]]]

#:log info $RSSI
#:log info $statusnow

:if ([:typeof $wlan1status] = "nothing") do={
     :set wlan1status $statusnow
  } else={:if ($wlan1status != $statusnow) do={
              :set mysubject ($interfacename." on ".[/system identity get name]." is ".$statusnow)
             /tool e-mail set address=[:resolve $SMTPserver]
             :foreach s in=[:toarray $myemail] do={
                  /tool e-mail send to=$s subject=$mysubject}
             :log info $mysubject
             :set wlan1status $statusnow
             :foreach int in=[/routing bgp peer find name=$peername] do={
                 :if ($statusnow = "up") do={
                      /routing bgp peer enable $int
                 } else={
                      /routing bgp peer disable $int
                 }
             }
         } 
 }
:if ($statusnow="up") do={
  :if ([:typeof $wlan1RSSI] = "nothing") do={
      :if ( $RSSI<$RSSIlevel) do={
          :set wlan1RSSI "BAD"
          :set mysubject ($interfacename." on ".[/system identity get name]." RSSI is ".$RSSI." (".$RSSIlevel.")")
          /tool e-mail set address=[:resolve $SMTPserver]
          :foreach s in=[:toarray $myemail] do={
              /tool e-mail send to=$s subject=$mysubject}
          :log info $mysubject
          :foreach int in=[/routing bgp peer find name=$peername] do={ /routing bgp peer disable $int }
      } else={
           :set wlan1RSSI "OK"
           :foreach int in=[/routing bgp peer find name=$peername] do={ /routing bgp peer enable $int }
      }
  } else={:if ( $RSSI<$RSSIlevel and $wlan1RSSI="OK") do={
                 :set wlan1RSSI "BAD"
                 :set mysubject ($interfacename." on ".[/system identity get name]." RSSI is ".$RSSI." (".$RSSIlevel.")")
                 /tool e-mail set address=[:resolve $SMTPserver]
                 :foreach s in=[:toarray $myemail] do={
                       /tool e-mail send to=$s subject=$mysubject}
                 :log info $mysubject
                 :foreach int in=[/routing bgp peer find name=$peername] do={ /routing bgp peer disable $int }
                 }
              :if ( !($RSSI<$RSSIlevel) and $wlan1RSSI="BAD") do={
                 :set wlan1RSSI "OK"
                 :set mysubject ($interfacename." on ".[/system identity get name]." RSSI is ".$RSSI." (".$RSSIlevel.")")
                 /tool e-mail set address=[:resolve $SMTPserver]
                 :foreach s in=[:toarray $myemail] do={
                        /tool e-mail send to=$s subject=$mysubject}
                 :log info $mysubject
                 :foreach int in=[/routing bgp peer find name=$peername] do={ /routing bgp peer enable $int }
               }
  }
}
#:log info "end"






Enable-Disable BGP peering based on signal strength