Logo AND Algorithmique Numérique Distribuée

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