Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move e_surf_link_sharing_policy_t structure to surf.h and fix the way to create link...
[simgrid.git] / src / surf / network.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "network_private.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
12                                 "Logging specific to the SURF network module");
13
14 surf_model_t surf_network_model = NULL;
15 static lmm_system_t network_maxmin_system = NULL;
16 static void (*network_solve) (lmm_system_t) = NULL;
17
18 double sg_latency_factor = 1.0;    /* default value; can be set by model or from command line */
19 double sg_bandwidth_factor = 1.0;  /* default value; can be set by model or from command line */
20 double sg_weight_S_parameter = 0.0;/* default value; can be set by model or from command line */
21
22 double sg_tcp_gamma = 0.0;
23 int sg_network_fullduplex = 0;
24
25
26 /******************************************************************************/
27 /*                           Factors callbacks                                */
28 /******************************************************************************/ 
29 static double constant_latency_factor(double size)
30 {
31   return sg_latency_factor;
32 }
33
34 static double constant_bandwidth_factor(double size)
35 {
36   return sg_bandwidth_factor;
37 }
38
39 static double constant_bandwidth_constraint(double rate, double bound, double size)
40 {
41   return rate;
42 }
43
44 /**********************/
45 /*   SMPI callbacks   */
46 /**********************/
47 static double smpi_latency_factor(double size)
48 {
49   /* 1 B <= size <= 1 KiB */
50   if (size <= 1024.0) {
51     return 1.0056;
52   }
53
54   /* 2 KiB <= size <= 32 KiB */
55   if (size <= 32768.0) {
56     return 1.8805;
57   }
58
59   /* 64 KiB <= size <= 4 MiB */
60   return 22.7111;
61 }
62
63 static double smpi_bandwidth_factor(double size)
64 {
65   /* 1 B <= size <= 1 KiB */
66   if (size <= 1024.0) {
67     return 0.2758;
68   }
69
70   /* 2 KiB <= size <= 32 KiB */
71   if (size <= 32768.0) {
72     return 0.5477;
73   }
74
75   /* 64 KiB <= size <= 4 MiB */
76   return 0.9359;
77 }
78
79 static double smpi_bandwidth_constraint(double rate, double bound, double size)
80 {
81   return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
82 }
83
84
85 static double (*latency_factor_callback)(double) = &constant_latency_factor;
86 static double (*bandwidth_factor_callback)(double) = &constant_bandwidth_factor;
87 static double (*bandwidth_constraint_callback)(double, double, double) = &constant_bandwidth_constraint;
88
89
90 static link_CM02_t net_link_new(char *name,
91                             double bw_initial,
92                             tmgr_trace_t bw_trace,
93                             double lat_initial,
94                             tmgr_trace_t lat_trace,
95                             e_surf_resource_state_t
96                             state_initial,
97                             tmgr_trace_t state_trace,
98                             e_surf_link_sharing_policy_t
99                             policy, xbt_dict_t properties)
100 {
101   link_CM02_t nw_link = (link_CM02_t)
102     surf_resource_lmm_new(sizeof(s_link_CM02_t),
103                           surf_network_model, name, properties,
104                           network_maxmin_system,
105                           sg_bandwidth_factor * bw_initial,
106                           history,
107                           state_initial, state_trace,
108                           bw_initial, bw_trace);
109
110   xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_set, name),
111               "Link '%s' declared several times in the platform file.", name);
112
113   nw_link->lat_current = lat_initial;
114   if (lat_trace)
115     nw_link->lat_event =
116       tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
117
118   if (policy == SURF_LINK_FATPIPE)
119     lmm_constraint_shared(nw_link->lmm_resource.constraint);
120
121   xbt_dict_set(surf_network_model->resource_set, name, nw_link,
122                surf_resource_free);
123 #ifdef HAVE_TRACING
124   TRACE_surf_link_declaration (name, bw_initial, lat_initial);
125 #endif
126
127   return nw_link;
128 }
129
130 static void net_parse_link_init(void)
131 {
132   char *name_link;
133   double bw_initial;
134   tmgr_trace_t bw_trace;
135   double lat_initial;
136   tmgr_trace_t lat_trace;
137   e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
138   e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
139   tmgr_trace_t state_trace;
140
141   name_link = xbt_strdup(A_surfxml_link_id);
142   surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
143   bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
144   surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
145   lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
146
147   xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON)
148               || (A_surfxml_link_state ==
149                   A_surfxml_link_state_OFF), "Invalid state");
150   if (A_surfxml_link_state == A_surfxml_link_state_ON)
151     state_initial_link = SURF_RESOURCE_ON;
152   else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
153     state_initial_link = SURF_RESOURCE_OFF;
154
155   if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
156     policy_initial_link = SURF_LINK_SHARED;
157   else if (A_surfxml_link_sharing_policy ==
158            A_surfxml_link_sharing_policy_FATPIPE)
159     policy_initial_link = SURF_LINK_FATPIPE;
160
161   state_trace = tmgr_trace_new(A_surfxml_link_state_file);
162
163   net_link_new(name_link, bw_initial, bw_trace,
164            lat_initial, lat_trace, state_initial_link, state_trace,
165            policy_initial_link, xbt_dict_new());
166
167 }
168
169 static void net_create_resource(char *name,
170         double bw_initial,
171         tmgr_trace_t bw_trace,
172         double lat_initial,
173         tmgr_trace_t lat_trace,
174         e_surf_resource_state_t
175         state_initial,
176         tmgr_trace_t state_trace,
177         e_surf_link_sharing_policy_t policy,
178         xbt_dict_t properties)
179 {
180         net_link_new(name, bw_initial, bw_trace,
181                    lat_initial, lat_trace, state_initial, state_trace,
182                    policy, xbt_dict_new());
183 }
184 static void net_add_traces(void)
185 {
186   xbt_dict_cursor_t cursor = NULL;
187   char *trace_name, *elm;
188
189   static int called = 0;
190   if (called)
191     return;
192   called = 1;
193
194   /* connect all traces relative to network */
195   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
196     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
197     link_CM02_t link =
198       xbt_dict_get_or_null(surf_network_model->resource_set, elm);
199
200     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
201                 trace_name, elm);
202     xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined",
203                 trace_name, elm);
204
205     link->lmm_resource.state_event =
206       tmgr_history_add_trace(history, trace, 0.0, 0, link);
207   }
208
209   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
210     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
211     link_CM02_t link =
212       xbt_dict_get_or_null(surf_network_model->resource_set, elm);
213
214     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
215                 trace_name, elm);
216     xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined",
217                 trace_name, elm);
218
219     link->lmm_resource.power.event =
220       tmgr_history_add_trace(history, trace, 0.0, 0, link);
221   }
222
223   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
224     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
225     link_CM02_t link =
226       xbt_dict_get_or_null(surf_network_model->resource_set, elm);
227
228     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
229                 trace_name, elm);
230     xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined",
231                 trace_name, elm);
232
233     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
234   }
235 }
236
237 static void net_define_callbacks(const char *file)
238 {
239   /* Figuring out the network links */
240   surfxml_add_callback(STag_surfxml_link_cb_list, &net_parse_link_init);
241   surfxml_add_callback(ETag_surfxml_platform_cb_list, &net_add_traces);
242 }
243
244 static int net_resource_used(void *resource_id)
245 {
246   return lmm_constraint_used(network_maxmin_system,
247                              ((surf_resource_lmm_t) resource_id)->constraint);
248 }
249
250 static int net_action_unref(surf_action_t action)
251 {
252   action->refcount--;
253   if (!action->refcount) {
254     xbt_swag_remove(action, action->state_set);
255     if (((surf_action_network_CM02_t) action)->variable)
256       lmm_variable_free(network_maxmin_system,
257                         ((surf_action_network_CM02_t) action)->variable);
258     free(action);
259     return 1;
260   }
261   return 0;
262 }
263
264 static void net_action_cancel(surf_action_t action)
265 {
266   surf_network_model->action_state_set((surf_action_t) action,
267                                        SURF_ACTION_FAILED);
268   return;
269 }
270
271 static void net_action_recycle(surf_action_t action)
272 {
273   return;
274 }
275
276 static int net_get_link_latency(surf_action_t action)
277 {
278   return action->latency_limited;
279 }
280
281 static double net_action_get_remains(surf_action_t action)
282 {
283   return action->remains;
284 }
285
286 static double net_share_resources(double now)
287 {
288   s_surf_action_network_CM02_t s_action;
289   surf_action_network_CM02_t action = NULL;
290   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
291   double min;
292
293   min = generic_maxmin_share_resources(running_actions,
294                                        xbt_swag_offset(s_action,
295                                                        variable),
296                                        network_maxmin_system, network_solve);
297
298 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable)  )))
299
300   xbt_swag_foreach(action, running_actions) {
301         if( lmm_is_variable_limited_by_latency(action->variable) ){
302                 (action->generic_action).latency_limited = 1;
303         }else{
304                 (action->generic_action).latency_limited = 0;
305         }
306     if (action->latency > 0) {
307       if (min < 0)
308         min = action->latency;
309       else if (action->latency < min)
310         min = action->latency;
311     }
312   }
313
314   return min;
315 }
316
317 static void net_update_actions_state(double now, double delta)
318 {
319   double deltap = 0.0;
320   surf_action_network_CM02_t action = NULL;
321   surf_action_network_CM02_t next_action = NULL;
322   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
323   /*
324      xbt_swag_t failed_actions =
325      surf_network_model->states.failed_action_set;
326    */
327
328   xbt_swag_foreach_safe(action, next_action, running_actions) {
329
330 #ifdef HAVE_TRACING
331     xbt_dynar_t route = used_routing->get_route(action->src, action->dst);
332     link_CM02_t link;
333     unsigned int i;
334     xbt_dynar_foreach(route, i, link) {
335         TRACE_surf_link_set_utilization (link->lmm_resource.generic_resource.name,
336           action->generic_action.data, lmm_variable_getvalue(action->variable), now-delta, delta);
337     }
338 #endif
339
340     deltap = delta;
341     if (action->latency > 0) {
342       if (action->latency > deltap) {
343         double_update(&(action->latency), deltap);
344         deltap = 0.0;
345       } else {
346         double_update(&(deltap), action->latency);
347         action->latency = 0.0;
348       }
349       if ((action->latency == 0.0) && !(action->suspended))
350         lmm_update_variable_weight(network_maxmin_system, action->variable,
351                                    action->weight);
352     }
353     double_update(&(action->generic_action.remains),
354                   lmm_variable_getvalue(action->variable) * deltap);
355     if (action->generic_action.max_duration != NO_MAX_DURATION)
356       double_update(&(action->generic_action.max_duration), delta);
357
358     if ((action->generic_action.remains <= 0) &&
359         (lmm_get_variable_weight(action->variable) > 0)) {
360       action->generic_action.finish = surf_get_clock();
361       surf_network_model->action_state_set((surf_action_t) action,
362                                            SURF_ACTION_DONE);
363     } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
364                && (action->generic_action.max_duration <= 0)) {
365       action->generic_action.finish = surf_get_clock();
366       surf_network_model->action_state_set((surf_action_t) action,
367                                            SURF_ACTION_DONE);
368     }
369   }
370
371   return;
372 }
373
374 static void net_update_resource_state(void *id,
375                                   tmgr_trace_event_t event_type,
376                                   double value, double date)
377 {
378   link_CM02_t nw_link = id;
379   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
380   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
381   /*     value, event_type); */
382
383   if (event_type == nw_link->lmm_resource.power.event) {
384     double delta =
385       sg_weight_S_parameter / value - sg_weight_S_parameter /
386       (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale);
387     lmm_variable_t var = NULL;
388     lmm_element_t elem = NULL;
389     surf_action_network_CM02_t action = NULL;
390
391     nw_link->lmm_resource.power.peak = value;
392     lmm_update_constraint_bound(network_maxmin_system,
393                                 nw_link->lmm_resource.constraint,
394                                 sg_bandwidth_factor *
395                                 (nw_link->lmm_resource.power.peak *
396                                  nw_link->lmm_resource.power.scale));
397 #ifdef HAVE_TRACING
398     TRACE_surf_link_set_bandwidth (date, nw_link->lmm_resource.generic_resource.name, sg_bandwidth_factor * (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale));
399 #endif
400     if (sg_weight_S_parameter > 0) {
401       while ((var = lmm_get_var_from_cnst
402               (network_maxmin_system, nw_link->lmm_resource.constraint,
403                &elem))) {
404         action = lmm_variable_id(var);
405         action->weight += delta;
406         if (!(action->suspended))
407           lmm_update_variable_weight(network_maxmin_system, action->variable,
408                                      action->weight);
409       }
410     }
411     if (tmgr_trace_event_free(event_type))
412       nw_link->lmm_resource.power.event = NULL;
413   } else if (event_type == nw_link->lat_event) {
414     double delta = value - nw_link->lat_current;
415     lmm_variable_t var = NULL;
416     lmm_element_t elem = NULL;
417     surf_action_network_CM02_t action = NULL;
418
419     nw_link->lat_current = value;
420     while ((var = lmm_get_var_from_cnst
421             (network_maxmin_system, nw_link->lmm_resource.constraint,
422              &elem))) {
423       action = lmm_variable_id(var);
424       action->lat_current += delta;
425       action->weight += delta;
426       if (action->rate < 0)
427         lmm_update_variable_bound(network_maxmin_system, action->variable,
428                                   sg_tcp_gamma / (2.0 * action->lat_current));
429       else{
430         lmm_update_variable_bound(network_maxmin_system, action->variable,
431                                   min(action->rate,
432                                       sg_tcp_gamma / (2.0 *
433                                                       action->lat_current)));
434
435         if(action->rate < sg_tcp_gamma / (2.0 * action->lat_current) ){
436                 INFO0("Flow is limited BYBANDWIDTH");
437         }else{
438                 INFO1("Flow is limited BYLATENCY, latency of flow is %f",action->lat_current);
439         }
440       }
441       if (!(action->suspended))
442         lmm_update_variable_weight(network_maxmin_system, action->variable,
443                                    action->weight);
444
445     }
446     if (tmgr_trace_event_free(event_type))
447       nw_link->lat_event = NULL;
448   } else if (event_type == nw_link->lmm_resource.state_event) {
449     if (value > 0)
450       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
451     else {
452       lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
453       lmm_variable_t var = NULL;
454       lmm_element_t elem = NULL;
455
456       nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
457       while ((var = lmm_get_var_from_cnst
458               (network_maxmin_system, cnst, &elem))) {
459         surf_action_t action = lmm_variable_id(var);
460
461         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
462             surf_action_state_get(action) == SURF_ACTION_READY) {
463           action->finish = date;
464           surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
465         }
466       }
467     }
468     if (tmgr_trace_event_free(event_type))
469       nw_link->lmm_resource.state_event = NULL;
470   } else {
471     CRITICAL0("Unknown event ! \n");
472     xbt_abort();
473   }
474
475   return;
476 }
477
478
479 static surf_action_t net_communicate(const char *src_name, const char *dst_name,
480                                  int src, int dst, double size, double rate)
481 {
482   unsigned int i;
483   link_CM02_t link;
484   int failed = 0;
485   surf_action_network_CM02_t action = NULL;
486   double bandwidth_bound;
487   /* LARGE PLATFORMS HACK:
488      Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node
489      Use the cluster_id for ->id */
490   xbt_dynar_t route = used_routing->get_route(src, dst);
491   xbt_dynar_t back_route = NULL;
492   int constraints_per_variable = 0;
493
494   if( sg_network_fullduplex == 1){
495           back_route = used_routing->get_route(dst, src);
496   }
497
498   /* LARGE PLATFORMS HACK:
499      total_route_size = route_size + src->link_nb + dst->nb */
500
501   XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
502   /* LARGE PLATFORMS HACK:
503      assert on total_route_size */
504   xbt_assert2(xbt_dynar_length(route),
505               "You're trying to send data from %s to %s but there is no connection between these two hosts.",
506               src_name, dst_name);
507
508   xbt_dynar_foreach(route, i, link) {
509     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
510       failed = 1;
511       break;
512     }
513   }
514   action =
515     surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
516                     surf_network_model, failed);
517   (action->generic_action).latency_limited = 0;
518
519   xbt_swag_insert(action, action->generic_action.state_set);
520   action->rate = rate;
521
522   action->latency = 0.0;
523   action->weight = 0.0;
524   bandwidth_bound = -1.0;
525   xbt_dynar_foreach(route, i, link) {
526     action->latency += link->lat_current;
527     action->weight +=
528       link->lat_current +
529       sg_weight_S_parameter /
530       (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
531     if(bandwidth_bound < 0.0)
532       bandwidth_bound = (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
533     else
534       bandwidth_bound = min(bandwidth_bound, (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale));
535   }
536   /* LARGE PLATFORMS HACK:
537      Add src->link and dst->link latencies */
538   action->lat_current = action->latency;
539   action->latency *= (*latency_factor_callback)(size);
540   action->rate = (*bandwidth_constraint_callback)(action->rate, bandwidth_bound, size);
541
542   /* LARGE PLATFORMS HACK:
543      lmm_variable_new(..., total_route_size) */
544   if(back_route != NULL){
545           constraints_per_variable = xbt_dynar_length(route)+xbt_dynar_length(back_route);
546   }else{
547           constraints_per_variable = xbt_dynar_length(route);
548   }
549
550   if (action->latency > 0)
551     action->variable =
552       lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,constraints_per_variable);
553   else
554     action->variable =
555       lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,constraints_per_variable);
556
557   if (action->rate < 0) {
558     if (action->lat_current > 0)
559       lmm_update_variable_bound(network_maxmin_system, action->variable,
560                                 sg_tcp_gamma / (2.0 * action->lat_current));
561     else
562       lmm_update_variable_bound(network_maxmin_system, action->variable,
563                                 -1.0);
564   } else {
565     if (action->lat_current > 0)
566       lmm_update_variable_bound(network_maxmin_system, action->variable,
567                                 min(action->rate,
568                                     sg_tcp_gamma / (2.0 *
569                                                     action->lat_current)));
570     else
571       lmm_update_variable_bound(network_maxmin_system, action->variable,
572                                 action->rate);
573   }
574
575   xbt_dynar_foreach(route, i, link) {
576     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
577                action->variable, 1.0);
578   }
579
580   if( sg_network_fullduplex == 1){
581           DEBUG1("Fullduplex active adding backward flow using 5%c", '%');
582           xbt_dynar_foreach(back_route, i, link) {
583                   lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
584                action->variable, .05);
585           }
586   }  /* LARGE PLATFORMS HACK:
587      expand also with src->link and dst->link */
588
589   /* saving the src and dst of this communication */
590   action->src = src;
591   action->dst = dst;
592
593   XBT_OUT;
594
595   return (surf_action_t) action;
596 }
597
598 static double net_get_link_bandwidth(const void *link)
599 {
600   surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
601   return lmm->power.peak * lmm->power.scale;
602 }
603
604 static int net_link_shared(const void *link)
605 {
606   return lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
607 }
608
609 static void net_action_suspend(surf_action_t action)
610 {
611   ((surf_action_network_CM02_t) action)->suspended = 1;
612   lmm_update_variable_weight(network_maxmin_system,
613                              ((surf_action_network_CM02_t) action)->variable,
614                              0.0);
615 }
616
617 static void net_action_resume(surf_action_t action)
618 {
619   if (((surf_action_network_CM02_t) action)->suspended) {
620     lmm_update_variable_weight(network_maxmin_system,
621                                ((surf_action_network_CM02_t)
622                                 action)->variable,
623                                ((surf_action_network_CM02_t) action)->weight);
624     ((surf_action_network_CM02_t) action)->suspended = 0;
625   }
626 }
627
628 static int net_action_is_suspended(surf_action_t action)
629 {
630   return ((surf_action_network_CM02_t) action)->suspended;
631 }
632
633 static void net_action_set_max_duration(surf_action_t action, double duration)
634 {
635   action->max_duration = duration;
636 }
637
638 static void net_finalize(void)
639 {
640   surf_model_exit(surf_network_model);
641   surf_network_model = NULL;
642
643   used_routing->finalize();
644   lmm_system_free(network_maxmin_system);
645   network_maxmin_system = NULL;
646 }
647
648 static void surf_network_model_init_internal(void)
649 {
650   surf_network_model = surf_model_init();
651
652   surf_network_model->name = "network";
653   surf_network_model->action_unref = net_action_unref;
654   surf_network_model->action_cancel = net_action_cancel;
655   surf_network_model->action_recycle = net_action_recycle;
656   surf_network_model->get_remains = net_action_get_remains;
657   surf_network_model->get_latency_limited = net_get_link_latency;
658
659   surf_network_model->model_private->resource_used = net_resource_used;
660   surf_network_model->model_private->share_resources = net_share_resources;
661   surf_network_model->model_private->update_actions_state =
662     net_update_actions_state;
663   surf_network_model->model_private->update_resource_state =
664     net_update_resource_state;
665   surf_network_model->model_private->finalize = net_finalize;
666
667   surf_network_model->suspend = net_action_suspend;
668   surf_network_model->resume = net_action_resume;
669   surf_network_model->is_suspended = net_action_is_suspended;
670   surf_cpu_model->set_max_duration = net_action_set_max_duration;
671
672   surf_network_model->extension.network.communicate = net_communicate;
673   surf_network_model->extension.network.get_link_bandwidth =
674     net_get_link_bandwidth;
675   surf_network_model->extension.network.link_shared = net_link_shared;
676   surf_network_model->extension.network.add_traces = net_add_traces;
677   surf_network_model->extension.network.create_resource = net_create_resource;
678
679   if (!network_maxmin_system)
680     network_maxmin_system = lmm_system_new();
681
682   routing_model_create(sizeof(link_CM02_t),
683                        net_link_new(xbt_strdup("__loopback__"),
684                                 498000000, NULL, 0.000015, NULL,
685                                 SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE,
686                                 NULL));
687 }
688
689
690
691 /************************************************************************/
692 /* New model based on LV08 and experimental results of MPI ping-pongs   */
693 /************************************************************************/
694 void surf_network_model_init_SMPI(const char *filename)
695 {
696
697   if (surf_network_model)
698     return;
699   surf_network_model_init_internal();
700   latency_factor_callback = &smpi_latency_factor;
701   bandwidth_factor_callback = &smpi_bandwidth_factor;
702   bandwidth_constraint_callback = &smpi_bandwidth_constraint;
703   net_define_callbacks(filename);
704   xbt_dynar_push(model_list, &surf_network_model);
705   network_solve = lmm_solve;
706
707   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
708
709   update_model_description(surf_network_model_description,
710                            "SMPI", surf_network_model);
711 }
712
713 /************************************************************************/
714 /* New model based on optimizations discussed during this thesis        */
715 /************************************************************************/
716 void surf_network_model_init_LegrandVelho(const char *filename)
717 {
718
719   if (surf_network_model)
720     return;
721   surf_network_model_init_internal();
722   net_define_callbacks(filename);
723   xbt_dynar_push(model_list, &surf_network_model);
724   network_solve = lmm_solve;
725
726   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor",10.4);
727   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
728   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
729
730   update_model_description(surf_network_model_description,
731                            "LV08", surf_network_model);
732 }
733
734 /***************************************************************************/
735 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
736 /***************************************************************************/
737 /* @TechReport{      rr-lip2002-40, */
738 /*   author        = {Henri Casanova and Loris Marchal}, */
739 /*   institution   = {LIP}, */
740 /*   title         = {A Network Model for Simulation of Grid Application}, */
741 /*   number        = {2002-40}, */
742 /*   month         = {oct}, */
743 /*   year          = {2002} */
744 /* } */
745 void surf_network_model_init_CM02(const char *filename)
746 {
747
748   if (surf_network_model)
749     return;
750   surf_network_model_init_internal();
751   net_define_callbacks(filename);
752   xbt_dynar_push(model_list, &surf_network_model);
753   network_solve = lmm_solve;
754
755   update_model_description(surf_network_model_description,
756                            "CM02", surf_network_model);
757 }
758
759 void surf_network_model_init_Reno(const char *filename)
760 {
761   if (surf_network_model)
762     return;
763   surf_network_model_init_internal();
764   net_define_callbacks(filename);
765
766   xbt_dynar_push(model_list, &surf_network_model);
767   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
768   network_solve = lagrange_solve;
769
770   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
771   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
772   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
773
774   update_model_description(surf_network_model_description,
775                            "Reno", surf_network_model);
776 }
777
778
779 void surf_network_model_init_Reno2(const char *filename)
780 {
781   if (surf_network_model)
782     return;
783   surf_network_model_init_internal();
784   net_define_callbacks(filename);
785
786   xbt_dynar_push(model_list, &surf_network_model);
787   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
788                                     func_reno2_fpi);
789   network_solve = lagrange_solve;
790
791   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
792   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
793   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S_parameter", 8775);
794
795   update_model_description(surf_network_model_description,
796                            "Reno2", surf_network_model);
797 }
798
799 void surf_network_model_init_Vegas(const char *filename)
800 {
801   if (surf_network_model)
802     return;
803   surf_network_model_init_internal();
804   net_define_callbacks(filename);
805
806   xbt_dynar_push(model_list, &surf_network_model);
807   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
808                                     func_vegas_fpi);
809   network_solve = lagrange_solve;
810
811   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
812   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
813   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
814
815   update_model_description(surf_network_model_description,
816                            "Vegas", surf_network_model);
817 }
818
819