#! /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 "NS2-SGU1"
./run_switch_cmd.exp corner-switch-q2 "port show statistics 5"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 5" | grep "pkt.*Err:\|Consider"
echo "SGU1-TCU1"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 6" | grep "pkt.*Err:\|Consider"
echo "NS4-SGU2"
./run_switch_cmd.exp corner-switch-q4 "port show statistics 5"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 6" | grep "pkt.*Err:\|Consider"
echo "SGU2-TCU2"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 5" | grep "pkt.*Err:\|Consider"

set -o xtrace
# run TCU1/SGU1 traffic
ssh -q root@tcu1 "iperf3 -s -D -i 60 -1"
iperf3 -i 60 -n 6250000000 -c 192.168.129.1
ssh -q root@tcu1 "iperf3 -s -D -i 60 -1"
iperf3 -i 60 -n 6250000000 -c 192.168.129.1 -R

# run TCU1/SGU1 traffic
ssh -q root@tcu2 "iperf3 -s -D -i 60 -1"
iperf3 -i 60 -n 6250000000 -c 192.168.130.1
ssh -q root@tcu2 "iperf3 -s -D -i 60 -1"
iperf3 -i 60 -n 6250000000 -c 192.168.130.1 -R
set +o xtrace

# check post errors
echo "NS2-SGU1"
./run_switch_cmd.exp corner-switch-q2 "port show statistics 5"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 5" | grep "pkt.*Err:\|Consider"
echo "SGU1-TCU1"
./run_sgu_cmd.exp sg1 "bcm switch port mibs 6" | grep "pkt.*Err:\|Consider"
echo "NS4-SGU2"
./run_switch_cmd.exp corner-switch-q4 "port show statistics 5"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 6" | grep "pkt.*Err:\|Consider"
echo "SGU2-TCU2"
./run_sgu_cmd.exp sg2 "bcm switch port mibs 5" | grep "pkt.*Err:\|Consider"
