Logo AND Algorithmique Numérique Distribuée

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