3 # Copyright (c) 2011-2012, 2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
9 # Quick script to generate hierarchical clusters. Usage : <the script> p s d where :
10 # - p : 2^p gives the total number of hosts.
12 # - d : degree of inner nodes.
14 # output is the standard one.
17 #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.
19 # - Same bb_lat used for any routers inside (not that complicated to modify too).
20 # - 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
21 # - bb_lat and bb_bw used in any backbone of the tree.
22 # - 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).
34 $links_bw= "2250000000";
42 $p = Math::BigInt->new($p);
43 $d = Math::BigInt->new($d);
44 $s = Math::BigInt->new($s);
51 # Number of clusters to generate ? Update: I hate this bigInt package, the way it behaves is SO stupid
52 $totalnumberofhosts = Math::BigInt->new("2");
53 $totalnumberofhosts->bpow($p);
55 $totalnumberofCluster= $totalnumberofhosts->copy();
57 $totalnumberofCluster->bdiv($s);
59 # checking if we have to have something non homogeneous
60 if ($totalnumberofhosts->copy()->bmod($s) != 0 )
62 $totalnumberofCluster++;
63 $last= $totalnumberofhosts->copy()->bmod($s);
68 $height= $totalnumberofCluster->copy();
71 # Checking if an exact root exists
72 if ( $height->bcmp(Math::BigInt->new("1")) != 0 && ($height->copy()->bpow($d))->bcmp($totalnumberofCluster)) {
74 $height++; #will have to deal with empty set of clusters.
77 # print "Computed : \n";
78 # print STDERR "height: " . $height . "\n";
79 # print STDERR "totalnumberofhosts: " . $totalnumberofhosts . "\n";
80 # print STDERR "totalnumberofcluster: " . $totalnumberofCluster . "\n";
81 # print STDERR "last cluster size (if equals to cluster size, then all clusters will be homogeneous) : " . $last . "\n";
83 # Counter for giving unique IDs to ASes.
88 print "<?xml version='1.0'?>\n";
89 print "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n";
90 print "<platform version=\"3\">\n\n";
93 # Initiate recursion ...
96 # Closing tag, and then back home
97 print "</platform>\n";
100 # Recursive stuff for depth first Se... Creation
105 print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
107 # Curr router AS creation stuff
108 print "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
109 print " <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
111 # Saving my current number to return it to my father
112 my $toReturn = $ASnumber;
114 if ($currDepth<=$height && $totalnumberofCluster > 0)
116 # Creating current AS inner stuff
117 # I should have a table of sons numbers.
120 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
122 #saving this son in my tab ... recursive call to create ASes and cluster underneath
123 push(@tsons, &DF_creation($currDepth + 1));
126 # Creating link to this son
127 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
129 # curr backbone creation
130 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
131 # Full routing AS to AS declaration
132 for (my $i =1; $i<=$createdSons ; $i++)
134 for (my $j =$i+1; $j<=$createdSons ; $j++)
136 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
137 print " dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
138 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
139 print " gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
140 print " symmetrical=\"YES\">\n";
142 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
143 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
144 print " <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
145 print "</ASroute>\n";
148 # Now routes to the exit AS
149 for (my $i =1; $i<=$createdSons ; $i++)
151 print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
152 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
153 print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
154 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
155 print " symmetrical=\"YES\">\n";
156 print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
157 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
158 print "</ASroute>\n";
161 # DO I have extra stuff to add ? I don't think so.
165 my $lastNumberOfClusterCreated = 0;
166 #I must create clusters now
167 for(my $i = 1; $i <= $cabinetnodes && $totalnumberofCluster>0 ; $i++) {
168 $lastNumberOfClusterCreated++;
169 if ($totalnumberofCluster==1)
171 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\"1-"
172 . $last . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
176 print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\""
177 . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
179 $totalnumberofCluster--;
181 # Creating links to clusters
182 for(my $i = 1; $i <= $lastNumberOfClusterCreated ; $i++) {
183 print "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
187 # curr backbone creation
188 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
190 # I must create routes between clusters now
191 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
193 for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
195 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
196 print " dst=\"" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "\"\n";
198 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
199 print " gw_dst=\"" . $prefix . "c_" . $toReturn . "_" . $j . "-" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "_router" . $suffix . "\"\n";
200 print " symmetrical=\"YES\">\n";
202 print " <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
203 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
204 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
205 print "</ASroute>\n";
208 # Now routes to the exit AS
209 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
211 print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
212 print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
214 print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
215 print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
216 print " symmetrical=\"YES\">\n";
217 print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
218 print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
219 print "</ASroute>\n";
222 # Should be done with it...