Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix generated platform. Right number of clusters
[simgrid.git] / examples / platforms / generation_scripts / create_hierarchical_clusters.pl
1 #! /usr/bin/perl
2
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.
6 # - s : cluster size
7 # - d : degree of inner nodes.
8 #
9 # output is the standard one. 
10
11 #
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. 
13 # Other infos : 
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).
18
19
20 use Math::BigInt;
21
22 $prefix= ""; 
23 $suffix= "";
24 $bw= "125000000";
25 $power= "1000000000";
26 $lat= "5E-5";
27 $bb_bw= "2250000000";
28 $bb_lat= "5E-4"; 
29 $links_bw= "2250000000";
30 $links_lat= "5E-5";
31 $id= "";
32
33 $p = $ARGV[0];
34 $s = $ARGV[1];
35 $d = $ARGV[2];
36
37 $p = Math::BigInt->new($p);
38 $d = Math::BigInt->new($d);
39 $s = Math::BigInt->new($s);
40
41 $cabinetnodes= $d;
42 $nbsons= $d;
43 $radical= "1-" . $s;
44 $last=$s;
45
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);
49
50 $totalnumberofCluster= $totalnumberofhosts->copy();
51
52 $totalnumberofCluster->bdiv($s);
53
54 # checking if we have to have something non homogeneous
55 if ($totalnumberofhosts->copy()->bmod($s) != 0 ) 
56         {
57                 $totalnumberofCluster++;
58                 $last= $totalnumberofhosts->copy()->bmod($s);
59         }
60
61 # Calculating height
62
63 $height= $totalnumberofCluster->copy();
64 $height->broot($d);
65
66 # Checking if an exact root exists
67 if ( $height->bcmp(Math::BigInt->new("1")) != 0 && ($height->copy()->bpow($d))->bcmp($totalnumberofCluster)) {  
68         
69         $height++; #will have to deal with empty set of clusters.       
70         }
71 # debug stuff   
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";
77
78 # Counter for giving unique IDs to ASes.
79 $ASnumber;
80 $ASnumber = 0;
81
82 # Printing preamble
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";
86
87         
88 # Initiate recursion ...
89 &DF_creation(0);
90
91 # Closing tag, and then back home
92 print "</platform>\n";  
93
94
95 # Recursive stuff for depth first Se... Creation
96 sub DF_creation {
97         my($currDepth) = @_;
98         
99         # Curr AS creation
100         print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\"  routing=\"Full\">\n";   
101         
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";
105         print "</AS>\n";
106         # Saving my current number to return it to my father
107         my $toReturn = $ASnumber;
108         $ASnumber++;
109         if ($currDepth<=$height && $totalnumberofCluster > 0)
110                 {               
111                 # Creating current AS inner stuff
112                 # I should have a table of sons numbers.
113                 my @tsons = ();
114                 my $createdSons = 0;
115                 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
116                 {
117                 #saving this son in my tab ...  recursive call to create ASes and cluster underneath
118                 push(@tsons, &DF_creation($currDepth + 1)); 
119                 $createdSons++;
120                 #               
121                 # Creating link to this son
122                 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";        
123                 }
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++)
128                 {
129                                         for (my $j =$i+1; $j<=$createdSons ; $j++)
130                                         {
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";
136                                                 
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";
141                                         }
142                 }
143                 # Now routes to the exit AS
144                 for (my $i =1; $i<=$createdSons ; $i++)
145                 {
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";                   
154                 }
155                 print "</AS>\n";
156                 # DO I have extra stuff to add ? I don't think so.              
157                 return $toReturn;
158                 }
159         else { # On leaves, 
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)
165                         {
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";        
168                         }
169                         else 
170                         {       
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";     
173                         }
174                         $totalnumberofCluster--;
175                         }       
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";
179                 }
180
181                 # 
182                 # curr backbone creation 
183                 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
184         
185                 # I must create routes between clusters now 
186                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
187                         {
188                                         for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
189                                         {
190                                                 print  "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix .  "\"\n";
191                                                 print " dst=\"" .  $prefix . "cl_" . $toReturn . "_" . $j . $suffix .  "\"\n";
192
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";
196                                                 
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";
201                                         }
202                         }
203                 # Now routes to the exit AS
204                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
205                 {
206                         print  "<ASroute src=\""  . $prefix . "cl_" . $toReturn . "_" . $i . $suffix  . "\"\n";
207                         print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
208                         # SAME HERE !!
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";                   
215                 }
216                 print "</AS>\n";
217         # Should be done with it...
218         return $toReturn;
219         }
220
221 }