Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use env to find script interpreters
[simgrid.git] / examples / msg / bittorrent / generate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2012, 2014. The SimGrid Team.
4 # All rights reserved.
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
8
9 # This script generates a specific deployment file for the Bittorrent example.
10 # It assumes that the platform will be a cluster.
11 # Usage: python generate.py nb_nodes nb_bits end_date percentage
12 # Example: python generate.py 10000 5000
13
14 import sys, random
15
16 if len(sys.argv) != 4:
17         print("Usage: python generate.py nb_nodes end_date seed_percentage > deployment_file.xml")
18         sys.exit(1)
19
20 nb_nodes = int(sys.argv[1])
21 end_date = int(sys.argv[2])
22 seed_percentage = int(sys.argv[3]);
23
24 nb_bits = 24
25 max_id = 2 ** nb_bits - 1
26 all_ids = [42]
27
28 sys.stdout.write("<?xml version='1.0'?>\n"
29 "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
30 "<platform version=\"3\">\n"
31 "  <process host=\"c-0.me\" function=\"tracker\"><argument value=\"%d\"/></process>\n" % end_date)
32
33 for i in range(1, nb_nodes):
34
35   ok = False
36   while not ok:
37     my_id = random.randint(0, max_id)
38     ok = not my_id in all_ids
39   start_date = i * 10
40   line = "  <process host=\"c-%d.me\" function=\"peer\"><argument value=\"%d\" /><argument value=\"%d\" />" % (i, my_id, end_date)
41   if random.randint(0,100) < seed_percentage:
42     line += "<argument value=\"1\" />"
43   line += "</process>\n";
44   sys.stdout.write(line)
45   all_ids.append(my_id)
46 sys.stdout.write("</platform>")
47