#!/usr/bin/env bash

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

echo "measures convergence of a topology for some nodes from coldstart (i.e. start until last RIB download"

set -e

ulimit -n 4096

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

echo running as $$
echo "measuring last RIB transaction time vs. node startup time (effective convergence) ..."

../bin/rift-environ --version

# sleep about 4 secs (milliseconds in hex = 8 * 512 )

OF=/tmp/rift.out.$$

../bin/rift-environ -vv topology ../topology/3pod2edge4acc3core100pfx.yaml  -u -DD  > $OF 2>&1  << EOF
sleep 800
quit

EOF

# derive all the times

cat $OF | ./lib/countfloodcountfilter.sh
cat $OF | ./lib/countfloodretransmits.sh
cat $OF | ./lib/countfloodreductions.sh
./lib/eventstats.sh $OF
echo

for N in core_1 agg_101 edge_1001 core_2 agg_201 edge_2001 core_3
do
    LFT=`egrep "node $N configured" $OF`
    echo "$N started: " $LFT
    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
