Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
aa216e7706a4de656a435031fab175cbc69068f8
[simgrid.git] / src / surf / VirtualMachineImpl.hpp
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <boost/intrusive/list.hpp>
8 #include <deque>
9
10 #include <xbt/base.h>
11
12 #include "src/surf/HostImpl.hpp"
13
14 #ifndef VM_INTERFACE_HPP_
15 #define VM_INTERFACE_HPP_
16
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.
19
20 namespace simgrid {
21 namespace surf {
22
23 /***********
24  * Classes *
25  ***********/
26
27 class XBT_PRIVATE VMModel;
28 class XBT_PRIVATE VirtualMachineImpl;
29
30 /*************
31  * Callbacks *
32  *************/
33
34 /** @ingroup SURF_callbacks
35  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
36  */
37 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmCreation;
38
39 /** @ingroup SURF_callbacks
40  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
41  */
42 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmDestruction;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
46  */
47 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmStateChange;
48
49 /************
50  * Resource *
51  ************/
52
53 /** @ingroup SURF_vm_interface
54  * @brief SURF VM interface class
55  * @details A VM represent a virtual machine
56  */
57 class VirtualMachineImpl : public HostImpl {
58 public:
59   VirtualMachineImpl(const char* name, simgrid::s4u::Host* host);
60   ~VirtualMachineImpl();
61
62   /** @brief Suspend the VM */
63   virtual void suspend();
64
65   /** @brief Resume the VM */
66   virtual void resume();
67
68   /** @brief Save the VM (Not yet implemented) */
69   virtual void save();
70
71   /** @brief Restore the VM (Not yet implemented) */
72   virtual void restore();
73
74   /** @brief Migrate the VM to the destination host */
75   virtual void migrate(sg_host_t dest_PM);
76
77   /** @brief Get the physical machine hosting the VM */
78   sg_host_t getPm();
79
80   virtual void setBound(double bound);
81
82   /* The vm object of the lower layer */
83   CpuAction* action_ = nullptr;
84
85 protected:
86   simgrid::s4u::Host* hostPM_;
87
88 public:
89   e_surf_vm_state_t getState();
90   void setState(e_surf_vm_state_t state);
91   static std::deque<VirtualMachineImpl*> allVms_;
92
93 protected:
94   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
95 };
96
97 /*********
98  * Model *
99  *********/
100 /** @ingroup SURF_vm_interface
101  * @brief SURF VM model interface class
102  * @details A model is an object which handle the interactions between its Resources and its Actions
103  */
104 class VMModel : public HostModel {
105 public:
106   /**
107    * @brief Create a new VM
108    *
109    * @param name The name of the new VM
110    * @param host_PM The real machine hosting the VM
111    */
112   s4u::Host* createVM(const char* name, sg_host_t host_PM);
113   void adjustWeightOfDummyCpuActions() override{};
114
115   double nextOccuringEvent(double now) override;
116   void updateActionsState(double /*now*/, double /*delta*/) override{};
117 };
118 }
119 }
120
121 #endif /* VM_INTERFACE_HPP_ */