Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I comment all the calls to used_routing, in order to use global routing.
[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(action, SURF_ACTION_FAILED);
267 }
268
269 void net_action_recycle(surf_action_t action)
270 {
271   return;
272 }
273
274 int net_get_link_latency(surf_action_t action)
275 {
276   return action->latency_limited;
277 }
278
279 double net_action_get_remains(surf_action_t action)
280 {
281   return action->remains;
282 }
283
284 static double net_share_resources(double now)
285 {
286   s_surf_action_network_CM02_t s_action;
287   surf_action_network_CM02_t action = NULL;
288   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
289   double min;
290
291   min = generic_maxmin_share_resources(running_actions,
292                                        xbt_swag_offset(s_action,
293                                                        variable),
294                                        network_maxmin_system, network_solve);
295
296 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable)  )))
297
298   xbt_swag_foreach(action, running_actions) {
299         if( lmm_is_variable_limited_by_latency(action->variable) ){
300                 (action->generic_action).latency_limited = 1;
301         }else{
302                 (action->generic_action).latency_limited = 0;
303         }
304     if (action->latency > 0) {
305       if (min < 0)
306         min = action->latency;
307       else if (action->latency < min)
308         min = action->latency;
309     }
310   }
311
312   return min;
313 }
314
315 static void net_update_actions_state(double now, double delta)
316 {
317   double deltap = 0.0;
318   surf_action_network_CM02_t action = NULL;
319   surf_action_network_CM02_t next_action = NULL;
320   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
321   /*
322      xbt_swag_t failed_actions =
323      surf_network_model->states.failed_action_set;
324    */
325
326   xbt_swag_foreach_safe(action, next_action, running_actions) {
327 #ifdef HAVE_TRACING
328 // COMMENTED BY DAVID
329 //     xbt_dynar_t route = used_routing->get_route(action->src, action->dst);
330 //     
331 //     link_CM02_t link;
332 //     unsigned int i;
333 //     xbt_dynar_foreach(route, i, link) {
334 //      TRACE_surf_link_set_utilization (link->lmm_resource.generic_resource.name,
335 //           action->generic_action.data, lmm_variable_getvalue(action->variable), now-delta, delta);
336 //     }
337 #endif
338     deltap = delta;
339     if (action->latency > 0) {
340       if (action->latency > deltap) {
341         double_update(&(action->latency), deltap);
342         deltap = 0.0;
343       } else {
344         double_update(&(deltap), action->latency);
345         action->latency = 0.0;
346       }
347       if ((action->latency == 0.0) && !(action->suspended))
348         lmm_update_variable_weight(network_maxmin_system, action->variable,
349                                    action->weight);
350     }
351 #ifdef HAVE_TRACING
352     xbt_dynar_t route = used_routing->get_route(action->src, action->dst);
353     link_CM02_t link;
354     unsigned int i;
355     xbt_dynar_foreach(route, i, link) {
356       TRACE_surf_link_set_utilization (link->lmm_resource.generic_resource.name,
357           action->generic_action.data, lmm_variable_getvalue(action->variable), now-delta, delta);
358     }
359 #endif
360     double_update(&(action->generic_action.remains),
361                   lmm_variable_getvalue(action->variable) * deltap);
362     if (action->generic_action.max_duration != NO_MAX_DURATION)
363       double_update(&(action->generic_action.max_duration), delta);
364
365     if ((action->generic_action.remains <= 0) &&
366         (lmm_get_variable_weight(action->variable) > 0)) {
367       action->generic_action.finish = surf_get_clock();
368       surf_network_model->action_state_set((surf_action_t) action,
369                                            SURF_ACTION_DONE);
370     } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
371                && (action->generic_action.max_duration <= 0)) {
372       action->generic_action.finish = surf_get_clock();
373       surf_network_model->action_state_set((surf_action_t) action,
374                                            SURF_ACTION_DONE);
375     }
376   }
377
378   return;
379 }
380
381 static void net_update_resource_state(void *id,
382                                   tmgr_trace_event_t event_type,
383                                   double value, double date)
384 {
385   link_CM02_t nw_link = id;
386   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
387   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
388   /*     value, event_type); */
389
390   if (event_type == nw_link->lmm_resource.power.event) {
391     double delta =
392       sg_weight_S_parameter / value - sg_weight_S_parameter /
393       (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale);
394     lmm_variable_t var = NULL;
395     lmm_element_t elem = NULL;
396     surf_action_network_CM02_t action = NULL;
397
398     nw_link->lmm_resource.power.peak = value;
399     lmm_update_constraint_bound(network_maxmin_system,
400                                 nw_link->lmm_resource.constraint,
401                                 sg_bandwidth_factor *
402                                 (nw_link->lmm_resource.power.peak *
403                                  nw_link->lmm_resource.power.scale));
404 #ifdef HAVE_TRACING
405     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));
406 #endif
407     if (sg_weight_S_parameter > 0) {
408       while ((var = lmm_get_var_from_cnst
409               (network_maxmin_system, nw_link->lmm_resource.constraint,
410                &elem))) {
411         action = lmm_variable_id(var);
412         action->weight += delta;
413         if (!(action->suspended))
414           lmm_update_variable_weight(network_maxmin_system, action->variable,
415                                      action->weight);
416       }
417     }
418     if (tmgr_trace_event_free(event_type))
419       nw_link->lmm_resource.power.event = NULL;
420   } else if (event_type == nw_link->lat_event) {
421     double delta = value - nw_link->lat_current;
422     lmm_variable_t var = NULL;
423     lmm_element_t elem = NULL;
424     surf_action_network_CM02_t action = NULL;
425
426     nw_link->lat_current = value;
427     while ((var = lmm_get_var_from_cnst
428             (network_maxmin_system, nw_link->lmm_resource.constraint,
429              &elem))) {
430       action = lmm_variable_id(var);
431       action->lat_current += delta;
432       action->weight += delta;
433       if (action->rate < 0)
434         lmm_update_variable_bound(network_maxmin_system, action->variable,
435                                   sg_tcp_gamma / (2.0 * action->lat_current));
436       else{
437         lmm_update_variable_bound(network_maxmin_system, action->variable,
438                                   min(action->rate,
439                                       sg_tcp_gamma / (2.0 *
440                                                       action->lat_current)));
441
442         if(action->rate < sg_tcp_gamma / (2.0 * action->lat_current) ){
443                 INFO0("Flow is limited BYBANDWIDTH");
444         }else{
445                 INFO1("Flow is limited BYLATENCY, latency of flow is %f",action->lat_current);
446         }
447       }
448       if (!(action->suspended))
449         lmm_update_variable_weight(network_maxmin_system, action->variable,
450                                    action->weight);
451
452     }
453     if (tmgr_trace_event_free(event_type))
454       nw_link->lat_event = NULL;
455   } else if (event_type == nw_link->lmm_resource.state_event) {
456     if (value > 0)
457       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
458     else {
459       lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
460       lmm_variable_t var = NULL;
461       lmm_element_t elem = NULL;
462
463       nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
464       while ((var = lmm_get_var_from_cnst
465               (network_maxmin_system, cnst, &elem))) {
466         surf_action_t action = lmm_variable_id(var);
467
468         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
469             surf_action_state_get(action) == SURF_ACTION_READY) {
470           action->finish = date;
471           surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
472         }
473       }
474     }
475     if (tmgr_trace_event_free(event_type))
476       nw_link->lmm_resource.state_event = NULL;
477   } else {
478     CRITICAL0("Unknown event ! \n");
479     xbt_abort();
480   }
481
482   return;
483 }
484
485
486 static surf_action_t net_communicate(const char *src_name, const char *dst_name,
487                                  int src, int dst, double size, double rate)
488 {
489   unsigned int i;
490   link_CM02_t link;
491   int failed = 0;
492   surf_action_network_CM02_t action = NULL;
493   double bandwidth_bound;
494   /* LARGE PLATFORMS HACK:
495      Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node
496      Use the cluster_id for ->id */
497
498   //xbt_dynar_t route = used_routing->get_route(src, dst);  // COMMENTED BY DAVID
499   xbt_dynar_t route = global_routing->get_route(src_name, dst_name);
500   xbt_dynar_t back_route = NULL;
501   int constraints_per_variable = 0;
502
503   if( sg_network_fullduplex == 1){
504           //back_route = used_routing->get_route(dst, src);  // COMMENTED BY DAVID
505           back_route = global_routing->get_route(src_name, dst_name);
506   }
507   
508   /* LARGE PLATFORMS HACK:
509      total_route_size = route_size + src->link_nb + dst->nb */
510
511   XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
512   /* LARGE PLATFORMS HACK:
513      assert on total_route_size */
514   xbt_assert2(xbt_dynar_length(route),
515               "You're trying to send data from %s to %s but there is no connection between these two hosts.",
516               src_name, dst_name);
517
518   xbt_dynar_foreach(route, i, link) {
519     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
520       failed = 1;
521       break;
522     }
523   }
524   action =
525     surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
526                     surf_network_model, failed);
527   (action->generic_action).latency_limited = 0;
528
529   xbt_swag_insert(action, action->generic_action.state_set);
530   action->rate = rate;
531
532   action->latency = 0.0;
533   action->weight = 0.0;
534   bandwidth_bound = -1.0;
535   xbt_dynar_foreach(route, i, link) {
536     action->latency += link->lat_current;
537     action->weight +=
538       link->lat_current +
539       sg_weight_S_parameter /
540       (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
541     if(bandwidth_bound < 0.0)
542       bandwidth_bound = (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
543     else
544       bandwidth_bound = min(bandwidth_bound, (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale));
545   }
546   /* LARGE PLATFORMS HACK:
547      Add src->link and dst->link latencies */
548   action->lat_current = action->latency;
549   action->latency *= (*latency_factor_callback)(size);
550   action->rate = (*bandwidth_constraint_callback)(action->rate, bandwidth_bound, size);
551
552   /* LARGE PLATFORMS HACK:
553      lmm_variable_new(..., total_route_size) */
554   if(back_route != NULL){
555           constraints_per_variable = xbt_dynar_length(route)+xbt_dynar_length(back_route);
556   }else{
557           constraints_per_variable = xbt_dynar_length(route);
558   }
559
560   if (action->latency > 0)
561     action->variable =
562       lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,constraints_per_variable);
563   else
564     action->variable =
565       lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,constraints_per_variable);
566
567   if (action->rate < 0) {
568     if (action->lat_current > 0)
569       lmm_update_variable_bound(network_maxmin_system, action->variable,
570                                 sg_tcp_gamma / (2.0 * action->lat_current));
571     else
572       lmm_update_variable_bound(network_maxmin_system, action->variable,
573                                 -1.0);
574   } else {
575     if (action->lat_current > 0)
576       lmm_update_variable_bound(network_maxmin_system, action->variable,
577                                 min(action->rate,
578                                     sg_tcp_gamma / (2.0 *
579                                                     action->lat_current)));
580     else
581       lmm_update_variable_bound(network_maxmin_system, action->variable,
582                                 action->rate);
583   }
584
585   xbt_dynar_foreach(route, i, link) {
586     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
587                action->variable, 1.0);
588   }
589
590   if( sg_network_fullduplex == 1){
591           DEBUG1("Fullduplex active adding backward flow using 5%c", '%');
592           xbt_dynar_foreach(back_route, i, link) {
593                   lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
594                action->variable, .05);
595           }
596   }  /* LARGE PLATFORMS HACK:
597      expand also with src->link and dst->link */
598
599   /* saving the src and dst of this communication */
600   action->src = src;
601   action->dst = dst;
602
603   XBT_OUT;
604
605   return (surf_action_t) action;
606 }
607
608 static double net_get_link_bandwidth(const void *link)
609 {
610   surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
611   return lmm->power.peak * lmm->power.scale;
612 }
613
614 static int net_link_shared(const void *link)
615 {
616   return lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
617 }
618
619 static void net_action_suspend(surf_action_t action)
620 {
621   ((surf_action_network_CM02_t) action)->suspended = 1;
622   lmm_update_variable_weight(network_maxmin_system,
623                              ((surf_action_network_CM02_t) action)->variable,
624                              0.0);
625 }
626
627 static void net_action_resume(surf_action_t action)
628 {
629   if (((surf_action_network_CM02_t) action)->suspended) {
630     lmm_update_variable_weight(network_maxmin_system,
631                                ((surf_action_network_CM02_t)
632                                 action)->variable,
633                                ((surf_action_network_CM02_t) action)->weight);
634     ((surf_action_network_CM02_t) action)->suspended = 0;
635   }
636 }
637
638 static int net_action_is_suspended(surf_action_t action)
639 {
640   return ((surf_action_network_CM02_t) action)->suspended;
641 }
642
643 void net_action_set_max_duration(surf_action_t action, double duration)
644 {
645   action->max_duration = duration;
646 }
647
648 static void net_finalize(void)
649 {
650   surf_model_exit(surf_network_model);
651   surf_network_model = NULL;
652
653   //used_routing->finalize(); // COMMENTED BY DAVID
654   
655   global_routing->finalize();
656   
657   lmm_system_free(network_maxmin_system);
658   network_maxmin_system = NULL;
659 }
660
661 static void surf_network_model_init_internal(void)
662 {
663   surf_network_model = surf_model_init();
664
665   surf_network_model->name = "network";
666   surf_network_model->action_unref = net_action_unref;
667   surf_network_model->action_cancel = net_action_cancel;
668   surf_network_model->action_recycle = net_action_recycle;
669   surf_network_model->get_remains = net_action_get_remains;
670   surf_network_model->get_latency_limited = net_get_link_latency;
671
672   surf_network_model->model_private->resource_used = net_resource_used;
673   surf_network_model->model_private->share_resources = net_share_resources;
674   surf_network_model->model_private->update_actions_state =
675     net_update_actions_state;
676   surf_network_model->model_private->update_resource_state =
677     net_update_resource_state;
678   surf_network_model->model_private->finalize = net_finalize;
679
680   surf_network_model->suspend = net_action_suspend;
681   surf_network_model->resume = net_action_resume;
682   surf_network_model->is_suspended = net_action_is_suspended;
683   surf_cpu_model->set_max_duration = net_action_set_max_duration;
684
685   surf_network_model->extension.network.communicate = net_communicate;
686   surf_network_model->extension.network.get_link_bandwidth =
687     net_get_link_bandwidth;
688   surf_network_model->extension.network.link_shared = net_link_shared;
689   surf_network_model->extension.network.add_traces = net_add_traces;
690   surf_network_model->extension.network.create_resource = net_create_resource;
691
692   if (!network_maxmin_system)
693     network_maxmin_system = lmm_system_new();
694
695   routing_model_create(sizeof(link_CM02_t),
696                        net_link_new(xbt_strdup("__loopback__"),
697                                 498000000, NULL, 0.000015, NULL,
698                                 SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE,
699                                 NULL));
700 }
701
702
703
704 /************************************************************************/
705 /* New model based on LV08 and experimental results of MPI ping-pongs   */
706 /************************************************************************/
707 void surf_network_model_init_SMPI(const char *filename)
708 {
709
710   if (surf_network_model)
711     return;
712   surf_network_model_init_internal();
713   latency_factor_callback = &smpi_latency_factor;
714   bandwidth_factor_callback = &smpi_bandwidth_factor;
715   bandwidth_constraint_callback = &smpi_bandwidth_constraint;
716   net_define_callbacks(filename);
717   xbt_dynar_push(model_list, &surf_network_model);
718   network_solve = lmm_solve;
719
720   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
721
722   update_model_description(surf_network_model_description,
723                            "SMPI", surf_network_model);
724 }
725
726 /************************************************************************/
727 /* New model based on optimizations discussed during this thesis        */
728 /************************************************************************/
729 void surf_network_model_init_LegrandVelho(const char *filename)
730 {
731
732   if (surf_network_model)
733     return;
734   surf_network_model_init_internal();
735   net_define_callbacks(filename);
736   xbt_dynar_push(model_list, &surf_network_model);
737   network_solve = lmm_solve;
738
739   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor",10.4);
740   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
741   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
742
743   update_model_description(surf_network_model_description,
744                            "LV08", surf_network_model);
745 }
746
747 /***************************************************************************/
748 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
749 /***************************************************************************/
750 /* @TechReport{      rr-lip2002-40, */
751 /*   author        = {Henri Casanova and Loris Marchal}, */
752 /*   institution   = {LIP}, */
753 /*   title         = {A Network Model for Simulation of Grid Application}, */
754 /*   number        = {2002-40}, */
755 /*   month         = {oct}, */
756 /*   year          = {2002} */
757 /* } */
758 void surf_network_model_init_CM02(const char *filename)
759 {
760
761   if (surf_network_model)
762     return;
763   surf_network_model_init_internal();
764   net_define_callbacks(filename);
765   xbt_dynar_push(model_list, &surf_network_model);
766   network_solve = lmm_solve;
767
768   update_model_description(surf_network_model_description,
769                            "CM02", surf_network_model);
770 }
771
772 void surf_network_model_init_Reno(const char *filename)
773 {
774   if (surf_network_model)
775     return;
776   surf_network_model_init_internal();
777   net_define_callbacks(filename);
778
779   xbt_dynar_push(model_list, &surf_network_model);
780   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
781   network_solve = lagrange_solve;
782
783   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
784   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
785   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
786
787   update_model_description(surf_network_model_description,
788                            "Reno", surf_network_model);
789 }
790
791
792 void surf_network_model_init_Reno2(const char *filename)
793 {
794   if (surf_network_model)
795     return;
796   surf_network_model_init_internal();
797   net_define_callbacks(filename);
798
799   xbt_dynar_push(model_list, &surf_network_model);
800   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
801                                     func_reno2_fpi);
802   network_solve = lagrange_solve;
803
804   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
805   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
806   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S_parameter", 8775);
807
808   update_model_description(surf_network_model_description,
809                            "Reno2", surf_network_model);
810 }
811
812 void surf_network_model_init_Vegas(const char *filename)
813 {
814   if (surf_network_model)
815     return;
816   surf_network_model_init_internal();
817   net_define_callbacks(filename);
818
819   xbt_dynar_push(model_list, &surf_network_model);
820   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
821                                     func_vegas_fpi);
822   network_solve = lagrange_solve;
823
824   xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
825   xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
826   xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
827
828   update_model_description(surf_network_model_description,
829                            "Vegas", surf_network_model);
830 }
831
832