1 /* Copyright (c) 2004-2023. 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 SIMGRID_KERNEL_HOST_INTERFACE_HPP
7 #define SIMGRID_KERNEL_HOST_INTERFACE_HPP
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/CpuImpl.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12 #include <xbt/PropertyHolder.hpp>
16 namespace simgrid::kernel::resource {
21 /** @ingroup Model_host_interface
22 * @brief Host model interface class
23 * @details A model is an object which handle the interactions between its Resources and its Actions
25 class XBT_PRIVATE HostModel : public Model {
28 virtual Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) = 0;
30 virtual Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
31 const double* bytes_amount, double rate) = 0;
32 virtual Action* io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk,
39 /** @ingroup Model_host_interface
40 * @brief 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, public actor::ObjectAccessSimcallItem {
45 boost::intrusive::list<actor::ActorImpl,
46 boost::intrusive::member_hook<actor::ActorImpl, boost::intrusive::list_member_hook<>,
47 &actor::ActorImpl::host_actor_list_hook>>;
49 ActorList actor_list_;
50 std::vector<actor::ProcessArg*> actors_at_boot_;
52 std::map<std::string, DiskImpl*, std::less<>> disks_;
53 std::map<std::string, VirtualMachineImpl*, std::less<>> vms_;
54 std::string name_{"noname"};
55 routing::NetZoneImpl* englobing_zone_ = nullptr;
59 virtual ~HostImpl(); // Use destroy() instead of this destructor.
62 friend VirtualMachineImpl;
63 explicit HostImpl(const std::string& name);
65 void destroy(); // Must be called instead of the destructor
67 std::vector<s4u::Disk*> get_disks() const;
68 s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
69 s4u::VirtualMachine* create_vm(const std::string& name, int core_amount, size_t ramsize = 1024);
70 s4u::VirtualMachine* create_vm(const std::string& name, s4u::VirtualMachine* vm);
71 void destroy_vm(const std::string& name);
72 void add_disk(const s4u::Disk* disk);
73 void remove_disk(const std::string& name);
74 /** @brief Moves VM from this host to destination. Only sets the vm_ accordingly */
75 void move_vm(VirtualMachineImpl* vm, HostImpl* destination);
76 std::vector<s4u::VirtualMachine*> get_vms() const;
77 VirtualMachineImpl* get_vm_by_name_or_null(const std::string& name) const;
79 virtual const s4u::Host* get_iface() const { return &piface_; }
80 virtual s4u::Host* get_iface() { return &piface_; }
82 /** Retrieves the name of that host as a C++ string */
83 std::string const& get_name() const { return name_; }
84 /** Retrieves the name of that host as a C string */
85 const char* get_cname() const { return name_.c_str(); }
87 routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
88 /** @brief Set the NetZone in which this Host is included */
89 HostImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
92 void turn_off(const actor::ActorImpl* issuer);
93 std::vector<s4u::ActorPtr> get_all_actors();
94 size_t get_actor_count() const;
95 void add_actor(actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
96 void remove_actor(actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
97 void add_actor_at_boot(actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
101 template <class F> void foreach_actor(F function)
103 for (auto& actor : actor_list_)
107 } // namespace simgrid::kernel::resource
109 #endif /* HOST_INTERFACE_HPP */