Logo AND Algorithmique Numérique Distribuée

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