wanlinkinfo.in 2.8 KB
Newer Older
Chad Barb's avatar
 
Chad Barb committed
1 2
#!/usr/bin/perl -w
use English;
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use Getopt::Std;

#
# Need to join with nodes/reserved to make sure node is not dead or
# in the hwdown group.
# 

sub usage()
{
    print STDOUT
	"Usage: wanlinkinfo [-d] [-m] [-b]\n".
	"       Use -m to output virtual node counts per phys node.\n".
        "       Use -b to output bandwidth matrix.\n";
    exit(-1);
}
my  $optlist = "dmb";

#
# Configure variables
#
my $TB = "@prefix@";
Chad Barb's avatar
 
Chad Barb committed
24

25 26 27 28
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
Chad Barb's avatar
 
Chad Barb committed
29
use libdb;
30 31 32 33 34 35
use libtestbed;

# Locals
my $debug	= 0;
my $dobw	= 0;
my $dovirt	= 0;
Chad Barb's avatar
 
Chad Barb committed
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#
# Turn off line buffering on output
#
$| = 1;

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV) {
    usage();
}
if (defined($options{"d"})) {
    $debug = 1;
}
if (defined($options{"m"})) {
    $dovirt = 1;
}
if (defined($options{"b"})) {
    $dobw= 1;
}

my $result =
    DBQueryFatal("SELECT node_id1,iface1,node_id2,iface2,time,bandwidth " .
		 "FROM widearea_delays");
Chad Barb's avatar
 
Chad Barb committed
70 71 72

my %nodename = ();
my %speeds   = ();
Chad Barb's avatar
Chad Barb committed
73
my %bws   = ();
Chad Barb's avatar
 
Chad Barb committed
74

75 76
while (my ($node_id1, $iface1, $node_id2, $iface2, $time, $bw) =
       $result->fetchrow) {
Chad Barb's avatar
 
Chad Barb committed
77 78 79 80 81 82 83 84 85
    my $msectime = $time * 1000;
    my $glom1    = $node_id1 . ":" . $iface1;
    my $glom2    = $node_id2 . ":" . $iface2;

    # print "Got $glom1 to $glom2 in $msectime ms\n";
    $nodename{ $glom1 } = "1";
    $nodename{ $glom2 } = "1";

    $speeds{ $glom1 . "+" . $glom2 } = $msectime;
Chad Barb's avatar
Chad Barb committed
86
    $bws{ $glom1 . "+" . $glom2 } = $bw;
Chad Barb's avatar
 
Chad Barb committed
87 88 89 90
}

print scalar( keys %nodename ) . "\n";

91 92 93 94 95
#
# XXX The boss node ends up first strictly by accident. We need to know
#     which is really the boss so we can fix the mappings to it in the
#     v section.
# 
Chad Barb's avatar
 
Chad Barb committed
96 97 98 99
foreach my $i (sort (keys %nodename)) {
    print "$i\n";
}

100 101 102 103 104 105 106 107 108 109 110
#
# XXX Hardwired for now. Should read the DB to see what the max allowed
#     is (which is not stored in the DB yet), and the number already
#     allocated, and send the difference in as the max. 
# 
if ($dovirt) {
    foreach my $i (sort (keys %nodename)) {
	print "4\n";
    }
}

Chad Barb's avatar
 
Chad Barb committed
111 112 113 114 115 116 117 118 119 120
foreach my $i (sort (keys %nodename)) {
    foreach my $j (sort (keys %nodename)) {
	my $s = "0";
	if (exists $speeds{ $i."+".$j } ) {
	    $s = $speeds{ $i . "+" . $j };
	} 
	print sprintf( "%-5i ", $s );
    }
    print "\n";
}
Chad Barb's avatar
Chad Barb committed
121

122 123 124 125 126 127 128 129 130 131 132 133 134
if ($dobw) {
    foreach my $i (sort (keys %nodename)) {
	foreach my $j (sort (keys %nodename)) {
	    # the following is conceptually
	    # the bandwidth of a machine to itself.
	    # using ttcp, a typical value was found to be 180 MB/sec
	    my $s = "180000"; 
	    if (exists $bws{ $i."+".$j } ) {
		$s = $bws{ $i . "+" . $j };
	    } 
	    print sprintf( "%-6i ", $s );
	}
	print "\n";
Chad Barb's avatar
Chad Barb committed
135 136
    }
}