Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add (empty) ChangeLog entry for release 3.10.
[simgrid.git] / examples / bittorrent / generate.py
1 #!/usr/bin/python
2
3 # This script generates a specific deployment file for the Bittorrent example.
4 # It assumes that the platform will be a cluster.
5 # Usage: python generate.py nb_nodes nb_bits end_date percentage
6 # Example: python generate.py 10000 5000
7
8 import sys, random
9
10 if len(sys.argv) != 4:
11         print("Usage: python generate.py nb_nodes end_date seed_percentage > deployment_file.xml")
12         sys.exit(1)
13
14 nb_nodes = int(sys.argv[1])
15 end_date = int(sys.argv[2])
16 seed_percentage = int(sys.argv[3]);
17
18 nb_bits = 24
19 max_id = 2 ** nb_bits - 1
20 all_ids = [42]
21
22 sys.stdout.write("<?xml version='1.0'?>\n"
23 "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
24 "<platform version=\"3\">\n"
25 "  <process host=\"c-0.me\" function=\"bittorrent.Tracker\"><argument value=\"%d\"/></process>\n" % end_date)
26
27 for i in range(1, nb_nodes):
28
29   ok = False
30   while not ok:
31     my_id = random.randint(0, max_id)
32     ok = not my_id in all_ids
33   start_date = i * 10
34   line = "  <process host=\"c-%d.me\" function=\"bittorrent.Peer\"><argument value=\"%d\" /><argument value=\"%d\" />" % (i, my_id, end_date)
35   if random.randint(0,100) < seed_percentage:
36     line += "<argument value=\"1\" />"
37   line += "</process>\n";
38   sys.stdout.write(line)
39   all_ids.append(my_id)
40 sys.stdout.write("</platform>")
41