#!/usr/bin/perl

# Run ssh-agent .ssh/id_rsa and sfskey login fubob@ny.lcs.mit.edu before 
# starting

$| = 1;


$trials    =   100;


@rextests     = "bench-rex";
@rexstargets = ( "cookies ny grape-bay am redlab" ) ;

@sshtests     = "bench-ssh"; 
@sshtargets  = ( "cookies new-york grape-bay amsterdam redlab" );


# Test latency of resumed Rex sessions on low latency network (.4ms RT ping)
system "rex -XT cookies.lcs.mit.edu:sjtpx9265ja4ma62rehm45rfxnfd26wg";
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o rex-second.log -f \"%Uuser %Ssystem %eelapsed\" rex -XT cookies.lcs.mit.edu:sjtpx9265ja4ma62rehm45rfxnfd26wg";
}

# Test latency of first Rex on low latency network
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o rex.log -f \"%Uuser %Ssystem %eelapsed\" rex -XT cookies.lcs.mit.edu:sjtpx9265ja4ma62rehm45rfxnfd26wg";
    system "rex -XT cookies.lcs.mit.edu:sjtpx9265ja4ma62rehm45rfxnfd26wg killall proxy";
}

# Test latency of SSH2 on low latency network
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o ssh.log -f \"%Uuser %Ssystem %eelapsed\" ssh -2 -ax cookies.lcs.mit.edu";
}

# Test latency of unresumed SSL connections with client and server auth
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o ssl.log -f \"%Uuser %Ssystem %eelapsed\" ./ssl.sh";
}

exit;

# Test latency of resumed Rex sessions on high latency network (8ms RT ping,
# slower server though)
#OpenBSD 3.1 (GENERIC) #7: Thu May  2 17:19:35 EDT 2002
#    dm@orchard.scs.cs.nyu.edu:/home/or/dm/src/sys/arch/i386/compile/GENERIC
#cpu0: Intel Pentium III (Coppermine) ("GenuineIntel" 686-class) 803 MHz
#cpu0: FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,SYS,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SIMD
#real mem  = 536444928 (523872K)
#avail mem = 491581440 (480060K)

system "rex -XT ludlow.scs.cs.nyu.edu:u24ikrue28y62mnge6v7k36e2qcyy7fc /usr/bin/true";
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o rex-second-nyu.log -f \"%Uuser %Ssystem %eelapsed\" rex -XT ludlow.scs.cs.nyu.edu:u24ikrue28y62mnge6v7k36e2qcyy7fc /usr/bin/true";
}

# Test latency of first Rex on low latency network
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o rex-nyu.log -f \"%Uuser %Ssystem %eelapsed\" rex -XT ludlow.scs.cs.nyu.edu:u24ikrue28y62mnge6v7k36e2qcyy7fc /usr/bin/true";
    system "rex -XT ludlow.scs.cs.nyu.edu:u24ikrue28y62mnge6v7k36e2qcyy7fc killall proxy";
}

# Test latency of SSH2 on low latency network
for ($trial = 0; $trial < $trials; $trial++ ) {
    system "/usr/bin/time -a -o ssh-nyu.log -f \"%Uuser %Ssystem %eelapsed\" ssh -2 -ax ludlow.scs.cs.nyu.edu /usr/bin/true";
}

exit;

foreach $rextest (@rextests) {

    foreach $target ( @rextargets ) {
	
	for ($trial = 0; $trial < $trials; $trial++ ) {
	    system "/usr/bin/time $target";
	
	}
	
    }
}
