fillwires.pl 3.99 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
#
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
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
#
# 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75
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") {
76 77 78 79 80 81
	$wires_per_node = $experimental_interfaces;
	if ($control_net == 0) {
	    $card_start = 1;
	} else {
	    $card_start = 0;
	}
Robert Ricci's avatar
Robert Ricci committed
82 83
} elsif ($type eq "Control") {
	$wires_per_node = 1;
84 85 86 87
	$card_start = $control_net;

	# We don't use the cardmap for the control net
	undef %cardmap;
Robert Ricci's avatar
Robert Ricci committed
88 89 90 91 92 93 94
} 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;
95 96
my $node_num = $2 - $node_increment; # Will be decremented the
				     # first the through the for loop
Robert Ricci's avatar
Robert Ricci committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

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)) {
112
		$node_num += $node_increment;
Robert Ricci's avatar
Robert Ricci committed
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
	}
	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|;

}