Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a8ddce849d307004d41f37240a4959d941dd49e4
[simgrid.git] / src / surf / vm_interface.hpp
1 /* Copyright (c) 2004-2014. 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 "host_interface.hpp"
8
9 #ifndef VM_INTERFACE_HPP_
10 #define VM_INTERFACE_HPP_
11
12 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
13                           // It corresponds to the cost of a VM running no tasks.
14
15 /***********
16  * Classes *
17  ***********/
18
19 class VMModel;
20 typedef VMModel *VMModelPtr;
21
22 class VM;
23 typedef VM *VMPtr;
24
25 class VMLmm;
26 typedef VMLmm *VMLmmPtr;
27
28 /*************
29  * Callbacks *
30  *************/
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks handler which emit the callbacks after VM creation *
34  * @details Callback functions have the following signature: `void(VMPtr)`
35  */
36 extern surf_callback(void, VMPtr) VMCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks handler which emit the callbacks after VM destruction *
40  * @details Callback functions have the following signature: `void(VMPtr)`
41  */
42 extern surf_callback(void, VMPtr) VMDestructedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks handler which emit the callbacks after VM State changed *
46  * @details Callback functions have the following signature: `void(VMActionPtr)`
47  */
48 extern surf_callback(void, VMPtr) VMStateChangedCallbacks;
49
50 /*********
51  * Model *
52  *********/
53 /** @ingroup SURF_vm_interface
54  * @brief SURF VM model interface class
55  * @details A model is an object which handle the interactions between its Resources and its Actions
56  */
57 class VMModel : public HostModel {
58 public:
59   VMModel();
60   ~VMModel(){};
61
62   HostPtr createHost(const char *name){DIE_IMPOSSIBLE;}
63
64   /**
65    * @brief Create a new VM
66    *
67    * @param name The name of the new VM
68    * @param host_PM The real machine hosting the VM
69    *
70    */
71   virtual VMPtr createVM(const char *name, surf_resource_t host_PM)=0;
72   void adjustWeightOfDummyCpuActions() {};
73
74   typedef boost::intrusive::list<VM,
75                                  boost::intrusive::constant_time_size<false> >
76           vm_list_t;
77   static vm_list_t ws_vms;
78 };
79
80 /************
81  * Resource *
82  ************/
83
84 /** @ingroup SURF_vm_interface
85  * @brief SURF VM interface class
86  * @details A VM represent a virtual machine
87  */
88 class VM : public Host,
89            public boost::intrusive::list_base_hook<> {
90 public:
91   /**
92    * @brief VM constructor
93    *
94    * @param model VMModel associated to this VM
95    * @param name The name of the VM
96    * @param props Dictionary of properties associated to this VM
97    * @param netElm The RoutingEdge associated to this VM
98    * @param cpu The Cpu associated to this VM
99    */
100   VM(ModelPtr model, const char *name, xbt_dict_t props,
101                         RoutingEdgePtr netElm, CpuPtr cpu);
102
103   /**
104    * @brief WdorkstationVM destructor
105    */
106   ~VM();
107
108   void setState(e_surf_resource_state_t state);
109
110   /**
111    * @brief Suspend the VM
112    */
113   virtual void suspend()=0;
114
115   /**
116    * @brief Resume the VM
117    */
118   virtual void resume()=0;
119
120   /**
121    * @brief Save the VM (Not yet implemented)
122    */
123   virtual void save()=0;
124
125   /**
126    * @brief Restore the VM (Not yet implemented)
127    */
128   virtual void restore()=0;
129
130   /**
131    * @brief Migrate the VM to the destination host
132    *
133    * @param ind_vm_ws_dest The destination host
134    */
135   virtual void migrate(surf_resource_t ind_vm_ws_dest)=0;
136
137   /**
138    * @brief Get the physical machine hosting the VM
139    * @return The physical machine hosting the VM
140    */
141   virtual surf_resource_t getPm()=0;
142
143   virtual void setBound(double bound)=0;
144   virtual void setAffinity(CpuPtr cpu, unsigned long mask)=0;
145
146   /* The vm object of the lower layer */
147   CpuActionPtr p_action;
148   HostPtr p_subWs;  // Pointer to the ''host'' OS
149   e_surf_vm_state_t p_currentState;
150 };
151
152 /**********
153  * Action *
154  **********/
155
156 #endif /* VM_INTERFACE_HPP_ */