Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'torus'
[simgrid.git] / src / surf / network_interface.hpp
1 /* Copyright (c) 2004-2013. 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 "surf_routing.hpp"
9
10 #ifndef SURF_NETWORK_INTERFACE_HPP_
11 #define SURF_NETWORK_INTERFACE_HPP_
12
13 /***********
14  * Classes *
15  ***********/
16 class NetworkModel;
17 typedef NetworkModel *NetworkModelPtr;
18
19 class NetworkLink;
20 typedef NetworkLink *NetworkLinkPtr;
21
22 class NetworkAction;
23 typedef NetworkAction *NetworkActionPtr;
24
25 /*********
26  * Tools *
27  *********/
28
29 void net_define_callbacks(void);
30
31 /*********
32  * Model *
33  *********/
34 /** @ingroup SURF_network_interface
35  * @brief SURF network model interface class
36  * @details A model is an object which handle the interactions between its Resources and its Actions
37  */
38 class NetworkModel : public Model {
39 public:
40   /**
41    * @brief NetworkModel constructor
42    */
43   NetworkModel() : Model("network") {
44   };
45
46   /**
47    * @brief NetworkModel constructor
48    * 
49    * @param name The name of the NetworkModel
50    */
51   NetworkModel(const char *name) : Model(name) {
52         f_networkSolve = lmm_solve;
53         m_haveGap = false;
54   };
55
56   /**
57    * @brief The destructor of the NetworkModel
58    */
59   ~NetworkModel() {
60         if (p_maxminSystem)
61           lmm_system_free(p_maxminSystem);
62         if (p_actionHeap)
63           xbt_heap_free(p_actionHeap);
64         if (p_modifiedSet)
65           delete p_modifiedSet;
66   }
67
68   /**
69    * @brief Create a NetworkLink
70    * 
71    * @param name The name of the NetworkLink
72    * @param bw_initial The initial bandwidth of the NetworkLink in bytes per second
73    * @param bw_trace The trace associated to the NetworkLink bandwidth [TODO]
74    * @param lat_initial The initial latency of the NetworkLink in seconds
75    * @param lat_trace The trace associated to the NetworkLink latency [TODO]
76    * @param state_initial The initial NetworkLink (state)[e_surf_resource_state_t]
77    * @param state_trace The trace associated to the NetworkLink (state)[e_surf_resource_state_t] [TODO]
78    * @param policy The sharing policy of the NetworkLink
79    * @param properties Dictionary of properties associated to this Resource
80    * @return The created NetworkLink
81    */
82   virtual NetworkLinkPtr createResource(const char *name,
83                                    double bw_initial,
84                                    tmgr_trace_t bw_trace,
85                                    double lat_initial,
86                                    tmgr_trace_t lat_trace,
87                                    e_surf_resource_state_t state_initial,
88                                    tmgr_trace_t state_trace,
89                                    e_surf_link_sharing_policy_t policy,
90                                    xbt_dict_t properties)=0;
91
92
93   virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
94
95   /**
96    * @brief Create a communication between two [TODO]
97    * @details [TODO]
98    * 
99    * @param src The source [TODO]
100    * @param dst The destination [TODO]
101    * @param size The size of the communication in bytes
102    * @param rate The 
103    * @return The action representing the communication
104    */
105   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
106                                            double size, double rate)=0;
107
108   /**
109    * @brief Get the route between two RoutingEdge
110    * @details [TODO]
111    * 
112    * @param src [TODO]
113    * @param dst [TODO]
114    * 
115    * @return A xbt_dynar_t of [TODO]
116    */
117   virtual xbt_dynar_t getRoute(RoutingEdgePtr src, RoutingEdgePtr dst); //FIXME: kill field? That is done by the routing nowadays
118
119   /**
120    * @brief Function pointer to the function to use to solve the lmm_system_t
121    * 
122    * @param system The lmm_system_t to solve
123    */
124   void (*f_networkSolve)(lmm_system_t);
125
126   /**
127    * @brief [brief description]
128    * @details [long description]
129    * 
130    * @param size [description]
131    * @return [description]
132    */
133   virtual double latencyFactor(double size);
134
135   /**
136    * @brief [brief description]
137    * @details [long description]
138    * 
139    * @param size [description]
140    * @return [description]
141    */
142   virtual double bandwidthFactor(double size);
143
144   /**
145    * @brief [brief description]
146    * @details [long description]
147    * 
148    * @param rate [description]
149    * @param bound [description]
150    * @param size [description]
151    * @return [description]
152    */
153   virtual double bandwidthConstraint(double rate, double bound, double size);
154   bool m_haveGap;
155 };
156
157 /************
158  * Resource *
159  ************/
160  /** @ingroup SURF_network_interface
161   * @brief SURF network link interface class
162   * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
163   */
164 class NetworkLink : public Resource {
165 public:
166   /**
167    * @brief NetworkLink constructor
168    * 
169    * @param model The CpuModel associated to this NetworkLink
170    * @param name The name of the NetworkLink
171    * @param props Dictionary of properties associated to this NetworkLink
172    */
173   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
174
175   /**
176    * @brief NetworkLink constructor
177    * 
178    * @param model The CpuModel associated to this NetworkLink
179    * @param name The name of the NetworkLink
180    * @param props Dictionary of properties associated to this NetworkLink
181    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
182    * @param history [TODO]
183    * @param state_trace [TODO]
184    */
185   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
186                       lmm_constraint_t constraint,
187                   tmgr_history_t history,
188                   tmgr_trace_t state_trace);
189
190   /**
191    * @brief Get the bandwidth in bytes per second of current NetworkLink
192    * 
193    * @return The bandwith in bytes per second of the current NetworkLink
194    */
195   virtual double getBandwidth();
196
197   /**
198    * @brief Get the latency in seconds of current NetworkLink
199    * 
200    * @return The latency in seconds of the current NetworkLink
201    */
202   virtual double getLatency();
203
204   /**
205    * @brief Check if the NetworkLink is shared
206    * @details [long description]
207    * 
208    * @return true if the current NetwokrLink is shared, false otherwise
209    */
210   virtual bool isShared();
211
212   /**
213    * @brief Check if the NetworkLink is used
214    * 
215    * @return true if the current NetwokrLink is used, false otherwise
216    */
217   bool isUsed();
218
219   /* Using this object with the public part of
220     model does not make sense */
221   double m_latCurrent;
222   tmgr_trace_event_t p_latEvent;
223
224   /* LMM */
225   tmgr_trace_event_t p_stateEvent;
226   s_surf_metric_t p_power;
227 };
228
229 /**********
230  * Action *
231  **********/
232 /** @ingroup SURF_network_interface
233  * @brief SURF network action interface class
234  * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
235  */
236 class NetworkAction : public Action {
237 public:
238   /**
239    * @brief NetworkAction constructor
240    * 
241    * @param model The NetworkModel associated to this NetworkAction
242    * @param cost The cost of this  NetworkAction in [TODO]
243    * @param failed [description]
244    */
245   NetworkAction(ModelPtr model, double cost, bool failed)
246   : Action(model, cost, failed) {}
247
248   /**
249    * @brief NetworkAction constructor
250    * 
251    * @param model The NetworkModel associated to this NetworkAction
252    * @param cost The cost of this  NetworkAction in [TODO]
253    * @param failed [description]
254    * @param var The lmm variable associated to this Action if it is part of a LMM component
255    */
256   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
257   : Action(model, cost, failed, var) {};
258
259   double m_latency;
260   double m_latCurrent;
261   double m_weight;
262   double m_rate;
263   const char* p_senderLinkName;
264   double m_senderGap;
265   double m_senderSize;
266   xbt_fifo_item_t p_senderFifoItem;
267 #ifdef HAVE_LATENCY_BOUND_TRACKING
268   int m_latencyLimited;
269 #endif
270
271 };
272
273 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
274
275