
## Author: Mete Rodoper
# For more detail refer How to run a Virtual Mobility experiment on ORBIT


#1) Image  all grid nodes
#2) Turn all grid nodes on
#3) Run CreateMobilitySetup
#4) Install ath0 ports to nodes
#5) Copy the Click files to nodes
#6) Run "click-install mob*.click"

system("orbit load all click-2.4.26-20051204.ndz"); # Imaging all nodes for Virtual Mobility

system("orbit tell on all grip"); # Turning all nodes on

system("CreateMobilitySetup"); #Create Mobility Script for preparing Click Router Files

open(VMGenList,"ls VM*.txt |");
@genVMList = <VMGenList>;
print " @genVMList";
open(VMList,"listofvms.txt");
@allVMtxtFiles = <VMList>;
print " @allVMtxtFiles";

$count=1;

while($count < @genVMList + 1) # Turn the ath0 interface up for all path nodes used during the experiment
{

	open(myInput, "<VM$count.txt");
	while(<myInput>)
        {
        	my($line) = $_;

        	chomp($line); # Remove the spaces

        	@myArrayNum1 = split(/-/, $line);
        	@myArrayNum2 = split(/e/, $myArrayNum1[0]);
        	$firstNumber=$myArrayNum2[1];
        	$secondNumber=$myArrayNum1[1];

        	system("ssh root\@node$firstNumber-$secondNumber modprobe ath_pci");
        	system("ssh root\@node$firstNumber-$secondNumber ifconfig ath0 up");
      		system("ssh root\@node$firstNumber-$secondNumber exit");

        }

        $count = $count + 1;
}

open(myInput, "<listofvms.txt"); # Turn the ath0 interface up for all vm nodes used during the experiment
while(<myInput>)
{
	my($line) = $_;

        chomp($line); # Remove the spaces

	@myArrayNum1 = split(/-/, $line);
	@myArrayNum2 = split(/e/, $myArrayNum1[0]);
	$firstNumber=$myArrayNum2[1];
	$secondNumber=$myArrayNum1[1];

	system("ssh root\@node$firstNumber-$secondNumber modprobe ath_pci");
	system("ssh root\@node$firstNumber-$secondNumber ifconfig ath0 up");
	system("ssh root\@node$firstNumber-$secondNumber exit");
}
$count=1;

while($count < @genVMList + 1) # Copy click router files to all path nodes used during the experiment
{

	open(myInput, "<VM$count.txt");
	while(<myInput>)
        {

	        my($line) = $_;	
	        chomp($line); # Remove the spaces

        	@myArrayNum1 = split(/-/, $line);
        	@myArrayNum2 = split(/e/, $myArrayNum1[0]);
        	$firstNumber=$myArrayNum2[1];
        	$secondNumber=$myArrayNum1[1];


        	system("scp EthernetAddresses/mob_node_src_generated_Node_$firstNumber_$secondNumber.click setup.sh root\@node$firstNumber-$secondNumber:~");
        }

        $count = $count + 1;
}

$mycounter=1;
open(myInput, "<listofvms.txt");
while(<myInput>) # Copy click router files to all vm nodes used during the experiment
{
	my($line) = $_;
        chomp($line); # Remove the spaces

	@myArrayNum1 = split(/-/, $line);
	@myArrayNum2 = split(/e/, $myArrayNum1[0]);
	$firstNumber=$myArrayNum2[1];
	$secondNumber=$myArrayNum1[1];

	system("scp EthernetAddresses/mob_server_src_generated_VM$mycounter.click setup.sh root\@node$firstNumber-$secondNumber:~");
	$mycounter++;
}

$count=1;

while($count < @genVMList + 1) # Run Click Router Scripts for all path nodes used during the experiment
{

	open(myInput, "<VM$count.txt");
	while(<myInput>)
        {
        my($line) = $_;

        chomp($line); # Remove the spaces

        @myArrayNum1 = split(/-/, $line);
        @myArrayNum2 = split(/e/, $myArrayNum1[0]);
        $firstNumber=$myArrayNum2[1];
        $secondNumber=$myArrayNum1[1];

        system("ssh root\@node$firstNumber-$secondNumber click-install mob*.click");
        system("ssh root\@node$firstNumber-$secondNumber exit");

        }

        $count = $count + 1;
}

open(myInput, "<listofvms.txt"); # Run Click Router Scripts for all vm nodes used during the experiment
while(<myInput>)
{
	my($line) = $_;

        chomp($line); # Remove the spaces

	@myArrayNum1 = split(/-/, $line);
	@myArrayNum2 = split(/e/, $myArrayNum1[0]);
	$firstNumber=$myArrayNum2[1];
	$secondNumber=$myArrayNum1[1];

        system("ssh root\@node$firstNumber-$secondNumber click-install mob*.click");
        system("ssh root\@node$firstNumber-$secondNumber exit");
}
