#!/bin/bash

test_ping(){
	local sender_dev=$1
	local sender_eth=$2
	local receiver_dev=$3
	local receiver_eth=$4
	local receiver_ip=$5

	loss=$(ssh $sender_dev "ping -c 5 -W 2 -I eth$sender_eth $receiver_ip | awk -F', ' '/packet loss/ {print \$3}' | awk '{print int(\$1)}'")
	echo $loss
}

loss_count=0

localloss=$(test_ping "router1" 1 "pc1" 1 "10.5.1.1")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router1" 2 "router2" 2 "10.5.3.4")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router1" 3 "router3" 2 "10.5.4.3")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router1" 4 "router4" 1 "10.5.2.4")
loss_count=$(($loss_count+$localloss))
echo $loss_count

localloss=$(test_ping "router2" 1 "pc2" 1 "10.5.2.1")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router2" 3 "router3" 3 "10.5.6.2")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router2" 4 "router4" 2 "10.5.5.4")
loss_count=$(($loss_count+$localloss))
echo $loss_count

localloss=$(test_ping "router3" 1 "pc3" 1 "10.5.3.1")
loss_count=$(($loss_count+$localloss))
echo $loss_count
localloss=$(test_ping "router3" 4 "router4" 3 "10.5.7.2")
loss_count=$(($loss_count+$localloss))
echo $loss_count

echo $loss_count


