Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge back the master trunk into the smpi branch
[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";
86
87         
88 # Initiate recursion ...
89 &DF_creation(0);
90
91 # Closing tag, and then back home
92 print "</platform>\n";  
93
94 # Recursive stuff for depth first Se... Creation
95 sub DF_creation {
96         my($currDepth) = @_;
97         
98         # Curr AS creation
99         print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\"  routing=\"Full\">\n";   
100         
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";
104         print "</AS>\n";
105         # Saving my current number to return it to my father
106         my $toReturn = $ASnumber;
107         $ASnumber++;
108         if ($currDepth<$height && $totalnumberofCluster > 0)
109                 {               
110                 # Creating current AS inner stuff
111                 # I should have a table of sons numbers.
112                 my @tsons = ();
113                 my $createdSons = 0;
114                 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
115                 {
116                 #saving this son in my tab ...  recursive call to create ASes and cluster underneath
117                 push(@tsons, &DF_creation($currDepth + 1)); 
118                 $createdSons++;
119                 #               
120                 # Creating link to this son
121                 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";        
122                 }
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++)
127                 {
128                                         for (my $j =$i+1; $j<=$createdSons ; $j++)
129                                         {
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";
135                                                 
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";
140                                         }
141                 }
142                 # Now routes to the exit AS
143                 for (my $i =1; $i<=$createdSons ; $i++)
144                 {
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";                   
153                 }
154                 print "</AS>\n";
155                 # DO I have extra stuff to add ? I don't think so.              
156                 return $toReturn;
157                 }
158         else { # On leaves, 
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)
164                         {
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";        
167                         }
168                         else 
169                         {       
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";     
172                         }
173                         $totalnumberofCluster--;
174                         }       
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";
178                 }
179
180                 # 
181                 # curr backbone creation 
182                 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
183         
184                 # I must create routes between clusters now 
185                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
186                         {
187                                         for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
188                                         {
189                                                 print  "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix .  "\"\n";
190                                                 print " dst=\"" .  $prefix . "cl_" . $toReturn . "_" . $j . $suffix .  "\"\n";
191
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";
195                                                 
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";
200                                         }
201                         }
202                 # Now routes to the exit AS
203                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
204                 {
205                         print  "<ASroute src=\""  . $prefix . "cl_" . $toReturn . "_" . $i . $suffix  . "\"\n";
206                         print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
207                         # SAME HERE !!
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";                   
214                 }
215                 print "</AS>\n";
216         # Should be done with it...
217         return $toReturn;
218         }
219
220 }