Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
efcefc4cc75b7fefd49f9cbc70df5a9e3c4e4890
[simgrid.git] / src / surf / vm_interface.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 "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 fired after VM creation. Signature: `void(VM*)`
28  */
29 extern surf_callback(void, VM*) VMCreatedCallbacks;
30
31 /** @ingroup SURF_callbacks
32  * @brief Callbacks fired after VM destruction. Signature: `void(VM*)`
33  */
34 extern surf_callback(void, VM*) VMDestructedCallbacks;
35
36 /** @ingroup SURF_callbacks
37  * @brief Callbacks after VM State changes. Signature: `void(VMAction*)`
38  */
39 extern surf_callback(void, VM*) VMStateChangedCallbacks;
40
41 /************
42  * Resource *
43  ************/
44
45 /** @ingroup SURF_vm_interface
46  * @brief SURF VM interface class
47  * @details A VM represent a virtual machine
48  */
49 class VM : public Host {
50 public:
51   /**
52    * @brief Constructor
53    *
54    * @param model VMModel associated to this VM
55    * @param name The name of the VM
56    * @param props Dictionary of properties associated to this VM
57    * @param netElm The RoutingEdge associated to this VM
58    * @param cpu The Cpu associated to this VM
59    */
60   VM(Model *model, const char *name, xbt_dict_t props,
61                         RoutingEdge *netElm, Cpu *cpu);
62
63   /** @brief Destructor */
64   ~VM();
65
66   void setState(e_surf_resource_state_t state);
67
68   /** @brief Suspend the VM */
69   virtual void suspend()=0;
70
71   /** @brief Resume the VM */
72   virtual void resume()=0;
73
74   /** @brief Save the VM (Not yet implemented) */
75   virtual void save()=0;
76
77   /** @brief Restore the VM (Not yet implemented) */
78   virtual void restore()=0;
79
80   /** @brief Migrate the VM to the destination host */
81   virtual void migrate(surf_resource_t dest_PM)=0;
82
83   /** @brief Get the physical machine hosting the VM */
84   virtual surf_resource_t getPm()=0;
85
86   virtual void setBound(double bound)=0;
87   virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
88
89   /* The vm object of the lower layer */
90   CpuAction *p_action;
91   Host *p_subWs;  // Pointer to the ''host'' OS
92   e_surf_vm_state_t p_currentState;
93 public:
94   boost::intrusive::list_member_hook<> vm_hook;
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   VMModel() :HostModel(){}
107   ~VMModel(){};
108
109   Host *createHost(const char *name){DIE_IMPOSSIBLE;}
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    */
118   virtual VM *createVM(const char *name, surf_resource_t host_PM)=0;
119   void adjustWeightOfDummyCpuActions() {};
120
121   typedef boost::intrusive::member_hook<
122     VM, boost::intrusive::list_member_hook<>, &VM::vm_hook> VmOptions;
123   typedef boost::intrusive::list<VM, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
124   static vm_list_t ws_vms;
125 };
126
127 /**********
128  * Action *
129  **********/
130
131 #endif /* VM_INTERFACE_HPP_ */