ptopgen.in 4.35 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1 2
#!/usr/bin/perl -w

3 4 5 6 7 8 9
# Settings - Change these to your particular network.

# Switch interface speed - In Mbps
$switch_speed = 100;

######################################################################

10
my $TBROOT = "@prefix@";
11
use lib '@prefix@/lib';
12
require exitonwarn;
13
use libdb;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
14

15
%switches=();
16 17
%used_switches=();

18
# Read class/type maps
19 20
my $result = DBQueryFatal("select class,type,delay_capacity from node_types");
while (($class,$type,$delaycapacity) = $result->fetchrow_array) {
21
    $classes{$type} = $class;
22
    $nodetypes{$type} = $delaycapacity;
23
}
24
$result->finish;
25 26 27 28

# switches can't delay
$nodetypes{"switch"} = 0;

29
# Print switches
30 31
$result = DBQueryFatal("select node_id from nodes where role = \"testswitch\"");
while (($switch) = $result->fetchrow_array) {
32 33 34
    print "node $switch switch:1\n";
    $switches{$switch} = 1;
}
35
$result->finish;
36

Leigh B. Stoller's avatar
Leigh B. Stoller committed
37
# Find available nodes
38
$result = DBQueryFatal("select a.node_id,a.type from" .
Leigh B. Stoller's avatar
Leigh B. Stoller committed
39 40
		     " nodes as a left join reserved as b" .
		     " on a.node_id=b.node_id" .
41
		     " where b.node_id is null and a.role = \"testnode\"");
42
while (($node,$type) = $result->fetchrow_array) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
43 44 45 46 47 48 49 50 51
    # Shark hack
    if (($shelf,$number) = ($node =~ /^sh(\d+)-(\d+)/)) {
	if ($number == 1) {
	    $nodes{"sh$shelf"} = "shark-shelf";
	}
    } else {
	$nodes{$node} = $type;
    }
}
52
$result->finish;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
53 54


55
$sharklinks = "";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
56 57 58 59
foreach $node (keys(%nodes)) {
    if ($node =~ /^sh/) {
	print "node $node shark-shelf:1\n";
    } else {
60 61 62 63
	$text = "node $node $nodes{$node}:1 $classes{$nodes{$node}}:1";
	$delay_capacity = $nodetypes{$nodes{$node}};
	if ($delay_capacity > 0) {
	    $text .= " delay:$delay_capacity";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
64 65 66 67 68
	}
	print "$text\n";
    }
}

69
# Read interfaces
70
$result = DBQueryFatal("SELECT node_id,card,port,iface,interface_type" .
71
		     " from interfaces");
72
while (($node,$card,$port,$iface,$type) = $result->fetchrow_array) {
73 74 75 76 77
    $interfacemap{"$node:$card:$port"} = $iface;
    if ($type ne "") {
	$interfacetypes{"$node:$card:$port"} = $type;
    }
}
78
$result->finish;
79 80

# Read interface types
81 82
$result = DBQueryFatal("SELECT type,max_speed from interface_types");
while (($type,$speed) = $result->fetchrow_array) {
83 84
    $interfacespeeds{$type} = $speed;
}
85
$result->finish;
86

87
$result = DBQueryFatal("SELECT node_id1,card1,port1,node_id2,card2,port2" .
88
 		    " from wires where type=\"Node\" or type=\"Trunk\"");
89
while (($node1,$card1,$port1,$node2,$card2,$port2) = 
90
       $result->fetchrow_array) {
91
    if ((defined($nodes{$node1}) || defined($switches{$node1})) && 
92
	(defined($nodes{$node2}) || defined($switches{$node2}))) {
93 94 95 96 97 98 99 100 101
	$iface1 = get_iface($node1,$card1,$port1);
	$iface2 = get_iface($node2,$card2,$port2);
	$iface1bw = get_ifacebw($node1,$card1,$port1);
	$iface2bw = get_ifacebw($node2,$card2,$port2);
	if ($iface1bw < $iface2bw) {
	    $bw = $iface1bw;
	} else {
	    $bw = $iface2bw;
	}
102
	if (defined($switches{$node2})) {
103 104
	    $used_switches{$node2} = 1;
	}
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	if (defined($switches{$node1})) {
	    $used_switches{$node1} = 1;
	}
	if (defined($switches{$node1}) && defined($switches{$node2})) {
	    # interswitch link
	    if (defined($interconnects{"$node1:$node2"})) {
		$interconnects{"$node1:$node2"} += $bw;
	    } else {
		$interconnects{"$node1:$node2"} = $bw;
	    }
	} else {
	    # !!! - Here we use our knowledge that in the wires table links
	    # to the switch always come as node2.
	    print "link link-$node1:$iface1-$node2:$iface2 $node1:$node1/$iface1" .
		" $node2:$iface2 $bw 1\n";
	}
    } 
122
}
123
$result->finish;
124 125 126 127
foreach $interconnect (keys(%interconnects)) {
    ($src,$dst) = split(":",$interconnect);
    print "link link-$interconnect $src $dst $interconnects{$interconnect} 1\n";
}
128 129 130

print $sharklinks;

Leigh B. Stoller's avatar
Leigh B. Stoller committed
131
# Add a bunch of LANs
132 133 134 135 136 137
foreach $switch (keys(%used_switches)) {
    for ($i = 0;$i <= 20;$i++) {
	print "node lan-$switch-$i lan:1\n";
	print "link link-lan-$switch-$i lan-$switch-${i}:lan-$switch-$i" .
	    " $switch 100000 1000\n";
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
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


# Print out links
sub get_iface {
    ($node,$card,$port) = @_;
    if (defined($interfacemap{"$node:$card:$port"})) {
	return $interfacemap{"$node:$card:$port"};
    } else {
	# shark hack
	if ($node =~ /^sh/) {
	    return "eth0";
	} else {
	    return "(null)";
	}
	# end shark hack 
    }
};

# Find the bandwidth for an interface
sub get_ifacebw {
    ($node,$card,$port) = @_;
    if (defined($interfacetypes{"$node:$card:$port"})) {
	return $interfacespeeds{$interfacetypes{"$node:$card:$port"}};
    } else {
	return $switch_speed;
    }
}