Logo AND Algorithmique Numérique Distribuée

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