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 "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE Host;
27 class XBT_PRIVATE HostAction;
37 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
38 XBT_PUBLIC(void) host_add_traces();
47 /** @ingroup SURF_host_interface
48 * @brief SURF Host model interface class
49 * @details A model is an object which handle the interactions between its Resources and its Actions
51 class HostModel : public Model{
53 HostModel() : Model() {}
56 Host *createHost(const char *name, NetCard *net, Cpu *cpu, xbt_dict_t props);
57 void addTraces() override {DIE_IMPOSSIBLE;}
59 virtual void adjustWeightOfDummyCpuActions();
60 virtual Action *executeParallelTask(int host_nb,
66 bool shareResourcesIsIdempotent() override {return true;}
72 /** @ingroup SURF_host_interface
73 * @brief SURF Host interface class
74 * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
77 public simgrid::surf::Resource,
78 public simgrid::surf::PropertyHolder {
80 static simgrid::xbt::Extension<simgrid::s4u::Host, Host> EXTENSION_ID;
83 static void classInit(); // must be called before the first use of that class
85 * @brief Host constructor
87 * @param model HostModel associated to this Host
88 * @param name The name of the Host
89 * @param props Dictionary of properties associated to this Host
90 * @param storage The Storage associated to this Host
91 * @param cpu The Cpu associated to this Host
93 Host(HostModel *model, const char *name, xbt_dict_t props,
94 xbt_dynar_t storage, Cpu *cpu);
97 * @brief Host constructor
99 * @param model HostModel associated to this Host
100 * @param name The name of the Host
101 * @param props Dictionary of properties associated to this Host
102 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
103 * @param storage The Storage associated to this Host
104 * @param cpu The Cpu associated to this Host
106 Host(HostModel *model, const char *name, xbt_dict_t props,
107 lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
109 /* Host destruction logic */
110 /**************************/
114 HostModel *getModel()
116 return static_cast<HostModel*>(Resource::getModel());
118 void attach(simgrid::s4u::Host* host);
120 bool isOn() override;
121 bool isOff() override;
122 void turnOn() override;
123 void turnOff() override;
125 /** @brief Return the storage of corresponding mount point */
126 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
128 /** @brief Get the xbt_dict_t of mount_point: Storage */
129 virtual xbt_dict_t getMountedStorageList();
131 /** @brief Get the xbt_dynar_t of storages attached to the Host */
132 virtual xbt_dynar_t getAttachedStorageList();
137 * @param fullpath The full path to the file
138 * @return The StorageAction corresponding to the opening
140 virtual Action *open(const char* fullpath);
143 * @brief Close a file
145 * @param fd The file descriptor to close
146 * @return The StorageAction corresponding to the closing
148 virtual Action *close(surf_file_t fd);
151 * @brief Unlink a file
152 * @details [long description]
154 * @param fd [description]
155 * @return [description]
157 virtual int unlink(surf_file_t fd);
160 * @brief Get the size in bytes of the file
162 * @param fd The file descriptor to read
163 * @return The size in bytes of the file
165 virtual sg_size_t getSize(surf_file_t fd);
170 * @param fd The file descriptor to read
171 * @param size The size in bytes to read
172 * @return The StorageAction corresponding to the reading
174 virtual Action *read(surf_file_t fd, sg_size_t size);
177 * @brief Write a file
179 * @param fd The file descriptor to write
180 * @param size The size in bytes to write
181 * @return The StorageAction corresponding to the writing
183 virtual Action *write(surf_file_t fd, sg_size_t size);
186 * @brief Get the informations of a file descriptor
187 * @details The returned xbt_dynar_t contains:
188 * - the size of the file,
190 * - the storage name,
191 * - the storage typeId,
192 * - the storage content type
194 * @param fd The file descriptor
195 * @return An xbt_dynar_t with the file informations
197 virtual xbt_dynar_t getInfo(surf_file_t fd);
200 * @brief Get the current position of the file descriptor
202 * @param fd The file descriptor
203 * @return The current position of the file descriptor
205 virtual sg_size_t fileTell(surf_file_t fd);
208 * @brief Set the position indicator associated with the file descriptor to a new position
209 * @details [long description]
211 * @param fd The file descriptor
212 * @param offset The offset from the origin
213 * @param origin Position used as a reference for the offset
214 * - SEEK_SET: beginning of the file
215 * - SEEK_CUR: current position indicator
216 * - SEEK_END: end of the file
217 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
219 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
222 * @brief Move a file to another location on the *same mount point*.
223 * @details [long description]
225 * @param fd The file descriptor
226 * @param fullpath The new full path
227 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
228 * full path is not on the same mount point
230 virtual int fileMove(surf_file_t fd, const char* fullpath);
232 bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
233 void updateState(tmgr_trace_event_t event_type, double value, double date) override
234 {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
237 xbt_dynar_t p_storage;
239 simgrid::s4u::Host* p_host = nullptr;
241 /** @brief Get the list of virtual machines on the current Host */
242 xbt_dynar_t getVms();
245 /** @brief Retrieve a copy of the parameters of that VM/PM
246 * @details The ramsize and overcommit fields are used on the PM too */
247 void getParams(vm_params_t params);
248 /** @brief Sets the params of that VM/PM */
249 void setParams(vm_params_t params);
250 simgrid::s4u::Host* getHost() { return p_host; }
252 s_vm_params_t p_params;
258 #endif /* SURF_Host_INTERFACE_HPP_ */