3 # L.Bobelin (Perl newbie) 25th of November
4 # Quick script to generate hierarchical clusters. Usage : <the script> p s d where :
5 # - p : 2^p gives the total number of hosts.
7 # - d : degree of inner nodes.
9 # output is the standard one.
12 #Each node is numbered by a DFS in the tree. Each cluster is numbered by the DFS number of the leaf it is attached to and the number of cluster for each leaf.
14 # - Same bb_lat used for any routers inside (not that complicated to modify too).
15 # - constants defined in the first part of the script corresponding to classic cluster parameters. links_bw and links_lat added for the inner tree links
16 # - bb_lat and bb_bw used in any backbone of the tree.
17 # - fails if you set an obviously too small total number of hosts compared to the cluster size (generates a lot of stuff for nothing actually).
29 $links_bw= "2250000000";
37 $p = Math::BigInt->new($p);
38 $d = Math::BigInt->new($d);
39 $s = Math::BigInt->new($s);
46 # Number of clusters to generate ? Update: I hate this bigInt package, the way it behaves is SO stupid
47 $totalnumberofhosts = Math::BigInt->new("2");
48 $totalnumberofhosts->bpow($p);
50 $totalnumberofCluster= $totalnumberofhosts->copy();
52 $totalnumberofCluster->bdiv($s);
54 # checking if we have to have something non homogeneous
55 if ($totalnumberofhosts->copy()->bmod($s) != 0 )
57 $totalnumberofCluster++;
58 $last= $totalnumberofhosts->copy()->bmod($s);
63 $height= $totalnumberofCluster->copy();
66 # Checking if an exact root exists
67 if ( $height->bcmp(Math::BigInt->new("1")) != 0 && ($height->copy()->bpow($d))->bcmp($totalnumberofCluster)) {
69 $height++; #will have to deal with empty set of clusters.
72 #print "Computed : \n";
73 #print STDERR "height: " . $height . "\n";
74 #print STDERR "totalnumberofhosts: " . $totalnumberofhosts . "\n";
75 #print STDERR "totalnumberofcluster: " . $totalnumberofCluster . "\n";
76 #print STDERR "last cluster size (if equals to cluster size, then all clusters will be homogeneous) : " . $last . "\n";
78 # Counter for giving unique IDs to ASes.
83 print "<?xml version='1.0'?>\n";
84 print "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n";
85 print "<platform version=\"3\">\n";
88 # Initiate recursion ...
91 # Closing tag, and then back home
92 print "</platform>\n";
94 # Recursive stuff for depth first Se... Creation
99 print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
101 # Curr router AS creation stuff
102 print "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
103 print " <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
105 # Saving my current number to return it to my father
106 my $toReturn = $ASnumber;
108 if ($currDepth<$height && $totalnumberofCluster > 0)
110 # Creating current AS inner stuff
111 # I should have a table of sons numbers.
114 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
116 #saving this son in my tab ... recursive call to create ASes and cluster underneath
117 push(@tsons, &DF_creation($currDepth + 1));
120 # Creating link to this son
121 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
123 # curr backbone creation
124 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
125 # Full routing AS to AS declaration
126 for (my $i =1; $i<=$createdSons ; $i++)
128 for (my $j =$i+1; $j<=$createdSons ; $j++)
130 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
131 print " dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
132 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
133 print " gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
134 print " symmetrical=\"YES\">\n";
136 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
137 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
138 print " <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
139 print "</ASroute>\n";
142 # Now routes to the exit AS
143 for (my $i =1; $i<=$createdSons ; $i++)
145 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
146 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
147 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
148 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
149 print " symmetrical=\"YES\">\n";
150 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
151 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
152 print "</ASroute>\n";
155 # DO I have extra stuff to add ? I don't think so.
159 my $lastNumberOfClusterCreated = 0;
160 #I must create clusters now
161 for(my $i = 1; $i <= $cabinetnodes && $totalnumberofCluster>0 ; $i++) {
162 $lastNumberOfClusterCreated++;
163 if ($totalnumberofCluster==1)
165 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\"1-"
166 . $last . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
170 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\""
171 . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
173 $totalnumberofCluster--;
175 # Creating links to clusters
176 for(my $i = 1; $i <= $lastNumberOfClusterCreated ; $i++) {
177 print "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
181 # curr backbone creation
182 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
184 # I must create routes between clusters now
185 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
187 for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
189 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
190 print " dst=\"" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "\"\n";
192 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
193 print " gw_dst=\"" . $prefix . "c_" . $toReturn . "_" . $j . "-" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "_router" . $suffix . "\"\n";
194 print " symmetrical=\"YES\">\n";
196 print " <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
197 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
198 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
199 print "</ASroute>\n";
202 # Now routes to the exit AS
203 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
205 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
206 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
208 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
209 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
210 print " symmetrical=\"YES\">\n";
211 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
212 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
213 print "</ASroute>\n";
216 # Should be done with it...