Logo AND Algorithmique Numérique Distribuée

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