X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/639100ee11f3b66897b242b05f8782230b0dcd89..2aaa919aa7451546f9576b3a71fc41f896c24b31:/examples/msg/chainsend/generate_deployment_file.rb diff --git a/examples/msg/chainsend/generate_deployment_file.rb b/examples/msg/chainsend/generate_deployment_file.rb new file mode 100755 index 0000000000..fae59a8784 --- /dev/null +++ b/examples/msg/chainsend/generate_deployment_file.rb @@ -0,0 +1,97 @@ +#!/usr/bin/env ruby + +require 'rexml/document' + +class HostsExtractor + @@doc = nil + @@hosts = [] + + def initialize(xml) + @@doc = REXML::Document.new(xml) + @@doc.elements.each('platform') do |platform| + extract_hosts(platform) + end + end + + def extract_hosts(doc) + doc.elements.each('AS') do |as| + extract_hosts_from_AS(as) + extract_hosts(as) + end + end + + def extract_hosts_from_AS(doc) + doc.elements.each('host') do |h| + @@hosts << h.attributes['id'] + puts "hosts %s" % h.attributes['id'] + end + + doc.elements.each('cluster') do |c| + prefix = c.attributes['prefix'] + suffix = c.attributes['suffix'] + puts "%s %s %s" % [prefix, c.attributes['radical'], suffix] + expand_radical(c.attributes['radical']).each do |num| + @@hosts << "%s%s%s" % [prefix, num, suffix] + end + end + end + + def hosts + return @@hosts + end + + def expand_radical(radical) + l = [] + puts radical + radical.split(',').each do |range| + range.scan(/^\d+$/) { |x| l << x } + range.scan(/^(\d+)-(\d+)$/) { |x, y| (x..y).each do |i| l << i end } + end + return l + end +end + +class DeploymentGenerator + @@outfile = nil + + def initialize(fname) + @@outfile = File.new(fname, "w") + end + + def write_header + @@outfile.puts "" + @@outfile.puts "" + @@outfile.puts "" + end + + def write_process(name, function, hosts, args) + @@outfile.puts " " % name + hosts.zip(args).each do |h, a| + @@outfile.puts " " % [h, function] + @@outfile.puts " " % [a] + @@outfile.puts " " + end + end + + def write_footer + @@outfile.puts "" + end +end + +xml = File.read(ARGV.shift) +he = HostsExtractor.new(xml) + +raise "Cannot run with less than 2 hosts" unless he.hosts.size > 1 + +output = ARGV.shift +dg = DeploymentGenerator.new(output) +dg.write_header + +puts he.hosts +broadcaster = he.hosts.shift +peers = he.hosts + +dg.write_process("Broadcaster", "broadcaster", [broadcaster], [he.hosts.size]) +dg.write_process("Peers", "peer", peers, (1..he.hosts.size)) + +dg.write_footer