Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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-2011. The SimGrid team. All rights reserved.
9 #
10 # This file is part of the SimGrid project. This is free software:
11 # You can redistribute and/or modify it under the terms of the
12 # GNU LGPL (v2.1) licence.
13
14 =encoding UTF-8
15
16 =head1 NAME
17
18 simgrid_update_xml - updates simgrid XML files to lastest 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 3. 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 versionning.
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 (this is the current version)
69
70 =over 4
71
72 =item
73
74 The AS tag were introduced. Every plaform 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 =back
91
92 =head1 AUTHORS
93
94  The SimGrid team (simgrid-devel@lists.gforge.inria.fr)
95   
96 =head1 COPYRIGHT AND LICENSE
97
98 Copyright 2006-2011. The SimGrid team. All rights reserved.
99   
100 This program is free software; you may redistribute it and/or modify it
101 under the terms of GNU LGPL (v2.1) license.
102   
103 =cut
104
105
106 use strict;
107
108 my $fromversion=-1;
109 my $toversion=3;
110
111 my($output_string);
112
113 $ARGV[0] or die "simgrid_update_xml.pl <platform.xml>\n";
114 open INPUT, "$ARGV[0]" or die "Cannot open input file $ARGV[0]: $!\n";
115
116 $output_string = "<?xml version='1.0'?>\n".
117     "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n".
118     "<platform version=\"$toversion\">\n";
119
120
121 my($AS_opened)=0;
122
123 my $line;
124 while (defined($line = <INPUT>)) {
125     chomp $line;
126     # eat the header, whatever form it has
127     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
128     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
129     
130     if ($line =~ s/<platform(_description)? *>//) {
131         $fromversion = 0;
132         print "version 0\n";
133         next if !$line =~ /\S/;
134     } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
135         $fromversion = $1;
136         print "version $fromversion\n";
137         if ($fromversion == $toversion) {
138             die "Input platform file version is already $fromversion. This should be a no-op.\n";
139         }
140         if ($fromversion > $toversion) {
141             die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
142         }
143         next if !$line =~ /\S/;
144     }
145     
146     if ($fromversion == 0) {
147         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
148             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
149         }
150         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
151             $line = "$1<cpu${2}power=\"$3\"$4";
152         }
153         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
154             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
155         }
156         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
157             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
158         }
159     }
160
161     if ($fromversion < 2)  {
162         # The renamings (\b=zero-width word boundary check)
163         $line =~ s/\bplatform_description\b/platform/g;
164         $line =~ s/\bname\b/id/g;
165         $line =~ s/\bcpu\b/host/g;
166         $line =~ s/\bnetwork_link\b/link/g;
167         $line =~ s/\broute_element\b/link:ctn/g;
168     }
169     
170     if ($fromversion < 3)  {
171         $line =~ s/\blink:ctn\b/link_ctn/g;
172         $line =~ s/\btrace:connect\b/trace_connect/g;
173
174         if($AS_opened && (($line=~ /<\/platform>/) || ($line=~ /<process/))) {
175             $output_string .= "</AS>\n";
176             $AS_opened = 0;
177         }
178
179         if( (!$AS_opened) && (
180                 ($line =~ /<host/)    ||
181                 ($line =~ /<link/)    ||
182                 ($line =~ /<cluster/) ||
183                 ($line =~ /<router/)
184             )) {
185             $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
186             $AS_opened=1;
187         }
188     }
189         
190         if($line=~/<route /){$line =~ s/\<route/\<route symmetrical=\"NO\"/g;}
191     $output_string .= "$line\n";
192 }
193
194 close INPUT;
195
196 if ($fromversion == -1) {
197     die "Cannot retrieve the platform version\n";
198 }
199
200 open OUTPUT, "> $ARGV[0]";
201 print OUTPUT $output_string;
202 close OUTPUT;