Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* Cleanup the DTD by renaming:
[simgrid.git] / src / surf / workstation_KCCFLN05.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2005 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 "xbt/ex.h"
9 #include "xbt/dict.h"
10 #include "surf_private.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
13                                 "Logging specific to the SURF workstation module (KCCFLN05)");
14
15 typedef enum {
16   SURF_WORKSTATION_RESOURCE_CPU,
17   SURF_WORKSTATION_RESOURCE_LINK,
18 } e_surf_workstation_model_type_t;
19
20
21 /**************************************/
22 /********* router object **************/
23 /**************************************/
24 typedef struct router_KCCFLN05 {
25   char *name;           
26   unsigned int id;
27 } s_router_KCCFLN05_t, *router_KCCFLN05_t;
28
29
30 /**************************************/
31 /********* cpu object *****************/
32 /**************************************/
33 typedef struct cpu_KCCFLN05 {
34   surf_model_t model;
35   e_surf_workstation_model_type_t type; /* Do not move this field */
36   char *name;                                   /* Do not move this field */
37   lmm_constraint_t constraint;
38   lmm_constraint_t bus;
39   double power_scale;
40   double power_current;
41   double interference_send;
42   double interference_recv;
43   double interference_send_recv;
44   tmgr_trace_event_t power_event;
45   e_surf_cpu_state_t state_current;
46   tmgr_trace_event_t state_event;
47   int id;                       /* cpu and network card are a single object... */
48   xbt_dynar_t incomming_communications;
49   xbt_dynar_t outgoing_communications;
50   /*Handles the properties that can be added to cpu's*/
51   xbt_dict_t properties;
52 } s_cpu_KCCFLN05_t, *cpu_KCCFLN05_t;
53
54 /**************************************/
55 /*********** network object ***********/
56 /**************************************/
57
58 typedef struct network_link_KCCFLN05 {
59   surf_model_t model;
60   e_surf_workstation_model_type_t type; /* Do not move this field */
61   char *name;                                   /* Do not move this field */
62   lmm_constraint_t constraint;
63   double lat_current;
64   tmgr_trace_event_t lat_event;
65   double bw_current;
66   tmgr_trace_event_t bw_event;
67   e_surf_network_link_state_t state_current;
68   tmgr_trace_event_t state_event;
69   /*holds the properties that can be attached to the link*/
70   xbt_dict_t properties;
71 } s_network_link_KCCFLN05_t, *network_link_KCCFLN05_t;
72
73
74 typedef struct s_route_KCCFLN05 {
75   double impact_on_src;
76   double impact_on_dst;
77   double impact_on_src_with_other_recv;
78   double impact_on_dst_with_other_send;
79   network_link_KCCFLN05_t *links;
80   int size;
81 } s_route_KCCFLN05_t, *route_KCCFLN05_t;
82
83 /**************************************/
84 /*************** actions **************/
85 /**************************************/
86 typedef struct surf_action_workstation_KCCFLN05 {
87   s_surf_action_t generic_action;
88   double latency;
89   double lat_current;
90   lmm_variable_t variable;
91   double rate;
92   int suspended;
93   cpu_KCCFLN05_t src;           /* could be avoided */
94   cpu_KCCFLN05_t dst;           /* could be avoided */
95 } s_surf_action_workstation_KCCFLN05_t,
96   *surf_action_workstation_KCCFLN05_t;
97
98
99
100 static int nb_workstation = 0;
101 static s_route_KCCFLN05_t *routing_table = NULL;
102 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
103 static network_link_KCCFLN05_t loopback = NULL;
104 static xbt_dict_t parallel_task_network_link_set = NULL;
105 //added to work with GTNETS
106 static xbt_dict_t router_set = NULL;
107 static lmm_system_t maxmin_system = NULL;
108 /*xbt_dict_t network_link_set = NULL;*/
109
110
111 /* convenient function */
112 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
113 {
114   int cpt;
115   surf_action_workstation_KCCFLN05_t action = NULL;
116   if ((!xbt_dynar_length(cpu->incomming_communications)) &&
117       (!xbt_dynar_length(cpu->outgoing_communications))) {
118     /* No communications */
119     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
120                                 cpu->power_current * cpu->power_scale);
121   } else if ((!xbt_dynar_length(cpu->incomming_communications))
122              && (xbt_dynar_length(cpu->outgoing_communications))) {
123     /* Emission */
124     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
125                                 cpu->power_current * cpu->power_scale *
126                                 cpu->interference_send);
127     xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
128         lmm_elem_set_value(maxmin_system, cpu->constraint,
129                            action->variable,
130                            cpu->power_current * cpu->power_scale *
131                            ROUTE(action->src->id,
132                                  action->dst->id).impact_on_src);
133   } else if ((xbt_dynar_length(cpu->incomming_communications))
134              && (!xbt_dynar_length(cpu->outgoing_communications))) {
135     /* Reception */
136     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
137                                 cpu->power_current * cpu->power_scale *
138                                 cpu->interference_recv);
139     xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
140         lmm_elem_set_value(maxmin_system, cpu->constraint,
141                            action->variable,
142                            cpu->power_current * cpu->power_scale *
143                            ROUTE(action->src->id,
144                                  action->dst->id).impact_on_dst);
145   } else {
146     /* Emission & Reception */
147     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
148                                 cpu->power_current * cpu->power_scale *
149                                 cpu->interference_send_recv);
150     xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
151         lmm_elem_set_value(maxmin_system, cpu->constraint,
152                            action->variable,
153                            cpu->power_current * cpu->power_scale *
154                            ROUTE(action->src->id,
155                                  action->dst->id).
156                            impact_on_src_with_other_recv);
157     xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
158         lmm_elem_set_value(maxmin_system, cpu->constraint,
159                            action->variable,
160                            cpu->power_current * cpu->power_scale *
161                            ROUTE(action->src->id,
162                                  action->dst->id).
163                            impact_on_dst_with_other_send);
164   }
165 }
166
167 /**************************************/
168 /******* Resource Public     **********/
169 /**************************************/
170
171 static void *name_service(const char *name)
172 {
173   xbt_ex_t e;
174   void *res = NULL;
175
176   TRY {
177     res = xbt_dict_get(workstation_set, name);
178   } CATCH(e) {
179     if (e.category != not_found_error)
180       RETHROW;
181     WARN1("Host '%s' not found, verifing if it is a router", name);
182     res = NULL;
183     xbt_ex_free(e);
184   }
185
186   return res;
187 }
188
189 static const char *get_resource_name(void *resource_id)
190 {
191   /* We can freely cast as a cpu_KCCFLN05_t because it has the same
192      prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
193      will theoretically be given as an argument here. */
194   return ((cpu_KCCFLN05_t) resource_id)->name;
195 }
196
197 /* action_get_state is inherited from the surf module */
198
199 static void action_use(surf_action_t action)
200 {
201   action->using++;
202   return;
203 }
204
205 static int action_free(surf_action_t action)
206 {
207   int cpt;
208   surf_action_t act = NULL;
209   cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
210   cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
211
212   action->using--;
213   if (!action->using) {
214     xbt_swag_remove(action, action->state_set);
215     if (((surf_action_workstation_KCCFLN05_t) action)->variable)
216       lmm_variable_free(maxmin_system,
217                         ((surf_action_workstation_KCCFLN05_t) action)->
218                         variable);
219     if (src)
220       xbt_dynar_foreach(src->outgoing_communications, cpt, act)
221           if (act == action) {
222         xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
223         break;
224       }
225
226     if (dst)
227       xbt_dynar_foreach(dst->incomming_communications, cpt, act)
228           if (act == action) {
229         xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
230         break;
231       }
232
233     if (src && (!xbt_dynar_length(src->outgoing_communications)))
234       __update_cpu_usage(src);
235     if (dst && (!xbt_dynar_length(dst->incomming_communications)))
236       __update_cpu_usage(dst);
237
238     free(action);
239     return 1;
240   }
241   return 0;
242 }
243
244 static void action_cancel(surf_action_t action)
245 {
246   surf_action_change_state(action, SURF_ACTION_FAILED);
247   return;
248 }
249
250 static void action_recycle(surf_action_t action)
251 {
252   DIE_IMPOSSIBLE;
253   return;
254 }
255
256 /* action_change_state is inherited from the surf module */
257 /* action_set_data is inherited from the surf module */
258
259 static void action_suspend(surf_action_t action)
260 {
261   XBT_IN1("(%p))", action);
262   if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
263     ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
264     lmm_update_variable_weight(maxmin_system,
265                                ((surf_action_workstation_KCCFLN05_t)
266                                 action)->variable, 0.0);
267   }
268   XBT_OUT;
269 }
270
271 static void action_resume(surf_action_t action)
272 {
273   XBT_IN1("(%p)", action);
274   if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
275     if (((surf_action_workstation_KCCFLN05_t) action)->lat_current == 0.0)
276       lmm_update_variable_weight(maxmin_system,
277                                  ((surf_action_workstation_KCCFLN05_t)
278                                   action)->variable, action->priority);
279     else
280       lmm_update_variable_weight(maxmin_system,
281                                  ((surf_action_workstation_KCCFLN05_t)
282                                   action)->variable,
283                                  ((surf_action_workstation_KCCFLN05_t)
284                                   action)->lat_current);
285
286     ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
287   }
288   XBT_OUT;
289 }
290
291 static int action_is_suspended(surf_action_t action)
292 {
293   return (((surf_action_workstation_KCCFLN05_t) action)->suspended == 1);
294 }
295
296 static void action_set_max_duration(surf_action_t action, double duration)
297 {                               /* FIXME: should inherit */
298   XBT_IN2("(%p,%g)", action, duration);
299   action->max_duration = duration;
300   XBT_OUT;
301 }
302
303
304 static void action_set_priority(surf_action_t action, double priority)
305 {
306   XBT_IN2("(%p,%g)", action, priority);
307   action->priority = priority;
308   lmm_update_variable_weight(maxmin_system, ((surf_action_workstation_KCCFLN05_t) action)->variable, priority);
309
310   XBT_OUT;
311 }
312
313 /**************************************/
314 /******* Resource Private    **********/
315 /**************************************/
316
317 static int resource_used(void *resource_id)
318 {
319   /* We can freely cast as a network_link_KCCFLN05_t because it has
320      the same prefix as cpu_KCCFLN05_t */
321   if (((cpu_KCCFLN05_t) resource_id)->type ==
322       SURF_WORKSTATION_RESOURCE_CPU)
323     return (lmm_constraint_used
324             (maxmin_system, ((cpu_KCCFLN05_t) resource_id)->constraint)
325             || ((((cpu_KCCFLN05_t) resource_id)->bus) ?
326                 lmm_constraint_used(maxmin_system,
327                                     ((cpu_KCCFLN05_t) resource_id)->
328                                     bus) : 0));
329   else
330     return lmm_constraint_used(maxmin_system,
331                                ((network_link_KCCFLN05_t) resource_id)->
332                                constraint);
333
334 }
335
336 static double share_resources(double now)
337 {
338   s_surf_action_workstation_KCCFLN05_t s_action;
339   surf_action_workstation_KCCFLN05_t action = NULL;
340
341   xbt_swag_t running_actions =
342       surf_workstation_model->common_public->states.running_action_set;
343   double min = generic_maxmin_share_resources(running_actions,
344                                               xbt_swag_offset(s_action,
345                                                               variable),
346                                               maxmin_system,
347                                               lmm_solve);
348
349   xbt_swag_foreach(action, running_actions) {
350     if (action->latency > 0) {
351       if (min < 0) {
352         min = action->latency;
353         DEBUG3("Updating min (value) with %p (start %f): %f", action,
354                action->generic_action.start, min);
355       } else if (action->latency < min) {
356         min = action->latency;
357         DEBUG3("Updating min (latency) with %p (start %f): %f", action,
358                action->generic_action.start, min);
359       }
360     }
361   }
362
363   DEBUG1("min value : %f", min);
364
365   return min;
366 }
367
368 static void update_actions_state(double now, double delta)
369 {
370   double deltap = 0.0;
371   surf_action_workstation_KCCFLN05_t action = NULL;
372   surf_action_workstation_KCCFLN05_t next_action = NULL;
373   xbt_swag_t running_actions =
374       surf_workstation_model->common_public->states.running_action_set;
375
376   xbt_swag_foreach_safe(action, next_action, running_actions) {
377     deltap = delta;
378     if (action->latency > 0) {
379       if (action->latency > deltap) {
380         double_update(&(action->latency), deltap);
381         deltap = 0.0;
382       } else {
383         double_update(&(deltap), action->latency);
384         action->latency = 0.0;
385       }
386       if ((action->latency == 0.0) && (action->suspended == 0)) {
387         if ((action)->lat_current == 0.0)
388           lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
389         else
390           lmm_update_variable_weight(maxmin_system, action->variable,
391                                      action->lat_current);
392       }
393     }
394     DEBUG3("Action (%p) : remains (%g) updated by %g.",
395            action, action->generic_action.remains,
396            lmm_variable_getvalue(action->variable) * deltap);
397     double_update(&(action->generic_action.remains),
398                   lmm_variable_getvalue(action->variable) * deltap);
399
400     if (action->generic_action.max_duration != NO_MAX_DURATION)
401       double_update(&(action->generic_action.max_duration), delta);
402
403     if ((action->generic_action.remains <= 0) &&
404         (lmm_get_variable_weight(action->variable) > 0)) {
405       action->generic_action.finish = surf_get_clock();
406       surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
407     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
408                (action->generic_action.max_duration <= 0)) {
409       action->generic_action.finish = surf_get_clock();
410       surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
411     } else {
412       /* Need to check that none of the resource has failed */
413       lmm_constraint_t cnst = NULL;
414       int i = 0;
415       void *constraint_id = NULL;
416
417       while ((cnst =
418               lmm_get_cnst_from_var(maxmin_system, action->variable,
419                                     i++))) {
420         constraint_id = lmm_constraint_id(cnst);
421
422 /*      if(((network_link_KCCFLN05_t)constraint_id)->type== */
423 /*         SURF_WORKSTATION_RESOURCE_LINK) { */
424 /*        DEBUG2("Checking for link %s (%p)", */
425 /*               ((network_link_KCCFLN05_t)constraint_id)->name, */
426 /*               ((network_link_KCCFLN05_t)constraint_id)); */
427 /*      } */
428 /*      if(((cpu_KCCFLN05_t)constraint_id)->type== */
429 /*         SURF_WORKSTATION_RESOURCE_CPU) { */
430 /*        DEBUG3("Checking for cpu %s (%p) : %s", */
431 /*               ((cpu_KCCFLN05_t)constraint_id)->name, */
432 /*               ((cpu_KCCFLN05_t)constraint_id), */
433 /*               ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
434 /*      } */
435
436         if (((((network_link_KCCFLN05_t) constraint_id)->type ==
437               SURF_WORKSTATION_RESOURCE_LINK) &&
438              (((network_link_KCCFLN05_t) constraint_id)->state_current ==
439               SURF_NETWORK_LINK_OFF)) ||
440             ((((cpu_KCCFLN05_t) constraint_id)->type ==
441               SURF_WORKSTATION_RESOURCE_CPU) &&
442              (((cpu_KCCFLN05_t) constraint_id)->state_current ==
443               SURF_CPU_OFF))) {
444           DEBUG1("Action (%p) Failed!!", action);
445           action->generic_action.finish = surf_get_clock();
446           surf_action_change_state((surf_action_t) action,
447                                    SURF_ACTION_FAILED);
448           break;
449         }
450       }
451     }
452   }
453   return;
454 }
455
456 static void update_resource_state(void *id,
457                                   tmgr_trace_event_t event_type,
458                                   double value)
459 {
460   cpu_KCCFLN05_t cpu = id;
461   network_link_KCCFLN05_t nw_link = id;
462
463   if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
464     DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
465     if (event_type == nw_link->bw_event) {
466       nw_link->bw_current = value;
467       lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
468                                   nw_link->bw_current);
469     } else if (event_type == nw_link->lat_event) {
470       double delta = value - nw_link->lat_current;
471       lmm_variable_t var = NULL;
472       surf_action_workstation_KCCFLN05_t action = NULL;
473
474       nw_link->lat_current = value;
475       while (lmm_get_var_from_cnst
476              (maxmin_system, nw_link->constraint, &var)) {
477         action = lmm_variable_id(var);
478         action->lat_current += delta;
479         if (action->rate < 0)
480           lmm_update_variable_bound(maxmin_system, action->variable,
481                                     SG_TCP_CTE_GAMMA / (2.0 *
482                                                         action->
483                                                         lat_current));
484         else
485           lmm_update_variable_bound(maxmin_system, action->variable,
486                                     min(action->rate,
487                                         SG_TCP_CTE_GAMMA / (2.0 *
488                                                             action->
489                                                             lat_current)));
490         if (action->suspended == 0)
491           lmm_update_variable_weight(maxmin_system, action->variable,
492                                      action->lat_current);
493         lmm_update_variable_latency(maxmin_system, action->variable,
494                                     delta);
495
496
497       }
498     } else if (event_type == nw_link->state_event) {
499       if (value > 0)
500         nw_link->state_current = SURF_NETWORK_LINK_ON;
501       else
502         nw_link->state_current = SURF_NETWORK_LINK_OFF;
503     } else {
504       CRITICAL0("Unknown event ! \n");
505       xbt_abort();
506     }
507     return;
508   } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
509     DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
510     if (event_type == cpu->power_event) {
511       cpu->power_current = value;
512       __update_cpu_usage(cpu);
513     } else if (event_type == cpu->state_event) {
514       if (value > 0)
515         cpu->state_current = SURF_CPU_ON;
516       else
517         cpu->state_current = SURF_CPU_OFF;
518     } else {
519       CRITICAL0("Unknown event ! \n");
520       xbt_abort();
521     }
522     return;
523   } else {
524     DIE_IMPOSSIBLE;
525   }
526   return;
527 }
528
529 static void finalize(void)
530 {
531   int i, j;
532
533   xbt_dict_free(&network_link_set);
534   xbt_dict_free(&workstation_set);
535   xbt_dict_free(&router_set);
536   if (parallel_task_network_link_set != NULL) {
537     xbt_dict_free(&parallel_task_network_link_set);
538   }
539   xbt_swag_free(surf_workstation_model->common_public->states.
540                 ready_action_set);
541   xbt_swag_free(surf_workstation_model->common_public->states.
542                 running_action_set);
543   xbt_swag_free(surf_workstation_model->common_public->states.
544                 failed_action_set);
545   xbt_swag_free(surf_workstation_model->common_public->states.
546                 done_action_set);
547
548   free(surf_workstation_model->common_public);
549   free(surf_workstation_model->common_private);
550   free(surf_workstation_model->extension_public);
551
552   free(surf_workstation_model);
553   surf_workstation_model = NULL;
554
555   for (i = 0; i < nb_workstation; i++)
556     for (j = 0; j < nb_workstation; j++)
557       free(ROUTE(i, j).links);
558   free(routing_table);
559   routing_table = NULL;
560   nb_workstation = 0;
561
562   if (maxmin_system) {
563     lmm_system_free(maxmin_system);
564     maxmin_system = NULL;
565   }
566 }
567
568 /**************************************/
569 /******* Resource Private    **********/
570 /**************************************/
571
572 static surf_action_t execute(void *cpu, double size)
573 {
574   surf_action_workstation_KCCFLN05_t action = NULL;
575   cpu_KCCFLN05_t CPU = cpu;
576
577   XBT_IN2("(%s,%g)", CPU->name, size);
578   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
579
580   action->generic_action.using = 1;
581   action->generic_action.cost = size;
582   action->generic_action.remains = size;
583   action->generic_action.priority = 1.0;
584   action->generic_action.max_duration = NO_MAX_DURATION;
585   action->generic_action.start = surf_get_clock();
586   action->generic_action.finish = -1.0;
587   action->generic_action.model_type =
588       (surf_model_t) surf_workstation_model;
589   action->suspended = 0;
590
591   if (CPU->state_current == SURF_CPU_ON)
592     action->generic_action.state_set =
593         surf_workstation_model->common_public->states.
594         running_action_set;
595   else
596     action->generic_action.state_set =
597         surf_workstation_model->common_public->states.failed_action_set;
598   xbt_swag_insert(action, action->generic_action.state_set);
599
600   action->variable = lmm_variable_new(maxmin_system, action,
601                                       action->generic_action.priority,
602                                       -1.0, 1);
603   lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
604   XBT_OUT;
605   return (surf_action_t) action;
606 }
607
608 static surf_action_t action_sleep(void *cpu, double duration)
609 {
610   surf_action_workstation_KCCFLN05_t action = NULL;
611
612   XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
613
614   action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
615   action->generic_action.max_duration = duration;
616   action->suspended = 2;
617   lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
618
619   XBT_OUT;
620   return (surf_action_t) action;
621 }
622
623 static e_surf_cpu_state_t resource_get_state(void *cpu)
624 {
625   return ((cpu_KCCFLN05_t) cpu)->state_current;
626 }
627
628 static double get_speed(void *cpu, double load)
629 {
630   return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
631 }
632
633 static double get_available_speed(void *cpu)
634 {
635   return ((cpu_KCCFLN05_t) cpu)->power_current;
636 }
637
638 static xbt_dict_t get_property_list(void *cpu)
639 {
640   return ((cpu_KCCFLN05_t) cpu)->properties;
641 }
642
643 static surf_action_t communicate(void *src, void *dst, double size,
644                                  double rate)
645 {
646   surf_action_workstation_KCCFLN05_t action = NULL;
647   cpu_KCCFLN05_t card_src = src;
648   cpu_KCCFLN05_t card_dst = dst;
649   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
650   int route_size = route->size;
651   int i;
652
653   XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
654   xbt_assert2(route_size,
655               "You're trying to send data from %s to %s but there is no connexion between these two cards.",
656               card_src->name, card_dst->name);
657
658   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
659
660   action->generic_action.using = 1;
661   action->generic_action.cost = size;
662   action->generic_action.remains = size;
663   action->generic_action.max_duration = NO_MAX_DURATION;
664   action->generic_action.start = surf_get_clock();
665   action->generic_action.finish = -1.0;
666   action->src = src;
667   action->dst = dst;
668   action->generic_action.model_type =
669       (surf_model_t) surf_workstation_model;
670   action->suspended = 0;        /* Should be useless because of the 
671                                    calloc but it seems to help valgrind... */
672   action->generic_action.state_set =
673       surf_workstation_model->common_public->states.running_action_set;
674
675   xbt_dynar_push(card_src->outgoing_communications, &action);
676   xbt_dynar_push(card_dst->incomming_communications, &action);
677
678   xbt_swag_insert(action, action->generic_action.state_set);
679   action->rate = rate;
680
681   action->latency = 0.0;
682   for (i = 0; i < route_size; i++)
683     action->latency += route->links[i]->lat_current;
684   action->lat_current = action->latency;
685
686   if (action->latency > 0)
687     action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4);      /* +1 for the src bus
688                                                                                                    +1 for the dst bus
689                                                                                                    +1 for the src cpu
690                                                                                                    +1 for the dst cpu */
691   else
692     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
693                                         route_size + 4);
694
695   if (action->rate < 0) {
696     if (action->lat_current > 0)
697       lmm_update_variable_bound(maxmin_system, action->variable,
698                                 SG_TCP_CTE_GAMMA / (2.0 *
699                                                     action->lat_current));
700     else
701       lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
702   } else {
703     if (action->lat_current > 0)
704       lmm_update_variable_bound(maxmin_system, action->variable,
705                                 min(action->rate,
706                                     SG_TCP_CTE_GAMMA / (2.0 *
707                                                         action->
708                                                         lat_current)));
709     else
710       lmm_update_variable_bound(maxmin_system, action->variable,
711                                 action->rate);
712   }
713
714   lmm_update_variable_latency(maxmin_system, action->variable,
715                               action->latency); /* Should be useless */
716
717   for (i = 0; i < route_size; i++)
718     lmm_expand(maxmin_system, route->links[i]->constraint,
719                action->variable, 1.0);
720   if (card_src->bus)
721     lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
722   if (card_dst->bus)
723     lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
724   lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
725   lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
726
727   XBT_OUT;
728   return (surf_action_t) action;
729 }
730
731 static surf_action_t execute_parallel_task(int workstation_nb,
732                                            void **workstation_list,
733                                            double *computation_amount,
734                                            double *communication_amount,
735                                            double amount, double rate)
736 {
737   surf_action_workstation_KCCFLN05_t action = NULL;
738   int i, j, k;
739   int nb_link = 0;
740   int nb_host = 0;
741
742   if (parallel_task_network_link_set == NULL) {
743     parallel_task_network_link_set =
744         xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
745   }
746
747   /* Compute the number of affected resources... */
748   for (i = 0; i < workstation_nb; i++) {
749     for (j = 0; j < workstation_nb; j++) {
750       cpu_KCCFLN05_t card_src = workstation_list[i];
751       cpu_KCCFLN05_t card_dst = workstation_list[j];
752       int route_size = ROUTE(card_src->id, card_dst->id).size;
753       network_link_KCCFLN05_t *route =
754           ROUTE(card_src->id, card_dst->id).links;
755
756       if (communication_amount[i * workstation_nb + j] > 0)
757         for (k = 0; k < route_size; k++) {
758           xbt_dict_set(parallel_task_network_link_set, route[k]->name,
759                        route[k], NULL);
760         }
761     }
762   }
763   nb_link = xbt_dict_length(parallel_task_network_link_set);
764   xbt_dict_reset(parallel_task_network_link_set);
765
766
767   for (i = 0; i < workstation_nb; i++)
768     if (computation_amount[i] > 0)
769       nb_host++;
770
771   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
772   DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
773          action, nb_host, nb_link);
774   action->generic_action.using = 1;
775   action->generic_action.cost = amount;
776   action->generic_action.remains = amount;
777   action->generic_action.max_duration = NO_MAX_DURATION;
778   action->generic_action.start = surf_get_clock();
779   action->generic_action.finish = -1.0;
780   action->generic_action.model_type =
781       (surf_model_t) surf_workstation_model;
782   action->suspended = 0;        /* Should be useless because of the
783                                    calloc but it seems to help valgrind... */
784   action->generic_action.state_set =
785       surf_workstation_model->common_public->states.running_action_set;
786
787   xbt_swag_insert(action, action->generic_action.state_set);
788   action->rate = rate;
789
790   if (action->rate > 0)
791     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
792                                         nb_host + nb_link);
793   else
794     action->variable =
795         lmm_variable_new(maxmin_system, action, 1.0, action->rate,
796                          nb_host + nb_link);
797
798   for (i = 0; i < workstation_nb; i++)
799     if (computation_amount[i] > 0)
800       lmm_expand(maxmin_system,
801                  ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
802                  action->variable, computation_amount[i]);
803
804   for (i = 0; i < workstation_nb; i++) {
805     for (j = 0; j < workstation_nb; j++) {
806       cpu_KCCFLN05_t card_src = workstation_list[i];
807       cpu_KCCFLN05_t card_dst = workstation_list[j];
808       int route_size = ROUTE(card_src->id, card_dst->id).size;
809       network_link_KCCFLN05_t *route =
810           ROUTE(card_src->id, card_dst->id).links;
811
812       for (k = 0; k < route_size; k++) {
813         if (communication_amount[i * workstation_nb + j] > 0) {
814           lmm_expand_add(maxmin_system, route[k]->constraint,
815                          action->variable,
816                          communication_amount[i * workstation_nb + j]);
817         }
818       }
819     }
820   }
821
822   if (nb_link + nb_host == 0) {
823     action->generic_action.cost = 1.0;
824     action->generic_action.remains = 0.0;
825   }
826
827   return (surf_action_t) action;
828 }
829
830 /* returns an array of network_link_KCCFLN05_t */
831 static const void **get_route(void *src, void *dst)
832 {
833   cpu_KCCFLN05_t card_src = src;
834   cpu_KCCFLN05_t card_dst = dst;
835   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
836
837   return (const void **) route->links;
838 }
839
840 static int get_route_size(void *src, void *dst)
841 {
842   cpu_KCCFLN05_t card_src = src;
843   cpu_KCCFLN05_t card_dst = dst;
844   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
845   return route->size;
846 }
847
848 static const char *get_link_name(const void *link)
849 {
850   return ((network_link_KCCFLN05_t) link)->name;
851 }
852
853 static double get_link_bandwidth(const void *link)
854 {
855   return ((network_link_KCCFLN05_t) link)->bw_current;
856 }
857
858 static double get_link_latency(const void *link)
859 {
860   return ((network_link_KCCFLN05_t) link)->lat_current;
861 }
862
863 static xbt_dict_t get_link_property_list(void *link)
864 {
865  return ((network_link_KCCFLN05_t) link)->properties;
866 }
867
868
869 /**************************************/
870 /*** Resource Creation & Destruction **/
871 /**************************************/
872
873
874 static void router_free(void *router)
875 {
876   free(((router_KCCFLN05_t) router)->name);
877 }
878
879 static void router_new(const char *name)
880 {
881   static unsigned int nb_routers = 0;
882   router_KCCFLN05_t router;
883
884   INFO1("Creating a router %s", name);
885
886   router = xbt_new0(s_router_KCCFLN05_t, 1);
887
888   router->name = xbt_strdup(name);
889   router->id = nb_routers++;
890   xbt_dict_set(router_set, name, router, router_free);
891 }
892
893 static void parse_routers(void)
894 {
895   //add a dumb router just to be GTNETS compatible
896   router_new(A_surfxml_router_id);
897 }
898
899 static void cpu_free(void *cpu)
900 {
901   free(((cpu_KCCFLN05_t) cpu)->name);
902   xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
903   xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
904   free(cpu);
905 }
906
907 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
908                               double power_initial,
909                               tmgr_trace_t power_trace,
910                               e_surf_cpu_state_t state_initial,
911                               tmgr_trace_t state_trace,
912                               double interference_send,
913                               double interference_recv,
914                               double interference_send_recv,
915                               double max_outgoing_rate,
916                               xbt_dict_t cpu_properties_k)
917 {
918   cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
919
920   cpu->model = (surf_model_t) surf_workstation_model;
921   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
922   cpu->name = xbt_strdup(name);
923   cpu->id = nb_workstation++;
924
925   cpu->power_scale = power_scale;
926   xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
927
928   cpu->power_current = power_initial;
929   if (power_trace)
930     cpu->power_event =
931         tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
932
933   cpu->state_current = state_initial;
934   if (state_trace)
935     cpu->state_event =
936         tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
937
938   cpu->interference_send = interference_send;
939   cpu->interference_recv = interference_recv;
940   cpu->interference_send_recv = interference_send_recv;
941
942   cpu->constraint =
943       lmm_constraint_new(maxmin_system, cpu,
944                          cpu->power_current * cpu->power_scale);
945   if (max_outgoing_rate > 0)
946     cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
947
948   cpu->incomming_communications =
949       xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
950   cpu->outgoing_communications =
951       xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
952
953   /*add the property set*/
954   cpu->properties = current_property_set;
955  
956   xbt_dict_set(workstation_set, name, cpu, cpu_free);
957
958   return cpu;
959 }
960
961 static void create_routing_table(void)
962 {
963     routing_table = xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
964 }
965
966 static void parse_cpu_init(void)
967 {
968   double power_scale = 0.0;
969   double power_initial = 0.0;
970   tmgr_trace_t power_trace = NULL;
971   e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
972   tmgr_trace_t state_trace = NULL;
973   double interference_send = 0.0;
974   double interference_recv = 0.0;
975   double interference_send_recv = 0.0;
976   double max_outgoing_rate = -1.0;
977
978   surf_parse_get_double(&power_scale, A_surfxml_host_power);
979   surf_parse_get_double(&power_initial, A_surfxml_host_availability);
980   surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
981
982   xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
983               (A_surfxml_host_state == A_surfxml_host_state_OFF),
984               "Invalid state");
985   if (A_surfxml_host_state == A_surfxml_host_state_ON)
986     state_initial = SURF_CPU_ON;
987   if (A_surfxml_host_state == A_surfxml_host_state_OFF)
988     state_initial = SURF_CPU_OFF;
989   surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
990
991   surf_parse_get_double(&interference_send,
992                         A_surfxml_host_interference_send);
993   surf_parse_get_double(&interference_recv,
994                         A_surfxml_host_interference_recv);
995   surf_parse_get_double(&interference_send_recv,
996                         A_surfxml_host_interference_send_recv);
997   surf_parse_get_double(&max_outgoing_rate,
998                         A_surfxml_host_max_outgoing_rate);
999   current_property_set = xbt_dict_new();
1000   cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
1001           state_initial, state_trace, interference_send, interference_recv,
1002           interference_send_recv, max_outgoing_rate,/*add the properties*/current_property_set);
1003 }
1004
1005 static void network_link_free(void *nw_link)
1006 {
1007   free(((network_link_KCCFLN05_t) nw_link)->name);
1008   free(nw_link);
1009 }
1010
1011 static network_link_KCCFLN05_t network_link_new(char *name,
1012                                                 double bw_initial,
1013                                                 tmgr_trace_t bw_trace,
1014                                                 double lat_initial,
1015                                                 tmgr_trace_t lat_trace,
1016                                                 e_surf_network_link_state_t
1017                                                 state_initial,
1018                                                 tmgr_trace_t state_trace,
1019                                                 e_surf_network_link_sharing_policy_t
1020                                                 policy, xbt_dict_t network_properties_k)
1021 {
1022   network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
1023
1024
1025   nw_link->model = (surf_model_t) surf_workstation_model;
1026   nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
1027   nw_link->name = name;
1028   nw_link->bw_current = bw_initial;
1029   if (bw_trace)
1030     nw_link->bw_event =
1031         tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
1032   nw_link->state_current = state_initial;
1033   nw_link->lat_current = lat_initial;
1034   if (lat_trace)
1035     nw_link->lat_event =
1036         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
1037   if (state_trace)
1038     nw_link->state_event =
1039         tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
1040
1041   nw_link->constraint =
1042       lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
1043
1044   if (policy == SURF_NETWORK_LINK_FATPIPE)
1045     lmm_constraint_shared(nw_link->constraint);
1046
1047   /*add the property set*/
1048   nw_link->properties = network_properties_k;
1049
1050   xbt_dict_set(network_link_set, name, nw_link, network_link_free);
1051
1052   return nw_link;
1053 }
1054
1055 static void parse_network_link_init(void)
1056 {
1057   char *name_link;
1058   double bw_initial;
1059   tmgr_trace_t bw_trace;
1060   double lat_initial;
1061   tmgr_trace_t lat_trace;
1062   e_surf_network_link_state_t state_initial_link = SURF_NETWORK_LINK_ON;
1063   e_surf_network_link_sharing_policy_t policy_initial_link = SURF_NETWORK_LINK_SHARED;
1064   tmgr_trace_t state_trace;
1065
1066   name_link = xbt_strdup(A_surfxml_link_id);
1067   surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
1068   surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
1069   surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
1070   surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
1071
1072   xbt_assert0((A_surfxml_link_state ==
1073                A_surfxml_link_state_ON)
1074               || (A_surfxml_link_state ==
1075                   A_surfxml_link_state_OFF), "Invalid state");
1076   if (A_surfxml_link_state == A_surfxml_link_state_ON)
1077     state_initial_link = SURF_NETWORK_LINK_ON;
1078   else if (A_surfxml_link_state ==
1079            A_surfxml_link_state_OFF)
1080     state_initial_link = SURF_NETWORK_LINK_OFF;
1081
1082   if (A_surfxml_link_sharing_policy ==
1083       A_surfxml_link_sharing_policy_SHARED)
1084     policy_initial_link = SURF_NETWORK_LINK_SHARED;
1085   else if (A_surfxml_link_sharing_policy ==
1086            A_surfxml_link_sharing_policy_FATPIPE)
1087     policy_initial_link = SURF_NETWORK_LINK_FATPIPE;
1088
1089   surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
1090
1091  current_property_set = xbt_dict_new();
1092  network_link_new(name_link, bw_initial, bw_trace,
1093                    lat_initial, lat_trace, state_initial_link, state_trace,
1094                    policy_initial_link,/*add properties*/current_property_set);
1095 }
1096
1097 static void route_new(int src_id, int dst_id,
1098                       network_link_KCCFLN05_t * link_list, int nb_link,
1099                       double impact_on_src, double impact_on_dst,
1100                       double impact_on_src_with_other_recv,
1101                       double impact_on_dst_with_other_send)
1102 {
1103   route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1104
1105   route->size = nb_link;
1106   route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
1107   route->impact_on_src = impact_on_src;
1108   route->impact_on_dst = impact_on_dst;
1109   route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1110   route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1111
1112 }
1113
1114 static int nb_link;
1115 static int link_list_capacity;
1116 static network_link_KCCFLN05_t *link_list = NULL;
1117 static int src_id = -1;
1118 static int dst_id = -1;
1119 static double impact_on_src;
1120 static double impact_on_dst;
1121 static double impact_on_src_with_other_recv;
1122 static double impact_on_dst_with_other_send;
1123 static int is_first = 0;
1124
1125 static void parse_route_set_endpoints(void)
1126 {
1127   cpu_KCCFLN05_t cpu_tmp = NULL;
1128
1129   if (!is_first) create_routing_table();
1130   is_first = 1; 
1131
1132   cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1133   if (cpu_tmp != NULL) {
1134     src_id = cpu_tmp->id;
1135   } else {
1136     xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1137                 "Invalid name '%s': neither a cpu nor a router!",
1138                 A_surfxml_route_src);
1139     src_id = -1;
1140     return;
1141   }
1142
1143   cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1144   if (cpu_tmp != NULL) {
1145     dst_id = cpu_tmp->id;
1146   } else {
1147     xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1148                 "Invalid name '%s': neither a cpu nor a router!",
1149                 A_surfxml_route_dst);
1150     dst_id = -1;
1151     return;
1152   }
1153
1154   surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1155   surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1156   surf_parse_get_double(&impact_on_src_with_other_recv,
1157                         A_surfxml_route_impact_on_src_with_other_recv);
1158   surf_parse_get_double(&impact_on_dst_with_other_send,
1159                         A_surfxml_route_impact_on_dst_with_other_send);
1160
1161   nb_link = 0;
1162   link_list_capacity = 1;
1163   link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1164
1165 }
1166
1167 static void parse_route_elem(void)
1168 {
1169   xbt_ex_t e;
1170   if (nb_link == link_list_capacity) {
1171     link_list_capacity *= 2;
1172     link_list =
1173         xbt_realloc(link_list,
1174                     (link_list_capacity) *
1175                     sizeof(network_link_KCCFLN05_t));
1176   }
1177   TRY {
1178     link_list[nb_link++] =
1179         xbt_dict_get(network_link_set, A_surfxml_link_c_ctn_id);
1180   }
1181   CATCH(e) {
1182     RETHROW1("Link %s not found (dict raised this exception: %s)",
1183              A_surfxml_link_c_ctn_id);
1184   }
1185 }
1186
1187 static void parse_route_set_route(void)
1188 {
1189   if (src_id != -1 && dst_id != -1)
1190     route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1191               impact_on_dst, impact_on_src_with_other_recv,
1192               impact_on_dst_with_other_send);
1193
1194 }
1195
1196
1197 static void parse_file(const char *file)
1198 {
1199   int i;
1200
1201   /* Adding callback functions */
1202   surf_parse_reset_parser();
1203   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
1204   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
1205   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_routers);
1206   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_network_link_init);
1207   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
1208   surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
1209   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
1210
1211   /* Parse the file */
1212   surf_parse_open(file);
1213   xbt_assert1((!surf_parse()), "Parse error in %s", file);
1214   surf_parse_close();
1215   
1216   /* Adding loopback if needed */
1217   for (i = 0; i < nb_workstation; i++)
1218     if (!ROUTE(i, i).size) {
1219       if (!loopback)
1220         loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1221                                     498000000, NULL, 0.000015, NULL,
1222                                     SURF_NETWORK_LINK_ON, NULL,
1223                                     SURF_NETWORK_LINK_FATPIPE, NULL);
1224       ROUTE(i, i).size = 1;
1225       ROUTE(i, i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1226       ROUTE(i, i).links[0] = loopback;
1227     }
1228
1229 }
1230
1231 /**************************************/
1232 /********* Module  creation ***********/
1233 /**************************************/
1234
1235 static void model_init_internal(void)
1236 {
1237   s_surf_action_t action;
1238
1239   surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1240
1241   surf_workstation_model->common_private =
1242       xbt_new0(s_surf_model_private_t, 1);
1243   surf_workstation_model->common_public =
1244       xbt_new0(s_surf_model_public_t, 1);
1245   surf_workstation_model->extension_public =
1246       xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1247
1248   surf_workstation_model->common_public->states.ready_action_set =
1249       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1250   surf_workstation_model->common_public->states.running_action_set =
1251       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1252   surf_workstation_model->common_public->states.failed_action_set =
1253       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1254   surf_workstation_model->common_public->states.done_action_set =
1255       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1256
1257   surf_workstation_model->common_public->name_service = name_service;
1258   surf_workstation_model->common_public->get_resource_name =
1259       get_resource_name;
1260   surf_workstation_model->common_public->action_get_state =
1261       surf_action_get_state;
1262   surf_workstation_model->common_public->action_get_start_time =
1263       surf_action_get_start_time;
1264   surf_workstation_model->common_public->action_get_finish_time =
1265       surf_action_get_finish_time;
1266   surf_workstation_model->common_public->action_use = action_use;
1267   surf_workstation_model->common_public->action_free = action_free;
1268   surf_workstation_model->common_public->action_cancel = action_cancel;
1269   surf_workstation_model->common_public->action_recycle =
1270       action_recycle;
1271   surf_workstation_model->common_public->action_change_state =
1272       surf_action_change_state;
1273   surf_workstation_model->common_public->action_set_data =
1274       surf_action_set_data;
1275   surf_workstation_model->common_public->suspend = action_suspend;
1276   surf_workstation_model->common_public->resume = action_resume;
1277   surf_workstation_model->common_public->is_suspended =
1278       action_is_suspended;
1279   surf_workstation_model->common_public->set_max_duration =
1280       action_set_max_duration;
1281   surf_workstation_model->common_public->set_priority =
1282       action_set_priority;
1283   surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1284
1285   surf_workstation_model->common_private->resource_used = resource_used;
1286   surf_workstation_model->common_private->share_resources =
1287       share_resources;
1288   surf_workstation_model->common_private->update_actions_state =
1289       update_actions_state;
1290   surf_workstation_model->common_private->update_resource_state =
1291       update_resource_state;
1292   surf_workstation_model->common_private->finalize = finalize;
1293
1294   surf_workstation_model->extension_public->execute = execute;
1295   surf_workstation_model->extension_public->sleep = action_sleep;
1296   surf_workstation_model->extension_public->get_state =
1297       resource_get_state;
1298   surf_workstation_model->extension_public->get_speed = get_speed;
1299   surf_workstation_model->extension_public->get_available_speed =
1300       get_available_speed;
1301
1302   surf_workstation_model->common_public->get_cpu_properties = get_property_list;
1303   surf_workstation_model->common_public->get_link_properties = get_link_property_list;
1304
1305   surf_workstation_model->extension_public->communicate = communicate;
1306   surf_workstation_model->extension_public->execute_parallel_task =
1307       execute_parallel_task;
1308   surf_workstation_model->extension_public->get_route = get_route;
1309   surf_workstation_model->extension_public->get_route_size =
1310       get_route_size;
1311   surf_workstation_model->extension_public->get_link_name =
1312       get_link_name;
1313   surf_workstation_model->extension_public->get_link_bandwidth =
1314       get_link_bandwidth;
1315   surf_workstation_model->extension_public->get_link_latency =
1316       get_link_latency;
1317
1318   workstation_set = xbt_dict_new();
1319   router_set = xbt_dict_new();
1320   network_link_set = xbt_dict_new(); 
1321   if (!maxmin_system)
1322     maxmin_system = lmm_system_new();
1323 }
1324
1325 /**************************************/
1326 /*************** Generic **************/
1327 /**************************************/
1328 void surf_workstation_model_init_KCCFLN05(const char *filename)
1329 {
1330   xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1331   xbt_assert0(!surf_network_model,
1332               "network model type already defined");
1333   model_init_internal();
1334   parse_file(filename);
1335
1336   xbt_dynar_push(model_list, &surf_workstation_model);
1337 }