Logo AND Algorithmique Numérique Distribuée

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