Logo AND Algorithmique Numérique Distribuée

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