Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update to lastest XML conventions
[simgrid.git] / examples / gras / mutual_exclusion / simple_token / make_deployment.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 my $input    = shift @ARGV || die "Usage: $ARGV[0] platform_file.xml nb_host\n";
6 my $nb_hosts = shift @ARGV || 0;
7
8 my @host;
9
10 open IN,$input || die "Cannot open $input: $!\n";
11
12 while (<IN>) {
13   next unless /<host id="([^"]*)"/; # "
14   
15   push @host, $1;
16 }
17
18 die "No host found in $input. Is it really a SimGrid platform file?\nCheck that you didn't pass a deployment file, for example.\n"
19   unless (scalar @host);
20
21 if (! $nb_hosts) {
22     $nb_hosts = scalar @host;
23 }
24
25 # map { print "$_\n" } @host;
26
27 print "<?xml version='1.0'?>\n";
28 print "<!DOCTYPE platform SYSTEM \"surfxml.dtd\">\n";
29 print "<platform version=\"2\">\n\n";
30
31
32 my $it_port=4000;
33 my $it_host=0;
34
35 for (my $i=0; $i<$nb_hosts -1; $i++) {
36
37   print "  <process host=\"".$host[$it_host]."\" function=\"node\">\n";
38   print "    <argument value=\"". $it_port ."\"/>     <!-- port on which I am listening -->\n";
39   $it_host ++;
40   if ($it_host == scalar @host) {
41     $it_host=0;
42     $it_port++;
43   }
44   print "    <argument value=\"". $host[ $it_host ]."\"/>   <!-- peer (successor) host -->\n";
45   print "    <argument value=\"".($it_port)."\"/>     <!-- port on which peer is listening -->\n";
46   print "  </process>\n\n";
47                 
48 }
49
50 print "  <process host=\"".$host[$it_host]."\" function=\"node\">\n";
51 print "    <argument value=\"". $it_port ."\"/>     <!-- port on which I am listening -->\n";
52 print "    <argument value=\"". $host[ 0 ]."\"/>   <!-- peer (successor) host -->\n";
53 print "    <argument value=\"4000\"/>     <!-- port on which peer is listening -->\n";
54 print "    <argument value=\"--create-token\"/>   <!-- I'm first client, ie I have to create the token -->\n";
55 print "  </process>\n\n";
56
57 print "</platform\n";