Logo AND Algorithmique Numérique Distribuée

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