3 # This script updates the simgrid XML file passed as argument (modification in place)
4 # It is built to do the conversion incrementally (even if for now, only 2 versions are defined)
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 $output_string .= "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
24 $output_string .= "<platform version=\"$toversion\">\n";
25 $output_string .= " <AS id=\"AS0\" routing=\"Full\">\n";
28 while (defined($line = <INPUT>)) {
30 # eat the header, whatever form it has
31 next if ($line =~ s/<\?xml[^>]*>// && ! $line =~ /\S/); # just in case several tags are on the same line
32 next if ($line =~ s/<!DOCTYPE[^>]*>// && ! $line =~ /\S/);
34 if ($line =~ s/<platform(_description)? *>//) {
37 next if !$line =~ /\S/;
38 } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
40 print "version $fromversion\n";
41 if ($fromversion == $toversion) {
42 die "Input platform file version is already $fromversion. This should be a no-op.\n";
44 if ($fromversion > $toversion) {
45 die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
47 next if !$line =~ /\S/;
50 if ($fromversion == 0) {
51 while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
52 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
54 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
55 $line = "$1<cpu${2}power=\"$3\"$4";
57 while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
58 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
60 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
61 $line = "$1<network_link${2}bandwidth=\"$3\"$4";
65 if ($fromversion < 2) {
66 # The renamings (\b=zero-width word boundary check)
67 $line =~ s/\bplatform_description\b/platform/g;
68 $line =~ s/\bname\b/id/g;
69 $line =~ s/\bcpu\b/host/g;
70 $line =~ s/\bnetwork_link\b/link/g;
71 $line =~ s/\broute_element\b/link:ctn/g;
74 if ($fromversion < 3) {
75 if($line =~ /^(.*)<\/platform>(.*)$/) {
76 $output_string .= " <\/AS>\n<\/platform>";
78 $output_string .= "$line\n";
80 $line =~ s/\blink:ctn\b/link_ctn/g;
81 $line =~ s/\btrace:connect\b/trace_connect/g;
87 if ($fromversion == -1) {
88 die "Cannot retrieve the platform version\n";
91 open OUTPUT, "> $ARGV[0]";
92 print OUTPUT $output_string;