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.
9 # Number of cluster per leaf is given by cabinetnodes attr.
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
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.
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"/>
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.
28 # Counter for giving unique IDs to ASes.
37 open IN, "$infile" || die "Cannot parse " . $infile . " ...\n";
38 open OUT,">$outfile" || die "Cannot use the output file " . $outfile . " ...\n";
40 while ($line = <IN>) {
41 # looking for good lines.
42 if ($line =~ / cabinetnodes=/)
43 { #Retrieving informations
44 ($line=~ /cabinetnodes=\"([^\"]*)/);
46 ($line=~ /height=\"([^\"]*)/);
48 ($line=~ /nbsons=\"([^\"]*)/);
50 ($line=~ /id=\"([^\"]*)/);
52 ($line=~ /prefix=\"([^\"]*)/);
54 ($line=~ /suffix=\"([^\"]*)/);
56 ($line=~ /bw=\"([^\"]*)/);
58 ($line=~ /power=\"([^\"]*)/);
60 ($line=~ /lat=\"([^\"]*)/);
62 ($line=~ /bb_bw=\"([^\"]*)/);
64 ($line=~ /bb_lat=\"([^\"]*)/);
66 ($line=~ /links_bw=\"([^\"]*)/);
68 ($line=~ /links_lat=\"([^\"]*)/);
70 ($line=~ /radical=\"([^\"]*)/);
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";
99 print $infile . " -> " . $outfile . " ... Done.\n";
101 # Recursive stuff for depth first Se... Creation
106 print OUT "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
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";
112 # Saving my current number to return it to my father
113 my $toReturn = $ASnumber;
115 if ($currDepth<$height)
117 # Creating current AS inner stuff
118 # I should have a table of sons numbers.
120 for (my $i =1; $i<=$nbsons ; $i++)
122 #saving this son in my tab ... recursive call to create ASes and cluster underneath
123 push(@tsons, &DF_creation($currDepth + 1));
125 # Creating link to this son
126 print OUT "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
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++)
133 for (my $j =$i+1; $j<=$nbsons ; $j++)
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";
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";
147 # Now routes to the exit AS
148 for (my $i =1; $i<=$nbsons ; $i++)
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";
160 # DO I have extra stuff to add ? I don't think so.
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";
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";
176 # curr backbone creation
177 print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
179 # I must create routes between clusters now
180 for (my $i =1; $i<=$cabinetnodes ; $i++)
182 for (my $j =$i+1; $j<=$cabinetnodes ; $j++)
184 print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
185 print OUT " dst=\"" . $prefix . "cluster_" . $toReturn . $j . $suffix . "\"\n";
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";
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";
197 # Now routes to the exit AS
198 for (my $i =1; $i<=$cabinetnodes ; $i++)
200 print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
201 print OUT " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
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";
211 # Should be done with it...