0
0
0
s2sdefault

I was working on a lab to replicate a customer's impending upgrade. One of the things we need to do prior to this upgrade is change some routing and go from OSPF to Static routes. Part of my testing and validation involved finding how long it would take for the staic route to be removed from the routing table after some changes were made. How am I going to figure THAT out...?

With a script of course! In short, the script takes a time stamp, and checks the routing table every second for some specific routes. If they are found to have the D flag (indicating it is a Dynamic route), then we output to the screen that it is still dynamic, wait a second, then loop through again. Once the route is found to no longer be dynamic, again output this to the screen, take a new timestamp, do some math, and finally output the total execution time in milliseconds. Let's take a look at the whole script:

#! /bin/bash

# Get a start timestamp

T="$(date +%s%N)"

# while loop

STOP="false"

while [[ $STOP == "false" ]]

do

This here is the key route I needed to watch. I needed to watch and see how long it would take for the D flag to disappear, but still remain an existing route. This would give me my indication that the Dynamic Routing and routes are no longer present, but that this key route still existed.

    FLAGS=$(netstat -rn|grep 192.168.254|awk '{print $4}' )

    if [[ $FLAGS == "UGD" ]]

    then

        echo "Route 192.168.254.0 - Still Dynamic"

    else [[ $FLAGS == "UG" ]]

        TOTAL_TIME="$(($(date +%s%N)-T))"

        STOP="true"

    fi

This here next route was purely Dynamic, and I had no desire to keep/replace this route. What I am doing here is simply watching the routing table, and once this route disappears, then again, we know that Dynamic Routing and Routes are no longer present.

    FLAGS=$(netstat -rn|grep 172.31.254|awk '{print $4}' )

    if [[ $FLAGS == "UGD" ]]

    the

        echo "Route 172.31.254.0 - Still Dynamic"

    elif [[ $FLAGS == "" ]]

    then

        echo "Route 172.31.254.0 - Gone"

    fi

sleep 1

done

# Math "convert" the time to milliseconds

TOTAL_TIME_MS="$((TOTAL_TIME/1000000))"

echo $TOTAL_TIME_MS

The "main" part of the script is the following command:

netstat -rn|grep 192.168.254|awk '{print $4}'

What this does is get the routing table, grep for just the route we are really interested in, then awk for the FLAGS column. We compare this output to a couple of possibilities, and make the decisions based on that. There is another, similar command for another route as well.In the end, the first route is the one I was looking to replace with a static route, so it was the main route I cared about. There was another Dynamic route as well, but we weren't replacing it. I wanted to have an eye on that route for when it disappeared from the routing table. This would indicate to me that the Dynamic Routes have indeed bee cleared out.

In the end, I left this script to run for over 25 minutes, and the routes never cleared out. This script never wound up giving the final time because of some other, pre-existing issues where the Dynamic Routes weren't actually getting cleared out. So while I never really got that final output, it was invaluable in helping me further troubleshoot this lab, and helping me with my work on this issue for my customer.

Feel free to download it, look it over, and comment below.

Downloads:
zip-11 routeTimer 1 HOT
Date-11Thursday, 24 September 2015 16:22 File Size-11 602 B Download-11 303 Download

Add comment


Security code
Refresh

0
0
0
s2sdefault