Logo AND Algorithmique Numérique Distribuée

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