Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finalize properties on AS.
[simgrid.git] / examples / platforms / generation_scripts / enhancedDTDwithHierarchicalCluster.pl
1 #! /usr/bin/perl
2
3 # L.Bobelin (Perl newbie) 24th of November
4 # Quick script to generate hierarchical clusters. Usage : add the special cluster tag (description below) in your "normal" platform file. Then run the script :
5 # - First arg : the input file where you midified your cluster tag
6 # - Second one : the output file where all the stuff will be generated.
7 # Builds a complete tree to access clusters ; each node of the tree is inclosed in an AS, where full routing applies.
8 #
9 # Number of cluster per leaf is given by cabinetnodes attr.
10 #
11 #
12 # Choosed to modify a cluster tag to allow to give additional informations : 
13 # - nbsons : degree of inner  
14 # - height : tree heigth
15 # - cabinetnodes : cluster per leaf
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 #
19 #
20 # Example syntax for hierarchical cluster creation : 
21 # <cluster id="AS_cb1" prefix="cb1-" suffix=".dc1.acloud.com" power="5.2297E9" bw="1.25E8" lat="1.0E-4 bb_bw="1.25E9" bb_lat="1.0E-4" radical="0-99" cabinetnodes="4" height="3" nbsons="2" links_lat="1.0E-4" links_bw="1.25E9"/>
22 # Other infos : 
23 # - special tag has to be on one line because I don't want to bother with parsing issues
24 # - Same bb_lat used for any routers inside (not that complicated to modify too)
25 # - lame perl ? I'm a script kiddie in perl, it may well be my first perl stuff. 
26 # - Don't try to check or validate the modified file with the DTD, of course, as this is not a part of it.
27
28 # Counter for giving unique IDs to ASes.
29 $ASnumber;
30 $ASnumber = 0;
31
32 $infile;
33 $outfile; 
34
35 $infile = $ARGV[0];
36 $outfile = $ARGV[1];
37 open IN, "$infile" || die "Cannot parse " . $infile . " ...\n";
38 open OUT,">$outfile" || die "Cannot use the output file " . $outfile . " ...\n";
39 my $line;
40 while ($line = <IN>) {
41 # looking for good lines. 
42 if ($line =~ / cabinetnodes=/) 
43 { #Retrieving informations
44         ($line=~ /cabinetnodes=\"([^\"]*)/);
45         $cabinetnodes= $1;
46         ($line=~ /height=\"([^\"]*)/);
47         $height= $1;
48         ($line=~ /nbsons=\"([^\"]*)/);
49         $nbsons= $1;
50          ($line=~ /id=\"([^\"]*)/);
51         $id= $1;
52         ($line=~ /prefix=\"([^\"]*)/);
53         $prefix= $1; 
54         ($line=~ /suffix=\"([^\"]*)/);
55         $suffix= $1;
56         ($line=~ /bw=\"([^\"]*)/);
57         $bw= $1;
58         ($line=~ /power=\"([^\"]*)/);
59         $power= $1;
60         ($line=~ /lat=\"([^\"]*)/);
61         $lat= $1;
62         ($line=~ /bb_bw=\"([^\"]*)/);
63         $bb_bw= $1;
64         ($line=~ /bb_lat=\"([^\"]*)/);
65         $bb_lat= $1; 
66         ($line=~ /links_bw=\"([^\"]*)/);
67         $links_bw= $1;
68         ($line=~ /links_lat=\"([^\"]*)/);
69         $links_lat= $1;
70         ($line=~ /radical=\"([^\"]*)/);
71         $radical= $1;
72
73         print "Variables read : \n";
74         print "number of clusters in each cabinet: " . $cabinetnodes . "\n";
75         print "Tree heigth: " . $height . "\n";
76         print "Degree of each node: " . $nbsons . "\n";
77         print "General id: ". $id . "\n";
78         print "General prefix: " . $prefix . "\n";
79         print "General suffix: ". $suffix . "\n";
80         print "Bandwidth for cluster inner links: " . $bw . "\n";
81         print "Power for cluster nodes: " . $power . "\n";
82         print "Latency for clusters inner links :" . $lat . "\n";
83         print "Backbone bandwwidth (used in all backbones, including the tree ones):" . $bb_bw . "\n";
84         print "Backbone latency (used in all backbones, including the tree ones):" . $bb_lat . "\n";
85         print "Tree links bandwidth: " . $links_bw . "\n";
86         print "Tree links latency: " . $links_lat . "\n";
87         print "Radical: " . $radical . "\n";
88
89         
90         
91         &DF_creation(0);
92         }
93 else {
94 print OUT $line;
95 }
96 } #End while
97 close IN;
98 close OUT;
99 print $infile . " -> " . $outfile . " ... Done.\n";
100
101 # Recursive stuff for depth first Se... Creation
102 sub DF_creation {
103         my($currDepth) = @_;
104         
105         # Curr AS creation
106         print OUT "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\"  routing=\"Full\">\n";       
107         
108         # Curr router AS creation stuff
109         print OUT "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\"  routing=\"Full\">\n";                    
110         print OUT "     <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
111         print OUT "</AS>\n";
112         # Saving my current number to return it to my father
113         my $toReturn = $ASnumber;
114         $ASnumber++;
115         if ($currDepth<$height)
116                 {                               
117                 # Creating current AS inner stuff
118                 # I should have a table of sons numbers.
119                 my @tsons = ();
120                 for (my $i =1; $i<=$nbsons ; $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                 #               
125                 # Creating link to this son
126                 print OUT "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";    
127                 }
128                 # curr backbone creation 
129                 print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
130                 # Full routing AS to AS declaration
131                 for (my $i =1; $i<=$nbsons ; $i++)
132                 {
133                                         for (my $j =$i+1; $j<=$nbsons ; $j++)
134                                         {
135                                                 print OUT  "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
136                                                 print OUT "     dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
137                                                 print OUT "     gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
138                                                 print OUT "     gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
139                                                 print OUT "     symmetrical=\"YES\">\n";
140                                                 
141                                                 print OUT "             <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
142                                                 print OUT "             <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n"; 
143                                                 print OUT "             <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
144                                                 print OUT "</ASroute>\n";
145                                         }
146                 }
147                 # Now routes to the exit AS
148                 for (my $i =1; $i<=$nbsons ; $i++)
149                 {
150                         print OUT  "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
151                         print OUT "     dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
152                         print OUT "     gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
153                         print OUT "     gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
154                         print OUT "     symmetrical=\"YES\">\n";                                                
155                         print OUT "             <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
156                         print OUT "             <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n"; 
157                         print OUT "</ASroute>\n";                       
158                 }
159                 print OUT "</AS>\n";
160                 # DO I have extra stuff to add ? I don't think so.              
161                 return $toReturn;
162                 }
163         else { # On leaves, 
164                         
165                 #I must create clusters now
166                 for(my $i = 1; $i <= $cabinetnodes; $i++) {
167                         print OUT "<cluster id=\"". $prefix . "cluster_" . $toReturn . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn. $i . "-\" suffix=\"" . $suffix . "\" radical=\""
168                                 . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";     
169                         }       
170                 # Creating links to clusters
171                 for(my $i = 1; $i <= $cabinetnodes; $i++) {
172                         print OUT "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
173                 }
174
175                 # 
176                 # curr backbone creation 
177                 print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
178         
179                 # I must create routes between clusters now
180                 for (my $i =1; $i<=$cabinetnodes ; $i++)
181                         {
182                                         for (my $j =$i+1; $j<=$cabinetnodes ; $j++)
183                                         {
184                                                 print OUT  "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix .  "\"\n";
185                                                 print OUT "     dst=\"" .  $prefix . "cluster_" . $toReturn . $j . $suffix .  "\"\n";
186
187                                                 print OUT "     gw_src=\"" . $prefix . "c_" . $toReturn. $i . "-" . $prefix . "cluster_" . $toReturn . $i . $suffix . "_router" . $suffix  ."\"\n";
188                                                 print OUT "     gw_dst=\"" . $prefix . "c_" . $toReturn. $j . "-" . $prefix . "cluster_" . $toReturn . $j . $suffix  . "_router" . $suffix . "\"\n";
189                                                 print OUT "     symmetrical=\"YES\">\n";
190                                                 
191                                                 print OUT "             <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
192                                                 print OUT "             <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n"; 
193                                                 print OUT "             <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
194                                                 print OUT "</ASroute>\n";
195                                         }
196                         }
197                 # Now routes to the exit AS
198                 for (my $i =1; $i<=$cabinetnodes ; $i++)
199                 {
200                         print OUT  "<ASroute src=\""  . $prefix . "cluster_" . $toReturn . $i . $suffix  . "\"\n";
201                         print OUT "     dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
202                         # SAME HERE !!
203                         print OUT "     gw_src=\"" . $prefix . "c_" . $toReturn. $i . "-" . $prefix . "cluster_" . $toReturn . $i . $suffix . "_router" . $suffix  ."\"\n";
204                         print OUT "     gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
205                         print OUT "     symmetrical=\"YES\">\n";                                                
206                         print OUT "             <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
207                         print OUT "             <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n"; 
208                         print OUT "</ASroute>\n";                       
209                 }
210                 print OUT "</AS>\n";
211         # Should be done with it...
212         return $toReturn;
213         }
214
215 }