Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
32d94178df8344b42961a6442e0fe9d8a07c762c
[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   HostImpl *createHost(const char *name, kernel::routing::NetCard *net, Cpu *cpu);
55
56   virtual void adjustWeightOfDummyCpuActions();
57   virtual Action *executeParallelTask(int host_nb, sg_host_t *host_list,
58       double *flops_amount, double *bytes_amount, double rate);
59 };
60
61 /************
62  * Resource *
63  ************/
64 /** @ingroup SURF_host_interface
65  * @brief SURF Host interface class
66  * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
67  */
68 class HostImpl
69 : public simgrid::surf::Resource,
70   public simgrid::surf::PropertyHolder {
71 public:
72   static simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> EXTENSION_ID;
73
74 public:
75   /**
76    * @brief Host constructor
77    *
78    * @param model HostModel associated to this Host
79    * @param name The name of the Host
80    * @param storage The Storage associated to this Host
81    * @param cpu The Cpu associated to this Host
82    */
83   HostImpl(HostModel *model, const char *name, xbt_dynar_t storage, Cpu *cpu);
84
85   /**
86    * @brief Host constructor
87    *
88    * @param model HostModel associated to this Host
89    * @param name The name of the Host
90    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
91    * @param storage The Storage associated to this Host
92    * @param cpu The Cpu associated to this Host
93    */
94   HostImpl(HostModel *model, const char *name,
95       lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
96
97   /* Host destruction logic */
98   /**************************/
99   ~HostImpl() override;
100
101 public:
102   // Overload the method for covariant return type:
103   HostModel *getModel()
104   {
105     return static_cast<HostModel*>(Resource::getModel());
106   }
107   void attach(simgrid::s4u::Host* host);
108
109   bool isOn() const override;
110   bool isOff() const override;
111   void turnOn() override;
112   void turnOff() override;
113
114   /** @brief Return the storage of corresponding mount point */
115   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
116
117   /** @brief Get the xbt_dict_t of mount_point: Storage */
118   virtual xbt_dict_t getMountedStorageList();
119
120   /** @brief Get the xbt_dynar_t of storages attached to the Host */
121   virtual xbt_dynar_t getAttachedStorageList();
122
123   /**
124    * @brief Open a file
125    *
126    * @param fullpath The full path to the file
127    * @return The StorageAction corresponding to the opening
128    */
129   virtual Action *open(const char* fullpath);
130
131   /**
132    * @brief Close a file
133    *
134    * @param fd The file descriptor to close
135    * @return The StorageAction corresponding to the closing
136    */
137   virtual Action *close(surf_file_t fd);
138
139   /**
140    * @brief Unlink a file
141    * @details [long description]
142    *
143    * @param fd [description]
144    * @return [description]
145    */
146   virtual int unlink(surf_file_t fd);
147
148   /**
149    * @brief Get the size in bytes of the file
150    *
151    * @param fd The file descriptor to read
152    * @return The size in bytes of the file
153    */
154   virtual sg_size_t getSize(surf_file_t fd);
155
156   /**
157    * @brief Read a file
158    *
159    * @param fd The file descriptor to read
160    * @param size The size in bytes to read
161    * @return The StorageAction corresponding to the reading
162    */
163   virtual Action *read(surf_file_t fd, sg_size_t size);
164
165   /**
166    * @brief Write a file
167    *
168    * @param fd The file descriptor to write
169    * @param size The size in bytes to write
170    * @return The StorageAction corresponding to the writing
171    */
172   virtual Action *write(surf_file_t fd, sg_size_t size);
173
174   /**
175    * @brief Get the information of a file descriptor
176    * @details The returned xbt_dynar_t contains:
177    *  - the size of the file,
178    *  - the mount point,
179    *  - the storage name,
180    *  - the storage typeId,
181    *  - the storage content type
182    *
183    * @param fd The file descriptor
184    * @return An xbt_dynar_t with the file information
185    */
186   virtual xbt_dynar_t getInfo(surf_file_t fd);
187
188   /**
189    * @brief Get the current position of the file descriptor
190    *
191    * @param fd The file descriptor
192    * @return The current position of the file descriptor
193    */
194   virtual sg_size_t fileTell(surf_file_t fd);
195
196   /**
197    * @brief Set the position indicator associated with the file descriptor to a new position
198    * @details [long description]
199    *
200    * @param fd The file descriptor
201    * @param offset The offset from the origin
202    * @param origin Position used as a reference for the offset
203    *  - SEEK_SET: beginning of the file
204    *  - SEEK_CUR: current position indicator
205    *  - SEEK_END: end of the file
206    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
207    */
208   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
209
210   /**
211    * @brief Move a file to another location on the *same mount point*.
212    * @details [long description]
213    *
214    * @param fd The file descriptor
215    * @param fullpath The new full path
216    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
217    * full path is not on the same mount point
218    */
219   virtual int fileMove(surf_file_t fd, const char* fullpath);
220
221   bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
222   void apply_event(tmgr_trace_iterator_t event, double value) override
223     {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
224
225 public:
226   xbt_dynar_t storage_        = nullptr;
227   Cpu* cpu_                   = nullptr;
228   simgrid::s4u::Host* piface_ = nullptr;
229
230   /** @brief Get the list of virtual machines on the current Host */
231   xbt_dynar_t getVms();
232
233   /* common with vm */
234   /** @brief Retrieve a copy of the parameters of that VM/PM
235    *  @details The ramsize and overcommit fields are used on the PM too */
236   void getParams(vm_params_t params);
237   /** @brief Sets the params of that VM/PM */
238   void setParams(vm_params_t params);
239   simgrid::s4u::Host* getHost() { return piface_; }
240 private:
241   s_vm_params_t params_;
242 };
243
244 }
245 }
246
247 #endif /* SURF_Host_INTERFACE_HPP_ */