Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more attributes in python bindings
[simgrid.git] / teshsuite / python / platform-mix / platform-mix.py
1 # Copyright (c) 2006-2022. The SimGrid Team. All rights reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
5
6 from simgrid import Actor, Engine, Host, Mailbox, NetZone, LinkInRoute, this_actor
7 import sys
8
9 class Sender:
10   """
11   Send 1 message for each host
12   """
13   def __init__(self, hosts):
14     self.hosts = hosts
15
16   # Actors that are created as object will execute their __call__ method.
17   # So, the following constitutes the main function of the Sender actor.
18   def __call__(self):
19
20     for host in self.hosts:
21       mbox = Mailbox.by_name(host.name)
22       msg = "Hello. I'm " + str(this_actor.get_host().name)
23       size = int(1e6)
24       this_actor.info("Sending msg to " + host.name)
25       mbox.put(msg, size)
26
27     this_actor.info("Done dispatching all messages. Goodbye!")
28
29 class Receiver:
30   """
31   Receiver actor: wait for 1 messages and do operations
32   """
33
34   def __call__(self):
35     this_actor.execute(1e9)
36     for disk in Host.current().get_disks():
37       this_actor.info("Using disk " + disk.name)
38       disk.read(10000)
39       disk.write(10000)
40     mbox = Mailbox.by_name(this_actor.get_host().name)
41     msg = mbox.get()
42     this_actor.info("I got '%s'." % msg)
43     this_actor.info("Finished executing. Goodbye!")
44
45 def load_platform():
46   """ Creates a mixed platform, using many methods available in the API
47   """
48
49   root = NetZone.create_floyd_zone("root")
50   hosts = []
51   # dijkstra
52   dijkstra = NetZone.create_dijkstra_zone("dijkstra")
53   msg_base = "Creating zone: "
54   this_actor.info(msg_base + dijkstra.name)
55   dijkstra.set_parent(root)
56   host1 = dijkstra.create_host("host1", [1e9, 1e8])
57   host1.core_count = 2
58   hosts.append(host1)
59   host1.create_disk("disk1", 1e5, 1e4).seal()
60   host1.create_disk("disk2", "1MBps", "1Mbps").seal()
61   host1.seal()
62   host2 = dijkstra.create_host("host2", ["1Gf", "1Mf"]).seal()
63   hosts.append(host2)
64   link1 = dijkstra.create_link("link1_up", [1e9]).set_latency(1e-3).set_concurrency_limit(10).seal()
65   link2 = dijkstra.create_link("link1_down", ["1GBps"]).set_latency("1ms").seal()
66   dijkstra.add_route(host1.netpoint, host2.netpoint, None, None, [LinkInRoute(link1)], False)
67   dijkstra.add_route(host2.netpoint, host1.netpoint, None, None, [LinkInRoute(link2)], False)
68   dijkstra.seal()
69
70   # vivaldi
71   vivaldi = NetZone.create_vivaldi_zone("vivaldi")
72   this_actor.info(msg_base + vivaldi.name)
73   vivaldi.set_parent(root)
74   host3 = vivaldi.create_host("host3", 1e9).set_coordinates("1 1 1").seal()
75   host4 = vivaldi.create_host("host4", "1Gf").set_coordinates("2 2 2").seal()
76   hosts.append(host3)
77   hosts.append(host4)
78
79   # empty
80   empty = NetZone.create_empty_zone("empty")
81   this_actor.info(msg_base + empty.name)
82   empty.set_parent(root)
83   host5 = empty.create_host("host5", 1e9)
84   hosts.append(host5)
85   empty.seal()
86
87   # wifi
88   wifi = NetZone.create_wifi_zone("wifi")
89   this_actor.info(msg_base + wifi.name)
90   wifi.set_parent(root)
91   router = wifi.create_router("wifi_router")
92   wifi.set_property("access_point", "wifi_router")
93   host6 = wifi.create_host(
94       "host6", ["100.0Mf", "50.0Mf", "20.0Mf"]).seal()
95   hosts.append(host6)
96   wifi_link = wifi.create_link("AP1", ["54Mbps", "36Mbps", "24Mbps"]).seal()
97   wifi_link.set_host_wifi_rate(host6, 1)
98   wifi.seal()
99
100   # create routes between netzones
101   link_a = vivaldi.create_link("linkA", 1e9).seal()
102   link_b = vivaldi.create_link("linkB", "1GBps").seal()
103   link_c = vivaldi.create_link("linkC", "1GBps").seal()
104   root.add_route(dijkstra.netpoint, vivaldi.netpoint, host1.netpoint, host3.netpoint, [LinkInRoute(link_a)], True)
105   root.add_route(vivaldi.netpoint, empty.netpoint, host3.netpoint, host5.netpoint, [LinkInRoute(link_b)], True)
106   root.add_route(empty.netpoint, wifi.netpoint, host5.netpoint, router, [LinkInRoute(link_c)], True)
107
108   # create actors Sender/Receiver
109   Actor.create("sender", hosts[0], Sender(hosts))
110   for host in hosts:
111     Actor.create("receiver", host, Receiver())
112
113 ###################################################################################################
114
115 if __name__ == '__main__':
116   e = Engine(sys.argv)
117
118   # create platform
119   load_platform()
120
121   # runs the simulation
122   e.run()