1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <boost/intrusive/list.hpp>
12 #include "src/surf/HostImpl.hpp"
14 #ifndef VM_INTERFACE_HPP_
15 #define VM_INTERFACE_HPP_
17 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
18 // It corresponds to the cost of a VM running no tasks.
27 class XBT_PRIVATE VMModel;
28 class XBT_PRIVATE VirtualMachine;
34 /** @ingroup SURF_callbacks
35 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
37 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmCreation;
39 /** @ingroup SURF_callbacks
40 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
42 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmDestruction;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
47 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmStateChange;
53 /** @ingroup SURF_vm_interface
54 * @brief SURF VM interface class
55 * @details A VM represent a virtual machine
57 class VirtualMachine : public HostImpl {
59 VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
62 /** @brief Suspend the VM */
63 virtual void suspend();
65 /** @brief Resume the VM */
66 virtual void resume();
68 /** @brief Save the VM (Not yet implemented) */
71 /** @brief Restore the VM (Not yet implemented) */
72 virtual void restore();
74 /** @brief Migrate the VM to the destination host */
75 virtual void migrate(sg_host_t dest_PM);
77 /** @brief Get the physical machine hosting the VM */
80 virtual void setBound(double bound);
82 /* The vm object of the lower layer */
83 CpuAction *action_ = nullptr;
85 simgrid::s4u::Host *hostPM_;
88 void turnOn() override;
89 void turnOff() override;
91 e_surf_vm_state_t getState();
92 void setState(e_surf_vm_state_t state);
93 static std::deque<VirtualMachine*> allVms_;
96 e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
102 /** @ingroup SURF_vm_interface
103 * @brief SURF VM model interface class
104 * @details A model is an object which handle the interactions between its Resources and its Actions
106 class VMModel : public HostModel {
108 VMModel() :HostModel() {}
109 ~VMModel() = default;
112 * @brief Create a new VM
114 * @param name The name of the new VM
115 * @param host_PM The real machine hosting the VM
117 s4u::Host *createVM(const char *name, sg_host_t host_PM);
118 void adjustWeightOfDummyCpuActions() override {};
120 double next_occuring_event(double now) override;
121 void updateActionsState(double /*now*/, double /*delta*/) override {};
128 #endif /* VM_INTERFACE_HPP_ */