wanlinkinfo.in 5.21 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh Stoller's avatar
Leigh Stoller committed
2 3 4

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
6 7 8
# All rights reserved.
#

9
use English;
10 11 12 13 14 15 16 17 18 19
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
20
	"Usage: wanlinkinfo [-d] [-m [-c <count>]] [-b] [-l] [-p] [-r]\n".
21
	"       Use -m to output virtual node counts per phys node.\n".
22
        "       Use -b to output bandwidth matrix.\n".
23
        "       Use -p to output plr matrix.\n".
24
        "       Use -r to remove boss from matrix.\n".
25
        "       Use -l to use the latest data instead of aged data.\n";
26 27
    exit(-1);
}
28
my  $optlist = "dmc:blrp";
29 30 31 32 33

#
# Configure variables
#
my $TB = "@prefix@";
34

35 36 37 38
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
39
use libdb;
40 41 42 43 44
use libtestbed;

# Locals
my $debug	= 0;
my $dobw	= 0;
45
my $doplr	= 0;
46
my $dovirt	= 0;
47
my $collocate   = 10000;
48
my $dolatest	= 0;
49
my $noboss	= 0;
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#
# 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;
76 77 78
    if (defined($options{"c"})) {
	$collocate = $options{"c"};
    }
79 80 81 82
}
if (defined($options{"b"})) {
    $dobw= 1;
}
83 84 85
if (defined($options{"l"})) {
    $dolatest= 1;
}
86 87 88
if (defined($options{"r"})) {
    $noboss = 1;
}
89 90 91
if (defined($options{"p"})) {
    $doplr = 1;
}
92

93 94 95 96 97 98 99 100 101
my %nodename = ();
my %speeds   = ();
my %bws      = ();
my %plrs     = ();
my %freenodes= ();

#
# First get the widearea data.
# 
102
my $result =
103 104
    DBQueryFatal("SELECT node_id1,iface1,node_id2,iface2,time, " .
		 "       bandwidth,lossrate FROM " .
105 106 107
		 ($dolatest ? "widearea_recent " : "widearea_delays ") .
		 ($noboss ? "where node_id1!='boss' and ".
		  "                node_id2!='boss'" : ""));
108

109
while (my ($node_id1, $iface1, $node_id2, $iface2, $time, $bw, $plr) =
110
       $result->fetchrow) {
111

112
    my $msectime = $time * 1000;
113 114
    my $glom1    = $node_id1;
    my $glom2    = $node_id2;
115 116 117 118 119 120

    # 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
121
    $bws{ $glom1 . "+" . $glom2 } = $bw;
122
    $plrs{ $glom1 . "+" . $glom2 } = $plr;
123 124
}

125 126 127 128 129 130 131 132 133 134 135 136 137
#
# Need to figure out which nodes are free! This query not only looks
# for free nodes, but also for the virtual nodes that are assigned to
# them so that we can provide the multiplex count to the solver.
# It is essentially the same query as ptopgen.
#
my $DEADPID = NODEDEAD_PID();
my $DEADEID = NODEDEAD_EID();

$result =
    DBQueryFatal("select a.node_id,a.phys_nodeid,count(*) from nodes as a ".
		 "left join reserved as b on a.node_id=b.node_id ".
		 "left join reserved as m on a.phys_nodeid=m.node_id ".
138
		 "left join node_status as ns on a.phys_nodeid=ns.node_id ".
139 140
		 "left join node_types as nt on a.type=nt.type ".
		 "where b.node_id is null and ".
141
		 "      (nt.isremotenode=1 and ns.status='up' and ".
142 143 144 145 146 147 148
		 "       (m.node_id is null or ".
		 "        m.pid!='$DEADPID' or m.eid!='$DEADEID')) ".
		 "group by a.phys_nodeid");

while (my ($node_id, $phys_nodeid, $count) = $result->fetchrow) {
    if ($dovirt) {
	#
149 150
	# In dovirt mode, we care about how many free vnodes per real node,
	# limited by the requested collocate factor. 
151
	#
152 153 154
	$count = $collocate
	    if ($count > $collocate);
	
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
	if ($node_id ne $phys_nodeid) {
	    $freenodes{$phys_nodeid} = $count;
	}
    }
    else {
	#
	# In normal mode, we care about free phys nodes only.
	#
	if ($node_id eq $phys_nodeid) {
	    $freenodes{$phys_nodeid} = 1;
	}
    }
}

# The boss node is fake, and so gets a count of one when its included.
if (!$noboss) {
    my $boss = TBDB_WIDEAREA_LOCALNODE;
    
    $freenodes{$boss} = 1;
}

# Only free nodes are considered.
print scalar( keys %freenodes ) . "\n";
178

179
#
180
# XXX The boss node ends up first strictly by accident. 
181
# 
182
foreach my $i (sort (keys %freenodes)) {
183 184 185
    print "$i\n";
}

186
#
187
# Print the multiplex count.
188 189
# 
if ($dovirt) {
190 191
    foreach my $i (sort (keys %freenodes)) {
	my $vcount = $freenodes{$i};
192 193
	
	print "$vcount\n";
194 195 196
    }
}

197 198
foreach my $i (sort (keys %freenodes)) {
    foreach my $j (sort (keys %freenodes)) {
199 200
	my $s = (($i eq $j) ? 0 : -1);

201 202 203 204 205 206 207
	if (exists $speeds{ $i."+".$j } ) {
	    $s = $speeds{ $i . "+" . $j };
	} 
	print sprintf( "%-5i ", $s );
    }
    print "\n";
}
Chad Barb's avatar
Chad Barb committed
208

209
if ($dobw) {
210 211
    foreach my $i (sort (keys %freenodes)) {
	foreach my $j (sort (keys %freenodes)) {
212 213 214
	    # the following is conceptually
	    # the bandwidth of a machine to itself.
	    # using ttcp, a typical value was found to be 180 MB/sec
215 216
	    my $s = (($i eq $j) ? 180000 : -1);
	    
217 218 219 220 221 222
	    if (exists $bws{ $i."+".$j } ) {
		$s = $bws{ $i . "+" . $j };
	    } 
	    print sprintf( "%-6i ", $s );
	}
	print "\n";
Chad Barb's avatar
Chad Barb committed
223 224
    }
}
225 226

if ($doplr) {
227 228
    foreach my $i (sort (keys %freenodes)) {
	foreach my $j (sort (keys %freenodes)) {
229 230
	    my $s = 0;

231 232 233 234 235 236 237 238
	    if (exists $plrs{ $i."+".$j } ) {
		$s = $plrs{ $i . "+" . $j };
	    } 
	    print sprintf( "%.3f ", $s );
	}
	print "\n";
    }
}