Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make ns3 compile with new communicate (network_element_t)
[simgrid.git] / src / surf / network.c
1
2 /*
3  * Network with improved management of tasks, IM (Improved Management).
4  * Uses a heap to store actions so that the share_resources is faster.
5  * This model automatically sets the selective update flag to 1 and is
6  * highly dependent on the maxmin lmm module.
7  */
8
9 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
10  * All rights reserved.                                                     */
11
12 /* This program is free software; you can redistribute it and/or modify it
13  * under the terms of the license (GNU LGPL) which comes with this package. */
14
15 #include "network_private.h"
16 #include "xbt/log.h"
17 #include "xbt/str.h"
18
19 #include "surf_private.h"
20 #include "xbt/dict.h"
21 #include "maxmin_private.h"
22 #include "surf/surfxml_parse_values.h"
23 #include "surf/surf_resource.h"
24 #include "surf/surf_resource_lmm.h"
25
26 #undef GENERIC_LMM_ACTION
27 #undef GENERIC_ACTION
28 #define GENERIC_LMM_ACTION(action) (action)->generic_lmm_action
29 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
30
31
32 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
33                                 "Logging specific to the SURF network module");
34
35 surf_model_t surf_network_model = NULL;
36 static lmm_system_t network_maxmin_system = NULL;
37 static void (*network_solve) (lmm_system_t) = NULL;
38
39 xbt_dynar_t smpi_bw_factor = NULL;
40 xbt_dynar_t smpi_lat_factor = NULL;
41
42 typedef struct s_smpi_factor *smpi_factor_t;
43 typedef struct s_smpi_factor {
44   long factor;
45   double value;
46 } s_smpi_factor_t;
47
48
49 double sg_sender_gap = 0.0;
50 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
51 double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
52 double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
53
54 double sg_tcp_gamma = 0.0;
55 int sg_network_crosstraffic = 0;
56
57 xbt_dict_t gap_lookup = NULL;
58
59 e_UM_t network_update_mechanism = UM_UNDEFINED;
60 static int net_selective_update = 0;
61
62 static int net_action_is_suspended(surf_action_t action);
63 static void net_update_action_remaining_lazy(double now);
64
65 static xbt_swag_t net_modified_set = NULL;
66 static xbt_heap_t net_action_heap = NULL;
67
68
69 /******************************************************************************/
70 /*                           Factors callbacks                                */
71 /******************************************************************************/
72 static double constant_latency_factor(double size)
73 {
74   return sg_latency_factor;
75 }
76
77 static double constant_bandwidth_factor(double size)
78 {
79   return sg_bandwidth_factor;
80 }
81
82 static double constant_bandwidth_constraint(double rate, double bound,
83                                             double size)
84 {
85   return rate;
86 }
87
88 /**********************/
89 /*   SMPI callbacks   */
90 /**********************/
91 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
92 {
93   char *value = NULL;
94   unsigned int iter = 0;
95   s_smpi_factor_t fact;
96   xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
97
98   smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
99   radical_elements = xbt_str_split(smpi_coef_string, ";");
100   xbt_dynar_foreach(radical_elements, iter, value) {
101
102     radical_elements2 = xbt_str_split(value, ":");
103     if (xbt_dynar_length(radical_elements2) != 2)
104       xbt_die("Malformed radical for smpi factor!");
105     fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
106     fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
107     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
108     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
109     xbt_dynar_free(&radical_elements2);
110   }
111   xbt_dynar_free(&radical_elements);
112   return smpi_factor;
113 }
114
115 static double smpi_bandwidth_factor(double size)
116 {
117   if (!smpi_bw_factor)
118     smpi_bw_factor =
119         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/bw_factor"));
120
121   unsigned int iter = 0;
122   s_smpi_factor_t fact;
123   xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
124     if (size >= fact.factor) {
125       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
126       return fact.value;
127     }
128   }
129
130   return 1.0;
131 }
132
133 static double smpi_latency_factor(double size)
134 {
135   if (!smpi_lat_factor)
136     smpi_lat_factor =
137         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/lat_factor"));
138
139   unsigned int iter = 0;
140   s_smpi_factor_t fact;
141   xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
142     if (size >= fact.factor) {
143       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
144       return fact.value;
145     }
146   }
147
148   return 1.0;
149 }
150
151 /**--------- <copy/paste C code snippet in surf/network.c> -----------*/
152
153 static double smpi_bandwidth_constraint(double rate, double bound,
154                                         double size)
155 {
156   return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
157 }
158
159 static double (*latency_factor_callback) (double) =
160     &constant_latency_factor;
161 static double (*bandwidth_factor_callback) (double) =
162     &constant_bandwidth_factor;
163 static double (*bandwidth_constraint_callback) (double, double, double) =
164     &constant_bandwidth_constraint;
165
166 static void (*gap_append) (double, const link_CM02_t,
167                            surf_action_network_CM02_t) = NULL;
168 static void (*gap_remove) (surf_action_network_CM02_t) = NULL;
169
170 static void *net_create_resource(const char *name,
171                                  double bw_initial,
172                                  tmgr_trace_t bw_trace,
173                                  double lat_initial,
174                                  tmgr_trace_t lat_trace,
175                                  e_surf_resource_state_t
176                                  state_initial,
177                                  tmgr_trace_t state_trace,
178                                  e_surf_link_sharing_policy_t
179                                  policy, xbt_dict_t properties)
180 {
181   link_CM02_t nw_link = (link_CM02_t)
182       surf_resource_lmm_new(sizeof(s_link_CM02_t),
183                             surf_network_model, name, properties,
184                             network_maxmin_system,
185                             sg_bandwidth_factor * bw_initial,
186                             history,
187                             state_initial, state_trace,
188                             bw_initial, bw_trace);
189
190   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
191              "Link '%s' declared several times in the platform file.",
192              name);
193
194   nw_link->lat_current = lat_initial;
195   if (lat_trace)
196     nw_link->lat_event =
197         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
198
199   if (policy == SURF_LINK_FATPIPE)
200     lmm_constraint_shared(nw_link->lmm_resource.constraint);
201
202   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
203
204   return nw_link;
205 }
206
207 static void net_parse_link_init(sg_platf_link_cbarg_t link)
208 {
209   if (link->policy == SURF_LINK_FULLDUPLEX) {
210     char *link_id;
211     link_id = bprintf("%s_UP", link->id);
212     net_create_resource(link_id,
213                         link->bandwidth,
214                         link->bandwidth_trace,
215                         link->latency,
216                         link->latency_trace,
217                         link->state,
218                         link->state_trace, link->policy, link->properties);
219     xbt_free(link_id);
220     link_id = bprintf("%s_DOWN", link->id);
221     net_create_resource(link_id,
222                         link->bandwidth,
223                         link->bandwidth_trace,
224                         link->latency,
225                         link->latency_trace,
226                         link->state,
227                         link->state_trace, link->policy, link->properties);
228     xbt_free(link_id);
229   } else {
230     net_create_resource(link->id,
231                         link->bandwidth,
232                         link->bandwidth_trace,
233                         link->latency,
234                         link->latency_trace,
235                         link->state,
236                         link->state_trace, link->policy, link->properties);
237   }
238 }
239
240 static void net_add_traces(void)
241 {
242   xbt_dict_cursor_t cursor = NULL;
243   char *trace_name, *elm;
244
245   static int called = 0;
246   if (called)
247     return;
248   called = 1;
249
250   /* connect all traces relative to network */
251   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
252     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
253     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
254
255     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
256                trace_name, elm);
257     xbt_assert(trace,
258                "Cannot connect trace %s to link %s: trace undefined",
259                trace_name, elm);
260
261     link->lmm_resource.state_event =
262         tmgr_history_add_trace(history, trace, 0.0, 0, link);
263   }
264
265   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
266     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
267     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
268
269     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
270                trace_name, elm);
271     xbt_assert(trace,
272                "Cannot connect trace %s to link %s: trace undefined",
273                trace_name, elm);
274
275     link->lmm_resource.power.event =
276         tmgr_history_add_trace(history, trace, 0.0, 0, link);
277   }
278
279   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
280     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
281     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
282
283     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
284                trace_name, elm);
285     xbt_assert(trace,
286                "Cannot connect trace %s to link %s: trace undefined",
287                trace_name, elm);
288
289     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
290   }
291 }
292
293 static void net_define_callbacks(void)
294 {
295   /* Figuring out the network links */
296   sg_platf_link_add_cb(net_parse_link_init);
297   sg_platf_postparse_add_cb(net_add_traces);
298 }
299
300 static int net_resource_used(void *resource_id)
301 {
302   return lmm_constraint_used(network_maxmin_system, ((surf_resource_lmm_t)
303                                                      resource_id)->
304                              constraint);
305 }
306
307 static int net_action_unref(surf_action_t action)
308 {
309   action->refcount--;
310   if (!action->refcount) {
311     xbt_swag_remove(action, action->state_set);
312     if (((surf_action_lmm_t)action)->variable) {
313       lmm_variable_free(network_maxmin_system,
314                         ((surf_action_lmm_t) action)->variable);
315     }
316     if (network_update_mechanism == UM_LAZY) {  // remove action from the heap
317       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t) action);
318       xbt_swag_remove(action, net_modified_set);
319     }
320     surf_action_free(&action);
321     return 1;
322   }
323   return 0;
324 }
325
326
327
328 static void net_action_cancel(surf_action_t action)
329 {
330   XBT_DEBUG("cancel action %p", action);
331   surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
332   if (network_update_mechanism == UM_LAZY) {    // remove action from the heap
333     xbt_swag_remove(action, net_modified_set);
334     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t) action);
335   }
336 }
337
338 void net_action_recycle(surf_action_t action)
339 {
340   return;
341 }
342
343 #ifdef HAVE_LATENCY_BOUND_TRACKING
344 int net_get_link_latency_limited(surf_action_t action)
345 {
346   return action->latency_limited;
347 }
348 #endif
349
350 double net_action_get_remains(surf_action_t action)
351 {
352   if (network_update_mechanism == UM_LAZY)      /* update remains before return it */
353     net_update_action_remaining_lazy(surf_get_clock());
354   return action->remains;
355 }
356
357 static void net_update_action_remaining_lazy(double now)
358 {
359   surf_action_lmm_t action = NULL;
360   double delta = 0.0;
361
362   xbt_swag_foreach(action, net_modified_set) {
363
364     if (action->suspended != 0) {
365       continue;
366     }
367
368     delta = now - action->last_update;
369
370     double_update(&(((surf_action_t)action)->remains),
371                   lmm_variable_getvalue(action->variable) * delta);
372
373     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
374       double_update(&(((surf_action_t)action)->max_duration), delta);
375
376     if ((((surf_action_t)action)->remains <= 0) &&
377         (lmm_get_variable_weight(action->variable) > 0)) {
378       ((surf_action_t)action)->finish = surf_get_clock();
379       surf_network_model->action_state_set((surf_action_t) action,
380                                            SURF_ACTION_DONE);
381       surf_action_lmm_heap_remove(net_action_heap,action);
382     } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
383                && (((surf_action_t)action)->max_duration <= 0))) {
384       ((surf_action_t)action)->finish = surf_get_clock();
385       surf_network_model->action_state_set((surf_action_t) action,
386                                            SURF_ACTION_DONE);
387       surf_action_lmm_heap_remove(net_action_heap,action);
388     }
389
390     action->last_update = now;
391   }
392 }
393
394 static double net_share_resources_full(double now)
395 {
396   s_surf_action_lmm_t s_action;
397   surf_action_network_CM02_t action = NULL;
398   xbt_swag_t running_actions =
399       surf_network_model->states.running_action_set;
400   double min;
401
402   min = generic_maxmin_share_resources(running_actions,
403                                        xbt_swag_offset(s_action,
404                                                        variable),
405                                        network_maxmin_system,
406                                        network_solve);
407
408 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable)  )))
409
410   xbt_swag_foreach(action, running_actions) {
411 #ifdef HAVE_LATENCY_BOUND_TRACKING
412     if (lmm_is_variable_limited_by_latency(GENERIC_LMM_ACTION(action).variable)) {
413       action->latency_limited = 1;
414     } else {
415       action->latency_limited = 0;
416     }
417 #endif
418     if (action->latency > 0) {
419       min = (min < 0) ? action->latency : min(min, action->latency);
420     }
421   }
422
423   XBT_DEBUG("Min of share resources %f", min);
424
425   return min;
426 }
427
428 static double net_share_resources_lazy(double now)
429 {
430   surf_action_network_CM02_t action = NULL;
431   double min = -1;
432   double value;
433
434   XBT_DEBUG
435       ("Before share resources, the size of modified actions set is %d",
436        xbt_swag_size(net_modified_set));
437   net_update_action_remaining_lazy(now);
438
439   lmm_solve(network_maxmin_system);
440
441   XBT_DEBUG
442       ("After share resources, The size of modified actions set is %d",
443        xbt_swag_size(net_modified_set));
444
445   xbt_swag_foreach(action, net_modified_set) {
446     int max_dur_flag = 0;
447
448     if (GENERIC_ACTION(action).state_set !=
449         surf_network_model->states.running_action_set)
450       continue;
451
452     /* bogus priority, skip it */
453     if (GENERIC_ACTION(action).priority <= 0)
454       continue;
455
456     min = -1;
457     value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
458     if (value > 0) {
459       if (GENERIC_ACTION(action).remains > 0) {
460         value = GENERIC_ACTION(action).remains / value;
461         min = now + value;
462       } else {
463         value = 0.0;
464         min = now;
465       }
466     }
467
468     if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
469         && (min == -1
470             || GENERIC_ACTION(action).start +
471             GENERIC_ACTION(action).max_duration < min)) {
472       min = GENERIC_ACTION(action).start +
473           GENERIC_ACTION(action).max_duration;
474       max_dur_flag = 1;
475     }
476
477     XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
478               GENERIC_ACTION(action).start, now + value,
479               GENERIC_ACTION(action).max_duration);
480
481     if (min != -1) {
482       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
483       surf_action_lmm_heap_insert(net_action_heap,(surf_action_lmm_t)action, min, max_dur_flag ? MAX_DURATION : NORMAL);
484       XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
485                 now);
486     } else DIE_IMPOSSIBLE;
487   }
488
489   //hereafter must have already the min value for this resource model
490   if (xbt_heap_size(net_action_heap) > 0)
491     min = xbt_heap_maxkey(net_action_heap) - now;
492   else
493     min = -1;
494
495   XBT_DEBUG("The minimum with the HEAP %lf", min);
496
497   return min;
498 }
499
500 static void net_update_actions_state_full(double now, double delta)
501 {
502   double deltap = 0.0;
503   surf_action_network_CM02_t action = NULL;
504   surf_action_network_CM02_t next_action = NULL;
505   xbt_swag_t running_actions =
506       surf_network_model->states.running_action_set;
507   /*
508      xbt_swag_t failed_actions =
509      surf_network_model->states.failed_action_set;
510    */
511
512   xbt_swag_foreach_safe(action, next_action, running_actions) {
513     deltap = delta;
514     if (action->latency > 0) {
515       if (action->latency > deltap) {
516         double_update(&(action->latency), deltap);
517         deltap = 0.0;
518       } else {
519         double_update(&(deltap), action->latency);
520         action->latency = 0.0;
521       }
522       if ((action->latency == 0.0) && !(GENERIC_LMM_ACTION(action).suspended))
523         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
524                                    action->weight);
525     }
526 #ifdef HAVE_TRACING
527     if (TRACE_is_enabled()) {
528       int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
529       unsigned int i;
530       for (i = 0; i < n; i++){
531         lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
532                                                             GENERIC_LMM_ACTION(action).variable,
533                                                             i);
534         link_CM02_t link = lmm_constraint_id(constraint);
535         TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
536                                         ((surf_action_t)action)->category,
537                                         lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
538                                         now - delta,
539                                         delta);
540       }
541     }
542 #endif
543     if (!lmm_get_number_of_cnst_from_var
544         (network_maxmin_system, GENERIC_LMM_ACTION(action).variable)) {
545       /* There is actually no link used, hence an infinite bandwidth.
546        * This happens often when using models like vivaldi.
547        * In such case, just make sure that the action completes immediately.
548        */
549       double_update(&(GENERIC_ACTION(action).remains),
550                     GENERIC_ACTION(action).remains);
551     }
552     double_update(&(GENERIC_ACTION(action).remains),
553                   lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * deltap);
554     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
555       double_update(&(((surf_action_t)action)->max_duration), delta);
556
557     if ((GENERIC_ACTION(action).remains <= 0) &&
558         (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
559       ((surf_action_t)action)->finish = surf_get_clock();
560       surf_network_model->action_state_set((surf_action_t) action,
561                                            SURF_ACTION_DONE);
562
563       if (gap_remove)
564         gap_remove(action);
565     } else if ((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
566                && (((surf_action_t)action)->max_duration <= 0)) {
567       ((surf_action_t)action)->finish = surf_get_clock();
568       surf_network_model->action_state_set((surf_action_t) action,
569                                            SURF_ACTION_DONE);
570       if (gap_remove)
571         gap_remove(action);
572     }
573   }
574
575   return;
576 }
577
578 static void net_update_actions_state_lazy(double now, double delta)
579 {
580   surf_action_network_CM02_t action = NULL;
581
582   while ((xbt_heap_size(net_action_heap) > 0)
583          && (double_equals(xbt_heap_maxkey(net_action_heap), now))) {
584     action = xbt_heap_pop(net_action_heap);
585     XBT_DEBUG("Action %p: finish", action);
586     GENERIC_ACTION(action).finish = surf_get_clock();
587 #ifdef HAVE_TRACING
588     if (TRACE_is_enabled()) {
589       int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
590       unsigned int i;
591       for (i = 0; i < n; i++){
592         lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
593                                                             GENERIC_LMM_ACTION(action).variable,
594                                                             i);
595         link_CM02_t link = lmm_constraint_id(constraint);
596         TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
597                                         ((surf_action_t)action)->category,
598                                         lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
599                                         GENERIC_LMM_ACTION(action).last_update,
600                                         now - GENERIC_LMM_ACTION(action).last_update);
601       }
602     }
603 #endif
604
605     // if I am wearing a latency hat
606     if (GENERIC_LMM_ACTION(action).hat == LATENCY) {
607       lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
608                                  action->weight);
609       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
610       GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
611
612       // if I am wearing a max_duration or normal hat
613     } else if (GENERIC_LMM_ACTION(action).hat == MAX_DURATION ||
614         GENERIC_LMM_ACTION(action).hat == NORMAL) {
615       // no need to communicate anymore
616       // assume that flows that reached max_duration have remaining of 0
617       GENERIC_ACTION(action).remains = 0;
618       ((surf_action_t)action)->finish = surf_get_clock();
619       surf_network_model->action_state_set((surf_action_t) action,
620                                            SURF_ACTION_DONE);
621       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
622     }
623   }
624   return;
625 }
626
627 static void net_update_resource_state(void *id,
628                                       tmgr_trace_event_t event_type,
629                                       double value, double date)
630 {
631   link_CM02_t nw_link = id;
632   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
633   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
634   /*     value, event_type); */
635
636   if (event_type == nw_link->lmm_resource.power.event) {
637     double delta =
638         sg_weight_S_parameter / value - sg_weight_S_parameter /
639         (nw_link->lmm_resource.power.peak *
640          nw_link->lmm_resource.power.scale);
641     lmm_variable_t var = NULL;
642     lmm_element_t elem = NULL;
643     surf_action_network_CM02_t action = NULL;
644
645     nw_link->lmm_resource.power.peak = value;
646     lmm_update_constraint_bound(network_maxmin_system,
647                                 nw_link->lmm_resource.constraint,
648                                 sg_bandwidth_factor *
649                                 (nw_link->lmm_resource.power.peak *
650                                  nw_link->lmm_resource.power.scale));
651 #ifdef HAVE_TRACING
652     TRACE_surf_link_set_bandwidth(date,
653                                   (char
654                                    *) (((nw_link->lmm_resource).
655                                         generic_resource).name),
656                                   sg_bandwidth_factor *
657                                   (nw_link->lmm_resource.power.peak *
658                                    nw_link->lmm_resource.power.scale));
659 #endif
660     if (sg_weight_S_parameter > 0) {
661       while ((var = lmm_get_var_from_cnst
662               (network_maxmin_system, nw_link->lmm_resource.constraint,
663                &elem))) {
664         action = lmm_variable_id(var);
665         action->weight += delta;
666         if (!(GENERIC_LMM_ACTION(action).suspended))
667           lmm_update_variable_weight(network_maxmin_system,
668                                      GENERIC_LMM_ACTION(action).variable, action->weight);
669       }
670     }
671     if (tmgr_trace_event_free(event_type))
672       nw_link->lmm_resource.power.event = NULL;
673   } else if (event_type == nw_link->lat_event) {
674     double delta = value - nw_link->lat_current;
675     lmm_variable_t var = NULL;
676     lmm_element_t elem = NULL;
677     surf_action_network_CM02_t action = NULL;
678
679     nw_link->lat_current = value;
680     while ((var = lmm_get_var_from_cnst
681             (network_maxmin_system, nw_link->lmm_resource.constraint,
682              &elem))) {
683       action = lmm_variable_id(var);
684       action->lat_current += delta;
685       action->weight += delta;
686       if (action->rate < 0)
687         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
688                                   sg_tcp_gamma / (2.0 *
689                                                   action->lat_current));
690       else {
691         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
692                                   min(action->rate,
693                                       sg_tcp_gamma / (2.0 *
694                                                       action->
695                                                       lat_current)));
696
697         if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
698           XBT_INFO("Flow is limited BYBANDWIDTH");
699         } else {
700           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
701                    action->lat_current);
702         }
703       }
704       if (!(GENERIC_LMM_ACTION(action).suspended))
705         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
706                                    action->weight);
707
708     }
709     if (tmgr_trace_event_free(event_type))
710       nw_link->lat_event = NULL;
711   } else if (event_type == nw_link->lmm_resource.state_event) {
712     if (value > 0)
713       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
714     else {
715       lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
716       lmm_variable_t var = NULL;
717       lmm_element_t elem = NULL;
718
719       nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
720       while ((var = lmm_get_var_from_cnst
721               (network_maxmin_system, cnst, &elem))) {
722         surf_action_t action = lmm_variable_id(var);
723
724         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
725             surf_action_state_get(action) == SURF_ACTION_READY) {
726           action->finish = date;
727           surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
728         }
729       }
730     }
731     if (tmgr_trace_event_free(event_type))
732       nw_link->lmm_resource.state_event = NULL;
733   } else {
734     XBT_CRITICAL("Unknown event ! \n");
735     xbt_abort();
736   }
737
738   XBT_DEBUG
739       ("There were a resource state event, need to update actions related to the constraint (%p)",
740        nw_link->lmm_resource.constraint);
741   return;
742 }
743
744
745 static surf_action_t net_communicate(void *src,
746                                      void *dst, double size,
747                                      double rate)
748 {
749   unsigned int i;
750   link_CM02_t link;
751   int failed = 0;
752   surf_action_network_CM02_t action = NULL;
753   double bandwidth_bound;
754   double latency = 0.0;
755   xbt_dynar_t back_route = NULL;
756   int constraints_per_variable = 0;
757
758   xbt_dynar_t route = xbt_dynar_new(global_routing->size_of_link, NULL);
759
760   XBT_IN("(%s,%s,%g,%g)", ((network_element_t)src)->name, ((network_element_t)dst)->name, size, rate);
761
762   routing_get_route_and_latency((network_element_t)src, (network_element_t)dst, &route, &latency);
763   xbt_assert(!xbt_dynar_is_empty(route) || latency,
764              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
765              ((network_element_t)src)->name, ((network_element_t)dst)->name);
766
767   xbt_dynar_foreach(route, i, link) {
768     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
769       failed = 1;
770       break;
771     }
772   }
773   if (sg_network_crosstraffic == 1) {
774     routing_get_route_and_latency((network_element_t)dst, (network_element_t)src, &back_route, NULL);
775     xbt_dynar_foreach(back_route, i, link) {
776       if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
777         failed = 1;
778         break;
779       }
780     }
781   }
782
783   action =
784       surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
785                       surf_network_model, failed);
786 #ifdef HAVE_LATENCY_BOUND_TRACKING
787   action->latency_limited = 0;
788 #endif
789   action->weight = action->latency = latency;
790
791   xbt_swag_insert(action, ((surf_action_t)action)->state_set);
792   action->rate = rate;
793   if (network_update_mechanism == UM_LAZY) {
794     GENERIC_LMM_ACTION(action).index_heap = -1;
795     GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
796   }
797
798   bandwidth_bound = -1.0;
799   if (sg_weight_S_parameter > 0) {
800     xbt_dynar_foreach(route, i, link) {
801       action->weight +=
802           sg_weight_S_parameter /
803           (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
804     }
805   }
806   xbt_dynar_foreach(route, i, link) {
807     double bb = bandwidth_factor_callback(size) *
808         (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
809     bandwidth_bound =
810         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
811   }
812
813   action->lat_current = action->latency;
814   action->latency *= latency_factor_callback(size);
815   action->rate =
816       bandwidth_constraint_callback(action->rate, bandwidth_bound, size);
817   if (gap_append) {
818     xbt_assert(!xbt_dynar_is_empty(route),
819                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
820
821     link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0);
822     gap_append(size, link, action);
823     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
824               action, ((network_element_t)src)->name, ((network_element_t)dst)->name, action->sender.gap,
825               action->latency);
826   }
827
828   constraints_per_variable = xbt_dynar_length(route);
829   if (back_route != NULL)
830     constraints_per_variable += xbt_dynar_length(back_route);
831
832   if (action->latency > 0) {
833     GENERIC_LMM_ACTION(action).variable =
834         lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
835                          constraints_per_variable);
836     if (network_update_mechanism == UM_LAZY) {
837       // add to the heap the event when the latency is payed
838       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
839                 action->latency + GENERIC_LMM_ACTION(action).last_update);
840       surf_action_lmm_heap_insert(net_action_heap,(surf_action_lmm_t)action, action->latency + GENERIC_LMM_ACTION(action).last_update,
841                   xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
842     }
843   } else
844     GENERIC_LMM_ACTION(action).variable =
845         lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
846                          constraints_per_variable);
847
848   if (action->rate < 0) {
849     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
850                               (action->lat_current > 0) ?
851                               sg_tcp_gamma / (2.0 *
852                                               action->lat_current) : -1.0);
853   } else {
854     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
855                               (action->lat_current > 0) ?
856                               min(action->rate,
857                                   sg_tcp_gamma / (2.0 *
858                                                   action->lat_current))
859                               : action->rate);
860   }
861
862   xbt_dynar_foreach(route, i, link) {
863     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
864                GENERIC_LMM_ACTION(action).variable, 1.0);
865   }
866
867   if (sg_network_crosstraffic == 1) {
868     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
869     xbt_dynar_foreach(back_route, i, link) {
870       lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
871                  GENERIC_LMM_ACTION(action).variable, .05);
872     }
873   }
874
875   xbt_dynar_free(&route);
876   XBT_OUT();
877
878   return (surf_action_t) action;
879 }
880
881 static xbt_dynar_t net_get_route(void *src, void *dst)
882 {
883   xbt_dynar_t route = NULL;
884   routing_get_route_and_latency(src, dst, &route, NULL);
885   return route;
886 }
887
888 static double net_get_link_bandwidth(const void *link)
889 {
890   surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
891   return lmm->power.peak * lmm->power.scale;
892 }
893
894 static double net_get_link_latency(const void *link)
895 {
896   return ((link_CM02_t) link)->lat_current;
897 }
898
899 static int net_link_shared(const void *link)
900 {
901   return
902       lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
903 }
904
905 static void net_action_suspend(surf_action_t action)
906 {
907   ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 1;
908   lmm_update_variable_weight(network_maxmin_system,
909                              ((surf_action_network_CM02_t)
910                               action)->generic_lmm_action.variable, 0.0);
911
912   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
913     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
914 }
915
916 static void net_action_resume(surf_action_t action)
917 {
918   if (((surf_action_network_CM02_t) action)->generic_lmm_action.suspended) {
919     lmm_update_variable_weight(network_maxmin_system,
920                                ((surf_action_network_CM02_t)
921                                 action)->generic_lmm_action.variable,
922                                ((surf_action_network_CM02_t)
923                                 action)->weight);
924     ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 0;
925     if (network_update_mechanism == UM_LAZY)    // remove action from the heap
926       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
927   }
928 }
929
930 static int net_action_is_suspended(surf_action_t action)
931 {
932   return ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended;
933 }
934
935 void net_action_set_max_duration(surf_action_t action, double duration)
936 {
937   action->max_duration = duration;
938   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
939     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
940 }
941
942 #ifdef HAVE_TRACING
943 static void net_action_set_category(surf_action_t action,
944                                     const char *category)
945 {
946   action->category = xbt_strdup(category);
947 }
948 #endif
949
950 static void net_finalize(void)
951 {
952   surf_model_exit(surf_network_model);
953   surf_network_model = NULL;
954
955   lmm_system_free(network_maxmin_system);
956   network_maxmin_system = NULL;
957
958   if (network_update_mechanism == UM_LAZY) {
959     xbt_heap_free(net_action_heap);
960     xbt_swag_free(net_modified_set);
961   }
962
963   if (smpi_bw_factor)
964     xbt_dynar_free(&smpi_bw_factor);
965   if (smpi_lat_factor)
966     xbt_dynar_free(&smpi_lat_factor);
967 }
968
969 static void smpi_gap_append(double size, const link_CM02_t link,
970                             surf_action_network_CM02_t action)
971 {
972   const char *src = link->lmm_resource.generic_resource.name;
973   xbt_fifo_t fifo;
974   surf_action_network_CM02_t last_action;
975   double bw;
976
977   if (sg_sender_gap > 0.0) {
978     if (!gap_lookup) {
979       gap_lookup = xbt_dict_new();
980     }
981     fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
982     action->sender.gap = 0.0;
983     if (fifo && xbt_fifo_size(fifo) > 0) {
984       /* Compute gap from last send */
985       last_action =
986           (surf_action_network_CM02_t)
987           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
988       bw = net_get_link_bandwidth(link);
989       action->sender.gap =
990           last_action->sender.gap + max(sg_sender_gap,
991                                         last_action->sender.size / bw);
992       action->latency += action->sender.gap;
993     }
994     /* Append action as last send */
995     action->sender.link_name = link->lmm_resource.generic_resource.name;
996     fifo =
997         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
998                                           action->sender.link_name);
999     if (!fifo) {
1000       fifo = xbt_fifo_new();
1001       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
1002     }
1003     action->sender.fifo_item = xbt_fifo_push(fifo, action);
1004     action->sender.size = size;
1005   }
1006 }
1007
1008 static void smpi_gap_remove(surf_action_network_CM02_t action)
1009 {
1010   xbt_fifo_t fifo;
1011   size_t size;
1012
1013   if (sg_sender_gap > 0.0 && action->sender.link_name
1014       && action->sender.fifo_item) {
1015     fifo =
1016         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
1017                                           action->sender.link_name);
1018     xbt_fifo_remove_item(fifo, action->sender.fifo_item);
1019     size = xbt_fifo_size(fifo);
1020     if (size == 0) {
1021       xbt_fifo_free(fifo);
1022       xbt_dict_remove(gap_lookup, action->sender.link_name);
1023       size = xbt_dict_length(gap_lookup);
1024       if (size == 0) {
1025         xbt_dict_free(&gap_lookup);
1026       }
1027     }
1028   }
1029 }
1030
1031 static void surf_network_model_init_internal(void)
1032 {
1033   s_surf_action_network_CM02_t comm;
1034   surf_network_model = surf_model_init();
1035
1036   surf_network_model->name = "network";
1037   surf_network_model->action_unref = net_action_unref;
1038   surf_network_model->action_cancel = net_action_cancel;
1039   surf_network_model->action_recycle = net_action_recycle;
1040   surf_network_model->get_remains = net_action_get_remains;
1041 #ifdef HAVE_LATENCY_BOUND_TRACKING
1042   surf_network_model->get_latency_limited = net_get_link_latency_limited;
1043 #endif
1044 #ifdef HAVE_TRACING
1045   surf_network_model->set_category = net_action_set_category;
1046 #endif
1047
1048   surf_network_model->model_private->resource_used = net_resource_used;
1049   if (network_update_mechanism == UM_LAZY) {
1050     surf_network_model->model_private->share_resources =
1051         net_share_resources_lazy;
1052     surf_network_model->model_private->update_actions_state =
1053         net_update_actions_state_lazy;
1054   } else if (network_update_mechanism == UM_FULL) {
1055     surf_network_model->model_private->share_resources =
1056         net_share_resources_full;
1057     surf_network_model->model_private->update_actions_state =
1058         net_update_actions_state_full;
1059   }
1060
1061   surf_network_model->model_private->update_resource_state =
1062       net_update_resource_state;
1063   surf_network_model->model_private->finalize = net_finalize;
1064
1065   surf_network_model->suspend = net_action_suspend;
1066   surf_network_model->resume = net_action_resume;
1067   surf_network_model->is_suspended = net_action_is_suspended;
1068   surf_cpu_model->set_max_duration = net_action_set_max_duration;
1069
1070   surf_network_model->extension.network.communicate = net_communicate;
1071   surf_network_model->extension.network.get_route = net_get_route;
1072   surf_network_model->extension.network.get_link_bandwidth =
1073       net_get_link_bandwidth;
1074   surf_network_model->extension.network.get_link_latency =
1075       net_get_link_latency;
1076   surf_network_model->extension.network.link_shared = net_link_shared;
1077   surf_network_model->extension.network.add_traces = net_add_traces;
1078   surf_network_model->extension.network.create_resource =
1079       net_create_resource;
1080
1081   if (!network_maxmin_system)
1082     network_maxmin_system = lmm_system_new(net_selective_update);
1083
1084   routing_model_create(sizeof(link_CM02_t),
1085                        net_create_resource("__loopback__",
1086                                            498000000, NULL, 0.000015, NULL,
1087                                            SURF_RESOURCE_ON, NULL,
1088                                            SURF_LINK_FATPIPE, NULL));
1089
1090   if (network_update_mechanism == UM_LAZY) {
1091     net_action_heap = xbt_heap_new(8, NULL);
1092     xbt_heap_set_update_callback(net_action_heap,
1093                                  surf_action_lmm_update_index_heap);
1094     net_modified_set =
1095         xbt_swag_new(xbt_swag_offset(comm, generic_lmm_action.action_list_hookup));
1096     network_maxmin_system->keep_track = net_modified_set;
1097   }
1098 }
1099
1100 static void set_update_mechanism(void)
1101 {
1102   char *optim = xbt_cfg_get_string(_surf_cfg_set, "network/optim");
1103   int select =
1104       xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
1105
1106   if (!strcmp(optim, "Full")) {
1107     network_update_mechanism = UM_FULL;
1108     net_selective_update = select;
1109   } else if (!strcmp(optim, "Lazy")) {
1110     network_update_mechanism = UM_LAZY;
1111     net_selective_update = 1;
1112     xbt_assert((select == 1)
1113                ||
1114                (xbt_cfg_is_default_value
1115                 (_surf_cfg_set, "network/maxmin_selective_update")),
1116                "Disabling selective update while using the lazy update mechanism is dumb!");
1117   } else {
1118     xbt_die("Unsupported optimization (%s) for this model", optim);
1119   }
1120 }
1121
1122 /************************************************************************/
1123 /* New model based on LV08 and experimental results of MPI ping-pongs   */
1124 /************************************************************************/
1125 /* @Inproceedings{smpi_ipdps, */
1126 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
1127 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
1128 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
1129 /*  address={Anchorage (Alaska) USA}, */
1130 /*  month=may, */
1131 /*  year={2011} */
1132 /*  } */
1133 void surf_network_model_init_SMPI(void)
1134 {
1135
1136   if (surf_network_model)
1137     return;
1138   set_update_mechanism();
1139
1140   surf_network_model_init_internal();
1141   latency_factor_callback = &smpi_latency_factor;
1142   bandwidth_factor_callback = &smpi_bandwidth_factor;
1143   bandwidth_constraint_callback = &smpi_bandwidth_constraint;
1144   gap_append = &smpi_gap_append;
1145   gap_remove = &smpi_gap_remove;
1146   net_define_callbacks();
1147   xbt_dynar_push(model_list, &surf_network_model);
1148   network_solve = lmm_solve;
1149
1150   xbt_cfg_setdefault_double(_surf_cfg_set, "network/sender_gap", 10e-6);
1151   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1152 }
1153
1154 /************************************************************************/
1155 /* New model based on optimizations discussed during Pedro Velho's thesis*/
1156 /************************************************************************/
1157 /* @techreport{VELHO:2011:HAL-00646896:1, */
1158 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
1159 /*      title = {{Flow-level network models: have we reached the limits?}}, */
1160 /*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
1161 /*      type = {Rapport de recherche}, */
1162 /*      institution = {INRIA}, */
1163 /*      number = {RR-7821}, */
1164 /*      year = {2011}, */
1165 /*      month = Nov, */
1166 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
1167 /*  } */
1168 void surf_network_model_init_LegrandVelho(void)
1169 {
1170   if (surf_network_model)
1171     return;
1172
1173   set_update_mechanism();
1174
1175   surf_network_model_init_internal();
1176   net_define_callbacks();
1177   xbt_dynar_push(model_list, &surf_network_model);
1178   network_solve = lmm_solve;
1179
1180   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor",
1181                             13.01);
1182   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1183                             0.97);
1184   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 20537);
1185 }
1186
1187 /***************************************************************************/
1188 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
1189 /***************************************************************************/
1190 /* @TechReport{      rr-lip2002-40, */
1191 /*   author        = {Henri Casanova and Loris Marchal}, */
1192 /*   institution   = {LIP}, */
1193 /*   title         = {A Network Model for Simulation of Grid Application}, */
1194 /*   number        = {2002-40}, */
1195 /*   month         = {oct}, */
1196 /*   year          = {2002} */
1197 /* } */
1198 void surf_network_model_init_CM02(void)
1199 {
1200
1201   if (surf_network_model)
1202     return;
1203
1204   set_update_mechanism();
1205   surf_network_model_init_internal();
1206   net_define_callbacks();
1207   xbt_dynar_push(model_list, &surf_network_model);
1208   network_solve = lmm_solve;
1209
1210   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 1.0);
1211   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1212                             1.0);
1213   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 0.0);
1214 }
1215
1216 /***************************************************************************/
1217 /* The models from Steven H. Low                                           */
1218 /***************************************************************************/
1219 /* @article{Low03,                                                         */
1220 /*   author={Steven H. Low},                                               */
1221 /*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
1222 /*   year={2003},                                                          */
1223 /*   journal={{IEEE/ACM} Transactions on Networking},                      */
1224 /*    volume={11}, number={4},                                             */
1225 /*  }                                                                      */
1226 void surf_network_model_init_Reno(void)
1227 {
1228   if (surf_network_model)
1229     return;
1230
1231   set_update_mechanism();
1232   surf_network_model_init_internal();
1233   net_define_callbacks();
1234
1235   xbt_dynar_push(model_list, &surf_network_model);
1236   lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
1237                                     func_reno_fpi);
1238   network_solve = lagrange_solve;
1239
1240   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1241   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1242                             0.92);
1243   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1244 }
1245
1246
1247 void surf_network_model_init_Reno2(void)
1248 {
1249   if (surf_network_model)
1250     return;
1251
1252   set_update_mechanism();
1253   surf_network_model_init_internal();
1254   net_define_callbacks();
1255
1256   xbt_dynar_push(model_list, &surf_network_model);
1257   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
1258                                     func_reno2_fpi);
1259   network_solve = lagrange_solve;
1260
1261   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1262   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1263                             0.92);
1264   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S_parameter",
1265                             8775);
1266 }
1267
1268 void surf_network_model_init_Vegas(void)
1269 {
1270   if (surf_network_model)
1271     return;
1272
1273   set_update_mechanism();
1274   surf_network_model_init_internal();
1275   net_define_callbacks();
1276
1277   xbt_dynar_push(model_list, &surf_network_model);
1278   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
1279                                     func_vegas_fpi);
1280   network_solve = lagrange_solve;
1281
1282   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1283   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1284                             0.92);
1285   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1286 }