Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
feaea00c5b4dbfe88d0fe6830d310450d86f6b95
[simgrid.git] / examples / deprecated / java / app / bittorrent / generate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2013-2019. 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
15 import random
16
17 if len(sys.argv) != 4:
18     print(
19         "Usage: python generate.py nb_nodes end_date seed_percentage > deployment_file.xml")
20     sys.exit(1)
21
22 nb_nodes = int(sys.argv[1])
23 end_date = int(sys.argv[2])
24 seed_percentage = int(sys.argv[3])
25
26 nb_bits = 24
27 max_id = 2 ** nb_bits - 1
28 all_ids = [42]
29
30 sys.stdout.write("<?xml version='1.0'?>\n"
31                  "<!DOCTYPE platform SYSTEM \"https://simgrid.org/simgrid.dtd\">\n"
32                  "<platform version=\"3\">\n"
33                  "  <process host=\"c-0.me\" function=\"bittorrent.Tracker\"><argument value=\"%d\"/></process>\n" %
34                  end_date)
35
36 for i in range(1, nb_nodes):
37
38     ok = False
39     while not ok:
40         my_id = random.randint(0, max_id)
41         ok = my_id not in all_ids
42     start_date = i * 10
43     line = "  <process host=\"c-%d.me\" function=\"bittorrent.Peer\"><argument value=\"%d\" />" \
44            "<argument value=\"%d\" />" % (i, my_id, end_date)
45     if random.randint(0, 100) < seed_percentage:
46         line += "<argument value=\"1\" />"
47     line += "</process>\n"
48     sys.stdout.write(line)
49     all_ids.append(my_id)
50 sys.stdout.write("</platform>")