#! /bin/bash

# https://confluence.zooxlabs.com/display/SPG/SEGA+2+-+Diagrams
#
# Dev   Conn  Switch
# TUX   2-1   0
# -     2-5   1
# BOX2  2-2   2
# SGU2  2-4   3
# BOX3  2-3   4
# NS2   3-1   5
# TCU1  3-2   6
# -     -     7
# SGU1  Int   8
#
# Dev   Conn  Switch
# TCU3  2-1   0
# -     2-5   1
# BOX4  2-2   2
# SGU1  2-4   3
# BOX1  2-3   4
# TCU2  3-1   5
# NS4   3-2   6
# -     -     7
# SGU2  Int   8


# check pre errors
echo "SGU1-TUX"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 0" | grep "pkt.*Err:\|Consider"
echo "SGU1-BOX2"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 2" | grep "pkt.*Err:\|Consider"
echo "SGU1-BOX3"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 4" | grep "pkt.*Err:\|Consider"
echo "SGU1-SGU2"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 3" | grep "pkt.*Err:\|Consider"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 3" | grep "pkt.*Err:\|Consider"
# echo "SGU2-TCU3"
# ./run_sgu_cmd.exp sg2 "bcm switch port mibs 0" | grep "pkt.*Err:\|Consider"
echo "SGU2-BOX4"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 2" | grep "pkt.*Err:\|Consider"
echo "SGU2-BOX1"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 4" | grep "pkt.*Err:\|Consider"

pushd ~/driving
# run traffic
set -o xtrace
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.20 -n 6250000 -s 1000 -r 100000 -i 60 # TUX
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.30 -n 6250000 -s 1000 -r 100000 -i 60 # BOX1
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.31 -n 6250000 -s 1000 -r 100000 -i 60 # BOX2
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.32 -n 6250000 -s 1000 -r 100000 -i 60 # BOX3
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.33 -n 6250000 -s 1000 -r 100000 -i 60 # BOX4
bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.1 -n 6250000 -s 1000 -r 100000 -i 60 # SGU1 from SGU2
# bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.2 -n 6250000 -s 1000 -r 100000 -i 60 # SGU2 from SGU1
# bazel run //experimental/ihartwig/icmptraffic -- 192.168.128.40 -n 6250000 -s 1000 -r 100000 -i 60 # TCU3 expected no link
set +o xtrace
popd

# check post errors
echo "SGU1-TUX"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 0" | grep "pkt.*Err:\|Consider"
echo "SGU1-BOX2"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 2" | grep "pkt.*Err:\|Consider"
echo "SGU1-BOX3"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 4" | grep "pkt.*Err:\|Consider"
echo "SGU1-SGU2"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 3" | grep "pkt.*Err:\|Consider"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 3" | grep "pkt.*Err:\|Consider"
# echo "SGU2-TCU3"
# ./run_sgu_cmd.exp sg2 "bcm switch port mibs 0" | grep "pkt.*Err:\|Consider"
echo "SGU2-BOX4"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 2" | grep "pkt.*Err:\|Consider"
echo "SGU2-BOX1"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 4" | grep "pkt.*Err:\|Consider"
