Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix an example of vm migration
[simgrid.git] / src / surf / network_cm02.cpp
1 #include "network_cm02.hpp"
2 #include "maxmin_private.h"
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   ActionLmmPtr comm = NULL;
249
250   char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
251   int select =
252       xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
253
254   if (!strcmp(optim, "Full")) {
255     p_updateMechanism = UM_FULL;
256     m_selectiveUpdate = select;
257   } else if (!strcmp(optim, "Lazy")) {
258     p_updateMechanism = UM_LAZY;
259     m_selectiveUpdate = 1;
260     xbt_assert((select == 1)
261                ||
262                (xbt_cfg_is_default_value
263                 (_sg_cfg_set, "network/maxmin_selective_update")),
264                "Disabling selective update while using the lazy update mechanism is dumb!");
265   } else {
266     xbt_die("Unsupported optimization (%s) for this model", optim);
267   }
268
269   if (!p_maxminSystem)
270         p_maxminSystem = lmm_system_new(m_selectiveUpdate);
271
272   const char* lb_name = "__loopback__";
273   routing_model_create(static_cast<ResourcePtr>(createResource(lb_name,
274                                                    498000000, NULL, 0.000015, NULL,
275                                                    SURF_RESOURCE_ON, NULL,
276                                                    SURF_LINK_FATPIPE, NULL)));
277
278   if (p_updateMechanism == UM_LAZY) {
279         p_actionHeap = xbt_heap_new(8, NULL);
280         xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
281         p_modifiedSet = xbt_swag_new(xbt_swag_offset(*comm, p_actionListHookup));
282         p_maxminSystem->keep_track = p_modifiedSet;
283   }
284
285   m_haveGap = false;
286 }
287
288 NetworkLinkPtr NetworkCm02Model::createResource(const char *name,
289                                  double bw_initial,
290                                  tmgr_trace_t bw_trace,
291                                  double lat_initial,
292                                  tmgr_trace_t lat_trace,
293                                  e_surf_resource_state_t state_initial,
294                                  tmgr_trace_t state_trace,
295                                  e_surf_link_sharing_policy_t policy,
296                                  xbt_dict_t properties)
297 {
298   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
299              "Link '%s' declared several times in the platform file.",
300              name);
301
302   NetworkCm02LinkLmmPtr nw_link =
303                   new NetworkCm02LinkLmm(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
304                                                  state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
305
306
307   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast<ResourcePtr>(nw_link));
308   XBT_DEBUG("Create link '%s'",name);
309
310   return nw_link;
311 }
312
313 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
314 {
315   NetworkCm02ActionLmmPtr action;
316   while ((xbt_heap_size(p_actionHeap) > 0)
317          && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
318     action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap);
319     XBT_DEBUG("Something happened to action %p", action);
320 #ifdef HAVE_TRACING
321     if (TRACE_is_enabled()) {
322       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
323       int i;
324       for (i = 0; i < n; i++){
325         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
326                                                             action->getVariable(),
327                                                             i);
328         NetworkCm02LinkLmmPtr link = static_cast<NetworkCm02LinkLmmPtr>(lmm_constraint_id(constraint));
329         TRACE_surf_link_set_utilization(link->getName(),
330                                         action->getCategory(),
331                                         (lmm_variable_getvalue(action->getVariable())*
332                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
333                                                 action->getVariable(),
334                                                 i)),
335                                         action->getLastUpdate(),
336                                         now - action->getLastUpdate());
337       }
338     }
339 #endif
340
341     // if I am wearing a latency hat
342     if (action->getHat() == LATENCY) {
343       XBT_DEBUG("Latency paid for action %p. Activating", action);
344       lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight);
345       action->heapRemove(p_actionHeap);
346       action->refreshLastUpdate();
347
348         // if I am wearing a max_duration or normal hat
349     } else if (action->getHat() == MAX_DURATION ||
350         action->getHat() == NORMAL) {
351         // no need to communicate anymore
352         // assume that flows that reached max_duration have remaining of 0
353       XBT_DEBUG("Action %p finished", action);
354       action->setRemains(0);
355       action->finish();
356       action->setState(SURF_ACTION_DONE);
357       action->heapRemove(p_actionHeap);
358
359       action->gapRemove();
360     }
361   }
362   return;
363 }
364
365 ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
366                                                 double size, double rate)
367 {
368   unsigned int i;
369   void *_link;
370   NetworkCm02LinkLmmPtr link;
371   int failed = 0;
372   NetworkCm02ActionLmmPtr action = NULL;
373   double bandwidth_bound;
374   double latency = 0.0;
375   xbt_dynar_t back_route = NULL;
376   int constraints_per_variable = 0;
377
378   xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
379
380   XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate);
381
382   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
383   xbt_assert(!xbt_dynar_is_empty(route) || latency,
384              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
385              src->p_name, dst->p_name);
386
387   xbt_dynar_foreach(route, i, _link) {
388         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
389     if (link->getState() == SURF_RESOURCE_OFF) {
390       failed = 1;
391       break;
392     }
393   }
394   if (sg_network_crosstraffic == 1) {
395           routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
396     xbt_dynar_foreach(back_route, i, _link) {
397       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
398       if (link->getState() == SURF_RESOURCE_OFF) {
399         failed = 1;
400         break;
401       }
402     }
403   }
404
405   action = new NetworkCm02ActionLmm(this, size, failed);
406
407 #ifdef HAVE_LATENCY_BOUND_TRACKING
408   action->m_latencyLimited = 0;
409 #endif
410   action->m_weight = action->m_latency = latency;
411
412   //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet);
413   action->m_rate = rate;
414   if (p_updateMechanism == UM_LAZY) {
415     action->m_indexHeap = -1;
416     action->m_lastUpdate = surf_get_clock();
417   }
418
419   bandwidth_bound = -1.0;
420   if (sg_weight_S_parameter > 0) {
421     xbt_dynar_foreach(route, i, _link) {
422       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
423       action->m_weight += sg_weight_S_parameter / link->getBandwidth();
424     }
425   }
426   xbt_dynar_foreach(route, i, _link) {
427         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
428     double bb = bandwidthFactor(size) * link->getBandwidth(); //(link->p_power.peak * link->p_power.scale);
429     bandwidth_bound =
430         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
431   }
432
433   action->m_latCurrent = action->m_latency;
434   action->m_latency *= latencyFactor(size);
435   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
436   if (m_haveGap) {
437     xbt_assert(!xbt_dynar_is_empty(route),
438                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
439
440     //link = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0);
441     link = dynamic_cast<NetworkCm02LinkLmmPtr>(*static_cast<ResourcePtr *>(xbt_dynar_get_ptr(route, 0)));
442     gapAppend(size, link, action);
443     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
444               action, src->p_name, dst->p_name, action->m_senderGap,
445               action->m_latency);
446   }
447
448   constraints_per_variable = xbt_dynar_length(route);
449   if (back_route != NULL)
450     constraints_per_variable += xbt_dynar_length(back_route);
451
452   if (action->m_latency > 0) {
453     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
454                          constraints_per_variable);
455     if (p_updateMechanism == UM_LAZY) {
456       // add to the heap the event when the latency is payed
457       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
458                 action->m_latency + action->m_lastUpdate);
459       action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
460     }
461   } else
462     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
463
464   if (action->m_rate < 0) {
465     lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
466   } else {
467     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);
468   }
469
470   xbt_dynar_foreach(route, i, _link) {
471         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
472     lmm_expand(p_maxminSystem, link->constraint(), action->getVariable(), 1.0);
473   }
474
475   if (sg_network_crosstraffic == 1) {
476     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
477     xbt_dynar_foreach(back_route, i, _link) {
478       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
479       lmm_expand(p_maxminSystem, link->constraint(), action->getVariable(), .05);
480     }
481   }
482
483   xbt_dynar_free(&route);
484   XBT_OUT();
485
486   return action;
487 }
488
489
490
491 /************
492  * Resource *
493  ************/
494 NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
495                                    lmm_system_t system,
496                                    double constraint_value,
497                                    tmgr_history_t history,
498                                    e_surf_resource_state_t state_init,
499                                    tmgr_trace_t state_trace,
500                                    double metric_peak,
501                                    tmgr_trace_t metric_trace,
502                                    double lat_initial,
503                                    tmgr_trace_t lat_trace,
504                                    e_surf_link_sharing_policy_t policy)
505 : Resource(model, name, props),
506   NetworkLinkLmm(lmm_constraint_new(system, this, constraint_value), history, state_trace)
507 {
508   m_stateCurrent = state_init;
509
510   p_power.scale = 1.0;
511   p_power.peak = metric_peak;
512   if (metric_trace)
513     p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, static_cast<ResourcePtr>(this));
514   else
515     p_power.event = NULL;
516
517   m_latCurrent = lat_initial;
518   if (lat_trace)
519         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(this));
520
521   if (policy == SURF_LINK_FATPIPE)
522         lmm_constraint_shared(constraint());
523 }
524
525
526
527 void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type,
528                                       double value, double date)
529 {
530   /*   printf("[" "%g" "] Asking to update network card \"%s\" with value " */
531   /*     "%g" " for event %p\n", surf_get_clock(), nw_link->name, */
532   /*     value, event_type); */
533
534   if (event_type == p_power.event) {
535     double delta =
536         sg_weight_S_parameter / value - sg_weight_S_parameter /
537         (p_power.peak * p_power.scale);
538     lmm_variable_t var = NULL;
539     lmm_element_t elem = NULL;
540     NetworkCm02ActionLmmPtr action = NULL;
541
542     p_power.peak = value;
543     lmm_update_constraint_bound(getModel()->getMaxminSystem(),
544                                 constraint(),
545                                 sg_bandwidth_factor *
546                                 (p_power.peak * p_power.scale));
547 #ifdef HAVE_TRACING
548     TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_power.peak * p_power.scale);
549 #endif
550     if (sg_weight_S_parameter > 0) {
551       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), constraint(), &elem))) {
552         action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
553         action->m_weight += delta;
554         if (!action->isSuspended())
555           lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
556       }
557     }
558     if (tmgr_trace_event_free(event_type))
559       p_power.event = NULL;
560   } else if (event_type == p_latEvent) {
561     double delta = value - m_latCurrent;
562     lmm_variable_t var = NULL;
563     lmm_element_t elem = NULL;
564     NetworkCm02ActionLmmPtr action = NULL;
565
566     m_latCurrent = value;
567     while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), constraint(), &elem))) {
568       action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
569       action->m_latCurrent += delta;
570       action->m_weight += delta;
571       if (action->m_rate < 0)
572         lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), sg_tcp_gamma / (2.0 * action->m_latCurrent));
573       else {
574         lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(),
575                                   min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
576
577         if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
578           XBT_INFO("Flow is limited BYBANDWIDTH");
579         } else {
580           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
581                    action->m_latCurrent);
582         }
583       }
584       if (!action->isSuspended())
585         lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
586
587     }
588     if (tmgr_trace_event_free(event_type))
589       p_latEvent = NULL;
590   } else if (event_type == p_stateEvent) {
591     if (value > 0)
592       m_stateCurrent = SURF_RESOURCE_ON;
593     else {
594       lmm_constraint_t cnst = constraint();
595       lmm_variable_t var = NULL;
596       lmm_element_t elem = NULL;
597
598       m_stateCurrent = SURF_RESOURCE_OFF;
599       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
600         ActionPtr action = (ActionPtr) lmm_variable_id(var);
601
602         if (action->getState() == SURF_ACTION_RUNNING ||
603             action->getState() == SURF_ACTION_READY) {
604           action->setFinishTime(date);
605           action->setState(SURF_ACTION_FAILED);
606         }
607       }
608     }
609     if (tmgr_trace_event_free(event_type))
610       p_stateEvent = NULL;
611   } else {
612     XBT_CRITICAL("Unknown event ! \n");
613     xbt_abort();
614   }
615
616   XBT_DEBUG
617       ("There were a resource state event, need to update actions related to the constraint (%p)",
618        constraint());
619   return;
620 }
621
622 /**********
623  * Action *
624  **********/
625 void NetworkCm02ActionLmm::updateRemainingLazy(double now)
626 {
627   double delta = 0.0;
628
629   if (m_suspended != 0)
630     return;
631
632   delta = now - m_lastUpdate;
633
634   if (m_remains > 0) {
635     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
636     double_update(&(m_remains), m_lastValue * delta);
637
638     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
639   }
640
641   if (m_maxDuration != NO_MAX_DURATION)
642     double_update(&m_maxDuration, delta);
643
644   if (m_remains <= 0 &&
645       (lmm_get_variable_weight(getVariable()) > 0)) {
646     finish();
647     setState(SURF_ACTION_DONE);
648
649     heapRemove(getModel()->getActionHeap());
650   } else if (((m_maxDuration != NO_MAX_DURATION)
651       && (m_maxDuration <= 0))) {
652     finish();
653     setState(SURF_ACTION_DONE);
654     heapRemove(getModel()->getActionHeap());
655   }
656
657   m_lastUpdate = now;
658   m_lastValue = lmm_variable_getvalue(getVariable());
659 }
660 void NetworkCm02ActionLmm::recycle()
661 {
662   return;
663 }
664