Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enable warnings for C++, and stop hiding potential problems.
[simgrid.git] / examples / platforms / conf / transform_optorsim_platform.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 if($#ARGV!=0) {
5     die "Usage: perl transfrom_optorsim_platform.pl <file.conf>\n";
6 }
7
8 my($conf_file)=$ARGV[0];
9
10 open FILE, $conf_file or die "Unable to open $conf_file";
11
12 print "<?xml version='1.0'?>\n";
13 print "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n";
14 print "<platform version=\"3\">\n";
15 print "<AS  id=\"AS0\"  routing=\"Floyd\">\n";
16
17 my $line;
18 my @tokens;
19 my $token;
20 my $dst = 0;
21 my $src = 0;
22 my @list_of_name;
23 my $num_link = 0;
24
25 my @links = ();
26 my @links_router = ();
27 my @routers = ();
28 my @hosts = ();
29 my @is_router = ();
30 my @routes = ();
31 my @routes_router = ();
32 my @routes_cluster = ();
33 my $nb_host;
34 while(defined($line=<FILE>))
35 {
36         
37 if($line =~ /^#(.*)\)(.*)$/)
38 {
39         print "<!--$1 $2-->\n";
40         push @list_of_name, $2;
41 }
42 elsif($line =~ /^([0-9]*) ([0-9]*) ([0-9]*) (.*)$/)
43 {
44         if($1 == "0"){
45                 push @is_router, 1;
46                 if(@list_of_name){
47                         push @routers, "\t\t<router id=\"$list_of_name[$src]\"/>\n";
48                 }
49                 else{
50                         push @routers, "\t\t<router id=\"router$src\"/>\n";
51                 }
52         }
53         else{
54                 push @is_router, 0;
55                 $nb_host = $1;
56                 if(@list_of_name){
57                         push @hosts, "\t<cluster id=\"$list_of_name[$src]\" prefix=\"$list_of_name[$src]-\" suffix=\"\"\n";
58                         push @hosts, "\t         radical=\"1-$nb_host\" power=\"1000000000\"    bw=\"125000000\"     lat=\"5E-5\"\n";
59                         push @hosts, "\t         router_id=\"$list_of_name[$src]-router\"/>\n";
60                 }
61                 else{
62                         push @hosts, "\t<cluster id=\"cluster$src\" prefix=\"$list_of_name[$src]-\" suffix=\"\"\n";
63                         push @hosts, "\t         radical=\"1-$nb_host\" power=\"1000000000\"    bw=\"125000000\"     lat=\"5E-5\"\n";
64                         push @hosts, "\t         router_id=\"cluster$src-router\"/>\n";
65                 }
66         }               
67         my $table = $4;
68         @tokens = split(/ /,$table);
69         foreach $token (@tokens) {
70                 if($src >= $dst){
71                         if($token != "0") #if there is a link between src and dst
72                         {       
73                                 #Create a link                          
74                                 if($1 == "0"){ 
75                                         push @links_router, "\t\t<link id=\"link$num_link\" bandwidth=\"$token\"/>\n";
76                                 }
77                                 else{
78                                         push @links, "\t<link id=\"link$num_link\" bandwidth=\"$token\"/>\n";
79                                 }
80
81                                 #Create the route between router and router
82                                 if($is_router[$src] && $is_router[$dst]) 
83                                 {
84                                         if(@list_of_name){
85                                                 push @routes_router, "\t\t<route src=\"$list_of_name[$src]\" dst=\"$list_of_name[$dst]\">\n";
86                                         }
87                                         else{
88                                                 push @routes_router, "\t\t<route src=\"router$src\" dst=\"router$dst\">\n";
89                                         }
90                                         push @routes_router, "\t\t\t<link_ctn id=\"link$num_link\"/>\n";
91                                         push @routes_router, "\t\t</route>\n";
92                                 }
93
94                                 #Create the route between cluster and cluster
95                                 elsif(!$is_router[$src] && !$is_router[$dst]) 
96                                 {
97                                         if(@list_of_name){
98                                         push @routes_cluster, "\t\t<ASroute src=\"$list_of_name[$src]\" dst=\"$list_of_name[$dst]\"\n";
99                                         push @routes_cluster, "\t\t     gw_src=\"$list_of_name[$src]-router\" gw_dst=\"$list_of_name[$dst]-router\">\n";
100                                         }
101                                         else{
102                                         push @routes_cluster, "\t\t<ASroute src=\"cluster$src\" dst=\"cluster$dst\"\n";
103                                         push @routes_cluster, "\t\t    gw_src=\"cluster$src-router\" dst=\"cluster$dst-router\">\n";
104                                         }
105                                         push @routes_cluster, "\t\t\t<link_ctn id=\"link$num_link\"/>\n";
106                                         push @routes_cluster, "\t\t</ASroute>\n";
107                                 }                               
108                                 else
109                                 {
110                                         push @routes, "\t<ASroute ";
111                                         if(@list_of_name){
112                                                 if($is_router[$src])    #router
113                                                         {push @routes, "src=\"AS_intern\" gw_src=\"$list_of_name[$src]\"\n";}
114                                                 else                    #cluster
115                                                         {push @routes, "src=\"$list_of_name[$src]\" gw_src=\"$list_of_name[$src]-router\"\n";}
116
117
118                                                 if($is_router[$dst])    #router
119                                                         {push @routes, "\t\tdst=\"AS_intern\" gw_dst=\"$list_of_name[$dst]\">\n";}
120                                                 else                    #cluster
121                                                         {push @routes, "\t\tdst=\"$list_of_name[$dst]\" gw_dst=\"$list_of_name[$dst]-router\">\n";}
122                                         }
123                                         else{
124                                                 if($is_router[$src])    #router
125                                                         {push @routes, "src=\"AS_intern\" gw_src=\"router$src\"\n";}
126                                                 else                    #cluster
127                                                         {push @routes, "src=\"cluster$src\" gw_src=\"cluster$src-router\"\n";}
128
129
130                                                 if($is_router[$dst])    #router
131                                                         {push @routes, "\t\tdst=\"AS_intern\" gw_dst=\"router$dst\">\n";}
132                                                 else                    #cluster
133                                                         {push @routes, "\t\tdst=\"cluster$dst\" gw_dst=\"cluster$dst-router\">\n";}
134                                         }
135                                         push @routes, "\t\t<link_ctn id=\"link$num_link\"/>\n";
136                                         push @routes, "\t</ASroute>\n";
137
138                                 }
139
140                                 $num_link++;    
141                         }
142                 }
143                 $dst++;
144         }
145         $src++;
146         $dst = 0;
147 }
148 else
149 {
150 die;
151 }
152         
153         
154 }
155 close(FILE);
156
157 print "\t<AS  id=\"AS_intern\"  routing=\"Floyd\">\n";
158 print @routers;
159 print @links_router;
160 print @routes_router;
161 print "\t</AS>\n";
162 print "\n";     
163 print @hosts;
164 print @routes_cluster;
165 print "\n";
166
167 print @links;
168 print "\n";
169 print @routes;
170 print "\n";
171
172 print "</AS>\n";
173 print "</platform>";
174
175 print " \n";