Posted on July 9, 2015 1:05 pm
 |  Asked by Nicholas Kasioulis
 |  11451 views
RESOLVED
0
0
Print Friendly, PDF & Email

Hi There,

I was wondering if there is any mechanism in Arista switches  to track reachability of an IP, something similar to ip SLA icmp-echo.

 

 

Marked as spam
1
Posted by Alexis Dacquay
Answered on July 14, 2015 12:51 pm

Nicholas,

There are simple ways to achieve this, via scripting and AEM (events handler).

The first option is to simply track ICMP reachability via a bash script. You include the actions you want inside the script, such as adding/removing static routes, or else.

Bash script example:

#!/bin/bash

HOSTUP=Y
PingInterval=2
FailureCount=3
Count=0
while true; do

for i in 172.16.0.1
do
ping -c 1 -W 1 $i &> /dev/null
PingResult=$?

if [ $PingResult = "1" ]; then
let "Count++"
if [ "$HOSTUP" = "Y" ]; then
if [ $Count = "$FailureCount" ]; then
NOW=`date`
echo "Host is down at" $NOW >> /mnt/flash/RouteTrack.log
FastCli -p15 -c '
enable
conf term
no ip route 10.0.0.0/24 172.16.0.1'
HOSTUP=N
fi
else
HOSTUP=N
fi
fi

if [ $PingResult = "0" ]; then
if [ "$HOSTUP" = "N" ]; then
NOW=`date`
echo "Host is up at" $NOW >> /mnt/flash/RouteTrack.log
Count=0
FastCli -p15 -c '
enable
conf term
ip route 10.0.0.0/24 172.16.0.1'
HOSTUP=Y
else
HOSTUP=Y
fi
fi
done

sleep $PingInterval
done

 

The script checks for the ping reachability to 172.16.0.1 and do the following:
– Removes the static route to 10.0.0.0/24 upon 3 successive ping failures. You can change the number of ping failures using ’FailureCount’ variable.
– Installs the static route to 10.0.0.0/24 when the ping to 172.16.0.1 is successful.

’PingInterval’ indicates the frequency of ICMP pings. I have set it to 2 seconds in the script.

Here’s the instructions to install the script:

1. Copy the file to /mnt/flash on the switch.
2. Please change the variables ’PingInterval’ and ’FailureCount’ inside the script to suit your needs.
3. Create a event handler in Arista EOS CLI to run this script on boot. This will also start the script in the background.

event-handler RouteTrack
  trigger on-boot
  delay 300
  action bash /mnt/flash/RouteTack.sh

You can find the script logs in /mnt/flash/RouteTrack.log.

 

Please share if you have anything specific in mind.

For more script ideas, including reachability via the routing table (vs ICMP), you may look at https://github.com/arista-eosext

 

Regards,

Alexis

0
Posted by Nicholas Kasioulis
Answered on July 14, 2015 1:00 pm

Thank you very much Alexis for the clear explanation. your answer exceeded my expectations!!! :)

0
Posted by Scott
Answered on August 12, 2015 7:03 pm

Tried this script and it worked. I would like to terminate the script, however, I logged out of the switch and logged back in so I am unsure which PID to kill since it seems to keep changing.

0
Posted by Mark Berly
Answered on August 12, 2015 7:11 pm

Go into bash and try:

ps -ef | grep <name>

name = whatever you called the process in the event-handler

This should return the PID

0
Posted by Bijan Raminzad
Answered on November 19, 2015 5:15 am

Hi there,

We are using 7304 and 7308 devices for one of our customers in Australia. They use all 4 management ports for redundancy and I really needed to provide an automated solution, similar to IP SLA icmp-echo, to track the default gateway reachability and take an action accordingly.

I thought it might be worthwhile to share it with you.

Detection:

We did not want to change/modify the script every time that the management IP address of device is changed, hence, the script is designed to detect/calculate two variables in each cycle:

  1. Active management port (default exit interface)
  2. Default gateway IP address based on the configured IP address on any management port which is UP (assuming that the first usable IP of the subnet is the default gateway IP address).

Logging:

If any switching happens, a log message will be saved on a log file. The size of this file is checked by the script and it will not become more than 10Mb. The log file maximum size is configurable.

#!/bin/bash

PingInterval=5
FailureCount=3
Count=0

LogFileLocation=/mnt/flash/RDN-Redundancy/RDN-Redundancy.log
LogFileMaxSize=10000
while true; do

######## FIND THE DEFAULT EXIT INTERFACE ############
Interface=$(route | grep default | awk '{print$8}’)
if [ ”$Interface” == ”” ]; then
Temp=$(FastCli -p15 -c ’sho runn | in ip route’ | awk '{print$4}’)
if [[ ”$Temp” =~ ”Management0” ]]; then
Interface=”ma0”
else
Interface=”ma1_2”
fi
fi

####### FIND THE DEFAULT GATEWAY IP ADDRESS BASED ON CONFIGURED MANAGEMENT IP #########

MgmtPort=$(route | grep -o '[ma]{2,2}[0-9_]{1,3}’ | tail -1 | tr -d ’ntr’)
Subnet=$(ip addr show $MgmtPort | grep inet | grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/[0-9]{1,2}’ | tr -d ’ntr’)
NETID=$(ipcalc -n -4 $Subnet | grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’)
IFS=’.’ read -ra arr <<< ”$NETID”
let ”arr[3]++”

IP=$(IFS=$’.'; echo ”${arr[*]}” )

####### PING THE DEFAULT GATEWAY IP USING THE DEFAULT EXIT INTERFACE ############
ping -c 1 -W 1 -I $Interface $IP &> /dev/null
PingResult=$?
####### IF THE DEFALT GATEWAY DOES NOT REPLY TO THE PING REQUEST ###########################

if [ ”$PingResult” != ”0” ]; then
let ”Count++”
else
Count=0
fi

if [ ”$Count” = ”$FailureCount” ]; then
FastCli -p15 -c ’
enable
configure
ip route 0.0.0.0/0 management 1/2 1
ip route 0.0.0.0/0 management 2/2 2
no ip route 0.0.0.0/0 management 0’
Count=0

TIME=$(date)
echo ”Switched to the Secondary mgmt port–>” $TIME >> $LogFileLocation
FileSize=$(stat -c%s ”$LogFileLocation”)
if [ ”$FileSize” -ge ”$LogFileMaxSize” ]; then
cp $LogFileLocation ${LogFileLocation}-old
rm $LogFileLocation
fi

Interface=ma1_2
sleep 5
ping -c 1 -W 1 -I $Interface $IP &> /dev/null
PingResult=$?

if [ ”$PingResult” != ”0” ]; then
Interface=ma2_2
sleep 5
ping -c 1 -W 1 -I $Interface $IP &> /dev/null
PingResult=$?
fi

if [ ”$PingResult” != ”0” ]; then
FastCli -p15 -c ’
enable
configure
ip route 0.0.0.0/0 management 0
no ip route 0.0.0.0/0 management 1/2 1
no ip route 0.0.0.0/0 management 2/2 2’
Interface=ma0
Count=0

TIME=$(date)
echo ”Switched to the Primary mgmt port–>” $TIME >> $LogFileLocation
FileSize=$(stat -c%s ”$LogFileLocation”)
if [ ”$FileSize” -ge ”$LogFileMaxSize” ]; then
cp $LogFileLocation ${LogFileLocation}-old
rm $LogFileLocation
fi

fi

fi
sleep $PingInterval
done

I have a demo version of this script, which helps a lot for understanding and troubleshooting. Please let me know if you need that version.

Hope this helps. Your feedback is much appreciated.

Bijan

0
Posted by Alexis Dacquay
Answered on June 7, 2016 8:15 am

You can also use pings inside a VRF. For details, investigate Linux netns (Linux Name spaces), which are related to VRFs in EOS.

1) Display all network namespaces

user@bash-EOS1:~$ ip netns
< ...>
< ...>

2) Find out which namespace you’re interested in, in our case we are interested in

user@bash-EOS1:~$ sudo ip netns exec ifconfig

tap0f0dec7e-31 Link encap:Ethernet HWaddr fa:16:3e:74:2e:87

inet addr:1.0.0.8 Bcast:1.0.0.255 Mask:255.255.255.0

inet6 addr: fe80::f816:3eff:fe74:2e87/64 Scope:Link

3. Ping the VM from within the vrf

user@bash-EOS1:~$ sudo ip netns exec ping -c 1 1.0.0.9

PING 1.0.0.9 (1.0.0.9) 56(84) bytes of data.

64 bytes from 1.0.0.9: icmp_seq=1 ttl=64 time=159 ms

Post your Answer

You must be logged in to post an answer.