Logo AND Algorithmique Numérique Distribuée

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