Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6ae01d5f5c1953e2430bddefb6f989da562c7185
[simgrid.git] / src / surf / HostImpl.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 "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
12
13 #include <xbt/base.h>
14
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
17
18 /***********
19  * Classes *
20  ***********/
21
22 namespace simgrid {
23 namespace surf {
24
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE HostImpl;
27 class XBT_PRIVATE HostAction;
28
29
30 }
31 }
32
33 /*********
34  * Tools *
35  *********/
36
37 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
38
39 /*********
40  * Model *
41  *********/
42
43 namespace simgrid {
44 namespace surf {
45
46 /** @ingroup SURF_host_interface
47  * @brief SURF Host model interface class
48  * @details A model is an object which handle the interactions between its Resources and its Actions
49  */
50 class HostModel : public Model {
51 public:
52   HostModel() : Model() {}
53
54   virtual void adjustWeightOfDummyCpuActions();
55   virtual Action *executeParallelTask(int host_nb, sg_host_t *host_list,
56       double *flops_amount, double *bytes_amount, double rate);
57 };
58
59 /************
60  * Resource *
61  ************/
62 /** @ingroup SURF_host_interface
63  * @brief SURF Host interface class
64  * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
65  */
66 class HostImpl
67 : public simgrid::surf::Resource,
68   public simgrid::surf::PropertyHolder {
69
70 public:
71   /**
72    * @brief Host constructor
73    *
74    * @param model HostModel associated to this Host
75    * @param name The name of the Host
76    * @param storage The Storage associated to this Host
77    */
78   HostImpl(HostModel* model, const char* name, xbt_dynar_t storage);
79
80   /**
81    * @brief Host constructor
82    *
83    * @param model HostModel associated to this Host
84    * @param name The name of the Host
85    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
86    * @param storage The Storage associated to this Host
87    */
88   HostImpl(HostModel* model, const char* name, lmm_constraint_t constraint, xbt_dynar_t storage);
89
90   /* Host destruction logic */
91   /**************************/
92   ~HostImpl() override;
93
94 public:
95   // Overload the method for covariant return type:
96   HostModel *getModel()
97   {
98     return static_cast<HostModel*>(Resource::getModel());
99   }
100   void attach(simgrid::s4u::Host* host);
101
102   /** @brief Return the storage of corresponding mount point */
103   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
104
105   /** @brief Get the xbt_dict_t of mount_point: Storage */
106   virtual xbt_dict_t getMountedStorageList();
107
108   /** @brief Get the xbt_dynar_t of storages attached to the Host */
109   virtual xbt_dynar_t getAttachedStorageList();
110
111   /**
112    * @brief Open a file
113    *
114    * @param fullpath The full path to the file
115    * @return The StorageAction corresponding to the opening
116    */
117   virtual Action *open(const char* fullpath);
118
119   /**
120    * @brief Close a file
121    *
122    * @param fd The file descriptor to close
123    * @return The StorageAction corresponding to the closing
124    */
125   virtual Action *close(surf_file_t fd);
126
127   /**
128    * @brief Unlink a file
129    * @details [long description]
130    *
131    * @param fd [description]
132    * @return [description]
133    */
134   virtual int unlink(surf_file_t fd);
135
136   /**
137    * @brief Get the size in bytes of the file
138    *
139    * @param fd The file descriptor to read
140    * @return The size in bytes of the file
141    */
142   virtual sg_size_t getSize(surf_file_t fd);
143
144   /**
145    * @brief Read a file
146    *
147    * @param fd The file descriptor to read
148    * @param size The size in bytes to read
149    * @return The StorageAction corresponding to the reading
150    */
151   virtual Action *read(surf_file_t fd, sg_size_t size);
152
153   /**
154    * @brief Write a file
155    *
156    * @param fd The file descriptor to write
157    * @param size The size in bytes to write
158    * @return The StorageAction corresponding to the writing
159    */
160   virtual Action *write(surf_file_t fd, sg_size_t size);
161
162   /**
163    * @brief Get the information of a file descriptor
164    * @details The returned xbt_dynar_t contains:
165    *  - the size of the file,
166    *  - the mount point,
167    *  - the storage name,
168    *  - the storage typeId,
169    *  - the storage content type
170    *
171    * @param fd The file descriptor
172    * @return An xbt_dynar_t with the file information
173    */
174   virtual xbt_dynar_t getInfo(surf_file_t fd);
175
176   /**
177    * @brief Get the current position of the file descriptor
178    *
179    * @param fd The file descriptor
180    * @return The current position of the file descriptor
181    */
182   virtual sg_size_t fileTell(surf_file_t fd);
183
184   /**
185    * @brief Set the position indicator associated with the file descriptor to a new position
186    * @details [long description]
187    *
188    * @param fd The file descriptor
189    * @param offset The offset from the origin
190    * @param origin Position used as a reference for the offset
191    *  - SEEK_SET: beginning of the file
192    *  - SEEK_CUR: current position indicator
193    *  - SEEK_END: end of the file
194    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
195    */
196   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
197
198   /**
199    * @brief Move a file to another location on the *same mount point*.
200    * @details [long description]
201    *
202    * @param fd The file descriptor
203    * @param fullpath The new full path
204    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
205    * full path is not on the same mount point
206    */
207   virtual int fileMove(surf_file_t fd, const char* fullpath);
208
209   bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
210   void apply_event(tmgr_trace_iterator_t event, double value) override
211     {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
212
213 public:
214   xbt_dynar_t storage_        = nullptr;
215   simgrid::s4u::Host* piface_ = nullptr;
216
217   /** @brief Get the list of virtual machines on the current Host */
218   xbt_dynar_t getVms();
219
220   /* common with vm */
221   /** @brief Retrieve a copy of the parameters of that VM/PM
222    *  @details The ramsize and overcommit fields are used on the PM too */
223   void getParams(vm_params_t params);
224   /** @brief Sets the params of that VM/PM */
225   void setParams(vm_params_t params);
226   simgrid::s4u::Host* getHost() { return piface_; }
227 private:
228   s_vm_params_t params_;
229 };
230
231 }
232 }
233
234 #endif /* SURF_Host_INTERFACE_HPP_ */