Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
59439d0f14dbdeb7567c7c756806107512a615e5
[simgrid.git] / tools / platform_generation / msgplatform2surfxml.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 $ARGV[0] or die "msg2surf.pl <platform.txt>";
6 open INPUT, "$ARGV[0]" or die;
7
8 my($line);
9 my($parsing_host) = 0;
10 my($parsing_link) = 0;
11 my($parsing_route) = 0;
12 my($lat);
13 my(@link_list) = ();
14 my($link);
15
16 print "<?xml version='1.0'?>\n";
17 print "<!DOCTYPE platform_description SYSTEM \"surfxml.dtd\">\n";
18 print "<platform_description>\n";
19
20 while(defined($line=<INPUT>)){
21     chomp $line;
22     if($line=~/HOSTS/) {
23         $parsing_host=1;
24         next;
25     }
26     if($line=~/LINKS/) {
27         $parsing_host=0;
28         $parsing_link=1;
29         next;
30     }
31     if($line=~/ROUTES/) {
32         $parsing_link=0;
33         $parsing_route=1;
34         next;
35     }
36
37     if($parsing_host) {
38         if($line=~ /^\s*(\w+)\s+([0-9\.]+)\s*$/) {
39             print "  <cpu name=\"$1\" power=\"$2\"/>\n";
40         } else die "Cannot understand line \"$line\"\n";
41     }
42     if($parsing_link) {
43         if($line=~ /^\s*(\w+)\s+([0-9\.]+)\s*([0-9\.]+)\s*$/) {
44             $lat=$3; 
45             $lat/=1000;
46             print "  <network_link name=\"$1\" bandwidth=\"$2\" latency=\"$lat\"/>\n";
47         } else die "Cannot understand line \"$line\"\n";
48     }
49     if($parsing_route) {
50         if($line=~ /^\s*(\w+)\s+(\w+)\s+\((.*)\)\s*$/) {
51             @link_list=split(/\s+/, $3);
52             print "  <route src=\"$1\" dst=\"$2\">";
53             foreach $link (@link_list) {
54               print "<route_element name=\"$link\"/>";
55             }
56             print "</route>\n";
57         } else die "Cannot understand line \"$line\"\n";
58     }
59 }
60 print "</platform_description>\n";
61
62