Logo AND Algorithmique Numérique Distribuée

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