Logo AND Algorithmique Numérique Distribuée

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