Logo AND Algorithmique Numérique Distribuée

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