#!/bin/bash

run205=$1
if [ "$run205" = "y" ]; then
	bash /home/rnp/2/205.sh y 4
fi
echo "206" > /home/rnp/2/206.txt

assign_ip(){
	local dev=$1
	local eth_num=$2
	local ip=$3
	ssh $dev "ip link set dev eth$eth_num up"
	ssh $dev "ip addr add $ip dev eth$eth_num"
	echo "dev $dev eth$eth_num assign $ip"
}

assign_ip "pc1" 1 "2001:db8:5::1/64"
assign_ip "pc2" 1 "2001:db8:5::2/64"

get_v6(){
	local output=$1
	local eth_n=$2
	echo "$output" | grep -A 1 "^[0-9]: eth$eth_n" | awk '/inet6/ && /global/ {split($2, a, "/"); print a[1]}'
}

ping6_dev(){
	local dev=$1
	local ip=$2
	local eth_n=$3
	local output=$(ssh $dev "ping6 -c 5 -W 2 -I eth$eth_n $ip")
	echo $output
}

pc1_ip6=$(ssh "pc1" "ip -6 addr show")
echo $pc1_ip6
pc1_6=$(get_v6 "$pc1_ip6" 1)
echo $pc1_6

pc2_ip6=$(ssh "pc2" "ip -6 addr show")
echo $pc2_ip6
pc2_6=$(get_v6 "$pc2_ip6" 1)
echo $pc2_6

output=$(ping6_dev "pc1" "$pc2_6" 1)
echo "pc1 ping6 pc2"
echo "pc1 ping6 pc2">> /home/rnp/2/206.txt
echo "ping6 -c 5 -W 2 -I eth1 $pc2_6"
echo "ping6 -c 5 -W 2 -I eth1 $pc2_6">> /home/rnp/2/206.txt
echo "$output" 
echo "$output" >> /home/rnp/2/206.txt

output=$(ping6_dev "pc2" "$pc1_6" 1)
echo "pc2 ping6 pc1"
echo "pc2 ping6 pc1">> /home/rnp/2/206.txt
echo "ping6 -c 5 -W 2 -I eth1 $pc1_6"
echo "ping6 -c 5 -W 2 -I eth1 $pc1_6">> /home/rnp/2/206.txt
echo "$output" 
echo "$output" >> /home/rnp/2/206.txt

