Logo AND Algorithmique Numérique Distribuée

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