Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / surf / HostImpl.hpp
1 /* Copyright (c) 2004-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 #ifndef SURF_HOST_INTERFACE_HPP
7 #define SURF_HOST_INTERFACE_HPP
8
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/DiskImpl.hpp"
11 #include "src/surf/StorageImpl.hpp"
12 #include "src/surf/cpu_interface.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include <xbt/PropertyHolder.hpp>
15
16 #include <vector>
17
18 namespace simgrid {
19 namespace surf {
20
21 /*********
22  * Model *
23  *********/
24
25 /** @ingroup SURF_host_interface
26  * @brief SURF Host model interface class
27  * @details A model is an object which handle the interactions between its Resources and its Actions
28  */
29 class XBT_PRIVATE HostModel : public kernel::resource::Model {
30 public:
31   HostModel() : Model(Model::UpdateAlgo::FULL) {}
32
33   virtual kernel::resource::Action* execute_parallel(const std::vector<s4u::Host*>& host_list,
34                                                      const double* flops_amount, const double* bytes_amount,
35                                                      double rate) = 0;
36 };
37
38 /************
39  * Resource *
40  ************/
41 /** @ingroup SURF_host_interface
42  * @brief SURF Host interface class
43  * @details A host represents a machine with an aggregation of a Cpu, a RoutingEdge and a Storage
44  */
45 class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
46   std::vector<kernel::actor::ProcessArg*> actors_at_boot_;
47   s4u::Host* piface_ = nullptr; // we must have a pointer there because the VM wants to change the piface in its ctor
48   std::map<std::string, kernel::resource::StorageImpl*, std::less<>> storage_;
49   std::vector<kernel::resource::DiskImpl*> disks_;
50
51 public:
52   friend simgrid::vm::VirtualMachineImpl;
53   explicit HostImpl(s4u::Host* host);
54   virtual ~HostImpl();
55
56   std::vector<s4u::Disk*> get_disks() const;
57   void set_disks(const std::vector<kernel::resource::DiskImpl*>& disks, s4u::Host* host);
58   void add_disk(const s4u::Disk* disk);
59   void remove_disk(const std::string& disk_name);
60
61   /** @brief Get the vector of storages (by names) attached to the Host */
62   virtual std::vector<const char*> get_attached_storages();
63   std::unordered_map<std::string, s4u::Storage*>* get_mounted_storages();
64   void set_storages(const std::map<std::string, kernel::resource::StorageImpl*, std::less<>>& storages)
65   {
66     storage_ = storages;
67   }
68
69   s4u::Host* get_iface() const { return piface_; }
70
71   void turn_on() const;
72   void turn_off(const kernel::actor::ActorImpl* issuer);
73   std::vector<s4u::ActorPtr> get_all_actors();
74   size_t get_actor_count() const;
75   void add_actor(kernel::actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
76   void remove_actor(kernel::actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
77   void add_actor_at_boot(kernel::actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
78
79   using ActorList = boost::intrusive::list<
80       kernel::actor::ActorImpl,
81       boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
82                                     &kernel::actor::ActorImpl::host_actor_list_hook>>;
83
84   // FIXME: make these private
85   ActorList actor_list_;
86 };
87 }
88 }
89
90 XBT_PUBLIC_DATA simgrid::surf::HostModel* surf_host_model;
91
92 #endif /* SURF_HOST_INTERFACE_HPP */