Logo AND Algorithmique Numérique Distribuée

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