fillwires.pl 3.3 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2
#!/usr/bin/perl -w

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


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
#
# fillwires.pl - script to fill out the wires table for testbed nodes
#

#
# '#defines' - Edit these, depending on your nodes
#

# At Utah, we have lower numbered wires on the bottom of the rack: so, as
# wire numbers increment, node numbers decrement. If you have the opposite,
# change this variable to +1;
$node_increment = -1;

# The number of experimental interfaces on each node
$experimental_interfaces = 4;

# Since the wires on the back of the node may not correspond directly to the
# actual interface numbering (ie. the lowest numbered wire may not be eth0),
# we have the map below. In the example below, the lowest numbered wire on each
# node corresponds to eth3, the next to eth4, etc. There should be as many
# enries in this table as the number in experimental_interfaces variable above.
# Note that on the right side, there is no 2. This is because, with these nodes,
# eth2 is the control net.
%cardmap = ( 0 => 3,
	     1 => 4,
	     2 => 0,
	     3 => 1);

# The interface number of the control net
$control_net = 2;

#
# end of defines
#

Robert Ricci's avatar
Robert Ricci committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58
if (@ARGV != 10) {
	die "Usage: $0 <start_cable> <end_cable> <type> <length> <start_node> <switch_name> <start_module> <start_port> <min_port> <max_port>\n";
}

# Grab arguments
my ($start_cable,$end_cable, $type, $length, $start_node, $switch_name,
	$start_module, $start_port, $min_port, $max_port) = @ARGV;

# Different cable types have slightly different numbering schemes - mainly,
# the number of wires per node. $card_start hold the base card number (eg.
# experimental wires connect to eth0-eth3, control network wires connect to 
# eth4) 
my ($wires_per_node, $card_start);
if ($type eq "Node") {
59 60 61 62 63 64
	$wires_per_node = $experimental_interfaces;
	if ($control_net == 0) {
	    $card_start = 1;
	} else {
	    $card_start = 0;
	}
Robert Ricci's avatar
Robert Ricci committed
65 66
} elsif ($type eq "Control") {
	$wires_per_node = 1;
67 68 69 70
	$card_start = $control_net;

	# We don't use the cardmap for the control net
	undef %cardmap;
Robert Ricci's avatar
Robert Ricci committed
71 72 73 74 75 76 77
} else {
	die "Sorry, $type is not a supported wire type\n";
}

# Parse the start_node they gave us
$start_node =~ /^(\D+)(\d+)$/;
my $node_type = $1;
78 79
my $node_num = $2 - $node_increment; # Will be decremented the
				     # first the through the for loop
Robert Ricci's avatar
Robert Ricci committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

if ((!$node_type) || (!$node_num)) {
	die "Invalid start node: $start_node\n";
}

my $switch_module  = $start_module;
my $switch_port = $start_port;

for (my $i = 0; $i <= ($end_cable - $start_cable); $i++ ) {

	my $cable = $start_cable + $i;

	# We assume that you start wiring from the bottom of the rack -
	# change the next line to $node_num++ if wiring from the top
	if (!($i % $wires_per_node)) {
95
		$node_num += $node_increment;
Robert Ricci's avatar
Robert Ricci committed
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
	}
	my $node1 = $node_type . $node_num;

	# Get the card number
	my $card1;
	if (! defined %cardmap) {
		$card1 = $card_start + $i % $wires_per_node;
	} else {
		$card1 = $cardmap{$i % $wires_per_node} + $card_start;
	}
	my $port1 = 1;

	my $node2 = $switch_name;
	my $card2 = $switch_module;
	my $port2 = $switch_port;

	# Wrap around to the next module on the switch if necessary 
	$switch_port++;
	if ($switch_port > $max_port) {
		$switch_module++;
		$switch_port = $min_port;
	}

	print qq|INSERT INTO wires VALUES ($cable,$length,"$type","$node1",| .
		qq|"$card1",$port1,"$node2", $card2, $port2);\n|;

}