Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fields already initialized by constructor of the base class Storage.
[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->p_variable);
323       int i;
324       for (i = 0; i < n; i++){
325         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
326                                                             action->p_variable,
327                                                             i);
328         NetworkCm02LinkLmmPtr link = static_cast<NetworkCm02LinkLmmPtr>(lmm_constraint_id(constraint));
329         TRACE_surf_link_set_utilization(link->m_name,
330                                         action->p_category,
331                                         (lmm_variable_getvalue(action->p_variable)*
332                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
333                                                 action->p_variable,
334                                                 i)),
335                                         action->m_lastUpdate,
336                                         now - action->m_lastUpdate);
337       }
338     }
339 #endif
340
341     // if I am wearing a latency hat
342     if (action->m_hat == LATENCY) {
343       XBT_DEBUG("Latency paid for action %p. Activating", action);
344       lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight);
345       action->heapRemove(p_actionHeap);
346       action->m_lastUpdate = surf_get_clock();
347
348         // if I am wearing a max_duration or normal hat
349     } else if (action->m_hat == MAX_DURATION ||
350         action->m_hat == NORMAL) {
351         // no need to communicate anymore
352         // assume that flows that reached max_duration have remaining of 0
353       action->m_finish = surf_get_clock();
354       XBT_DEBUG("Action %p finished", action);
355       action->m_remains = 0;
356       action->m_finish = surf_get_clock();
357       action->setState(SURF_ACTION_DONE);
358       action->heapRemove(p_actionHeap);
359
360       action->gapRemove();
361     }
362   }
363   return;
364 }
365
366 ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
367                                                 double size, double rate)
368 {
369   unsigned int i;
370   void *_link;
371   NetworkCm02LinkLmmPtr link;
372   int failed = 0;
373   NetworkCm02ActionLmmPtr action = NULL;
374   double bandwidth_bound;
375   double latency = 0.0;
376   xbt_dynar_t back_route = NULL;
377   int constraints_per_variable = 0;
378
379   xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
380
381   XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate);
382
383   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
384   xbt_assert(!xbt_dynar_is_empty(route) || latency,
385              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
386              src->p_name, dst->p_name);
387
388   xbt_dynar_foreach(route, i, _link) {
389         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
390     if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
391       failed = 1;
392       break;
393     }
394   }
395   if (sg_network_crosstraffic == 1) {
396           routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
397     xbt_dynar_foreach(back_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   }
405
406   action = new NetworkCm02ActionLmm(this, size, failed);
407
408 #ifdef HAVE_LATENCY_BOUND_TRACKING
409   action->m_latencyLimited = 0;
410 #endif
411   action->m_weight = action->m_latency = latency;
412
413   //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet);
414   action->m_rate = rate;
415   if (p_updateMechanism == UM_LAZY) {
416     action->m_indexHeap = -1;
417     action->m_lastUpdate = surf_get_clock();
418   }
419
420   bandwidth_bound = -1.0;
421   if (sg_weight_S_parameter > 0) {
422     xbt_dynar_foreach(route, i, _link) {
423       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
424       action->m_weight +=
425          sg_weight_S_parameter /
426          (link->p_power.peak * link->p_power.scale);
427     }
428   }
429   xbt_dynar_foreach(route, i, _link) {
430         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
431     double bb = bandwidthFactor(size) * (link->p_power.peak * link->p_power.scale);
432     bandwidth_bound =
433         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
434   }
435
436   action->m_latCurrent = action->m_latency;
437   action->m_latency *= latencyFactor(size);
438   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
439   if (m_haveGap) {
440     xbt_assert(!xbt_dynar_is_empty(route),
441                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
442
443     //link = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0);
444     link = dynamic_cast<NetworkCm02LinkLmmPtr>(*static_cast<ResourcePtr *>(xbt_dynar_get_ptr(route, 0)));
445     gapAppend(size, link, action);
446     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
447               action, src->p_name, dst->p_name, action->m_senderGap,
448               action->m_latency);
449   }
450
451   constraints_per_variable = xbt_dynar_length(route);
452   if (back_route != NULL)
453     constraints_per_variable += xbt_dynar_length(back_route);
454
455   if (action->m_latency > 0) {
456     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
457                          constraints_per_variable);
458     if (p_updateMechanism == UM_LAZY) {
459       // add to the heap the event when the latency is payed
460       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
461                 action->m_latency + action->m_lastUpdate);
462       action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
463     }
464   } else
465     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
466
467   if (action->m_rate < 0) {
468     lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
469   } else {
470     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);
471   }
472
473   xbt_dynar_foreach(route, i, _link) {
474         link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
475     lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, 1.0);
476   }
477
478   if (sg_network_crosstraffic == 1) {
479     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
480     xbt_dynar_foreach(back_route, i, _link) {
481       link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
482       lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, .05);
483     }
484   }
485
486   xbt_dynar_free(&route);
487   XBT_OUT();
488
489   return action;
490 }
491
492
493
494 /************
495  * Resource *
496  ************/
497 NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
498                                    lmm_system_t system,
499                                    double constraint_value,
500                                    tmgr_history_t history,
501                                    e_surf_resource_state_t state_init,
502                                    tmgr_trace_t state_trace,
503                                    double metric_peak,
504                                    tmgr_trace_t metric_trace,
505                                    double lat_initial,
506                                    tmgr_trace_t lat_trace,
507                                    e_surf_link_sharing_policy_t policy)
508 : Resource(model, name, props),
509   NetworkLinkLmm(system, constraint_value, history, state_init, state_trace, metric_peak, metric_trace)
510 {
511   m_latCurrent = lat_initial;
512   if (lat_trace)
513         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(this));
514
515   if (policy == SURF_LINK_FATPIPE)
516         lmm_constraint_shared(p_constraint);
517 }
518
519
520
521 void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type,
522                                       double value, double date)
523 {
524   /*   printf("[" "%g" "] Asking to update network card \"%s\" with value " */
525   /*     "%g" " for event %p\n", surf_get_clock(), nw_link->name, */
526   /*     value, event_type); */
527
528   if (event_type == p_power.event) {
529     double delta =
530         sg_weight_S_parameter / value - sg_weight_S_parameter /
531         (p_power.peak * p_power.scale);
532     lmm_variable_t var = NULL;
533     lmm_element_t elem = NULL;
534     NetworkCm02ActionLmmPtr action = NULL;
535
536     p_power.peak = value;
537     lmm_update_constraint_bound(p_model->p_maxminSystem,
538                                 p_constraint,
539                                 sg_bandwidth_factor *
540                                 (p_power.peak * p_power.scale));
541 #ifdef HAVE_TRACING
542     TRACE_surf_link_set_bandwidth(date, m_name, sg_bandwidth_factor * p_power.peak * p_power.scale);
543 #endif
544     if (sg_weight_S_parameter > 0) {
545       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
546         action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
547         action->m_weight += delta;
548         if (!action->m_suspended)
549           lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
550       }
551     }
552     if (tmgr_trace_event_free(event_type))
553       p_power.event = NULL;
554   } else if (event_type == p_latEvent) {
555     double delta = value - m_latCurrent;
556     lmm_variable_t var = NULL;
557     lmm_element_t elem = NULL;
558     NetworkCm02ActionLmmPtr action = NULL;
559
560     m_latCurrent = value;
561     while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
562       action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
563       action->m_latCurrent += delta;
564       action->m_weight += delta;
565       if (action->m_rate < 0)
566         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, sg_tcp_gamma / (2.0 * action->m_latCurrent));
567       else {
568         lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable,
569                                   min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
570
571         if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
572           XBT_INFO("Flow is limited BYBANDWIDTH");
573         } else {
574           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
575                    action->m_latCurrent);
576         }
577       }
578       if (!action->m_suspended)
579         lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
580
581     }
582     if (tmgr_trace_event_free(event_type))
583       p_latEvent = NULL;
584   } else if (event_type == p_stateEvent) {
585     if (value > 0)
586       p_stateCurrent = SURF_RESOURCE_ON;
587     else {
588       lmm_constraint_t cnst = p_constraint;
589       lmm_variable_t var = NULL;
590       lmm_element_t elem = NULL;
591
592       p_stateCurrent = SURF_RESOURCE_OFF;
593       while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, cnst, &elem))) {
594         ActionPtr action = (ActionPtr) lmm_variable_id(var);
595
596         if (action->getState() == SURF_ACTION_RUNNING ||
597             action->getState() == SURF_ACTION_READY) {
598           action->m_finish = date;
599           action->setState(SURF_ACTION_FAILED);
600         }
601       }
602     }
603     if (tmgr_trace_event_free(event_type))
604       p_stateEvent = NULL;
605   } else {
606     XBT_CRITICAL("Unknown event ! \n");
607     xbt_abort();
608   }
609
610   XBT_DEBUG
611       ("There were a resource state event, need to update actions related to the constraint (%p)",
612        p_constraint);
613   return;
614 }
615
616 /**********
617  * Action *
618  **********/
619 void NetworkCm02ActionLmm::updateRemainingLazy(double now)
620 {
621   double delta = 0.0;
622
623   if (m_suspended != 0)
624     return;
625
626   delta = now - m_lastUpdate;
627
628   if (m_remains > 0) {
629     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
630     double_update(&(m_remains), m_lastValue * delta);
631
632     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
633   }
634
635   if (m_maxDuration != NO_MAX_DURATION)
636     double_update(&m_maxDuration, delta);
637
638   if (m_remains <= 0 &&
639       (lmm_get_variable_weight(p_variable) > 0)) {
640     m_finish = surf_get_clock();
641     setState(SURF_ACTION_DONE);
642
643     heapRemove(p_model->p_actionHeap);
644   } else if (((m_maxDuration != NO_MAX_DURATION)
645       && (m_maxDuration <= 0))) {
646     m_finish = surf_get_clock();
647     setState(SURF_ACTION_DONE);
648     heapRemove(p_model->p_actionHeap);
649   }
650
651   m_lastUpdate = now;
652   m_lastValue = lmm_variable_getvalue(p_variable);
653 }
654 void NetworkCm02ActionLmm::recycle()
655 {
656   return;
657 }
658