Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document Virtual machines
[simgrid.git] / include / simgrid / s4u / VirtualMachine.hpp
1 /* Copyright (c) 2015-2020. 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 SIMGRID_S4U_VM_HPP
7 #define SIMGRID_S4U_VM_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Host.hpp>
11
12 namespace simgrid {
13 namespace s4u {
14
15 /** @ingroup s4u_api
16  *
17  * @tableofcontents
18  *
19  * A VM represents a virtual machine (or a container) that hosts actors.
20  * The total computing power that the contained actors can get is constrained to the virtual machine size.
21  *
22  */
23 class XBT_PUBLIC VirtualMachine : public s4u::Host {
24   vm::VirtualMachineImpl* const pimpl_vm_;
25   virtual ~VirtualMachine();
26
27 public:
28   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount);
29   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount, size_t ramsize);
30
31 #ifndef DOXYGEN
32   // No copy/move
33   VirtualMachine(VirtualMachine const&) = delete;
34   VirtualMachine& operator=(VirtualMachine const&) = delete;
35 #endif
36
37   enum class state {
38     CREATED, /**< created, but not yet started */
39     RUNNING,
40     SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
41     DESTROYED
42   };
43
44   vm::VirtualMachineImpl* get_impl() const { return pimpl_vm_; }
45   void start();
46   void suspend();
47   void resume();
48   void shutdown();
49   void destroy() override;
50
51   Host* get_pm() const;
52   void set_pm(Host* pm);
53   size_t get_ramsize() const;
54   void set_ramsize(size_t ramsize);
55   void set_bound(double bound);
56
57   VirtualMachine::state get_state();
58   static xbt::signal<void(VirtualMachine const&)> on_start;
59   static xbt::signal<void(VirtualMachine const&)> on_started;
60   static xbt::signal<void(VirtualMachine const&)> on_shutdown;
61   static xbt::signal<void(VirtualMachine const&)> on_suspend;
62   static xbt::signal<void(VirtualMachine const&)> on_resume;
63   static xbt::signal<void(VirtualMachine const&)> on_migration_start;
64   static xbt::signal<void(VirtualMachine const&)> on_migration_end;
65 };
66 } // namespace s4u
67 } // namespace simgrid
68
69 #endif