Logo AND Algorithmique Numérique Distribuée

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