Logo AND Algorithmique Numérique Distribuée

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