Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename conf to optorsim
[simgrid.git] / examples / platforms / optorsim / transform_optorsim_platform.pl
1 #!/usr/bin/env perl
2
3 # Copyright (c) 2011, 2014, 2016. 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 "<!-- This platform was automatically converted from the OptorSim platform.\n";
21 print "\n";
22 print "  OptorSim files only describes information of the cluster interconnexion.\n";
23 print "  In a sense, it reflects the topology of a National Research and Education\n";
24 print "  Network (NREN), but not of a full-fledged computational platform.\n";
25 print "  The caracteristics of each cluster have been artificially added.\n";
26 print "\n";
27 print "  We hope that you find it useful anyway. If you know how to complete\n";
28 print "  this information with data on the cluster configurations, please\n";
29 print "  drop us a mail so that we can add this information. -->\n\n";
30
31 print "<?xml version='1.0'?>\n";
32 print "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n";
33 print "<platform version=\"3\">\n";
34 print "<AS id=\"AS0\" routing=\"Floyd\">\n";
35
36 my $line;
37 my @tokens;
38 my $token;
39 my $dst = 0;
40 my $src = 0;
41 my @list_of_name;
42 my $num_link = 0;
43
44 my @links = ();
45 my @links_router = ();
46 my @routers = ();
47 my @hosts = ();
48 my @is_router = ();
49 my @routes = ();
50 my @routes_router = ();
51 my @routes_cluster = ();
52 my $nb_host;
53 while(defined($line=<FILE>)){
54     if($line =~ /^#(.*)\)(.*)$/)
55     {
56         print "<!--$1 $2-->\n";
57         push @list_of_name, $2;
58     }
59     elsif($line =~ /^([0-9]*) ([0-9]*) ([0-9]*) (.*)$/)
60     {
61         if($1 == "0"){
62             push @is_router, 1;
63             if(@list_of_name){
64                 push @routers, "    <router id=\"$list_of_name[$src]\"/>\n";
65             }
66             else{
67                 push @routers, "    <router id=\"router$src\"/>\n";
68             }
69         }
70         else{
71             push @is_router, 0;
72             $nb_host = $1;
73             if(@list_of_name){
74                 push @hosts, "  <cluster id=\"$list_of_name[$src]\" prefix=\"$list_of_name[$src]-\" suffix=\"\"\n";
75                 push @hosts, "           radical=\"1-$nb_host\" power=\"1000000000\" bw=\"125000000\" lat=\"5E-5\"\n";
76                 push @hosts, "           router_id=\"$list_of_name[$src]-router\"/>\n";
77             }
78             else{
79                 push @hosts, "  <cluster id=\"cluster$src\" prefix=\"$src-\" suffix=\"\"\n";
80                 push @hosts, "           radical=\"1-$nb_host\" power=\"1000000000\" bw=\"125000000\" lat=\"5E-5\"\n";
81                 push @hosts, "           router_id=\"cluster$src-router\"/>\n";
82             }
83         }               
84         my $table = $4;
85         @tokens = split(/ /,$table);
86         foreach $token (@tokens) {
87             if($src >= $dst){
88                 if($token != "0") #if there is a link between src and dst
89                 {       
90                     #Create a link                              
91                     if($1 == "0"){ 
92                         push @links_router, "    <link id=\"link$num_link\" bandwidth=\"$token\"/>\n";
93                     }
94                     else{
95                         push @links, "  <link id=\"link$num_link\" bandwidth=\"$token\"/>\n";
96                     }
97                     
98                     #Create the route between router and router
99                     if($is_router[$src] && $is_router[$dst]) 
100                     {
101                         if(@list_of_name){
102                             push @routes_router, "    <route src=\"$list_of_name[$src]\" dst=\"$list_of_name[$dst]\">";
103                         }
104                         else{
105                             push @routes_router, "    <route src=\"router$src\" dst=\"router$dst\">";
106                         }
107                         push @routes_router, " <link_ctn id=\"link$num_link\"/>";
108                         push @routes_router, " </route>\n";
109                     }
110                     
111                     #Create the route between cluster and cluster
112                     elsif(!$is_router[$src] && !$is_router[$dst]) 
113                     {
114                         if(@list_of_name){
115                             push @routes_cluster, "    <ASroute src=\"$list_of_name[$src]\" dst=\"$list_of_name[$dst]\"";
116                             push @routes_cluster, " gw_src=\"$list_of_name[$src]-router\" gw_dst=\"$list_of_name[$dst]-router\">\n";
117                         }
118                         else{
119                             push @routes_cluster, "    <ASroute src=\"cluster$src\" dst=\"cluster$dst\"";
120                             push @routes_cluster, " gw_src=\"cluster$src-router\" dst=\"cluster$dst-router\">\n";
121                         }
122                         push @routes_cluster, "      <link_ctn id=\"link$num_link\"/>\n";
123                         push @routes_cluster, "    </ASroute>\n";
124                     }                           
125                     else
126                     {
127                         push @routes, "  <ASroute ";
128                         if(@list_of_name){
129                             if($is_router[$src])        #router
130                             {push @routes, "src=\"AS_intern\" gw_src=\"$list_of_name[$src]\" ";}
131                             else                        #cluster
132                             {push @routes, "src=\"$list_of_name[$src]\" gw_src=\"$list_of_name[$src]-router\" ";}
133                             
134                             
135                             if($is_router[$dst])        #router
136                             {push @routes, "dst=\"AS_intern\" gw_dst=\"$list_of_name[$dst]\">\n";}
137                             else                        #cluster
138                             {push @routes, "dst=\"$list_of_name[$dst]\" gw_dst=\"$list_of_name[$dst]-router\">\n";}
139                         }
140                         else{
141                             if($is_router[$src])        #router
142                             {push @routes, "src=\"AS_intern\" gw_src=\"router$src\" ";}
143                             else                        #cluster
144                             {push @routes, "src=\"cluster$src\" gw_src=\"cluster$src-router\" ";}
145                             
146                             
147                             if($is_router[$dst])        #router
148                             {push @routes, "dst=\"AS_intern\" gw_dst=\"router$dst\">\n";}
149                             else                        #cluster
150                             {push @routes, "dst=\"cluster$dst\" gw_dst=\"cluster$dst-router\">\n";}
151                         }
152                         push @routes, "    <link_ctn id=\"link$num_link\"/>\n";
153                         push @routes, "  </ASroute>\n";
154                         
155                     }
156                     
157                     $num_link++;        
158                 }
159             }
160             $dst++;
161         }
162         $src++;
163         $dst = 0;
164     }
165     else
166     {
167         die;
168     }
169 }
170 close(FILE);
171
172 print "  <AS id=\"AS_intern\" routing=\"Floyd\">\n";
173 print @routers;
174 print @links_router;
175 print @routes_router;
176 print "  </AS>\n";
177 print "\n";     
178 print @hosts;
179 print @routes_cluster;
180 print "\n";
181
182 print @links;
183 print "\n";
184 print @routes;
185 print "</AS>\n";
186 print "</platform>";
187 print " \n";