Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / examples / c / app-bittorrent / generate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2012-2023. 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 """
10 This script generates a specific deployment file for the Bittorrent example.
11 It assumes that the platform will be a cluster.
12 Usage: python generate.py nb_nodes nb_bits end_date percentage
13 Example: python generate.py 10000 5000
14 """
15
16 import sys
17 import random
18
19 if len(sys.argv) != 4:
20     print(
21         "Usage: python generate.py nb_nodes end_date seed_percentage > deployment_file.xml")
22     sys.exit(1)
23
24 nb_nodes = int(sys.argv[1])
25 end_date = int(sys.argv[2])
26 seed_percentage = int(sys.argv[3])
27
28 nb_bits = 24
29 max_id = 2 ** nb_bits - 1
30 all_ids = [42]
31
32 sys.stdout.write("<?xml version='1.0'?>\n"
33                  "<!DOCTYPE platform SYSTEM \"https://simgrid.org/simgrid.dtd\">\n"
34                  "<platform version=\"4\">\n"
35                  "  <actor host=\"node-0.simgrid.org\" function=\"tracker\">\n"
36                  "    <argument value=\"%d\"/>\n  </actor>\n" % end_date)
37
38 for i in range(1, nb_nodes):
39
40     ok = False
41     while not ok:
42         my_id = random.randint(0, max_id)
43         ok = my_id not in all_ids
44     start_date = i * 10
45     line = "  <actor host=\"node-%d.simgrid.org\" function=\"peer\">\n" % i
46     line += "    <argument value=\"%d\"/>\n    <argument value=\"%d\"/>\n" % (
47         my_id, end_date)
48     if random.randint(0, 100) < seed_percentage:
49         line += "    <argument value=\"1\"/>\n"
50     line += "  </actor>\n"
51     sys.stdout.write(line)
52     all_ids.append(my_id)
53 sys.stdout.write("</platform>")