Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
classes can actually be created on demand
[simgrid.git] / src / surf / virtual_machine.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
9 #include <xbt/base.h>
10
11 #include "src/surf/HostImpl.hpp"
12
13 #ifndef VM_INTERFACE_HPP_
14 #define VM_INTERFACE_HPP_
15
16 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
17                           // It corresponds to the cost of a VM running no tasks.
18
19 namespace simgrid {
20 namespace surf {
21
22 /***********
23  * Classes *
24  ***********/
25
26 class XBT_PRIVATE VMModel;
27 class XBT_PRIVATE VirtualMachine;
28
29 /*************
30  * Callbacks *
31  *************/
32
33 /** @ingroup SURF_callbacks
34  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
35  */
36 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
40  */
41 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
45  */
46 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
47
48 /************
49  * Resource *
50  ************/
51
52 /** @ingroup SURF_vm_interface
53  * @brief SURF VM interface class
54  * @details A VM represent a virtual machine
55  */
56 class VirtualMachine : public HostImpl {
57 public:
58   VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
59   ~VirtualMachine();
60
61   /** @brief Suspend the VM */
62   virtual void suspend()=0;
63
64   /** @brief Resume the VM */
65   virtual void resume()=0;
66
67   /** @brief Save the VM (Not yet implemented) */
68   virtual void save()=0;
69
70   /** @brief Restore the VM (Not yet implemented) */
71   virtual void restore()=0;
72
73   /** @brief Migrate the VM to the destination host */
74   virtual void migrate(sg_host_t dest_PM)=0;
75
76   /** @brief Get the physical machine hosting the VM */
77   sg_host_t getPm();
78
79   virtual void setBound(double bound)=0;
80
81   /* The vm object of the lower layer */
82   CpuAction *action_;
83 protected:
84   simgrid::s4u::Host *hostPM_;
85
86 public:
87   void turnOn() override;
88   void turnOff() override;
89
90   e_surf_vm_state_t getState();
91   void setState(e_surf_vm_state_t state);
92 protected:
93   e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
94
95 public:
96   boost::intrusive::list_member_hook<> vm_hook;
97 };
98
99 /*********
100  * Model *
101  *********/
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
105  */
106 class VMModel : public HostModel {
107 public:
108   VMModel() :HostModel(){}
109   ~VMModel(){};
110
111   /**
112    * @brief Create a new VM
113    *
114    * @param name The name of the new VM
115    * @param host_PM The real machine hosting the VM
116    */
117   virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0;
118   void adjustWeightOfDummyCpuActions() {};
119
120   typedef boost::intrusive::member_hook<
121     VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
122   typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
123   static vm_list_t ws_vms;
124 };
125
126 }
127 }
128
129 #endif /* VM_INTERFACE_HPP_ */