Logo AND Algorithmique Numérique Distribuée

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