Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Remove sg_platf_mount_cb
[simgrid.git] / src / surf / sg_platf.cpp
1 /* Copyright (c) 2006-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "xbt/RngStream.h"
12 #include "simgrid/platf_interface.h"
13 #include "surf/surf_routing.h"
14
15 #include "src/simix/smx_private.h"
16
17 #include "cpu_interface.hpp"
18 #include "host_interface.hpp"
19
20 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
21 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
22 xbt_dynar_t sg_platf_host_link_cb_list = NULL;   // of sg_platf_host_link_cb_t
23 xbt_dynar_t sg_platf_link_cb_list = NULL;   // of sg_platf_link_cb_t
24 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
25 xbt_dynar_t sg_platf_peer_cb_list = NULL; // of sg_platf_peer_cb_t
26 xbt_dynar_t sg_platf_cluster_cb_list = NULL; // of sg_platf_cluster_cb_t
27 xbt_dynar_t sg_platf_cabinet_cb_list = NULL; // of sg_platf_cluster_cb_t
28 xbt_dynar_t sg_platf_AS_begin_cb_list = NULL; //of sg_platf_AS_begin_cb_t
29 xbt_dynar_t sg_platf_AS_end_cb_list = NULL; //of void_f_void_t
30 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
31 xbt_dynar_t sg_platf_prop_cb_list = NULL; // of sg_platf_prop_cb_t
32
33 xbt_dynar_t sg_platf_route_cb_list = NULL; // of sg_platf_route_cb_t
34 xbt_dynar_t sg_platf_ASroute_cb_list = NULL; // of sg_platf_ASroute_cb_t
35 xbt_dynar_t sg_platf_bypassRoute_cb_list = NULL; // of sg_platf_bypassRoute_cb_t
36 xbt_dynar_t sg_platf_bypassASroute_cb_list = NULL; // of sg_platf_bypassASroute_cb_t
37
38 xbt_dynar_t sg_platf_trace_cb_list = NULL;
39 xbt_dynar_t sg_platf_trace_connect_cb_list = NULL;
40
41 /* ***************************************** */
42 /* TUTORIAL: New TAG                         */
43
44 xbt_dynar_t sg_platf_gpu_cb_list = NULL;
45 /* ***************************************** */
46
47
48 static int surf_parse_models_setup_already_called = 0;
49
50 /* one RngStream for the platform, to respect some statistic rules */
51 static RngStream sg_platf_rng_stream = NULL;
52
53 /** Module management function: creates all internal data structures */
54 void sg_platf_init(void) {
55
56   //FIXME : Ugly, but useful...
57   if(sg_platf_host_cb_list)
58     return; //Already initialized, so do nothing...
59
60   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
61   sg_platf_host_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_link_cb_t), NULL);
62   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_router_cb_t), NULL);
63   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t), NULL);
64   sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
65   sg_platf_cluster_cb_list = xbt_dynar_new(sizeof(sg_platf_cluster_cb_t), NULL);
66   sg_platf_cabinet_cb_list = xbt_dynar_new(sizeof(sg_platf_cabinet_cb_t), NULL);
67   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
68   sg_platf_AS_begin_cb_list = xbt_dynar_new(sizeof(sg_platf_AS_cb_t),NULL);
69   sg_platf_AS_end_cb_list = xbt_dynar_new(sizeof(sg_platf_AS_cb_t),NULL);
70   sg_platf_prop_cb_list = xbt_dynar_new(sizeof(sg_platf_prop_cb_t),NULL);
71
72   sg_platf_route_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
73   sg_platf_ASroute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
74   sg_platf_bypassRoute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
75   sg_platf_bypassASroute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
76
77   sg_platf_trace_cb_list = xbt_dynar_new(sizeof(sg_platf_trace_cb_t), NULL);
78   sg_platf_trace_connect_cb_list = xbt_dynar_new(sizeof(sg_platf_trace_connect_cb_t), NULL);
79
80   /* ***************************************** */
81   /* TUTORIAL: New TAG                         */
82
83   sg_platf_gpu_cb_list = xbt_dynar_new(sizeof(sg_platf_gpu_cb_t), NULL);
84   /* ***************************************** */
85 }
86 /** Module management function: frees all internal data structures */
87 void sg_platf_exit(void) {
88   xbt_dynar_free(&sg_platf_host_cb_list);
89   xbt_dynar_free(&sg_platf_host_link_cb_list);
90   xbt_dynar_free(&sg_platf_router_cb_list);
91   xbt_dynar_free(&sg_platf_link_cb_list);
92   xbt_dynar_free(&sg_platf_postparse_cb_list);
93   xbt_dynar_free(&sg_platf_peer_cb_list);
94   xbt_dynar_free(&sg_platf_cluster_cb_list);
95   xbt_dynar_free(&sg_platf_cabinet_cb_list);
96   xbt_dynar_free(&sg_platf_AS_begin_cb_list);
97   xbt_dynar_free(&sg_platf_AS_end_cb_list);
98   xbt_dynar_free(&sg_platf_prop_cb_list);
99
100   xbt_dynar_free(&sg_platf_trace_cb_list);
101   xbt_dynar_free(&sg_platf_trace_connect_cb_list);
102
103   xbt_dynar_free(&sg_platf_route_cb_list);
104   xbt_dynar_free(&sg_platf_ASroute_cb_list);
105   xbt_dynar_free(&sg_platf_bypassRoute_cb_list);
106   xbt_dynar_free(&sg_platf_bypassASroute_cb_list);
107
108   /* ***************************************** */
109   /* TUTORIAL: New TAG                         */
110
111   xbt_dynar_free(&sg_platf_gpu_cb_list);
112
113   /* ***************************************** */
114
115   /* make sure that we will reinit the models while loading the platf once reinited */
116   surf_parse_models_setup_already_called = 0;
117 }
118
119 void sg_platf_new_host(sg_platf_host_cbarg_t host)
120 {
121
122   xbt_assert(! sg_host_by_name(host->id),
123                      "Refusing to create a second host named '%s'.", host->id);
124
125   RoutingEdge *net = NULL;
126   As* current_routing = routing_get_current();
127   if (current_routing)
128     net = routing_add_host(current_routing, host);
129
130   Cpu *cpu = surf_cpu_model_pm->createCpu(
131         host->id,
132         host->power_peak,
133         host->pstate,
134         host->power_scale,
135         host->power_trace,
136         host->core_amount,
137         host->initial_state,
138         host->state_trace,
139         host->properties);
140   surf_host_model->createHost(host->id, net, cpu);
141
142   unsigned int iterator;
143   sg_platf_host_cb_t fun;
144   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
145     fun(host);
146   }
147 }
148 void sg_platf_new_host_link(sg_platf_host_link_cbarg_t h){
149   unsigned int iterator;
150   sg_platf_host_link_cb_t fun;
151   xbt_dynar_foreach(sg_platf_host_link_cb_list, iterator, fun) {
152     fun(h);
153   }
154 }
155 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
156   unsigned int iterator;
157   sg_platf_router_cb_t fun;
158   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
159     fun(router);
160   }
161 }
162 void sg_platf_new_link(sg_platf_link_cbarg_t link){
163   unsigned int iterator;
164   sg_platf_link_cb_t fun;
165   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
166     fun(link);
167   }
168 }
169
170 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
171   unsigned int iterator;
172   sg_platf_peer_cb_t fun;
173   xbt_dynar_foreach(sg_platf_peer_cb_list, iterator, fun) {
174     fun(peer);
175   }
176 }
177 void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster){
178   unsigned int iterator;
179   sg_platf_cluster_cb_t fun;
180   xbt_dynar_foreach(sg_platf_cluster_cb_list, iterator, fun) {
181     fun(cluster);
182   }
183 }
184 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet){
185   unsigned int iterator;
186   sg_platf_cabinet_cb_t fun;
187   xbt_dynar_foreach(sg_platf_cabinet_cb_list, iterator, fun) {
188     fun(cabinet);
189   }
190 }
191 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage)
192 {
193   xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
194                "Reading a storage, processing unit \"%s\" already exists", storage->id);
195
196   // Verification of an existing type_id
197 #ifndef NDEBUG
198   void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
199 #endif
200   xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
201
202   XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
203       storage->id,
204       storage->type_id,
205       storage->content);
206
207   xbt_lib_set(storage_lib,
208       storage->id,
209       ROUTING_STORAGE_LEVEL,
210       (void *) xbt_strdup(storage->type_id));
211
212   void* stype = xbt_lib_get_or_null(storage_type_lib,
213                                     storage->type_id,
214                                     ROUTING_STORAGE_TYPE_LEVEL);
215   if(!stype) xbt_die("No storage type '%s'",storage->type_id);
216
217   // if storage content is not specified use the content of storage_type if exist
218   if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
219     storage->content = ((storage_type_t) stype)->content;
220     storage->content_type = ((storage_type_t) stype)->content_type;
221     XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
222         storage->id,((storage_type_t) stype)->content_type,
223         ((storage_type_t) stype)->type_id);
224   }
225
226   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
227       "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
228       "\n\t\tproperties '%p''\n",
229       storage->id,
230       ((storage_type_t) stype)->model,
231       ((storage_type_t) stype)->type_id,
232       storage->content,
233       storage->content_type,
234       storage->properties);
235
236   surf_storage_model->createStorage(storage->id,
237                                      ((storage_type_t) stype)->type_id,
238                                      storage->content,
239                                      storage->content_type,
240                                      storage->properties,
241                                      storage->attach);
242 }
243 void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type){
244
245   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
246                "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
247
248   storage_type_t stype = xbt_new0(s_storage_type_t, 1);
249   stype->model = xbt_strdup(storage_type->model);
250   stype->properties = storage_type->properties;
251   stype->content = xbt_strdup(storage_type->content);
252   stype->content_type = xbt_strdup(storage_type->content_type);
253   stype->type_id = xbt_strdup(storage_type->id);
254   stype->size = storage_type->size;
255   stype->model_properties = storage_type->model_properties;
256
257   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
258       "content '%s', and content_type '%s'",
259       stype->type_id,
260       stype->model,
261       storage_type->content,
262       storage_type->content_type);
263
264   xbt_lib_set(storage_type_lib,
265       stype->type_id,
266       ROUTING_STORAGE_TYPE_LEVEL,
267       (void *) stype);
268 }
269 void sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage)
270 {
271   THROW_UNIMPLEMENTED;
272 //  mount_t mnt = xbt_new0(s_mount_t, 1);
273 //  mnt->id = xbt_strdup(mstorage->type_id);
274 //  mnt->name = xbt_strdup(mstorage->name);
275 //
276 //  if(!mount_list){
277 //    XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
278 //    mount_list = xbt_dynar_new(sizeof(char *), NULL);
279 //  }
280 //  xbt_dynar_push(mount_list,(void *) mnt);
281 //  free(mnt->id);
282 //  free(mnt->name);
283 //  xbt_free(mnt);
284 //  XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
285 }
286
287 static void mount_free(void *p)
288 {
289   mount_t mnt = (mount_t) p;
290   xbt_free(mnt->name);
291 }
292
293 void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
294   // Verification of an existing storage
295 #ifndef NDEBUG
296   void* storage = xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL);
297 #endif
298   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
299
300   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
301
302   s_mount_t mnt;
303   mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
304   mnt.name = xbt_strdup(mount->name);
305
306   if(!mount_list){
307     XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
308     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
309   }
310   xbt_dynar_push(mount_list, &mnt);
311 }
312
313 void sg_platf_new_route(sg_platf_route_cbarg_t route) {
314   unsigned int iterator;
315   sg_platf_route_cb_t fun;
316   xbt_dynar_foreach(sg_platf_route_cb_list, iterator, fun) {
317     fun(route);
318   }
319 }
320 void sg_platf_new_ASroute(sg_platf_route_cbarg_t ASroute) {
321   unsigned int iterator;
322   sg_platf_route_cb_t fun;
323   xbt_dynar_foreach(sg_platf_ASroute_cb_list, iterator, fun) {
324     fun(ASroute);
325   }
326 }
327 void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute) {
328   unsigned int iterator;
329   sg_platf_route_cb_t fun;
330   xbt_dynar_foreach(sg_platf_bypassRoute_cb_list, iterator, fun) {
331     fun(bypassRoute);
332   }
333 }
334 void sg_platf_new_bypassASroute(sg_platf_route_cbarg_t bypassASroute) {
335   unsigned int iterator;
336   sg_platf_route_cb_t fun;
337   xbt_dynar_foreach(sg_platf_bypassASroute_cb_list, iterator, fun) {
338     fun(bypassASroute);
339   }
340 }
341 void sg_platf_new_prop(sg_platf_prop_cbarg_t prop) {
342   unsigned int iterator;
343   sg_platf_prop_cb_t fun;
344   xbt_dynar_foreach(sg_platf_prop_cb_list, iterator, fun) {
345     fun(prop);
346   }
347 }
348 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace) {
349   unsigned int iterator;
350   sg_platf_trace_cb_t fun;
351   xbt_dynar_foreach(sg_platf_trace_cb_list, iterator, fun) {
352     fun(trace);
353   }
354 }
355 void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) {
356   unsigned int iterator;
357   sg_platf_trace_connect_cb_t fun;
358   xbt_dynar_foreach(sg_platf_trace_connect_cb_list, iterator, fun) {
359     fun(trace_connect);
360   }
361 }
362
363 void sg_platf_new_process(sg_platf_process_cbarg_t process)
364 {
365   if (!simix_global)
366     xbt_die("Cannot create process without SIMIX.");
367
368   sg_host_t host = sg_host_by_name(process->host);
369   if (!host)
370     THROWF(arg_error, 0, "Host '%s' unknown", process->host);
371   xbt_main_func_t parse_code = SIMIX_get_registered_function(process->function);
372   xbt_assert(parse_code, "Function '%s' unknown", process->function);
373
374   double start_time = process->start_time;
375   double kill_time  = process->kill_time;
376   int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
377
378   smx_process_arg_t arg = NULL;
379   smx_process_t process_created = NULL;
380
381   arg = xbt_new0(s_smx_process_arg_t, 1);
382   arg->code = parse_code;
383   arg->data = NULL;
384   arg->hostname = sg_host_get_name(host);
385   arg->argc = process->argc;
386   arg->argv = xbt_new(char *,process->argc);
387   int i;
388   for (i=0; i<process->argc; i++)
389     arg->argv[i] = xbt_strdup(process->argv[i]);
390   arg->name = xbt_strdup(arg->argv[0]);
391   arg->kill_time = kill_time;
392   arg->properties = current_property_set;
393   if (!sg_host_simix(host)->boot_processes) {
394     sg_host_simix(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
395   }
396   xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
397
398   if (start_time > SIMIX_get_clock()) {
399     arg = xbt_new0(s_smx_process_arg_t, 1);
400     arg->name = (char*)(process->argv)[0];
401     arg->code = parse_code;
402     arg->data = NULL;
403     arg->hostname = sg_host_get_name(host);
404     arg->argc = process->argc;
405     arg->argv = (char**)(process->argv);
406     arg->kill_time = kill_time;
407     arg->properties = current_property_set;
408
409     XBT_DEBUG("Process %s(%s) will be started at time %f", arg->name,
410            arg->hostname, start_time);
411     SIMIX_timer_set(start_time, [](void* arg) {
412       SIMIX_process_create_from_wrapper((smx_process_arg_t) arg);
413     }, arg);
414   } else {                      // start_time <= SIMIX_get_clock()
415     XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_get_name(host));
416
417     if (simix_global->create_process_function)
418       process_created = simix_global->create_process_function(
419                                             (char*)(process->argv)[0],
420                                             parse_code,
421                                             NULL,
422                                             sg_host_get_name(host),
423                                             kill_time,
424                                             process->argc,
425                                             (char**)(process->argv),
426                                             current_property_set,
427                                             auto_restart, NULL);
428     else
429       process_created = simcall_process_create((char*)(process->argv)[0], parse_code, NULL, sg_host_get_name(host), kill_time, process->argc,
430           (char**)process->argv, current_property_set,auto_restart);
431
432     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
433     if (!process_created) {
434       return;
435     }
436   }
437   current_property_set = NULL;
438 }
439
440 void sg_platf_route_begin (sg_platf_route_cbarg_t route){
441   route->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
442 }
443 void sg_platf_ASroute_begin (sg_platf_route_cbarg_t ASroute){
444   ASroute->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
445 }
446
447 void sg_platf_route_end (sg_platf_route_cbarg_t route){
448   sg_platf_new_route(route);
449 }
450 void sg_platf_ASroute_end (sg_platf_route_cbarg_t ASroute){
451   sg_platf_new_ASroute(ASroute);
452 }
453
454 void sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route){
455   char *link_name = xbt_strdup(link_id);
456   xbt_dynar_push(route->link_list, &link_name);
457 }
458 void sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASroute){
459   char *link_name = xbt_strdup(link_id);
460   xbt_dynar_push(ASroute->link_list, &link_name);
461 }
462
463 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
464
465 void sg_platf_end() {
466   unsigned int iterator;
467   void_f_void_t fun;
468   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
469     fun();
470   }
471 }
472
473 void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) {
474   unsigned int iterator;
475   sg_platf_AS_cb_t fun;
476
477   if (!surf_parse_models_setup_already_called && !xbt_dynar_is_empty(sg_platf_AS_begin_cb_list)) {
478     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
479      * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
480      *
481      * I'm not sure for <trace> and <trace_connect>, there may be a bug here
482      * (FIXME: check it out by creating a file beginning with one of these tags)
483      * but cluster and peer create ASes internally, so putting the code in there is ok.
484      *
485      * We are also guarding against xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't
486      * want to initialize the models if we are parsing the file to get the deployment. That could happen if
487      * the same file would be used for platf and deploy: it'd contain AS tags even during the deploy parsing.
488      * Removing that guard would result of the models to get re-inited when parsing for deploy.
489      */
490     surf_parse_models_setup_already_called = 1;
491     surf_config_models_setup();
492   }
493
494   xbt_dynar_foreach(sg_platf_AS_begin_cb_list, iterator, fun) {
495     fun(AS);
496   }
497 }
498
499 void sg_platf_new_AS_end() {
500   unsigned int iterator;
501   void_f_void_t fun;
502   xbt_dynar_foreach(sg_platf_AS_end_cb_list, iterator, fun) {
503     fun();
504   }
505 }
506
507 /* ***************************************** */
508 /* TUTORIAL: New TAG                         */
509
510 void sg_platf_new_gpu(sg_platf_gpu_cbarg_t gpu) {
511   unsigned int iterator;
512   void_f_void_t fun;
513   xbt_dynar_foreach(sg_platf_gpu_cb_list, iterator, fun) {
514     fun();
515   }
516 }
517
518 void sg_platf_gpu_add_cb(sg_platf_gpu_cb_t fct) {
519   xbt_dynar_push(sg_platf_gpu_cb_list, &fct);
520 }
521
522 /* ***************************************** */
523
524
525 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
526   xbt_dynar_push(sg_platf_host_cb_list, &fct);
527 }
528 void sg_platf_host_link_add_cb(sg_platf_host_link_cb_t fct) {
529   xbt_dynar_push(sg_platf_host_link_cb_list, &fct);
530 }
531 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
532   xbt_dynar_push(sg_platf_link_cb_list, &fct);
533 }
534 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
535   xbt_dynar_push(sg_platf_router_cb_list, &fct);
536 }
537 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
538   xbt_dynar_push(sg_platf_peer_cb_list, &fct);
539 }
540 void sg_platf_cluster_add_cb(sg_platf_cluster_cb_t fct) {
541   xbt_dynar_push(sg_platf_cluster_cb_list, &fct);
542 }
543 void sg_platf_cabinet_add_cb(sg_platf_cabinet_cb_t fct) {
544   xbt_dynar_push(sg_platf_cabinet_cb_list, &fct);
545 }
546 void sg_platf_postparse_add_cb(void_f_void_t fct) {
547   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
548 }
549 void sg_platf_AS_begin_add_cb(sg_platf_AS_cb_t fct) {
550   xbt_dynar_push(sg_platf_AS_begin_cb_list, &fct);
551 }
552 void sg_platf_AS_end_add_cb(sg_platf_AS_cb_t fct) {
553   xbt_dynar_push(sg_platf_AS_end_cb_list, &fct);
554 }
555 void sg_platf_route_add_cb(sg_platf_route_cb_t fct) {
556   xbt_dynar_push(sg_platf_route_cb_list, &fct);
557 }
558 void sg_platf_ASroute_add_cb(sg_platf_route_cb_t fct) {
559   xbt_dynar_push(sg_platf_ASroute_cb_list, &fct);
560 }
561 void sg_platf_bypassRoute_add_cb(sg_platf_route_cb_t fct) {
562   xbt_dynar_push(sg_platf_bypassRoute_cb_list, &fct);
563 }
564 void sg_platf_bypassASroute_add_cb(sg_platf_route_cb_t fct) {
565   xbt_dynar_push(sg_platf_bypassASroute_cb_list, &fct);
566 }
567 void sg_platf_prop_add_cb(sg_platf_prop_cb_t fct) {
568   xbt_dynar_push(sg_platf_prop_cb_list, &fct);
569 }
570 void sg_platf_trace_add_cb(sg_platf_trace_cb_t fct) {
571   xbt_dynar_push(sg_platf_trace_cb_list, &fct);
572 }
573 void sg_platf_trace_connect_add_cb(sg_platf_trace_connect_cb_t fct) {
574   xbt_dynar_push(sg_platf_trace_connect_cb_list, &fct);
575 }
576 void sg_platf_rng_stream_init(unsigned long seed[6]) {
577   RngStream_SetPackageSeed(seed);
578   sg_platf_rng_stream = RngStream_CreateStream(NULL);
579 }
580
581 RngStream sg_platf_rng_stream_get(const char* id) {
582   RngStream stream = NULL;
583   unsigned int id_hash;
584
585   stream = RngStream_CopyStream(sg_platf_rng_stream);
586   id_hash = xbt_str_hash(id);
587   RngStream_AdvanceState(stream, 0, (long)id_hash);
588
589   return stream;
590 }