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\n";
88 # Initiate recursion ...
91 # Closing tag, and then back home
92 print "</platform>\n";
95 # Recursive stuff for depth first Se... Creation
100 print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
102 # Curr router AS creation stuff
103 print "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
104 print " <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
106 # Saving my current number to return it to my father
107 my $toReturn = $ASnumber;
109 if ($currDepth<=$height && $totalnumberofCluster > 0)
111 # Creating current AS inner stuff
112 # I should have a table of sons numbers.
115 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
117 #saving this son in my tab ... recursive call to create ASes and cluster underneath
118 push(@tsons, &DF_creation($currDepth + 1));
121 # Creating link to this son
122 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
124 # curr backbone creation
125 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
126 # Full routing AS to AS declaration
127 for (my $i =1; $i<=$createdSons ; $i++)
129 for (my $j =$i+1; $j<=$createdSons ; $j++)
131 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
132 print " dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
133 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
134 print " gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
135 print " symmetrical=\"YES\">\n";
137 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
138 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
139 print " <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
140 print "</ASroute>\n";
143 # Now routes to the exit AS
144 for (my $i =1; $i<=$createdSons ; $i++)
146 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
147 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
148 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
149 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
150 print " symmetrical=\"YES\">\n";
151 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
152 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
153 print "</ASroute>\n";
156 # DO I have extra stuff to add ? I don't think so.
160 my $lastNumberOfClusterCreated = 0;
161 #I must create clusters now
162 for(my $i = 1; $i <= $cabinetnodes && $totalnumberofCluster>0 ; $i++) {
163 $lastNumberOfClusterCreated++;
164 if ($totalnumberofCluster==1)
166 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\"1-"
167 . $last . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
171 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\""
172 . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
174 $totalnumberofCluster--;
176 # Creating links to clusters
177 for(my $i = 1; $i <= $lastNumberOfClusterCreated ; $i++) {
178 print "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
182 # curr backbone creation
183 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
185 # I must create routes between clusters now
186 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
188 for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
190 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
191 print " dst=\"" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "\"\n";
193 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
194 print " gw_dst=\"" . $prefix . "c_" . $toReturn . "_" . $j . "-" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "_router" . $suffix . "\"\n";
195 print " symmetrical=\"YES\">\n";
197 print " <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
198 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
199 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
200 print "</ASroute>\n";
203 # Now routes to the exit AS
204 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
206 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
207 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
209 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
210 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
211 print " symmetrical=\"YES\">\n";
212 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
213 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
214 print "</ASroute>\n";
217 # Should be done with it...