Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow users to retrieve hosts and links by the zone in which they have been declared
[simgrid.git] / src / surf / HostImpl.hpp
1 /* Copyright (c) 2004-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 #ifndef SURF_HOST_INTERFACE_HPP
7 #define SURF_HOST_INTERFACE_HPP
8
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/CpuImpl.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12 #include "src/kernel/resource/LinkImpl.hpp"
13 #include <xbt/PropertyHolder.hpp>
14
15 #include <vector>
16
17 namespace simgrid {
18 namespace kernel {
19 namespace resource {
20 /*********
21  * Model *
22  *********/
23
24 /** @ingroup SURF_host_interface
25  * @brief SURF Host model interface class
26  * @details A model is an object which handle the interactions between its Resources and its Actions
27  */
28 class XBT_PRIVATE HostModel : public Model {
29 public:
30   using Model::Model;
31   virtual Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) = 0;
32
33   virtual Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
34                                    const double* bytes_amount, double rate) = 0;
35 };
36
37 /************
38  * Resource *
39  ************/
40 /** @ingroup SURF_host_interface
41  * @brief SURF Host interface class
42  * @details A host represents a machine with an aggregation of a Cpu, a RoutingEdge and Disk(s)
43  */
44 class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
45   using ActorList =
46       boost::intrusive::list<actor::ActorImpl,
47                              boost::intrusive::member_hook<actor::ActorImpl, boost::intrusive::list_member_hook<>,
48                                                            &actor::ActorImpl::host_actor_list_hook>>;
49
50   ActorList actor_list_;
51   std::vector<actor::ProcessArg*> actors_at_boot_;
52   s4u::Host piface_;
53   std::map<std::string, DiskImpl*, std::less<>> disks_;
54   xbt::string name_{"noname"};
55   routing::NetZoneImpl* englobing_zone_ = nullptr;
56   bool sealed_ = false;
57
58 protected:
59   virtual ~HostImpl(); // Use destroy() instead of this destructor.
60   HostImpl(const std::string& name, s4u::Host* piface);
61
62 public:
63   friend VirtualMachineImpl;
64   explicit HostImpl(const std::string& name);
65
66   void destroy(); // Must be called instead of the destructor
67
68   std::vector<s4u::Disk*> get_disks() const;
69   s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
70   void add_disk(const s4u::Disk* disk);
71   void remove_disk(const std::string& name);
72
73   virtual const s4u::Host* get_iface() const { return &piface_; }
74   virtual s4u::Host* get_iface() { return &piface_; }
75
76   /** Retrieves the name of that host as a C++ string */
77   xbt::string const& get_name() const { return name_; }
78   /** Retrieves the name of that host as a C string */
79   const char* get_cname() const { return name_.c_str(); }
80
81   routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
82   /** @brief Set the NetZone in which this Host is included */
83   HostImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
84
85   void turn_on() const;
86   void turn_off(const actor::ActorImpl* issuer);
87   std::vector<s4u::ActorPtr> get_all_actors();
88   size_t get_actor_count() const;
89   void add_actor(actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
90   void remove_actor(actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
91   void add_actor_at_boot(actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
92
93   void seal();
94
95   template <class F> void foreach_actor(F function)
96   {
97     for (auto& actor : actor_list_)
98       function(actor);
99   }
100 };
101 } // namespace resource
102 } // namespace kernel
103 } // namespace simgrid
104
105 #endif /* HOST_INTERFACE_HPP */