Logo AND Algorithmique Numérique Distribuée

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