Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hide xbt_swag under the hood of mmalloc, its only remaining user.
[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-2016. The SimGrid Team.
9 # All rights reserved.
10 #
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of the license (GNU LGPL) which comes with this package.
13
14 =encoding UTF-8
15
16 =head1 NAME
17
18 simgrid_update_xml - updates simgrid XML files to latest version
19   
20 =head1 SYNOPSIS
21
22 B<simgrid_update_xml> I<xml_file>
23   
24 =head1 DESCRIPTION
25
26 simgrid_update_xml updates the simgrid XML file passed as argument.  The file
27 is modified in place, without any kind of backup. You may want to save a copy
28 before running the script.
29
30 In SimGrid XML files, the standard version is indicated in the version
31 attribute of the platform tag. Current version is 4. Here is a list of major
32 changes in each version.
33
34 =over 4
35
36 =item B<Version 0:> Used before SimGrid 3.3
37
38 =item B<Version 1:> Introduced in SimGrid 3.3
39
40 =over 4
41
42 =item 
43
44 The version attribute of platform were added to allow file versioning.
45
46 =item
47
48 The link bandwidth changed from Mb/s to b/s; and the CPU power were changed
49 from MFlop/s to Flop/s
50
51 =back
52
53 =item B<Version 2:> Introduced in SimGrid 3.4
54
55 =over 
56
57 =item 
58
59 Several tags were renamed: 
60
61   CPU -> HOST 
62   NETWORK_LINK -> LINK
63   ROUTE_ELEMENT ->  LINK_CTN
64   PLATFORM_DESCRIPTION -> PLATFORM
65
66 =back
67
68 =item B<Version 3:> Introduced in SimGrid 3.5
69
70 =over 4
71
72 =item
73
74 The AS tag were introduced. Every platform should now contain an englobing AS
75 tag.
76
77 =item 
78
79 Routes are now symmetric by default.
80
81 =item
82
83 Several tags were renamed (for sake of XML sanity):
84
85   LINK:CTN -> LINK_CTN
86   TRACE:CONNECT -> TRACE_CONNECT
87
88 =back
89
90 =item B<Version 4:> Introduced in SimGrid 3.13
91
92 =over 4
93
94 =item
95
96 Rename the attributes describing the amount of flop that a host / peer / cluster / cabinet can deliver per second.
97
98   <host power=...> -> <host speed=...>
99
100 =item
101
102 In <trace_connect>, attribute kind="POWER" is now kind="SPEED".
103
104 =item
105
106 The DOCTYPE points to the right URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd
107
108 =item
109
110 Units are now mandatory in attributes. USE THE SCRIPT sg_xml_unit_converter.py TO CONVERT THIS
111
112      - speed. Old default: 'f' or 'flops'. Also defined: 
113         'Yf',         'Zf',         'Ef',       'Pf',        'Tf',        'Gf',        'Mf',        'kf' 
114         'yottaflops', 'zettaflops', 'exaflops', 'petaflops', 'teraflops', 'gigaflops', 'megaflops', 'kiloflops'
115         
116      - bandwidth. Old default: 'Bps' bytes per second (or 'bps' but 1 Bps = 8 bps)
117        Also defined in bytes: 'TiBps', 'GiBps', 'MiBps', 'KiBps', 'TBps', 'GBps', 'MBps', 'kBps', 'Bps'
118        And the same in bits:  'Tibps', 'Gibps', 'Mibps', 'Kibps', 'Tbps', 'Gbps', 'Mbps', 'kbps', 'bps' 
119        
120      - latency. Old default: 's' second. Also defined:
121        'w' week, 'd' day, 'h' hour, 'm' minute, 'ms' millisecond, 'us' microsecond, 'ns' nanosecond, 'ps' picosecond   
122
123
124 =back
125
126 =item B<Version 4.1:> Introduced in SimGrid 3.16 (this is the current version)
127
128 =over 4
129
130 =item
131
132 Rename a few tags, but in a backward-compatible manner: the old names are still accepted.
133
134   AS            -> zone
135   ASroute       -> zoneRoute
136   bypassAsRoute -> bypassZoneRoute
137   process       -> actor
138
139 =back
140
141 =back
142
143 =head1 AUTHORS
144
145  The SimGrid team (simgrid-devel@lists.gforge.inria.fr)
146   
147 =head1 COPYRIGHT AND LICENSE
148
149 Copyright (c) 2006-2016. The SimGrid Team. All rights reserved.
150   
151 This program is free software; you may redistribute it and/or modify it
152 under the terms of GNU LGPL (v2.1) license.
153   
154 =cut
155
156
157 use strict;
158
159 my $fromversion=-1;
160 my $toversion=4.1;
161
162 my $filename = $ARGV[0] or die "Usage: simgrid_update_xml.pl file_to_convert.xml\nPlease provide an XML to convert as a parameter.\n";
163 open INPUT, "$filename" or die "Cannot open input file $filename: $!\n";
164
165 my $output_string = "<?xml version='1.0'?>\n".
166     "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n".
167     "<platform version=\"$toversion\">\n";
168
169 my($AS_opened)=0;
170
171 my $line;
172 while (defined($line = <INPUT>)) {
173     chomp $line;
174     # eat the header, whatever form it has
175     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
176     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
177     
178     if ($line =~ s/<platform(_description)? *>//) {
179         $fromversion = 0;
180         print "$filename was using version 0\n";
181         next if !$line =~ /\S/;
182     } elsif ($line =~ s/<platform.*version=["']*([0-9.]*)["']*>//) {
183         $fromversion = $1;
184         if ($fromversion == $toversion) {
185             warn "Input platform file $filename is already conformant to version $fromversion. This should be a no-op.\n";
186         }
187         if ($fromversion > $toversion) {
188             die "Input platform file $filename is more recent than this script (file version: $fromversion; script version: $toversion)\n";
189         }
190         next if !$line =~ /\S/;
191         print "$filename was using version $fromversion\n";
192     }
193     
194     if ($fromversion == 0) {
195         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
196             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
197         }
198         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
199             $line = "$1<cpu${2}power=\"$3\"$4";
200         }
201         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
202             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
203         }
204         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
205             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
206         }
207     }
208
209     if ($fromversion < 2)  {
210         # The renamings (\b=zero-width word boundary check)
211         $line =~ s/\bplatform_description\b/platform/g;
212         $line =~ s/\bname\b/id/g;
213         $line =~ s/\bcpu\b/host/g;
214         $line =~ s/\bnetwork_link\b/link/g;
215         $line =~ s/\broute_element\b/link:ctn/g;
216     }
217     
218     if ($fromversion < 3)  {
219         $line =~ s/\blink:ctn\b/link_ctn/g;
220         $line =~ s/\btrace:connect\b/trace_connect/g;
221
222         if($AS_opened && (($line=~ /<\/platform>/) || ($line=~ /<process/))) {
223             $output_string .= "</AS>\n";
224             $AS_opened = 0;
225         }
226
227         if( (!$AS_opened) && (
228                 ($line =~ /<host/)    ||
229                 ($line =~ /<link/)    ||
230                 ($line =~ /<cluster/) ||
231                 ($line =~ /<router/)
232             )) {
233             $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
234             $AS_opened=1;
235         }
236         
237         if($line=~/<route /){$line =~ s/\<route/\<route symmetrical=\"NO\"/g;}
238     }
239     if ($fromversion < 4) {
240         $line =~ s/\bpower\b/speed/g;   
241         $line =~ s/\bkind="POWER"/kind="SPEED"/g;
242     }
243     if ($fromversion < 4.1) {
244         $line =~ s/\bAS\b/zone/g;
245         $line =~ s/\bASroute\b/zoneRoute/g;
246         $line =~ s/\bbypassAsRoute\b/bypassZoneRoute/g;
247         $line =~ s/\bprocess\b/actor/g;
248     }
249         
250     $output_string .= "$line\n";
251 }
252
253 close INPUT;
254
255 if ($fromversion == -1) {
256     die "Cannot retrieve the platform version of $filename\n";
257 }
258
259 open OUTPUT, "> $filename";
260 print OUTPUT $output_string;
261 close OUTPUT;