Logo AND Algorithmique Numérique Distribuée

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