#!/bin/bash
echo "Have POX and your router sr running before executing these tests.."
echo

# TestCase 1
echo "*** Test Case 1 : Functionality : Ping from client to server1 ***"
timeout 5 ping -n -c 1 192.168.2.2 > .output.1

if grep -Fxq "1 packets transmitted, 1 received, 0% packet loss, time 0ms" .output.1
	then echo "Result : PASSED"
else echo "Result : FAILED"
fi

# TestCase 2
echo "*** Test Case 2 : Functionality : Traceroute from client to server2 ***"
timeout 5 traceroute -n 172.64.3.10 > .output.2

if grep "2  172.64.3.10" .output.2 > /dev/null
	then echo "Result : PASSED"
else echo "Result : FAILED"
fi

# TestCase 3
echo "*** Test Case 3 : Functionality : Get HTTP content from server1 ***"
timeout 5 wget 192.168.2.2 2>.output.3 

if grep "HTTP request sent, awaiting response... 200 OK" .output.3 > /dev/null
	then echo "Result : PASSED"
else echo "Result : FAILED"
fi

# TestCase 4
echo "*** Test Case 4 : ICMP : Send a ping from client to server with TTL 1, router should reject packet with TTL Exceeded ***"
timeout 5 ping -n -c 1 -t 1 192.168.2.2 >.output.4 

if grep -F "From 10.0.1.1 icmp_seq=1 Time to live exceeded" .output.4 > /dev/null
	then echo "Result : PASSED"
else echo "Result : FAILED"
fi

echo "*** Test Case 5 : Packet Sanity Check : When a packet of invalid Ethertype is sent, router should not process it ***"
timeout 10 python test.py 1 >/dev/null 
retval="$?"
if [[ $retval -ne 0 ]]; then
	echo "Result : FAILED"
	else
		echo "Result : PASSED"
fi
