Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove gtnets and ns3 pages for one: Packet level simulation.
[simgrid.git] / buildtools / Cmake / 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 @routers = ();
27 my @hosts = ();
28 my @routes = ();
29 my $power;
30 while(defined($line=<FILE>))
31 {
32         
33         if($line =~ /^#(.*)\)(.*)$/)
34         {
35                 print "<!--$1 $2-->\n";
36                 push @list_of_name, $2;
37         }
38         elsif($line =~ /^([0-9]*) ([0-9]*) ([0-9]*) (.*)$/)
39         {
40                 if($1.$2.$3 == "000"){
41                         if(@list_of_name){
42                                 push @routers, "\t<router id=\"$list_of_name[$src]\"/>\n";
43                         }
44                         else{
45                                 push @routers, "\t<router id=\"$src\"/>\n";
46                         }
47                 }
48                 else{
49                         $power = $1 * $3;
50                         if($power == 0){
51                                 $power=1;
52                         }
53                         if(@list_of_name){
54                                 push @hosts, "\t<host id=\"$list_of_name[$src]\" power=\"$power\"/>\n";
55                         }
56                         else{
57                                 push @hosts, "\t<host id=\"$src\" power=\"$power\"/>\n";
58                         }
59                 }               
60                 my $table = $4;
61                 @tokens = split(/ /,$table);
62                 foreach $token (@tokens) {
63                         if($token != "0"){
64                                 if($src <= $dst){
65                                         
66                                         push @links, "\t<link id=\"link$num_link\" bandwidth=\"$token\"/>\n";
67                                         
68                                         if(@list_of_name){
69                                                 push @routes, "\t<route src=\"$list_of_name[$src]\" dst=\"$list_of_name[$dst]\">\n";
70                                         }
71                                         else{
72                                                 push @routes, "\t<route src=\"$src\" dst=\"$dst\">\n";
73                                         }
74                                         push @routes, "\t\t<link_ctn id=\"link$num_link\"/>\n";
75                                         push @routes, "\t</route>\n";
76                                         $num_link++;
77                                 }
78                         }
79                         $dst++;
80                 }
81                 $src++;
82                 $dst = 0;
83     }
84     else
85     {
86         die;
87     }
88         
89         
90 }
91 close(FILE);
92         
93 print @hosts;
94 print "\n";
95 print @routers;
96 print "\n";
97 print @links;
98 print "\n";
99 print @routes;
100
101 print "</AS>\n";
102 print "</platform>";
103
104 print " \n";