Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[appveyor] try to get some info on appveyor installs
[simgrid.git] / examples / platforms / generation_scripts / create_hierarchical_clusters.pl
1 #! /usr/bin/perl
2
3 # Copyright (c) 2011-2012, 2014. The SimGrid Team.
4 # All rights reserved.
5
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.
8
9 # Quick script to generate hierarchical clusters. Usage : <the script> p s d  where :
10 # - p : 2^p gives the total number of hosts.
11 # - s : cluster size
12 # - d : degree of inner nodes.
13 #
14 # output is the standard one.
15 #
16 #
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. 
18 # Other infos : 
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).
23 #
24
25 use Math::BigInt;
26
27 $prefix= ""; 
28 $suffix= "";
29 $bw= "125000000";
30 $power= "1000000000";
31 $lat= "5E-5";
32 $bb_bw= "2250000000";
33 $bb_lat= "5E-4"; 
34 $links_bw= "2250000000";
35 $links_lat= "5E-5";
36 $id= "";
37
38 $p = $ARGV[0];
39 $s = $ARGV[1];
40 $d = $ARGV[2];
41
42 $p = Math::BigInt->new($p);
43 $d = Math::BigInt->new($d);
44 $s = Math::BigInt->new($s);
45
46 $cabinetnodes= $d;
47 $nbsons= $d;
48 $radical= "1-" . $s;
49 $last=$s;
50
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);
54
55 $totalnumberofCluster= $totalnumberofhosts->copy();
56
57 $totalnumberofCluster->bdiv($s);
58
59 # checking if we have to have something non homogeneous
60 if ($totalnumberofhosts->copy()->bmod($s) != 0 ) 
61         {
62                 $totalnumberofCluster++;
63                 $last= $totalnumberofhosts->copy()->bmod($s);
64         }
65
66 # Calculating height
67
68 $height= $totalnumberofCluster->copy();
69 $height->broot($d);
70
71 # Checking if an exact root exists
72 if ( $height->bcmp(Math::BigInt->new("1")) != 0 && ($height->copy()->bpow($d))->bcmp($totalnumberofCluster)) {  
73         
74         $height++; #will have to deal with empty set of clusters.       
75         }
76 # debug stuff   
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";
82
83 # Counter for giving unique IDs to ASes.
84 $ASnumber;
85 $ASnumber = 0;
86
87 # Printing preamble
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";
91
92         
93 # Initiate recursion ...
94 &DF_creation(0);
95
96 # Closing tag, and then back home
97 print "</platform>\n";  
98
99
100 # Recursive stuff for depth first Se... Creation
101 sub DF_creation {
102         my($currDepth) = @_;
103         
104         # Curr AS creation
105         print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\"  routing=\"Full\">\n";   
106         
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";
110         print "</AS>\n";
111         # Saving my current number to return it to my father
112         my $toReturn = $ASnumber;
113         $ASnumber++;
114         if ($currDepth<=$height && $totalnumberofCluster > 0)
115                 {               
116                 # Creating current AS inner stuff
117                 # I should have a table of sons numbers.
118                 my @tsons = ();
119                 my $createdSons = 0;
120                 for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
121                 {
122                 #saving this son in my tab ...  recursive call to create ASes and cluster underneath
123                 push(@tsons, &DF_creation($currDepth + 1)); 
124                 $createdSons++;
125                 #               
126                 # Creating link to this son
127                 print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";        
128                 }
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++)
133                 {
134                                         for (my $j =$i+1; $j<=$createdSons ; $j++)
135                                         {
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";
141                                                 
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";
146                                         }
147                 }
148                 # Now routes to the exit AS
149                 for (my $i =1; $i<=$createdSons ; $i++)
150                 {
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";                   
159                 }
160                 print "</AS>\n";
161                 # DO I have extra stuff to add ? I don't think so.              
162                 return $toReturn;
163                 }
164         else { # On leaves, 
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)
170                         {
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";        
173                         }
174                         else 
175                         {       
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";     
178                         }
179                         $totalnumberofCluster--;
180                         }       
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";
184                 }
185
186                 # 
187                 # curr backbone creation 
188                 print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
189         
190                 # I must create routes between clusters now 
191                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
192                         {
193                                         for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
194                                         {
195                                                 print  "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix .  "\"\n";
196                                                 print " dst=\"" .  $prefix . "cl_" . $toReturn . "_" . $j . $suffix .  "\"\n";
197
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";
201                                                 
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";
206                                         }
207                         }
208                 # Now routes to the exit AS
209                 for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
210                 {
211                         print  "<ASroute src=\""  . $prefix . "cl_" . $toReturn . "_" . $i . $suffix  . "\"\n";
212                         print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
213                         # SAME HERE !!
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";                   
220                 }
221                 print "</AS>\n";
222         # Should be done with it...
223         return $toReturn;
224         }
225
226 }