Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
795ae2ef8e89549934bcd0e721ed04a54ba216f7
[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 <xbt/base.h>
8
9 #include "host_interface.hpp"
10
11 #ifndef VM_INTERFACE_HPP_
12 #define VM_INTERFACE_HPP_
13
14 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
15                           // It corresponds to the cost of a VM running no tasks.
16
17 namespace simgrid {
18 namespace surf {
19
20 /***********
21  * Classes *
22  ***********/
23
24 class XBT_PRIVATE VMModel;
25 class XBT_PRIVATE VirtualMachine;
26
27 /*************
28  * Callbacks *
29  *************/
30
31 /** @ingroup SURF_callbacks
32  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
33  */
34 extern XBT_PRIVATE surf_callback(void, simgrid::surf::VirtualMachine*) VMCreatedCallbacks;
35
36 /** @ingroup SURF_callbacks
37  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
38  */
39 extern XBT_PRIVATE surf_callback(void, simgrid::surf::VirtualMachine*) VMDestructedCallbacks;
40
41 /** @ingroup SURF_callbacks
42  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
43  */
44 extern XBT_PRIVATE surf_callback(void, simgrid::surf::VirtualMachine*) VMStateChangedCallbacks;
45
46 /************
47  * Resource *
48  ************/
49
50 /** @ingroup SURF_vm_interface
51  * @brief SURF VM interface class
52  * @details A VM represent a virtual machine
53  */
54 class VirtualMachine : public Host {
55 public:
56   /**
57    * @brief Constructor
58    *
59    * @param model VMModel associated to this VM
60    * @param name The name of the VM
61    * @param props Dictionary of properties associated to this VM
62    * @param netElm The RoutingEdge associated to this VM
63    * @param cpu The Cpu associated to this VM
64    */
65   VirtualMachine(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
66                         RoutingEdge *netElm, Cpu *cpu);
67
68   /** @brief Destructor */
69   ~VirtualMachine();
70
71   void setState(e_surf_resource_state_t state);
72
73   /** @brief Suspend the VM */
74   virtual void suspend()=0;
75
76   /** @brief Resume the VM */
77   virtual void resume()=0;
78
79   /** @brief Save the VM (Not yet implemented) */
80   virtual void save()=0;
81
82   /** @brief Restore the VM (Not yet implemented) */
83   virtual void restore()=0;
84
85   /** @brief Migrate the VM to the destination host */
86   virtual void migrate(surf_resource_t dest_PM)=0;
87
88   /** @brief Get the physical machine hosting the VM */
89   virtual surf_resource_t getPm()=0;
90
91   virtual void setBound(double bound)=0;
92   virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
93
94   /* The vm object of the lower layer */
95   CpuAction *p_action;
96   Host *p_subWs;
97   e_surf_vm_state_t p_currentState;
98 public:
99   boost::intrusive::list_member_hook<> vm_hook;
100 };
101
102 /*********
103  * Model *
104  *********/
105 /** @ingroup SURF_vm_interface
106  * @brief SURF VM model interface class
107  * @details A model is an object which handle the interactions between its Resources and its Actions
108  */
109 class VMModel : public HostModel {
110 public:
111   VMModel() :HostModel(){}
112   ~VMModel(){};
113
114   Host *createHost(const char *name, RoutingEdge *netElm, Cpu *cpu){DIE_IMPOSSIBLE;}
115
116   /**
117    * @brief Create a new VM
118    *
119    * @param name The name of the new VM
120    * @param host_PM The real machine hosting the VM
121    *
122    */
123   virtual VirtualMachine *createVM(const char *name, surf_resource_t host_PM)=0;
124   void adjustWeightOfDummyCpuActions() {};
125
126   typedef boost::intrusive::member_hook<
127     VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
128   typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
129   static vm_list_t ws_vms;
130 };
131
132 /**********
133  * Action *
134  **********/
135
136 }
137 }
138
139 #endif /* VM_INTERFACE_HPP_ */