1 /* Copyright (c) 2004-2015. 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 fired after VM creation. Signature: `void(VM*)`
29 extern surf_callback(void, VM*) VMCreatedCallbacks;
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks fired after VM destruction. Signature: `void(VM*)`
34 extern surf_callback(void, VM*) VMDestructedCallbacks;
36 /** @ingroup SURF_callbacks
37 * @brief Callbacks after VM State changes. Signature: `void(VMAction*)`
39 extern surf_callback(void, VM*) VMStateChangedCallbacks;
44 /** @ingroup SURF_vm_interface
45 * @brief SURF VM model interface class
46 * @details A model is an object which handle the interactions between its Resources and its Actions
48 class VMModel : public HostModel {
50 VMModel() :HostModel(){}
53 Host *createHost(const char *name){DIE_IMPOSSIBLE;}
56 * @brief Create a new VM
58 * @param name The name of the new VM
59 * @param host_PM The real machine hosting the VM
62 virtual VM *createVM(const char *name, surf_resource_t host_PM)=0;
63 void adjustWeightOfDummyCpuActions() {};
65 typedef boost::intrusive::list<VM, boost::intrusive::constant_time_size<false> > vm_list_t;
66 static vm_list_t ws_vms;
73 /** @ingroup SURF_vm_interface
74 * @brief SURF VM interface class
75 * @details A VM represent a virtual machine
77 class VM : public Host,
78 public boost::intrusive::list_base_hook<> {
83 * @param model VMModel associated to this VM
84 * @param name The name of the VM
85 * @param props Dictionary of properties associated to this VM
86 * @param netElm The RoutingEdge associated to this VM
87 * @param cpu The Cpu associated to this VM
89 VM(Model *model, const char *name, xbt_dict_t props,
90 RoutingEdge *netElm, Cpu *cpu);
92 /** @brief Destructor */
95 void setState(e_surf_resource_state_t state);
97 /** @brief Suspend the VM */
98 virtual void suspend()=0;
100 /** @brief Resume the VM */
101 virtual void resume()=0;
103 /** @brief Save the VM (Not yet implemented) */
104 virtual void save()=0;
106 /** @brief Restore the VM (Not yet implemented) */
107 virtual void restore()=0;
109 /** @brief Migrate the VM to the destination host */
110 virtual void migrate(surf_resource_t dest_PM)=0;
112 /** @brief Get the physical machine hosting the VM */
113 virtual surf_resource_t getPm()=0;
115 virtual void setBound(double bound)=0;
116 virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
118 /* The vm object of the lower layer */
120 Host *p_subWs; // Pointer to the ''host'' OS
121 e_surf_vm_state_t p_currentState;
128 #endif /* VM_INTERFACE_HPP_ */