1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SURF_HOST_INTERFACE_HPP
7 #define SURF_HOST_INTERFACE_HPP
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/DiskImpl.hpp"
11 #include "src/surf/cpu_interface.hpp"
12 #include "src/surf/network_interface.hpp"
13 #include <xbt/PropertyHolder.hpp>
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
28 class XBT_PRIVATE HostModel : public kernel::resource::Model {
31 virtual kernel::resource::Action* execute_parallel(const std::vector<s4u::Host*>& host_list,
32 const double* flops_amount, const double* bytes_amount,
39 /** @ingroup SURF_host_interface
40 * @brief SURF Host interface class
41 * @details A host represents a machine with an aggregation of a Cpu, a RoutingEdge and Disk(s)
43 class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
44 using ActorList = boost::intrusive::list<
45 kernel::actor::ActorImpl,
46 boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
47 &kernel::actor::ActorImpl::host_actor_list_hook>>;
49 ActorList actor_list_;
50 std::vector<kernel::actor::ProcessArg*> actors_at_boot_;
52 std::vector<kernel::resource::DiskImpl*> disks_;
53 xbt::string name_{"noname"};
57 virtual ~HostImpl(); // Use destroy() instead of this destructor.
58 HostImpl(const std::string& name, s4u::Host* piface);
61 friend simgrid::vm::VirtualMachineImpl;
62 explicit HostImpl(const std::string& name);
64 void destroy(); // Must be called instead of the destructor
66 std::vector<s4u::Disk*> get_disks() const;
67 s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
68 void add_disk(const s4u::Disk* disk);
69 void remove_disk(const std::string& disk_name);
71 virtual const s4u::Host* get_iface() const { return &piface_; }
72 virtual s4u::Host* get_iface() { return &piface_; }
74 /** Retrieves the name of that host as a C++ string */
75 xbt::string const& get_name() const { return name_; }
76 /** Retrieves the name of that host as a C string */
77 const char* get_cname() const { return name_.c_str(); }
80 void turn_off(const kernel::actor::ActorImpl* issuer);
81 std::vector<s4u::ActorPtr> get_all_actors();
82 size_t get_actor_count() const;
83 void add_actor(kernel::actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
84 void remove_actor(kernel::actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
85 void add_actor_at_boot(kernel::actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
89 template <class F> void foreach_actor(F function)
91 for (auto& actor : actor_list_)
96 } // namespace simgrid
98 #endif /* SURF_HOST_INTERFACE_HPP */