Logo AND Algorithmique Numérique Distribuée

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