3 # Copyright (c) 2011-2012, 2014. The SimGrid Team.
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.
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.
14 # Number of cluster per leaf is given by cabinetnodes attr.
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
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.
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"/>
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.
33 # Counter for giving unique IDs to ASes.
42 open IN, "$infile" || die "Cannot parse " . $infile . " ...\n";
43 open OUT,">$outfile" || die "Cannot use the output file " . $outfile . " ...\n";
45 while ($line = <IN>) {
46 # looking for good lines.
47 if ($line =~ / cabinetnodes=/)
48 { #Retrieving informations
49 ($line=~ /cabinetnodes=\"([^\"]*)/);
51 ($line=~ /height=\"([^\"]*)/);
53 ($line=~ /nbsons=\"([^\"]*)/);
55 ($line=~ /id=\"([^\"]*)/);
57 ($line=~ /prefix=\"([^\"]*)/);
59 ($line=~ /suffix=\"([^\"]*)/);
61 ($line=~ /bw=\"([^\"]*)/);
63 ($line=~ /power=\"([^\"]*)/);
65 ($line=~ /lat=\"([^\"]*)/);
67 ($line=~ /bb_bw=\"([^\"]*)/);
69 ($line=~ /bb_lat=\"([^\"]*)/);
71 ($line=~ /links_bw=\"([^\"]*)/);
73 ($line=~ /links_lat=\"([^\"]*)/);
75 ($line=~ /radical=\"([^\"]*)/);
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";
104 print $infile . " -> " . $outfile . " ... Done.\n";
106 # Recursive stuff for depth first Se... Creation
111 print OUT "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
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";
117 # Saving my current number to return it to my father
118 my $toReturn = $ASnumber;
120 if ($currDepth<$height)
122 # Creating current AS inner stuff
123 # I should have a table of sons numbers.
125 for (my $i =1; $i<=$nbsons ; $i++)
127 #saving this son in my tab ... recursive call to create ASes and cluster underneath
128 push(@tsons, &DF_creation($currDepth + 1));
130 # Creating link to this son
131 print OUT "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
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++)
138 for (my $j =$i+1; $j<=$nbsons ; $j++)
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";
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";
152 # Now routes to the exit AS
153 for (my $i =1; $i<=$nbsons ; $i++)
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";
165 # DO I have extra stuff to add ? I don't think so.
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";
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";
181 # curr backbone creation
182 print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
184 # I must create routes between clusters now
185 for (my $i =1; $i<=$cabinetnodes ; $i++)
187 for (my $j =$i+1; $j<=$cabinetnodes ; $j++)
189 print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
190 print OUT " dst=\"" . $prefix . "cluster_" . $toReturn . $j . $suffix . "\"\n";
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";
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";
202 # Now routes to the exit AS
203 for (my $i =1; $i<=$cabinetnodes ; $i++)
205 print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
206 print OUT " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
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";
216 # Should be done with it...