Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8fa588e5dc4e930ea0550b81c33d844f91b80581
[simgrid.git] / src / surf / network.cpp
1 #include "network.hpp"
2 #include "maxmin_private.h"
3 #include "simgrid/sg_config.h"
4
5 extern "C" {
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
7                                 "Logging specific to the SURF network module");
8 }
9
10 NetworkCm02ModelPtr surf_network_model = NULL;
11
12 double sg_sender_gap = 0.0;
13 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
14 double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
15 double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
16
17 double sg_tcp_gamma = 0.0;
18 int sg_network_crosstraffic = 0;
19
20 /*************
21  * CallBacks *
22  *************/
23
24 static void net_parse_link_init(sg_platf_link_cbarg_t link){
25   if (link->policy == SURF_LINK_FULLDUPLEX) {
26     char *link_id;
27     link_id = bprintf("%s_UP", link->id);
28     surf_network_model->createResource(link_id,
29                       link->bandwidth,
30                       link->bandwidth_trace,
31                       link->latency,
32                       link->latency_trace,
33                       link->state,
34                       link->state_trace, link->policy, link->properties);
35     xbt_free(link_id);
36     link_id = bprintf("%s_DOWN", link->id);
37     surf_network_model->createResource(link_id,
38                       link->bandwidth,
39                       link->bandwidth_trace,
40                       link->latency,
41                       link->latency_trace,
42                       link->state,
43                       link->state_trace, link->policy, link->properties);
44     xbt_free(link_id);
45   } else {
46         surf_network_model->createResource(link->id,
47                       link->bandwidth,
48                       link->bandwidth_trace,
49                       link->latency,
50                       link->latency_trace,
51                       link->state,
52                       link->state_trace, link->policy, link->properties);
53   }
54 }
55
56 static void net_add_traces(void){
57   xbt_dict_cursor_t cursor = NULL;
58   char *trace_name, *elm;
59
60   static int called = 0;
61   if (called)
62     return;
63   called = 1;
64
65   /* connect all traces relative to network */
66   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
67     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
68     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
69                                      static_cast<ResourcePtr>(
70                                                   xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
71
72     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
73                trace_name, elm);
74     xbt_assert(trace,
75                "Cannot connect trace %s to link %s: trace undefined",
76                trace_name, elm);
77
78     link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
79   }
80
81   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
82     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
83     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
84                                  static_cast<ResourcePtr>(
85                                       xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
86
87     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
88                trace_name, elm);
89     xbt_assert(trace,
90                "Cannot connect trace %s to link %s: trace undefined",
91                trace_name, elm);
92
93     link->p_power.event = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
94   }
95
96   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
97     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
98     NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
99                                  static_cast<ResourcePtr>(
100                                       xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
101
102     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
103                trace_name, elm);
104     xbt_assert(trace,
105                "Cannot connect trace %s to link %s: trace undefined",
106                trace_name, elm);
107
108     link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
109   }
110 }
111
112 void net_define_callbacks(void)
113 {
114   /* Figuring out the network links */
115   sg_platf_link_add_cb(net_parse_link_init);
116   sg_platf_postparse_add_cb(net_add_traces);
117 }
118
119 /*********
120  * Model *
121  *********/
122
123 /************************************************************************/
124 /* New model based on optimizations discussed during Pedro Velho's thesis*/
125 /************************************************************************/
126 /* @techreport{VELHO:2011:HAL-00646896:1, */
127 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
128 /*      title = {{Flow-level network models: have we reached the limits?}}, */
129 /*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
130 /*      type = {Rapport de recherche}, */
131 /*      institution = {INRIA}, */
132 /*      number = {RR-7821}, */
133 /*      year = {2011}, */
134 /*      month = Nov, */
135 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
136 /*  } */
137 void surf_network_model_init_LegrandVelho(void)
138 {
139   if (surf_network_model)
140     return;
141
142   surf_network_model = new NetworkCm02Model();
143   net_define_callbacks();
144   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
145   xbt_dynar_push(model_list, &model);
146
147   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",
148                             13.01);
149   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
150                             0.97);
151   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537);
152 }
153
154 /***************************************************************************/
155 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
156 /***************************************************************************/
157 /* @TechReport{      rr-lip2002-40, */
158 /*   author        = {Henri Casanova and Loris Marchal}, */
159 /*   institution   = {LIP}, */
160 /*   title         = {A Network Model for Simulation of Grid Application}, */
161 /*   number        = {2002-40}, */
162 /*   month         = {oct}, */
163 /*   year          = {2002} */
164 /* } */
165 void surf_network_model_init_CM02(void)
166 {
167
168   if (surf_network_model)
169     return;
170
171   surf_network_model = new NetworkCm02Model();
172   net_define_callbacks();
173   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
174   xbt_dynar_push(model_list, &model);
175
176   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
177   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
178                             1.0);
179   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0);
180 }
181
182 /***************************************************************************/
183 /* The models from Steven H. Low                                           */
184 /***************************************************************************/
185 /* @article{Low03,                                                         */
186 /*   author={Steven H. Low},                                               */
187 /*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
188 /*   year={2003},                                                          */
189 /*   journal={{IEEE/ACM} Transactions on Networking},                      */
190 /*    volume={11}, number={4},                                             */
191 /*  }                                                                      */
192 void surf_network_model_init_Reno(void)
193 {
194   if (surf_network_model)
195     return;
196
197   surf_network_model = new NetworkCm02Model();
198   net_define_callbacks();
199   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
200   xbt_dynar_push(model_list, &model);
201   lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
202                                     func_reno_fpi);
203   surf_network_model->f_networkSolve = lagrange_solve;
204
205   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
206   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
207                             0.92);
208   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
209 }
210
211
212 void surf_network_model_init_Reno2(void)
213 {
214   if (surf_network_model)
215     return;
216
217   surf_network_model = new NetworkCm02Model();
218   net_define_callbacks();
219   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
220   xbt_dynar_push(model_list, &model);
221   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
222                                     func_reno2_fpi);
223   surf_network_model->f_networkSolve = lagrange_solve;
224
225   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
226   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
227                             0.92);
228   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S_parameter",
229                             8775);
230 }
231
232 void surf_network_model_init_Vegas(void)
233 {
234   if (surf_network_model)
235     return;
236
237   surf_network_model = new NetworkCm02Model();
238   net_define_callbacks();
239   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
240   xbt_dynar_push(model_list, &model);
241   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
242                                     func_vegas_fpi);
243   surf_network_model->f_networkSolve = lagrange_solve;
244
245   xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
246   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
247                             0.92);
248   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
249 }
250
251 void NetworkCm02Model::initialize()
252 {
253   ActionLmmPtr comm;
254
255   char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
256   int select =
257       xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
258
259   if (!strcmp(optim, "Full")) {
260     p_updateMechanism = UM_FULL;
261     m_selectiveUpdate = select;
262   } else if (!strcmp(optim, "Lazy")) {
263     p_updateMechanism = UM_LAZY;
264     m_selectiveUpdate = 1;
265     xbt_assert((select == 1)
266                ||
267                (xbt_cfg_is_default_value
268                 (_sg_cfg_set, "network/maxmin_selective_update")),
269                "Disabling selective update while using the lazy update mechanism is dumb!");
270   } else {
271     xbt_die("Unsupported optimization (%s) for this model", optim);
272   }
273
274   if (!p_maxminSystem)
275         p_maxminSystem = lmm_system_new(m_selectiveUpdate);
276
277   routing_model_create(static_cast<ResourcePtr>(createResource("__loopback__",
278                                                    498000000, NULL, 0.000015, NULL,
279                                                    SURF_RESOURCE_ON, NULL,
280                                                    SURF_LINK_FATPIPE, NULL)));
281
282   if (p_updateMechanism == UM_LAZY) {
283         p_actionHeap = xbt_heap_new(8, NULL);
284         xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
285         p_modifiedSet = xbt_swag_new(xbt_swag_offset(*comm, p_actionListHookup));
286         p_maxminSystem->keep_track = p_modifiedSet;
287   }
288 }
289
290 NetworkCm02LinkLmmPtr NetworkCm02Model::createResource(const char *name,
291                                  double bw_initial,
292                                  tmgr_trace_t bw_trace,
293                                  double lat_initial,
294                                  tmgr_trace_t lat_trace,
295                                  e_surf_resource_state_t state_initial,
296                                  tmgr_trace_t state_trace,
297                                  e_surf_link_sharing_policy_t policy,
298                                  xbt_dict_t properties)
299 {
300   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
301              "Link '%s' declared several times in the platform file.",
302              name);
303
304   NetworkCm02LinkLmmPtr nw_link =
305                   new NetworkCm02LinkLmm(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
306                                                  state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
307
308
309   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast<ResourcePtr>(nw_link));
310   XBT_DEBUG("Create link '%s'",name);
311
312   return nw_link;
313 }
314
315 void NetworkCm02Model::updateActionsStateLazy(double now, double delta)
316 {
317   NetworkCm02ActionLmmPtr action;
318   while ((xbt_heap_size(p_actionHeap) > 0)
319          && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
320     action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap);
321     XBT_DEBUG("Something happened to action %p", action);
322 #ifdef HAVE_TRACING
323     if (TRACE_is_enabled()) {
324       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->p_variable);
325       unsigned int i;
326       for (i = 0; i < n; i++){
327         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
328                                                             action->p_variable,
329                                                             i);
330         NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint));
331         TRACE_surf_link_set_utilization(link->m_name,
332                                         action->p_category,
333                                         (lmm_variable_getvalue(action->p_variable)*
334                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
335                                                 action->p_variable,
336                                                 i)),
337                                         action->m_lastUpdate,
338                                         now - action->m_lastUpdate);
339       }
340     }
341 #endif
342
343     // if I am wearing a latency hat
344     if (action->m_hat == LATENCY) {
345       XBT_DEBUG("Latency paid for action %p. Activating", action);
346       lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight);
347       action->heapRemove(p_actionHeap);
348       action->m_lastUpdate = surf_get_clock();
349
350         // if I am wearing a max_duration or normal hat
351     } else if (action->m_hat == MAX_DURATION ||
352         action->m_hat == NORMAL) {
353         // no need to communicate anymore
354         // assume that flows that reached max_duration have remaining of 0
355       action->m_finish = surf_get_clock();
356       XBT_DEBUG("Action %p finished", action);
357       action->m_remains = 0;
358       action->m_finish = surf_get_clock();
359       action->setState(SURF_ACTION_DONE);
360       action->heapRemove(p_actionHeap);
361
362       action->gapRemove();
363     }
364   }
365   return;
366 }
367
368 xbt_dynar_t NetworkCm02Model::getRoute(RoutingEdgePtr src, RoutingEdgePtr dst)
369 {
370   xbt_dynar_t route = NULL;
371   routing_platf->getRouteAndLatency(src, dst, &route, NULL);
372   return route;
373 }
374
375 ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
376                                                 double size, double rate)
377 {
378   unsigned int i;
379   void *_link;
380   NetworkCm02LinkLmmPtr link;
381   int failed = 0;
382   NetworkCm02ActionLmmPtr action = NULL;
383   double bandwidth_bound;
384   double latency = 0.0;
385   xbt_dynar_t back_route = NULL;
386   int constraints_per_variable = 0;
387
388   xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
389
390   XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate);
391
392   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
393   xbt_assert(!xbt_dynar_is_empty(route) || latency,
394              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
395              src->p_name, dst->p_name);
396
397   xbt_dynar_foreach(route, i, _link) {
398         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
399     if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
400       failed = 1;
401       break;
402     }
403   }
404   if (sg_network_crosstraffic == 1) {
405           routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
406     xbt_dynar_foreach(back_route, i, _link) {
407       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
408       if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
409         failed = 1;
410         break;
411       }
412     }
413   }
414
415   action = new NetworkCm02ActionLmm(this, size, failed);
416
417 #ifdef HAVE_LATENCY_BOUND_TRACKING
418   action->m_latencyLimited = 0;
419 #endif
420   action->m_weight = action->m_latency = latency;
421
422   //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet);
423   action->m_rate = rate;
424   if (p_updateMechanism == UM_LAZY) {
425     action->m_indexHeap = -1;
426     action->m_lastUpdate = surf_get_clock();
427   }
428
429   bandwidth_bound = -1.0;
430   if (sg_weight_S_parameter > 0) {
431     xbt_dynar_foreach(route, i, _link) {
432       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
433       action->m_weight +=
434          sg_weight_S_parameter /
435          (link->p_power.peak * link->p_power.scale);
436     }
437   }
438   xbt_dynar_foreach(route, i, _link) {
439         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
440     double bb = bandwidthFactor(size) * (link->p_power.peak * link->p_power.scale);
441     bandwidth_bound =
442         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
443   }
444
445   action->m_latCurrent = action->m_latency;
446   action->m_latency *= latencyFactor(size);
447   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
448   if (m_haveGap) {
449     xbt_assert(!xbt_dynar_is_empty(route),
450                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
451
452     //link = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0);
453     link = dynamic_cast<NetworkCm02LinkLmmPtr>(*static_cast<ResourcePtr *>(xbt_dynar_get_ptr(route, 0)));
454     gapAppend(size, link, action);
455     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
456               action, src->p_name, dst->p_name, action->m_senderGap,
457               action->m_latency);
458   }
459
460   constraints_per_variable = xbt_dynar_length(route);
461   if (back_route != NULL)
462     constraints_per_variable += xbt_dynar_length(back_route);
463
464   if (action->m_latency > 0) {
465     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
466                          constraints_per_variable);
467     if (p_updateMechanism == UM_LAZY) {
468       // add to the heap the event when the latency is payed
469       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
470                 action->m_latency + action->m_lastUpdate);
471       action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
472     }
473   } else
474     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
475
476   if (action->m_rate < 0) {
477     lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
478   } else {
479     lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
480   }
481
482   xbt_dynar_foreach(route, i, _link) {
483         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
484     lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, 1.0);
485   }
486
487   if (sg_network_crosstraffic == 1) {
488     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
489     xbt_dynar_foreach(back_route, i, _link) {
490       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
491       lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, .05);
492     }
493   }
494
495   xbt_dynar_free(&route);
496   XBT_OUT();
497
498   return action;
499 }
500
501 double NetworkCm02Model::latencyFactor(double size) {
502   return sg_latency_factor;
503 }
504
505 double NetworkCm02Model::bandwidthFactor(double size) {
506   return sg_bandwidth_factor;
507 }
508
509 double NetworkCm02Model::bandwidthConstraint(double rate, double bound, double size) {
510   return rate;
511 }
512
513 /************
514  * Resource *
515  ************/
516 NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
517                                    lmm_system_t system,
518                                    double constraint_value,
519                                    tmgr_history_t history,
520                                    e_surf_resource_state_t state_init,
521                                    tmgr_trace_t state_trace,
522                                    double metric_peak,
523                                    tmgr_trace_t metric_trace,
524                                    double lat_initial,
525                                    tmgr_trace_t lat_trace,
526                                    e_surf_link_sharing_policy_t policy)
527 : Resource(model, name, props),
528   ResourceLmm(model, name, props, system, constraint_value, history, state_init, state_trace, metric_peak, metric_trace),
529   NetworkCm02Link(model, name, props)
530 {
531   m_latCurrent = lat_initial;
532   if (lat_trace)
533         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(this));
534
535   if (policy == SURF_LINK_FATPIPE)
536         lmm_constraint_shared(p_constraint);
537 }
538
539 bool NetworkCm02LinkLmm::isUsed()
540 {
541   return lmm_constraint_used(p_model->p_maxminSystem, p_constraint);
542 }
543
544 double NetworkCm02Link::getLatency()
545 {
546   return m_latCurrent;
547 }
548
549 double NetworkCm02LinkLmm::getBandwidth()
550 {
551   return p_power.peak * p_power.scale;
552 }
553
554 bool NetworkCm02LinkLmm::isShared()
555 {
556   return lmm_constraint_is_shared(p_constraint);
557 }
558
559 void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type,
560                                       double value, double date)
561 {
562   /*   printf("[" "%g" "] Asking to update network card \"%s\" with value " */
563   /*     "%g" " for event %p\n", surf_get_clock(), nw_link->name, */
564   /*     value, event_type); */
565
566   if (event_type == p_power.event) {
567     double delta =
568         sg_weight_S_parameter / value - sg_weight_S_parameter /
569         (p_power.peak * p_power.scale);
570     lmm_variable_t var = NULL;
571     lmm_element_t elem = NULL;
572     NetworkCm02ActionLmmPtr action = NULL;
573
574     p_power.peak = value;
575     lmm_update_constraint_bound(p_model->p_maxminSystem,
576                                 p_constraint,
577                                 sg_bandwidth_factor *
578                                 (p_power.peak * p_power.scale));
579 #ifdef HAVE_TRACING
580     TRACE_surf_link_set_bandwidth(date, m_name, sg_bandwidth_factor * p_power.peak * p_power.scale);
581 #endif
582     if (sg_weight_S_parameter > 0) {
583       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
584         action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
585         action->m_weight += delta;
586         if (!action->m_suspended)
587           lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
588       }
589     }
590     if (tmgr_trace_event_free(event_type))
591       p_power.event = NULL;
592   } else if (event_type == p_latEvent) {
593     double delta = value - m_latCurrent;
594     lmm_variable_t var = NULL;
595     lmm_element_t elem = NULL;
596     NetworkCm02ActionLmmPtr action = NULL;
597
598     m_latCurrent = value;
599     while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
600       action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
601       action->m_latCurrent += delta;
602       action->m_weight += delta;
603       if (action->m_rate < 0)
604         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, sg_tcp_gamma / (2.0 * action->m_latCurrent));
605       else {
606         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable,
607                                   min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
608
609         if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
610           XBT_INFO("Flow is limited BYBANDWIDTH");
611         } else {
612           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
613                    action->m_latCurrent);
614         }
615       }
616       if (!action->m_suspended)
617         lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
618
619     }
620     if (tmgr_trace_event_free(event_type))
621       p_latEvent = NULL;
622   } else if (event_type == p_stateEvent) {
623     if (value > 0)
624       p_stateCurrent = SURF_RESOURCE_ON;
625     else {
626       lmm_constraint_t cnst = p_constraint;
627       lmm_variable_t var = NULL;
628       lmm_element_t elem = NULL;
629
630       p_stateCurrent = SURF_RESOURCE_OFF;
631       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, cnst, &elem))) {
632         ActionPtr action = (ActionPtr) lmm_variable_id(var);
633
634         if (action->getState() == SURF_ACTION_RUNNING ||
635             action->getState() == SURF_ACTION_READY) {
636           action->m_finish = date;
637           action->setState(SURF_ACTION_FAILED);
638         }
639       }
640     }
641     if (tmgr_trace_event_free(event_type))
642       p_stateEvent = NULL;
643   } else {
644     XBT_CRITICAL("Unknown event ! \n");
645     xbt_abort();
646   }
647
648   XBT_DEBUG
649       ("There were a resource state event, need to update actions related to the constraint (%p)",
650        p_constraint);
651   return;
652 }
653
654 /**********
655  * Action *
656  **********/
657 void NetworkCm02ActionLmm::updateRemainingLazy(double now)
658 {
659   double delta = 0.0;
660
661   if (m_suspended != 0)
662     return;
663
664   delta = now - m_lastUpdate;
665
666   if (m_remains > 0) {
667     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
668     double_update(&(m_remains), m_lastValue * delta);
669
670     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
671   }
672
673   if (m_maxDuration != NO_MAX_DURATION)
674     double_update(&m_maxDuration, delta);
675
676   if (m_remains <= 0 &&
677       (lmm_get_variable_weight(p_variable) > 0)) {
678     m_finish = surf_get_clock();
679     setState(SURF_ACTION_DONE);
680
681     heapRemove(p_model->p_actionHeap);
682   } else if (((m_maxDuration != NO_MAX_DURATION)
683       && (m_maxDuration <= 0))) {
684     m_finish = surf_get_clock();
685     setState(SURF_ACTION_DONE);
686     heapRemove(p_model->p_actionHeap);
687   }
688
689   m_lastUpdate = now;
690   m_lastValue = lmm_variable_getvalue(p_variable);
691 }
692 void NetworkCm02ActionLmm::recycle()
693 {
694   return;
695 }
696