Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fat trees progress
[simgrid.git] / src / surf / vm_workstation_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 "workstation_interface.hpp"
8
9 #ifndef VM_WORKSTATION_INTERFACE_HPP_
10 #define VM_WORKSTATION_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 void surf_vm_workstation_model_init(void);
16
17 /***********
18  * Classes *
19  ***********/
20
21 class WorkstationVMModel;
22 typedef WorkstationVMModel *WorkstationVMModelPtr;
23
24 class WorkstationVM;
25 typedef WorkstationVM *WorkstationVMPtr;
26
27 class WorkstationVMLmm;
28 typedef WorkstationVMLmm *WorkstationVMLmmPtr;
29
30 /*************
31  * Callbacks *
32  *************/
33
34 /** @ingroup SURF_callbacks
35  * @brief Callbacks handler which emit the callbacks after WorkstationVM creation *
36  * @details Callback functions have the following signature: `void(WorkstationVMPtr)`
37  */
38 extern surf_callback(void, WorkstationVMPtr) workstationVMCreatedCallbacks;
39
40 /** @ingroup SURF_callbacks
41  * @brief Callbacks handler which emit the callbacks after WorkstationVM destruction *
42  * @details Callback functions have the following signature: `void(WorkstationVMPtr)`
43  */
44 extern surf_callback(void, WorkstationVMPtr) workstationVMDestructedCallbacks;
45
46 /** @ingroup SURF_callbacks
47  * @brief Callbacks handler which emit the callbacks after WorkstationVM State changed *
48  * @details Callback functions have the following signature: `void(WorkstationVMActionPtr)`
49  */
50 extern surf_callback(void, WorkstationVMPtr) workstationVMStateChangedCallbacks;
51
52 /*********
53  * Model *
54  *********/
55 /** @ingroup SURF_vm_workstation_interface
56  * @brief SURF workstation VM model interface class
57  * @details A model is an object which handle the interactions between its Resources and its Actions
58  */
59 class WorkstationVMModel : public WorkstationModel {
60 public:
61   /**
62    * @brief WorkstationVMModel consrtuctor
63    */
64   WorkstationVMModel();
65
66     /**
67    * @brief WorkstationVMModel consrtuctor
68    */
69   ~WorkstationVMModel(){};
70
71   /**
72    * @brief Create a new WorkstationVM
73    * 
74    * @param name The name of the new WorkstationVM
75    * @param ind_phys_workstation The workstation hosting the VM
76    * 
77    */
78   virtual void createResource(const char *name, void *ind_phys_workstation)=0;
79
80   void adjustWeightOfDummyCpuActions() {};
81
82   typedef boost::intrusive::list<WorkstationVM,
83                                  boost::intrusive::constant_time_size<false> >
84           vm_list_t;
85   static vm_list_t ws_vms;
86 };
87
88 /************
89  * Resource *
90  ************/
91
92 /** @ingroup SURF_vm_workstation_interface
93  * @brief SURF workstation VM interface class
94  * @details A workstation VM represent an virtual machine
95  */
96 class WorkstationVM : public Workstation,
97                       public boost::intrusive::list_base_hook<> {
98 public:
99   /**
100    * @brief WorkstationVM consrtructor
101    * 
102    * @param model WorkstationModel associated to this Workstation
103    * @param name The name of the Workstation
104    * @param props Dictionary of properties associated to this Workstation
105    * @param netElm The RoutingEdge associated to this Workstation
106    * @param cpu The Cpu associated to this Workstation
107    */
108   WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
109                         RoutingEdgePtr netElm, CpuPtr cpu);
110
111   /**
112    * @brief WdorkstationVM destructor
113    */
114   ~WorkstationVM();
115
116   void setState(e_surf_resource_state_t state);
117
118   /**
119    * @brief Suspend the VM
120    */
121   virtual void suspend()=0;
122
123   /**
124    * @brief Resume the VM
125    */
126   virtual void resume()=0;
127
128   /**
129    * @brief Save the VM (Not yet implemented)
130    */
131   virtual void save()=0;
132
133   /**
134    * @brief Restore the VM (Not yet implemented)
135    */
136   virtual void restore()=0;
137
138   /**
139    * @brief Migrate the VM to the destination host
140    * 
141    * @param ind_vm_ws_dest The destination host
142    */
143   virtual void migrate(surf_resource_t ind_vm_ws_dest)=0;
144
145   /**
146    * @brief Get the physical machine hosting the VM
147    * @return The physical machine hosting the VM
148    */
149   virtual surf_resource_t getPm()=0;
150
151   virtual void setBound(double bound)=0;
152   virtual void setAffinity(CpuPtr cpu, unsigned long mask)=0;
153
154   /* The workstation object of the lower layer */
155   CpuActionPtr p_action;
156   WorkstationPtr p_subWs;  // Pointer to the ''host'' OS
157   e_surf_vm_state_t p_currentState;
158 };
159
160 /**********
161  * Action *
162  **********/
163
164 #endif /* VM_WORKSTATION_INTERFACE_HPP_ */