3 # This script updates the simgrid XML file passed as argument (modification in place)
4 # It is built to do the conversion incrementally.
6 # Copyright (C) 2006-2010. The SimGrid team. All rights reserved.
8 # This file is part of the SimGrid project. This is free software:
9 # You can redistribute and/or modify it under the terms of the
10 # GNU LGPL (v2.1) licence.
19 $ARGV[0] or die "simgrid_update_xml.pl <platform.xml>\n";
20 open INPUT, "$ARGV[0]" or die "Cannot open input file $ARGV[0]: $!\n";
22 $output_string = "<?xml version='1.0'?>\n".
23 "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n".
24 "<platform version=\"$toversion\">\n";
30 while (defined($line = <INPUT>)) {
32 # eat the header, whatever form it has
33 next if ($line =~ s/<\?xml[^>]*>// && ! $line =~ /\S/); # just in case several tags are on the same line
34 next if ($line =~ s/<!DOCTYPE[^>]*>// && ! $line =~ /\S/);
36 if ($line =~ s/<platform(_description)? *>//) {
39 next if !$line =~ /\S/;
40 } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
42 print "version $fromversion\n";
43 if ($fromversion == $toversion) {
44 die "Input platform file version is already $fromversion. This should be a no-op.\n";
46 if ($fromversion > $toversion) {
47 die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
49 next if !$line =~ /\S/;
52 if ($fromversion == 0) {
53 while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
54 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
56 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
57 $line = "$1<cpu${2}power=\"$3\"$4";
59 while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
60 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
62 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
63 $line = "$1<network_link${2}bandwidth=\"$3\"$4";
67 if ($fromversion < 2) {
68 # The renamings (\b=zero-width word boundary check)
69 $line =~ s/\bplatform_description\b/platform/g;
70 $line =~ s/\bname\b/id/g;
71 $line =~ s/\bcpu\b/host/g;
72 $line =~ s/\bnetwork_link\b/link/g;
73 $line =~ s/\broute_element\b/link:ctn/g;
76 if ($fromversion < 3) {
77 $line =~ s/\blink:ctn\b/link_ctn/g;
78 $line =~ s/\btrace:connect\b/trace_connect/g;
80 if($AS_opened && (($line=~ /<\/platform>/) || ($line=~ /<process/))) {
81 $output_string .= "</AS>\n";
85 if( (!$AS_opened) && (
88 ($line =~ /<cluster/) ||
91 $output_string .= " <AS id=\"AS0\" routing=\"Full\">\n";
96 if($line=~/<route /){$line =~ s/\<route/\<route symmetrical=\"NO\"/g;}
97 $output_string .= "$line\n";
102 if ($fromversion == -1) {
103 die "Cannot retrieve the platform version\n";
106 open OUTPUT, "> $ARGV[0]";
107 print OUTPUT $output_string;