#!/usr/bin/env bash

# run largish topology and flap a link looking for convergence times

# Copyright (c) 2016-, Juniper Networks, Inc.
# All rights reserved.

echo "--- flap a single link and measure nodes convergence time from flap to last RIB download"
echo "    This shows minimal blast radius and RIB impact of a link failure"
echo

set -e

ulimit -n 4096

`which python` --version || {
    echo "install python ..."
    exit 1
}

echo running as $$

OF=/tmp/rift.out.$$

../bin/rift-environ -c -vv topology -u -DD ../topology/3pod2edge4acc3core100pfx.yaml > $OF 2>&1 << EOF
sleep F00
bfd down node "core_1" interface "intf_1_104-"
bfd down node "agg_104" interface "intf_104_1-"
sleep A00
quit

EOF

egrep "stopping interface" $OF

# derive all the downtimes

echo
echo "--- last RIB transaction timestamps of key nodes"
echo

for N in core_1 core_2 core_3 agg_102 agg_103 agg_104 agg_201 agg_202 agg_301 agg_302 edge_1001 edge_1002 edge_2001 edge_3001
do
    LRT=`python lib/curlies.py "RIB stats for $N" < $OF | python lib/curlies.py " *last_transaction:" | egrep "(secs|msecs)"`
    echo "$N last RIB transaction: " $LRT
done

unlink $OF
