Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf::Host don't need no netcard
[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 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
37 XBT_PUBLIC(void) host_add_traces();
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::Host, Host> EXTENSION_ID;
80
81   /* callbacks */
82   static simgrid::surf::signal<void(Host*)> onCreation;    /** Called on each newly created object */
83   static simgrid::surf::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
84   static simgrid::surf::signal<void(Host*)> onStateChange; /** Called when the machine is turned on or off */
85
86 public:
87   /**
88    * @brief Host constructor
89    *
90    * @param model HostModel associated to this Host
91    * @param name The name of the Host
92    * @param props Dictionary of properties associated to this Host
93    * @param storage The Storage associated to this Host
94    * @param cpu The Cpu associated to this Host
95    */
96   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
97                       xbt_dynar_t storage, Cpu *cpu);
98
99   /**
100    * @brief Host constructor
101    *
102    * @param model HostModel associated to this Host
103    * @param name The name of the Host
104    * @param props Dictionary of properties associated to this Host
105    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
106    * @param storage The Storage associated to this Host
107    * @param cpu The Cpu associated to this Host
108    */
109   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
110       lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
111
112   /* Host destruction logic */
113   /**************************/
114 protected:
115   ~Host();
116 public:
117         void destroy(); // Must be called instead of the destructor
118 private:
119         bool currentlyDestroying_ = false;
120
121
122 public:
123   void attach(simgrid::Host* host);
124
125   bool isOn() override;
126   bool isOff() override;
127   void turnOn() override;
128   void turnOff() override;
129
130   /** @brief Return the storage of corresponding mount point */
131   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
132
133   /** @brief Get the xbt_dict_t of mount_point: Storage */
134   virtual xbt_dict_t getMountedStorageList();
135
136   /** @brief Get the xbt_dynar_t of storages attached to the Host */
137   virtual xbt_dynar_t getAttachedStorageList();
138
139   /**
140    * @brief Open a file
141    *
142    * @param fullpath The full path to the file
143    * @return The StorageAction corresponding to the opening
144    */
145   virtual Action *open(const char* fullpath);
146
147   /**
148    * @brief Close a file
149    *
150    * @param fd The file descriptor to close
151    * @return The StorageAction corresponding to the closing
152    */
153   virtual Action *close(surf_file_t fd);
154
155   /**
156    * @brief Unlink a file
157    * @details [long description]
158    *
159    * @param fd [description]
160    * @return [description]
161    */
162   virtual int unlink(surf_file_t fd);
163
164   /**
165    * @brief Get the size in bytes of the file
166    *
167    * @param fd The file descriptor to read
168    * @return The size in bytes of the file
169    */
170   virtual sg_size_t getSize(surf_file_t fd);
171
172   /**
173    * @brief Read a file
174    *
175    * @param fd The file descriptor to read
176    * @param size The size in bytes to read
177    * @return The StorageAction corresponding to the reading
178    */
179   virtual Action *read(surf_file_t fd, sg_size_t size);
180
181   /**
182    * @brief Write a file
183    *
184    * @param fd The file descriptor to write
185    * @param size The size in bytes to write
186    * @return The StorageAction corresponding to the writing
187    */
188   virtual Action *write(surf_file_t fd, sg_size_t size);
189
190   /**
191    * @brief Get the informations of a file descriptor
192    * @details The returned xbt_dynar_t contains:
193    *  - the size of the file,
194    *  - the mount point,
195    *  - the storage name,
196    *  - the storage typeId,
197    *  - the storage content type
198    *
199    * @param fd The file descriptor
200    * @return An xbt_dynar_t with the file informations
201    */
202   virtual xbt_dynar_t getInfo(surf_file_t fd);
203
204   /**
205    * @brief Get the current position of the file descriptor
206    *
207    * @param fd The file descriptor
208    * @return The current position of the file descriptor
209    */
210   virtual sg_size_t fileTell(surf_file_t fd);
211
212   /**
213    * @brief Set the position indicator associated with the file descriptor to a new position
214    * @details [long description]
215    *
216    * @param fd The file descriptor
217    * @param offset The offset from the origin
218    * @param origin Position used as a reference for the offset
219    *  - SEEK_SET: beginning of the file
220    *  - SEEK_CUR: current position indicator
221    *  - SEEK_END: end of the file
222    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
223    */
224   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
225
226   /**
227    * @brief Move a file to another location on the *same mount point*.
228    * @details [long description]
229    *
230    * @param fd The file descriptor
231    * @param fullpath The new full path
232    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
233    * full path is not on the same mount point
234    */
235   virtual int fileMove(surf_file_t fd, const char* fullpath);
236
237   bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
238   void updateState(tmgr_trace_event_t event_type, double value, double date) override
239     {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
240
241 public:
242   xbt_dynar_t p_storage;
243   Cpu *p_cpu;
244   simgrid::Host* p_host = nullptr;
245
246   /** @brief Get the list of virtual machines on the current Host */
247   xbt_dynar_t getVms();
248
249   /* common with vm */
250   /** @brief Retrieve a copy of the parameters of that VM/PM
251    *  @details The ramsize and overcommit fields are used on the PM too */
252   void getParams(vm_params_t params);
253   /** @brief Sets the params of that VM/PM */
254   void setParams(vm_params_t params);
255   simgrid::Host* getHost() { return p_host; }
256 private:
257   s_vm_params_t p_params;
258 };
259
260 }
261 }
262
263 #endif /* SURF_Host_INTERFACE_HPP_ */