Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Value stored to 'linelen' here is never read.
[simgrid.git] / tools / simgrid_update_xml.pl
1 #! /usr/bin/env perl
2 eval 'exec perl -S $0 ${1+"$@"}'
3     if $running_under_some_shell;
4
5 # This script updates the simgrid XML file passed as argument (modification in place)
6 # It is built to do the conversion incrementally.
7
8 # Copyright (c) 2006-2012. The SimGrid Team.
9 # All rights reserved.
10 #
11 # This file is part of the SimGrid project. This is free software:
12 # You can redistribute and/or modify it under the terms of the
13 # GNU LGPL (v2.1) licence.
14
15 =encoding UTF-8
16
17 =head1 NAME
18
19 simgrid_update_xml - updates simgrid XML files to latest version
20   
21 =head1 SYNOPSIS
22
23 B<simgrid_update_xml> I<xml_file>
24   
25 =head1 DESCRIPTION
26
27 simgrid_update_xml updates the simgrid XML file passed as argument.  The file
28 is modified in place, without any kind of backup. You may want to save a copy
29 before running the script.
30
31 In SimGrid XML files, the standard version is indicated in the version
32 attribute of the platform tag. Current version is 3. Here is a list of major
33 changes in each version.
34
35 =over 4
36
37 =item B<Version 0:> Used before SimGrid 3.3
38
39 =item B<Version 1:> Introduced in SimGrid 3.3
40
41 =over 4
42
43 =item 
44
45 The version attribute of platform were added to allow file versionning.
46
47 =item
48
49 The link bandwidth changed from Mb/s to b/s; and the CPU power were changed
50 from MFlop/s to Flop/s
51
52 =back
53
54 =item B<Version 2:> Introduced in SimGrid 3.4
55
56 =over 
57
58 =item 
59
60 Several tags were renamed: 
61
62   CPU -> HOST 
63   NETWORK_LINK -> LINK
64   ROUTE_ELEMENT ->  LINK_CTN
65   PLATFORM_DESCRIPTION -> PLATFORM
66
67 =back
68
69 =item B<Version 3:> Introduced in SimGrid 3.5 (this is the current version)
70
71 =over 4
72
73 =item
74
75 The AS tag were introduced. Every plaform should now contain an englobing AS
76 tag.
77
78 =item 
79
80 Routes are now symmetric by default.
81
82 =item
83
84 Several tags were renamed (for sake of XML sanity):
85
86   LINK:CTN -> LINK_CTN
87   TRACE:CONNECT -> TRACE_CONNECT
88
89 =back
90
91 =back
92
93 =head1 AUTHORS
94
95  The SimGrid team (simgrid-devel@lists.gforge.inria.fr)
96   
97 =head1 COPYRIGHT AND LICENSE
98
99 Copyright (c) 2006-2012. The SimGrid Team. All rights reserved.
100   
101 This program is free software; you may redistribute it and/or modify it
102 under the terms of GNU LGPL (v2.1) license.
103   
104 =cut
105
106
107 use strict;
108
109 my $fromversion=-1;
110 my $toversion=3;
111
112 my($output_string);
113
114 $ARGV[0] or die "simgrid_update_xml.pl <platform.xml>\n";
115 open INPUT, "$ARGV[0]" or die "Cannot open input file $ARGV[0]: $!\n";
116
117 $output_string = "<?xml version='1.0'?>\n".
118     "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n".
119     "<platform version=\"$toversion\">\n";
120
121
122 my($AS_opened)=0;
123
124 my $line;
125 while (defined($line = <INPUT>)) {
126     chomp $line;
127     # eat the header, whatever form it has
128     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
129     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
130     
131     if ($line =~ s/<platform(_description)? *>//) {
132         $fromversion = 0;
133         print "version 0\n";
134         next if !$line =~ /\S/;
135     } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
136         $fromversion = $1;
137         print "version $fromversion\n";
138         if ($fromversion == $toversion) {
139             die "Input platform file version is already $fromversion. This should be a no-op.\n";
140         }
141         if ($fromversion > $toversion) {
142             die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
143         }
144         next if !$line =~ /\S/;
145     }
146     
147     if ($fromversion == 0) {
148         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
149             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
150         }
151         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
152             $line = "$1<cpu${2}power=\"$3\"$4";
153         }
154         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
155             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
156         }
157         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
158             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
159         }
160     }
161
162     if ($fromversion < 2)  {
163         # The renamings (\b=zero-width word boundary check)
164         $line =~ s/\bplatform_description\b/platform/g;
165         $line =~ s/\bname\b/id/g;
166         $line =~ s/\bcpu\b/host/g;
167         $line =~ s/\bnetwork_link\b/link/g;
168         $line =~ s/\broute_element\b/link:ctn/g;
169     }
170     
171     if ($fromversion < 3)  {
172         $line =~ s/\blink:ctn\b/link_ctn/g;
173         $line =~ s/\btrace:connect\b/trace_connect/g;
174
175         if($AS_opened && (($line=~ /<\/platform>/) || ($line=~ /<process/))) {
176             $output_string .= "</AS>\n";
177             $AS_opened = 0;
178         }
179
180         if( (!$AS_opened) && (
181                 ($line =~ /<host/)    ||
182                 ($line =~ /<link/)    ||
183                 ($line =~ /<cluster/) ||
184                 ($line =~ /<router/)
185             )) {
186             $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
187             $AS_opened=1;
188         }
189     }
190         
191         if($line=~/<route /){$line =~ s/\<route/\<route symmetrical=\"NO\"/g;}
192     $output_string .= "$line\n";
193 }
194
195 close INPUT;
196
197 if ($fromversion == -1) {
198     die "Cannot retrieve the platform version\n";
199 }
200
201 open OUTPUT, "> $ARGV[0]";
202 print OUTPUT $output_string;
203 close OUTPUT;