1 /* Copyright (c) 2004-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "host_interface.hpp"
9 #ifndef VM_INTERFACE_HPP_
10 #define VM_INTERFACE_HPP_
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.
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)`
30 extern surf_callback(void, VM*) VMCreatedCallbacks;
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)`
36 extern surf_callback(void, VM*) VMDestructedCallbacks;
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)`
42 extern surf_callback(void, VM*) VMStateChangedCallbacks;
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
51 class VMModel : public HostModel {
56 Host *createHost(const char *name){DIE_IMPOSSIBLE;}
59 * @brief Create a new VM
61 * @param name The name of the new VM
62 * @param host_PM The real machine hosting the VM
65 virtual VM *createVM(const char *name, surf_resource_t host_PM)=0;
66 void adjustWeightOfDummyCpuActions() {};
68 typedef boost::intrusive::list<VM,
69 boost::intrusive::constant_time_size<false> >
71 static vm_list_t ws_vms;
78 /** @ingroup SURF_vm_interface
79 * @brief SURF VM interface class
80 * @details A VM represent a virtual machine
82 class VM : public Host,
83 public boost::intrusive::list_base_hook<> {
86 * @brief VM constructor
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
94 VM(Model *model, const char *name, xbt_dict_t props,
95 RoutingEdge *netElm, Cpu *cpu);
98 * @brief WdorkstationVM destructor
102 void setState(e_surf_resource_state_t state);
105 * @brief Suspend the VM
107 virtual void suspend()=0;
110 * @brief Resume the VM
112 virtual void resume()=0;
115 * @brief Save the VM (Not yet implemented)
117 virtual void save()=0;
120 * @brief Restore the VM (Not yet implemented)
122 virtual void restore()=0;
125 * @brief Migrate the VM to the destination host
127 * @param ind_vm_ws_dest The destination host
129 virtual void migrate(surf_resource_t ind_vm_ws_dest)=0;
132 * @brief Get the physical machine hosting the VM
133 * @return The physical machine hosting the VM
135 virtual surf_resource_t getPm()=0;
137 virtual void setBound(double bound)=0;
138 virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
140 /* The vm object of the lower layer */
142 Host *p_subWs; // Pointer to the ''host'' OS
143 e_surf_vm_state_t p_currentState;
150 #endif /* VM_INTERFACE_HPP_ */