Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
860f14925a0d9b1e3c484a374782a7565c7cf9cd
[simgrid.git] / src / surf / network_constant.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 "surf_private.h"
9 #include "xbt/dict.h"
10 #include "xbt/str.h"
11 #include "xbt/log.h"
12
13 typedef struct network_card_Constant {
14   char *name;
15   int id;
16 } s_network_card_Constant_t, *network_card_Constant_t;
17
18 typedef struct network_link_Constant {
19   surf_model_t model;   /* Any such object, added in a trace
20                                    should start by this field!!! */
21   xbt_dict_t properties;
22   /* Using this object with the public part of
23      model does not make sense */
24   char *name;
25   double bw_current;
26   tmgr_trace_event_t bw_event;
27   double lat_current;
28   tmgr_trace_event_t lat_event;
29   e_surf_link_state_t state_current;
30   tmgr_trace_event_t state_event;
31   lmm_constraint_t constraint;
32 } s_link_Constant_t, *link_Constant_t;
33
34 typedef struct surf_action_network_Constant {
35   s_surf_action_t generic_action;
36   double latency;
37   double lat_current;
38   lmm_variable_t variable;
39   double rate;
40   int suspended;
41   network_card_Constant_t src;
42   network_card_Constant_t dst;
43 } s_surf_action_network_Constant_t, *surf_action_network_Constant_t;
44
45 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
46
47 static lmm_system_t network_maxmin_system = NULL;
48 static void (*network_solve) (lmm_system_t) = NULL;
49
50 static xbt_dict_t network_card_set = NULL;
51
52 static int card_number = 0;
53 static int host_number = 0;
54 static link_Constant_t **routing_table = NULL;
55 static int *routing_table_size = NULL;
56 static link_Constant_t loopback = NULL;
57
58 #define ROUTE(i,j) routing_table[(i)+(j)*card_number]
59 #define ROUTE_SIZE(i,j) routing_table_size[(i)+(j)*card_number]
60
61 static void create_routing_table(void)
62 {
63   routing_table =
64       xbt_new0(link_Constant_t *, /*card_number * card_number */ host_number * host_number);
65   routing_table_size = xbt_new0(int, /*card_number * card_number*/ host_number * host_number);
66 }
67
68 static void link_free(void *nw_link)
69 {
70   free(((link_Constant_t) nw_link)->name);
71   free(nw_link);
72 }
73
74 static link_Constant_t link_new(char *name,
75                             double bw_initial,
76                             tmgr_trace_t bw_trace,
77                             double lat_initial,
78                             tmgr_trace_t lat_trace,
79                             e_surf_link_state_t
80                             state_initial,
81                             tmgr_trace_t state_trace,
82                             e_surf_link_sharing_policy_t
83                             policy, xbt_dict_t properties)
84 {
85   link_Constant_t nw_link = xbt_new0(s_link_Constant_t, 1);
86   xbt_assert1(!xbt_dict_get_or_null(link_set, name), 
87               "Link '%s' declared several times in the platform file.", name);   
88
89   nw_link->model = (surf_model_t) surf_network_model;
90   nw_link->name = name;
91   nw_link->bw_current = bw_initial;
92   if (bw_trace)
93     nw_link->bw_event =
94         tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
95   nw_link->lat_current = lat_initial;
96   if (lat_trace)
97     nw_link->lat_event =
98         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
99   nw_link->state_current = state_initial;
100   if (state_trace)
101     nw_link->state_event =
102         tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
103
104   nw_link->constraint =
105       lmm_constraint_new(network_maxmin_system, nw_link,
106                          nw_link->bw_current);
107
108   if (policy == SURF_LINK_FATPIPE)
109     lmm_constraint_shared(nw_link->constraint);
110
111   nw_link->properties = properties;
112
113   current_property_set = properties;
114
115   xbt_dict_set(link_set, name, nw_link, link_free);
116
117   return nw_link;
118 }
119
120 static void network_card_free(void *nw_card)
121 {
122   free(((network_card_Constant_t) nw_card)->name);
123   free(nw_card);
124 }
125
126 static int network_card_new(const char *card_name)
127 {
128   network_card_Constant_t card =
129       xbt_dict_get_or_null(network_card_set, card_name);
130
131   if (!card) {
132     card = xbt_new0(s_network_card_Constant_t, 1);
133     card->name = xbt_strdup(card_name);
134     card->id = card_number++;
135     xbt_dict_set(network_card_set, card_name, card, network_card_free);
136   }
137   return card->id;
138 }
139
140 static void route_new(int src_id, int dst_id,
141                       link_Constant_t * link_list, int nb_link)
142 {
143   ROUTE_SIZE(src_id, dst_id) = nb_link;
144   ROUTE(src_id, dst_id) = link_list =
145       xbt_realloc(link_list, sizeof(link_Constant_t) * nb_link);
146 }
147
148 static void parse_link_init(void)
149 {
150   char *name_link;
151   double bw_initial;
152   tmgr_trace_t bw_trace;
153   double lat_initial;
154   tmgr_trace_t lat_trace;
155   e_surf_link_state_t state_initial_link = SURF_LINK_ON;
156   e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
157   tmgr_trace_t state_trace;
158
159   name_link = xbt_strdup(A_surfxml_link_id);
160   surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
161   surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
162   surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
163   surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
164
165   xbt_assert0((A_surfxml_link_state ==
166                A_surfxml_link_state_ON)
167               || (A_surfxml_link_state ==
168                   A_surfxml_link_state_OFF), "Invalid state");
169   if (A_surfxml_link_state == A_surfxml_link_state_ON)
170     state_initial_link = SURF_LINK_ON;
171   else if (A_surfxml_link_state ==
172            A_surfxml_link_state_OFF)
173     state_initial_link = SURF_LINK_OFF;
174
175   if (A_surfxml_link_sharing_policy ==
176       A_surfxml_link_sharing_policy_SHARED)
177     policy_initial_link = SURF_LINK_SHARED;
178   else if (A_surfxml_link_sharing_policy ==
179            A_surfxml_link_sharing_policy_FATPIPE)
180     policy_initial_link = SURF_LINK_FATPIPE;
181
182   surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
183
184   link_new(name_link, bw_initial, bw_trace,
185                    lat_initial, lat_trace, state_initial_link, state_trace,
186                    policy_initial_link, xbt_dict_new());
187
188 }
189
190 static int src_id = -1;
191 static int dst_id = -1;
192
193 static void parse_route_set_endpoints(void)
194 {
195   src_id = network_card_new(A_surfxml_route_src);
196   dst_id = network_card_new(A_surfxml_route_dst);
197   route_action = A_surfxml_route_action;
198   route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
199 }
200
201 static void parse_route_set_route(void)
202 {
203   char *name;
204   if (src_id != -1 && dst_id != -1) {
205     name = bprintf("%x#%x",src_id, dst_id);
206     manage_route(route_table, name, route_action, 0);
207     free(name);    
208   }
209 }
210
211 static void add_loopback(void)
212 {
213   int i;
214   /* Adding loopback if needed */
215   for (i = 0; i < host_number; i++)
216     if (!ROUTE_SIZE(i, i)) {
217       if (!loopback)
218         loopback = link_new(xbt_strdup("__MSG_loopback__"),
219                                     498000000, NULL, 0.000015, NULL,
220                                     SURF_LINK_ON, NULL,
221                                     SURF_LINK_FATPIPE,NULL);
222       ROUTE_SIZE(i, i) = 1;
223       ROUTE(i, i) = xbt_new0(link_Constant_t, 1);
224       ROUTE(i, i)[0] = loopback;
225     }
226 }
227
228 static void add_route(void)
229 {
230   xbt_ex_t e;
231   int nb_link = 0;
232   unsigned int cpt = 0;    
233   int link_list_capacity = 0;
234   link_Constant_t *link_list = NULL;
235   xbt_dict_cursor_t cursor = NULL;
236   char *key,*data, *end;
237   const char *sep = "#";
238   xbt_dynar_t links, keys;
239
240   if (routing_table == NULL) create_routing_table();
241
242   xbt_dict_foreach(route_table, cursor, key, data) {
243           char* link = NULL;
244     nb_link = 0;
245     links = (xbt_dynar_t)data;
246     keys = xbt_str_split_str(key, sep);
247
248     link_list_capacity = xbt_dynar_length(links);
249     link_list = xbt_new(link_Constant_t, link_list_capacity);
250
251     src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
252     dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
253  
254     xbt_dynar_foreach (links, cpt, link) {
255       TRY {
256         link_list[nb_link++] = xbt_dict_get(link_set, link);
257       }
258       CATCH(e) {
259         RETHROW1("Link %s not found (dict raised this exception: %s)", link);
260       }     
261     }
262     route_new(src_id, dst_id, link_list, nb_link);
263    }
264
265    xbt_dict_free(&route_table);
266
267 }
268
269 static void count_hosts(void)
270 {
271    host_number++;
272 }
273
274
275 static void add_traces(void) {
276    xbt_dict_cursor_t cursor=NULL;
277    char *trace_name,*elm;
278    
279    static int called = 0;
280    if (called) return;
281    called = 1;
282
283    /* connect all traces relative to network */
284    xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
285       tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
286       link_Constant_t link = xbt_dict_get_or_null(link_set, elm);
287       
288       xbt_assert1(link, "Link %s undefined", elm);
289       xbt_assert1(trace, "Trace %s undefined", trace_name);
290       
291       link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
292    }
293
294    xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
295       tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
296       link_Constant_t link = xbt_dict_get_or_null(link_set, elm);
297       
298       xbt_assert1(link, "Link %s undefined", elm);
299       xbt_assert1(trace, "Trace %s undefined", trace_name);
300       
301       link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
302    }
303    
304    xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
305       tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
306       link_Constant_t link = xbt_dict_get_or_null(link_set, elm);
307       
308       xbt_assert1(link, "Link %s undefined", elm);
309       xbt_assert1(trace, "Trace %s undefined", trace_name);
310       
311       link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
312    }
313
314    xbt_dict_free(&trace_connect_list_host_avail);
315    xbt_dict_free(&trace_connect_list_power);
316    xbt_dict_free(&trace_connect_list_link_avail);
317    xbt_dict_free(&trace_connect_list_bandwidth);
318    xbt_dict_free(&trace_connect_list_latency);
319    
320    xbt_dict_free(&traces_set_list); 
321 }
322
323 static void define_callbacks(const char *file)
324 {
325   /* Figuring out the network links */
326   surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
327   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
328   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
329   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
330   surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
331   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
332   surfxml_add_callback(STag_surfxml_platform_cb_list, &init_data);
333   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
334   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
335   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
336   surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
337   surfxml_add_callback(STag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_endpoints);
338   surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_route);
339   surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_foreach);
340   surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_cluster);
341   surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_trace_init);
342   surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_trace_finalize);
343   surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list, &parse_trace_c_connect);
344 }
345
346 static void *name_service(const char *name)
347 {
348   network_card_Constant_t card = xbt_dict_get_or_null(network_card_set, name);
349   return card;
350 }
351
352 static const char *get_resource_name(void *resource_id)
353 {
354   return ((network_card_Constant_t) resource_id)->name;
355 }
356
357 static int resource_used(void *resource_id)
358 {
359   return lmm_constraint_used(network_maxmin_system,
360                              ((link_Constant_t) resource_id)->
361                              constraint);
362 }
363
364 static int action_free(surf_action_t action)
365 {
366   action->using--;
367   if (!action->using) {
368     xbt_swag_remove(action, action->state_set);
369     if (((surf_action_network_Constant_t) action)->variable)
370       lmm_variable_free(network_maxmin_system,
371                         ((surf_action_network_Constant_t) action)->variable);
372     free(action);
373     return 1;
374   }
375   return 0;
376 }
377
378 static void action_use(surf_action_t action)
379 {
380   action->using++;
381 }
382
383 static void action_cancel(surf_action_t action)
384 {
385   return;
386 }
387
388 static void action_recycle(surf_action_t action)
389 {
390   return;
391 }
392
393 static void action_change_state(surf_action_t action,
394                                 e_surf_action_state_t state)
395 {
396 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
397 /*     if(((surf_action_network_Constant_t)action)->variable) { */
398 /*       lmm_variable_disable(network_maxmin_system, ((surf_action_network_Constant_t)action)->variable); */
399 /*       ((surf_action_network_Constant_t)action)->variable = NULL; */
400 /*     } */
401
402   surf_action_change_state(action, state);
403   return;
404 }
405
406 static double share_resources(double now)
407 {
408   s_surf_action_network_Constant_t s_action;
409   surf_action_network_Constant_t action = NULL;
410   xbt_swag_t running_actions =
411       surf_network_model->common_public->states.running_action_set;
412   double min;
413
414   min = generic_maxmin_share_resources(running_actions,
415                                        xbt_swag_offset(s_action,
416                                                        variable),
417                                        network_maxmin_system,
418                                        network_solve);
419
420   xbt_swag_foreach(action, running_actions) {
421     if (action->latency > 0) {
422       if (min < 0)
423         min = action->latency;
424       else if (action->latency < min)
425         min = action->latency;
426     }
427   }
428
429   return min;
430 }
431
432 static void update_actions_state(double now, double delta)
433 {
434   double deltap = 0.0;
435   surf_action_network_Constant_t action = NULL;
436   surf_action_network_Constant_t next_action = NULL;
437   xbt_swag_t running_actions =
438       surf_network_model->common_public->states.running_action_set;
439   /*
440      xbt_swag_t failed_actions =
441      surf_network_model->common_public->states.failed_action_set;
442    */
443
444   xbt_swag_foreach_safe(action, next_action, running_actions) {
445     deltap = delta;
446     if (action->latency > 0) {
447       if (action->latency > deltap) {
448         double_update(&(action->latency), deltap);
449         deltap = 0.0;
450       } else {
451         double_update(&(deltap), action->latency);
452         action->latency = 0.0;
453       }
454       if ((action->latency == 0.0) && !(action->suspended))
455         lmm_update_variable_weight(network_maxmin_system, action->variable,
456                                    action->lat_current);
457     }
458     double_update(&(action->generic_action.remains),
459                   lmm_variable_getvalue(action->variable) * deltap);
460     if (action->generic_action.max_duration != NO_MAX_DURATION)
461       double_update(&(action->generic_action.max_duration), delta);
462
463     /*   if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
464
465     if ((action->generic_action.remains <= 0) &&
466         (lmm_get_variable_weight(action->variable) > 0)) {
467       action->generic_action.finish = surf_get_clock();
468       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
469     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
470                (action->generic_action.max_duration <= 0)) {
471       action->generic_action.finish = surf_get_clock();
472       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
473     } else {                    /* Need to check that none of the model has failed */
474       lmm_constraint_t cnst = NULL;
475       int i = 0;
476       link_Constant_t nw_link = NULL;
477
478       while ((cnst =
479               lmm_get_cnst_from_var(network_maxmin_system,
480                                     action->variable, i++))) {
481         nw_link = lmm_constraint_id(cnst);
482         if (nw_link->state_current == SURF_LINK_OFF) {
483           action->generic_action.finish = surf_get_clock();
484           action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
485           break;
486         }
487       }
488     }
489   }
490
491   return;
492 }
493
494 static void update_resource_state(void *id,
495                                   tmgr_trace_event_t event_type,
496                                   double value)
497 {
498   link_Constant_t nw_link = id;
499   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
500   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
501   /*     value, event_type); */
502
503   if (event_type == nw_link->bw_event) {
504     nw_link->bw_current = value;
505     lmm_update_constraint_bound(network_maxmin_system, nw_link->constraint,
506                                 nw_link->bw_current);
507   } else if (event_type == nw_link->lat_event) {
508     double delta = value - nw_link->lat_current;
509     lmm_variable_t var = NULL;
510     surf_action_network_Constant_t action = NULL;
511
512     nw_link->lat_current = value;
513     while (lmm_get_var_from_cnst
514            (network_maxmin_system, nw_link->constraint, &var)) {
515       action = lmm_variable_id(var);
516       action->lat_current += delta;
517       if (action->rate < 0)
518         lmm_update_variable_bound(network_maxmin_system, action->variable,
519                                   SG_TCP_CTE_GAMMA / (2.0 *
520                                                       action->
521                                                       lat_current));
522       else
523         lmm_update_variable_bound(network_maxmin_system, action->variable,
524                                   min(action->rate,
525                                       SG_TCP_CTE_GAMMA / (2.0 *
526                                                           action->
527                                                           lat_current)));
528       if (!(action->suspended))
529         lmm_update_variable_weight(network_maxmin_system, action->variable,
530                                    action->lat_current);
531       lmm_update_variable_latency(network_maxmin_system, action->variable,
532                                   delta);
533     }
534   } else if (event_type == nw_link->state_event) {
535     if (value > 0)
536       nw_link->state_current = SURF_LINK_ON;
537     else
538       nw_link->state_current = SURF_LINK_OFF;
539   } else {
540     CRITICAL0("Unknown event ! \n");
541     xbt_abort();
542   }
543
544   return;
545 }
546
547 static surf_action_t communicate(void *src, void *dst, double size,
548                                  double rate)
549 {
550   surf_action_network_Constant_t action = NULL;
551   network_card_Constant_t card_src = src;
552   network_card_Constant_t card_dst = dst;
553
554   XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
555
556   action = xbt_new0(s_surf_action_network_Constant_t, 1);
557
558   action->generic_action.using = 1;
559   action->generic_action.cost = size;
560   action->generic_action.remains = size;
561   action->generic_action.max_duration = NO_MAX_DURATION;
562   action->generic_action.start = surf_get_clock();
563   action->generic_action.finish = -1.0;
564   action->generic_action.model_type =
565       (surf_model_t) surf_network_model;
566   action->suspended = 0;
567   action->generic_action.state_set =
568       surf_network_model->common_public->states.running_action_set;
569
570   xbt_swag_insert(action, action->generic_action.state_set);
571   action->rate = rate;
572
573   action->latency = 1.0;
574   action->lat_current = action->latency;
575
576   XBT_OUT;
577
578   return (surf_action_t) action;
579 }
580
581 /* returns an array of link_Constant_t */
582 static const void **get_route(void *src, void *dst)
583 {
584   network_card_Constant_t card_src = src;
585   network_card_Constant_t card_dst = dst;
586   return (const void **) ROUTE(card_src->id, card_dst->id);
587 }
588
589 static int get_route_size(void *src, void *dst)
590 {
591   network_card_Constant_t card_src = src;
592   network_card_Constant_t card_dst = dst;
593   return ROUTE_SIZE(card_src->id, card_dst->id);
594 }
595
596 static const char *get_link_name(const void *link)
597 {
598   return ((link_Constant_t) link)->name;
599 }
600
601 static double get_link_bandwidth(const void *link)
602 {
603   return ((link_Constant_t) link)->bw_current;
604 }
605
606 static double get_link_latency(const void *link)
607 {
608   return ((link_Constant_t) link)->lat_current;
609 }
610
611 static xbt_dict_t get_properties(void *link)
612 {
613  return ((link_Constant_t) link)->properties;
614 }
615
616 static void action_suspend(surf_action_t action)
617 {
618   ((surf_action_network_Constant_t) action)->suspended = 1;
619   lmm_update_variable_weight(network_maxmin_system,
620                              ((surf_action_network_Constant_t) action)->
621                              variable, 0.0);
622 }
623
624 static void action_resume(surf_action_t action)
625 {
626   if (((surf_action_network_Constant_t) action)->suspended) {
627     lmm_update_variable_weight(network_maxmin_system,
628                                ((surf_action_network_Constant_t) action)->
629                                variable,
630                                ((surf_action_network_Constant_t) action)->
631                                lat_current);
632     ((surf_action_network_Constant_t) action)->suspended = 0;
633   }
634 }
635
636 static int action_is_suspended(surf_action_t action)
637 {
638   return ((surf_action_network_Constant_t) action)->suspended;
639 }
640
641 static void action_set_max_duration(surf_action_t action, double duration)
642 {
643   action->max_duration = duration;
644 }
645
646 static void finalize(void)
647 {
648   int i, j;
649
650   xbt_dict_free(&network_card_set);
651   xbt_dict_free(&link_set);
652   xbt_swag_free(surf_network_model->common_public->states.
653                 ready_action_set);
654   xbt_swag_free(surf_network_model->common_public->states.
655                 running_action_set);
656   xbt_swag_free(surf_network_model->common_public->states.
657                 failed_action_set);
658   xbt_swag_free(surf_network_model->common_public->states.
659                 done_action_set);
660   free(surf_network_model->common_public);
661   free(surf_network_model->common_private);
662   free(surf_network_model->extension_public);
663
664   free(surf_network_model);
665   surf_network_model = NULL;
666
667   loopback = NULL;
668   for (i = 0; i < card_number; i++)
669     for (j = 0; j < card_number; j++)
670       free(ROUTE(i, j));
671   free(routing_table);
672   routing_table = NULL;
673   free(routing_table_size);
674   routing_table_size = NULL;
675   card_number = 0;
676 }
677
678 static void surf_network_model_init_internal(void)
679 {
680   s_surf_action_t action;
681
682   surf_network_model = xbt_new0(s_surf_network_model_t, 1);
683
684   surf_network_model->common_private =
685       xbt_new0(s_surf_model_private_t, 1);
686   surf_network_model->common_public =
687       xbt_new0(s_surf_model_public_t, 1);
688   surf_network_model->extension_public =
689       xbt_new0(s_surf_network_model_extension_public_t, 1);
690
691   surf_network_model->common_public->states.ready_action_set =
692       xbt_swag_new(xbt_swag_offset(action, state_hookup));
693   surf_network_model->common_public->states.running_action_set =
694       xbt_swag_new(xbt_swag_offset(action, state_hookup));
695   surf_network_model->common_public->states.failed_action_set =
696       xbt_swag_new(xbt_swag_offset(action, state_hookup));
697   surf_network_model->common_public->states.done_action_set =
698       xbt_swag_new(xbt_swag_offset(action, state_hookup));
699
700   surf_network_model->common_public->name_service = name_service;
701   surf_network_model->common_public->get_resource_name =
702       get_resource_name;
703   surf_network_model->common_public->action_get_state =
704       surf_action_get_state;
705   surf_network_model->common_public->action_get_start_time =
706       surf_action_get_start_time;
707   surf_network_model->common_public->action_get_finish_time =
708       surf_action_get_finish_time;
709   surf_network_model->common_public->action_free = action_free;
710   surf_network_model->common_public->action_use = action_use;
711   surf_network_model->common_public->action_cancel = action_cancel;
712   surf_network_model->common_public->action_recycle = action_recycle;
713   surf_network_model->common_public->action_change_state =
714       action_change_state;
715   surf_network_model->common_public->action_set_data =
716       surf_action_set_data;
717   surf_network_model->common_public->name = "network";
718
719   surf_network_model->common_private->resource_used = resource_used;
720   surf_network_model->common_private->share_resources = share_resources;
721   surf_network_model->common_private->update_actions_state =
722       update_actions_state;
723   surf_network_model->common_private->update_resource_state =
724       update_resource_state;
725   surf_network_model->common_private->finalize = finalize;
726
727   surf_network_model->common_public->suspend = action_suspend;
728   surf_network_model->common_public->resume = action_resume;
729   surf_network_model->common_public->is_suspended = action_is_suspended;
730   surf_cpu_model->common_public->set_max_duration =
731       action_set_max_duration;
732
733   surf_network_model->extension_public->communicate = communicate;
734   surf_network_model->extension_public->get_route = get_route;
735   surf_network_model->extension_public->get_route_size = get_route_size;
736   surf_network_model->extension_public->get_link_name = get_link_name;
737   surf_network_model->extension_public->get_link_bandwidth =
738       get_link_bandwidth;
739   surf_network_model->extension_public->get_link_latency =
740       get_link_latency;
741
742   surf_network_model->common_public->get_properties =  get_properties;
743
744   link_set = xbt_dict_new();
745   network_card_set = xbt_dict_new();
746
747   if (!network_maxmin_system)
748     network_maxmin_system = lmm_system_new();
749 }
750
751 void surf_network_model_init_Constant(const char *filename)
752 {
753
754   if (surf_network_model)
755     return;
756   surf_network_model_init_internal();
757   define_callbacks(filename);
758   xbt_dynar_push(model_list, &surf_network_model);
759   network_solve = lmm_solve;
760
761   update_model_description(surf_network_model_description,
762                               surf_network_model_description_size,
763                               "Constant",
764                               (surf_model_t) surf_network_model);
765 }