wanassign.in 18.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
use Socket;
use IO::Handle;     # thousands of lines just for autoflush :-(

#
# XXX The iface stuff needs fixing. ti0/eth0. Look for strings below!
# 

sub usage()
{
    print STDOUT
	"Usage: wanassign [-d] [-n] <pid> <eid>\n";
    exit(-1);
}
my  $optlist = "dn";

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $wansolve    = "$TB/libexec/wanlinksolve";
my $wansolveargs= "-m 4 -2 7 -v";
my $waninfo     = "$TB/libexec/wanlinkinfo";
my $waninfoargs = "-b -m";

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

# Locals
my $debug	= 0;
my $impotent    = 0;
my $failed	= 0;
my $query_result;

#
# Turn off line buffering on output
#
$| = 1;

# un-taint path
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:$TB/libexec:$TB/sbin:$TB/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 != 2) {
    usage();
}
if (defined($options{"d"})) {
    $debug = 1;
}
if (defined($options{"n"})) {
    $impotent = 1;
}
my $pid = $ARGV[0];
my $eid = $ARGV[1];

#
# Untaint args.
#
if ($pid =~ /^([-\@\w]+)$/) {
    $pid = $1;
}
else {
    die("Bad data in pid: $pid.");
}
if ($eid =~ /^([-\@\w]+)$/) {
    $eid = $1;
}
else {
    die("Bad data in eid: $eid.");
}

#
# Type map. Map between class and type (node_types table). The table
# is indexed by type, and stores the class.
#
my %typemap		= ();

#
# Hashed array of vnodes and vlans. 
# 
my %virtnodes		= ();
my %virtlans		= ();

#
# Reverse mapping from link pairs to the lan they belong to.
#
my %rlanmap		= ();

#
# How many remote (widearea) nodes total.
#
my $remotecount		= 0;

#
# A list of nodes to allocate with nalloc when we finally get that far.
#
my @toreserve;
my %mappings;

#
# A node record (poor man struct). We create a hashed array of these,
# indexed by the vnode name.
#
sub newnode ($$$$$$) {
    my ($vname,$type,$isvirt,$isremote,$fixed,$physnode) = @_;

    printdb("  $vname $type isremote:$isremote isvirt:$isvirt " .
	    ($fixed ? $fixed : "") . " " .
            ($physnode ? $physnode : " ") . "\n");

    $virtnodes{$vname} = {
	VNAME    => $vname,
	TYPE     => $type,
	FIXED    => $fixed,	# tb-fix-node. This is the node name.
	ISREMOTE => $isremote,  
	ISVIRT   => $isvirt,    # is a multiplexed node.
	PHYSNODE => $physnode,  # if a multiplexed node, this is the real node.
	SOLUTION => undef,      # the solver solution. Might be same as FIXED.
	MAPPING  => undef,      # Final mapping. 
    };
    if ($isremote) {
	$remotecount += 1;
    }
}
sub isremotenode($)	{ return $virtnodes{$_[0]}->{ISREMOTE}; }
sub isfixednode($)	{ return $virtnodes{$_[0]}->{FIXED}; }
sub isvirtnode($)	{ return $virtnodes{$_[0]}->{ISVIRT}; }
sub physnode($)		{ return $virtnodes{$_[0]}->{PHYSNODE}; }

#
# A lan record (poor man struct). We create a hashed array of these,
# indexed by the vlan name. 
#
sub newvlan ($) {
    my ($vname) = @_;

    $virtlans{$vname} = {
	VNAME    => $vname,
	ISREMOTE => 0,
	MEMBERS  => [],
	COUNT    => 0,
	PARAMS   => {},
    };
}

#
# Get type map.
#
my $query_result =
    DBQueryFatal("select type,class from node_types");

while (my ($type,$class) = $query_result->fetchrow_array()) {
    $typemap{$type} = $class;

    # A class is also a valid type. You know its a class cause type=class.
    if (!defined($typemap{$class})) {
	$typemap{$class} = $class;
    }
}

#
# Load up virt_nodes. We only care about the virtual nodes.
#
printdb("Reading virt_nodes ...\n");

$query_result =
    DBQueryFatal("select distinct vname,vn.type,fixed, ".
		 " nt.isremotenode,nt.isvirtnode from virt_nodes as vn ".
		 "left join node_types as nt on ".
		 " nt.type=vn.type or nt.class=vn.type ".
		 "where pid='$pid' and eid='$eid'");

while (my ($vname,$type,$fixed,$isremote,$isvirt) =
       $query_result->fetchrow_array) {
    my $physnode = 0;
    
    if (! defined($fixed)) {
	$fixed = 0;
    }

    #
    # if its a vtype, no entry in node_types. vtypes break virtual nodes.
    # Need to look inside the vtype and make sure no mixing of remote and
    # physnodes. Later ...
    #
    if (! defined($isremote)) {
	$isremote = 0;
    }
    if (! defined($isvirt)) {
	$isvirt = 0;
    }
    #
    # A fixed node. Need to map that to the physnode so that
    # we can tell the solver (the p section of the solver operates on
    # the physnodes). This is a messy complication.
    # 
    if ($fixed) {
	TBPhysNodeID($fixed, \$physnode);
    }
    
    newnode($vname, $type, $isvirt, $isremote, $fixed, $physnode);
}

#
# XXX. At present, we cannot mix specific types and generic classes.
#      That is, the user cannot specify a pcvroninet and a pcvron. Thats
#      because we want to solve for pcvrons, but first we would have to
#      assign the pcvroninet nodes, and feed them in as fixed nodes. Thats
#      a suspect operation, and too much work right now.
#
# The following code checks to make sure no mixed types/classes.
#
my $typecount  = 0;
my $classcount = 0;
foreach my $vnode (keys(%virtnodes)) {
    if (isremotenode($vnode)) {
	my $virtnode = $virtnodes{$vnode};
	my $type     = $virtnode->{TYPE};

	if ($typemap{$type} eq $type) {
	    $classcount++;
	}
	else {
	    $typecount++;
	}
    }
}
if ($typecount && $classcount) {
    die("*** $0:\n".
	"    Bad mix of generic classes and specific types of remote nodes.\n".
	"    We cannot do that yet!\n");
}

#
# If no remote nodes, we are done.
#
if (! $remotecount) {
    print "There are no remote nodes. This is okay!\n";
    exit(0);
}

#
# Load up the virt lans to find the link characteristics.
#
printdb("Reading virt_lans ...\n");
$query_result =
    DBQueryFatal("select vname,member,delay,bandwidth,lossrate," .
		 "rdelay,rbandwidth,rlossrate " .
		 "from virt_lans where pid='$pid' and eid='$eid'");

while (my ($vname,$member,
	   $delay,$bandwidth,$lossrate,
	   $rdelay,$rbandwidth,$rlossrate) = $query_result->fetchrow_array) {
    my ($node) = split(":",$member);

    if (!defined($virtlans{$vname})) {
	newvlan($vname);
    }
    my $virtlan = $virtlans{$vname};

    if (isremotenode($node)) {
	$virtlan->{ISREMOTE} = 1;
    }
    $virtlan->{COUNT} += 1;
    push(@{$virtlan->{MEMBERS}}, $member);

    #
    # Create a data structure for the parameters.
    # 
    $virtlan->{PARAMS}{$member} = {
	DELAY       => $delay,
	BW          => $bandwidth,
	PLR         => $lossrate,
	RDELAY      => $rdelay,
	RBW         => $rbandwidth,
	RPLR        => $rlossrate,
    };
}

#
# Check the table, looking for remote nodes in lans.
#
foreach my $vname (keys(%virtlans)) {
    my $virtlan = $virtlans{$vname};
    my @members = @{$virtlan->{MEMBERS}};

    printdb("  $vname isremote:$virtlan->{ISREMOTE} @members\n");

    if ($virtlan->{ISREMOTE} && $virtlan->{COUNT} > 2) {
	die("*** $0:\n".
	    "    Lan $vname has a remote member. Not allowed!!\n");
    }

    # Just debugging.
    foreach my $member (@members) {
	my %params = %{$virtlan->{PARAMS}{$member}};

	printdb("    $member - ");
	foreach my $param (keys(%params)) {
	    printdb("$param:$params{$param} ");
	}
	printdb("\n");
    }

    #
    # Create a reverse mapping from the link members to the lans they
    # are part of. Indexed by names (without ports) since the wansolver
    # only cares about nodes.
    #
    foreach my $member1 (@members) {
	my ($node1) = split(":",$member1);
	
	foreach my $member2 (@members) {
	    my ($node2) = split(":",$member2);

	    # No self referential links!
	    if ($node1 eq $node2) {
		next;
	    }

	    if (defined($rlanmap{"$node1:$node2"})) {
		die("*** $0:\n".
		    "    Cannot have multiple links bewteen widearea nodes ".
		    "$node1:$node2\n");
	    }
	    $rlanmap{"$node1:$node2"} = $virtlan;
	}
    }
}

#
# Assign nodes
# 
if ($typecount) {
    #
    # If the user provided types instead of classes, we have to do the
    # assignment instead of using the solver. 
    # 
    foreach my $vnode (keys(%virtnodes)) {
	if (isremotenode($vnode) && isfixednode($vnode)) {
	    my $virtnode = $virtnodes{$vnode};

	    #
	    # A fixed node is easy. Just want to reserve it (or try to).
	    # 
	    $virtnode->{MAPPING} = $virtnode->{FIXED};
	    push(@toreserve, $virtnode->{FIXED});
	}
    }
    foreach my $vnode (keys(%virtnodes)) {
	if (isremotenode($vnode) && !isfixednode($vnode)) {
	    my $virtnode = $virtnodes{$vnode};
	    my $type     = $virtnode->{TYPE};

	    #
	    # Otherwise, create a list of vnodes for each type we need.
	    #
	    if (!defined($mappings{$type})) {
		$mappings{$type} = [];
	    }
	    push(@{$mappings{$type}}, $vnode);
	}
    }

    #
    # Okay, now that we know how many of each type, get some names
    # from the DB.
    #
    foreach my $type (keys(%mappings)) {
	my @vlist = @{$mappings{$type}};
	my $count = scalar(@vlist);
	my $omit  = "";

	printdb("Trying to find $count nodes of type $type\n");

	#
	# Must exclude anything we decided to reserve.
	#
	if (@toreserve) {
	    foreach my $n (@toreserve) {
		$omit .= "and a.node_id!='$n' ";
	    }
	}

	#
	# This query gets free nodes for the choosen type.
	#
	$query_result =
	    DBQueryFatal("select a.node_id from nodes as a ".
			 "left join reserved as b on a.node_id=b.node_id ".
			 "left join nodes as n on a.phys_nodeid=n.node_id ".
			 "where b.node_id is null and a.type='$type' ".
			 "$omit ".
			 "order by RAND() limit $count");
	if ($query_result->numrows != $count) {
	    # Not enough free nodes. Die.
	    die("*** $0:\n".
		"    Not enough free nodes of type $type!\n");
	}
	while (my ($mapping) = $query_result->fetchrow_array()) {
	    my $vnode    = pop(@vlist);
	    my $virtnode = $virtnodes{$vnode};

	    $virtnode->{MAPPING} = $mapping;
	    push(@toreserve, $mapping);
	}
    }
}
else {
    #
    # Run the solver
    #
    runwansolver();
}

printdb("Reserving @toreserve\n");

#
# Allocate the nodes we need. 
# 
if (!$impotent) {
    printdb("Allocating nodes ...\n");
    
    if (system("nalloc $pid $eid " . join(" ",@toreserve))) {
	die("*** $0\n".
	    "    Failed to reserve resources!\n");
    }
}

#
# Print out the mapping for the caller (assign_wrapper) in a more normalized
# format. We skip the "boss" node. Note this bogus test; need to change the
# wansolver to allow v2p mappings when fixing a node. 
#
foreach my $vnode (sort(keys(%virtnodes))) {
    if (!isremotenode($vnode)) {
	next;
    }
    my $virtnode = $virtnodes{$vnode};
    my $mapping  = $virtnode->{MAPPING};

    print STDOUT "$vnode mapsto $mapping\n";
}

exit $failed;

sub printdb {
    if ($debug) {
	print STDERR $_[0];
    }
};

#
# This big ball of goo runs the wan solver.
#
sub runwansolver() {
    #
    # Need to start the wansolver. 
    # We use perl IPC goo to create a child we can both write to and read from
    # (normal perl I/O provides just unidirectional I/O to a process).
    # 
    if (! socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC)) {
	die("*** $0:\n".
	    "    socketpair failed: $!\n");
    }
    CHILD->autoflush(1);
    PARENT->autoflush(1);

    my $childpid = fork();
    if (! $childpid) {
	close CHILD;

	#
	# Dup our descriptors to the parent, and exec the program.
	# The parent then talks to it read/write.
	#
	open(STDIN,  "<&PARENT") || die "Can't redirect stdin";
	open(STDOUT, ">&PARENT") || die "Can't redirect stdout";
	open(STDERR, ">&PARENT") || die "Can't redirect stderr";

	#
	# Start the solver. We will pipe in the stuff later.
	# 
        exec("nice $wansolve $wansolveargs");
        #exec("cat > /tmp/wansolve");
	#exec("cat /tmp/wansolved");
	die("*** $0:\n".
	    "    exec of $wansolve failed: $!\n");
    }
    close PARENT;

    #
    # Start the info program, and pipe in the results. The sad fact is that
    # we have to read the first section to get physical node names for tagging
    # the fixed nodes, but I'm not gonna worry about that right now since the
    # solver will just croak anyway. 
    #
    open(INFO, "$waninfo $waninfoargs |") or
	die("*** $0:\n".
	    "    Could not start $waninfo: $!\n");

    while (<INFO>) {
	print CHILD $_;
    }

    close(INFO) or
	die("*** $0:\n".
	    "    $waninfo: " . $? ? "exited with status $?.\n" :
	    "error closing pipe: $!\n");

    #
    # Now send it the second section.
    #
    # Number of v nodes first.
    #
    print CHILD $remotecount + 1 . "\n";

    #
    # Then a list of v nodes. The first is special (and bogus). We fix the
    # mapping for the boss node. Even worse, it requires knowing the name
    # of the boss.
    #
    my $seenboss = 0;

    foreach my $vnode (sort(keys(%virtnodes))) {
	if (isremotenode($vnode)) {
	    print CHILD "$vnode";

	    #
	    # Check for fixed mappings. 
	    #
	    if (isfixednode($vnode)) {
		print CHILD " " . physnode($vnode) . ":eth0";
	    }
	    print CHILD "\n";
	}
	elsif (!$seenboss) {
	    print CHILD "boss boss:ti0\n";
	    $seenboss = $vnode;
	}
    }

    #
    # Now create the latency and bandwidth matricies. We need to map all local
    # nodes onto a single row/column. For that, we use the $seenboss value; all
    # local node names are mapped into that name in the matrix (2D hash).
    #
    my %latmatrix	= ();
    my %bwmatrix	= ();

    foreach my $vnode1 (keys(%virtnodes)) {
	my $rowname = (!isremotenode($vnode1) ? $seenboss : $vnode1);
	
	foreach my $vnode2 (keys(%virtnodes)) {
	    my $virtlan = $rlanmap{"$vnode1:$vnode2"};
	    my $colname = (!isremotenode($vnode2) ? $seenboss : $vnode2);

	    if ($colname eq $rowname) {
		$latmatrix{$rowname}{$colname} = 0;
		$bwmatrix{$rowname}{$colname}  = 180000;
		next;
	    }
	    if (!defined($virtlan)) {
		# Beware, multiple pairs map to the same spot. Ick.
		if (!defined($latmatrix{$rowname}{$colname})) {
		    $latmatrix{$rowname}{$colname} = -1;
		}
		if (!defined($bwmatrix{$rowname}{$colname})) {
		    $bwmatrix{$rowname}{$colname} = -1;
		}
		next;
	    }
	    $latmatrix{$rowname}{$colname} =
		findlinkvalue($virtlan, "delay", $vnode1, $vnode2);
	    $bwmatrix{$rowname}{$colname} =
		findlinkvalue($virtlan, "bw", $vnode1, $vnode2);
	}
    }

    #
    # Now print out the matricies.
    # 
    foreach my $vnode1 (sort(keys(%latmatrix))) {
	foreach my $vnode2 (sort(keys(%{ $latmatrix{$vnode1}}))) {
	    printdb("$vnode1:$vnode2($latmatrix{$vnode1}{$vnode2})  ");
	    print CHILD "$latmatrix{$vnode1}{$vnode2}  ";
	}
	print CHILD "\n";
	printdb("\n");
    }

    foreach my $vnode1 (sort(keys(%bwmatrix))) {
	foreach my $vnode2 (sort(keys(%{ $bwmatrix{$vnode1}}))) {
	    printdb("$vnode1:$vnode2($bwmatrix{$vnode1}{$vnode2})  ");
	    print CHILD "$bwmatrix{$vnode1}{$vnode2}  ";
	}
	print CHILD "\n";
	printdb("\n");
    }

    #
    # Wait for the child to give us some output. We want to be careful not to
    # let it run too long.
    #
    local $SIG{ALRM} = sub { kill("TERM", $childpid); };
    alarm 120;

    #
    # Read back the solution. 
    #
    while (<CHILD>) {
	printdb($_);

	if ($_ =~ /(\S+)\smapsTo\s(\S+)/) {
	    # XXX
	    if ($1 eq "boss") {
		next;
	    }
	    my $virtnode = $virtnodes{$1};
	    my ($pnode)  = split(":", $2);

	    if ($pnode eq "boss") {
		die("*** $0:\n".
		    "    Oops, $1 was assigned to boss. That won't work!\n");
	    }
	    
	    $virtnode->{SOLUTION} = $pnode;
	}
    }
    close(CHILD);

    waitpid($childpid, 0);
    alarm 0;
    if ($?) {
	die("*** $0:\n".
	    ($? == 15) ? "$wansolve timed out looking for a solution.\n"
	               : "$wansolve failed with status: $?\n");
    }

    if ($failed) {
	die("*** $0:\n".
	    "    $wansolve failed to produce a valid result\n");
    }

    #
    # Okay, need to convert any vnodes that are virtual (multiplexed) into
    # a corresponding virtual node for the physnode that was choosen.
    # Yikes, thats confusing. 
    #
    foreach my $vnode (sort(keys(%virtnodes))) {
	my $virtnode = $virtnodes{$vnode};

	# At some point we will support virtual nodes on non-remote nodes
	if (!isremotenode($vnode)) {
	    next;
	}

	my $solution = $virtnode->{SOLUTION};

	if (!isvirtnode($vnode)) {
	    #
	    # The solution is the thing we want to allocate.
	    #
	    $virtnode->{MAPPING} = $solution;
	    push(@toreserve, $solution);
	}
	else {
	    #
	    # Otherwise, create a per-vnode list for each solution.
	    #
	    printdb("Adding $vnode to list for $solution\n");
	    
	    if (!defined($mappings{$solution})) {
		$mappings{$solution} = [];
	    }
	    push(@{$mappings{$solution}}, $vnode);
	}
    }

    #
    # Okay, now that we know how many of each virtual node, get some names
    # from the DB.
    #
    foreach my $solution (keys(%mappings)) {
	my @vlist = @{$mappings{$solution}};
	my $count = scalar(@vlist);
	my $omit  = "";

	#
	# Must exclude anything we decided to reserve so far.
	#
	if (@toreserve) {
	    foreach my $n (@toreserve) {
		$omit .= "and a.node_id!='$n' ";
	    }
	}

	#
	# This query gets free virtual nodes for the choosen solution.
	#
	$query_result =
	    DBQueryFatal("select a.node_id from nodes as a ".
			 "left join reserved as b on a.node_id=b.node_id ".
			 "left join nodes as n on a.phys_nodeid=n.node_id ".
			 "where b.node_id is null and a.role='virtnode' and ".
			 "a.phys_nodeid='$solution' ".
			 "$omit ".
			 "order by RAND() limit $count");
	if ($query_result->numrows != $count) {
	    # Not enough free nodes. Die.
	    die("*** $0:\n".
		"    Not enough free virtual nodes on $solution!\n");
	}
	while (my ($mapping) = $query_result->fetchrow_array()) {
	    my $vnode    = pop(@vlist);
	    my $virtnode = $virtnodes{$vnode};

	    $virtnode->{MAPPING} = $mapping;
	    push(@toreserve, $mapping);
	}
    }
}

#
# Given a lan, and a pair of nodes, find the link entries and return
# the desired one-way parameter.
#
sub findlinkvalue($$$$)
{
    my ($virtlan, $param, $vnode1, $vnode2) = @_;
    my ($member1, $member2);

    foreach my $member (@{$virtlan->{MEMBERS}}) {
	my ($node) = split(":",$member);

	if ($node eq $vnode1) {
	    $member1 = $member;
	    next;
	}
	if ($node eq $vnode2) {
	    $member2 = $member;
	    next;
	}
    }
    if (!defined($member1) || ! defined($member2)) {
	die("*** $0:\n".
	    "    Could not find members for link $vnode1:$vnode2!\n");
    }
    my %param1 = %{$virtlan->{PARAMS}{$member1}};
    my %param2 = %{$virtlan->{PARAMS}{$member2}};

    if ($param eq "bw") {
	return $param1{BW};
    }
    elsif ($param eq "delay") {
	return $param1{DELAY} + $param2{RDELAY};
    }
    else {
	die("*** $0:\n".
	    "    Bad param $param in findlinkvalue!\n");
    }
}