1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include <stdarg.h> /* va_arg */
13 #include "surf/surfxml_parse.h"
14 #include "surf/surf_private.h"
15 #include "simgrid/sg_config.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
18 "Logging specific to the SURF parsing module");
20 int ETag_surfxml_include_state(void);
22 #include "simgrid_dtd.c"
24 char* surf_parsed_filename = NULL; // to locate parse error messages
26 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
27 extern AS_t current_routing;
31 void surf_parse_error(const char *fmt, ...) {
34 char *msg = bvprintf(fmt,va);
36 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
38 void surf_parse_warn(const char *fmt, ...) {
41 char *msg = bvprintf(fmt,va);
43 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
47 double surf_parse_get_double(const char *string) {
49 int ret = sscanf(string, "%lg", &res);
51 surf_parse_error("%s is not a double", string);
52 //printf("Parsed double [%lg] %s\n", res, string);
56 int surf_parse_get_int(const char *string) {
58 int ret = sscanf(string, "%d", &res);
60 surf_parse_error("%s is not an integer", string);
64 double surf_parse_get_time(const char *string) {
66 double res = strtod(string, &ptr);
68 surf_parse_error("This is not a time: %s", string);
69 else if (strcmp(ptr, "ps") == 0)
71 else if (strcmp(ptr, "ns") == 0)
73 else if (strcmp(ptr, "us") == 0)
75 else if (strcmp(ptr, "ms") == 0)
77 else if (strcmp(ptr, "s") == 0)
79 else if (strcmp(ptr, "m") == 0)
81 else if (strcmp(ptr, "h") == 0)
83 else if (strcmp(ptr, "d") == 0)
85 else if (strcmp(ptr, "w") == 0)
90 double surf_parse_get_bandwidth(const char *string) {
92 double res = strtod(string, &ptr);
94 surf_parse_error("This is not a bandwidth: %s", string);
95 else if (strcmp(ptr, "KBps") == 0)
97 else if (strcmp(ptr, "MBps") == 0)
99 else if (strcmp(ptr, "GBps") == 0)
101 else if (strcmp(ptr, "TBps") == 0)
103 else if (strcmp(ptr, "Bps") == 0)
105 else if (strcmp(ptr, "kbps") == 0)
107 else if (strcmp(ptr, "mbps") == 0)
109 else if (strcmp(ptr, "gbps") == 0)
111 else if (strcmp(ptr, "tbps") == 0)
113 else if (strcmp(ptr, "bps") == 0)
118 double surf_parse_get_power(const char *string) {
120 double res = strtod(string, &ptr);
122 surf_parse_error("This is not a power: %s", string);
123 else if (strcmp(ptr, "kiloflops") == 0)
125 else if (strcmp(ptr, "megaflops") == 0)
127 else if (strcmp(ptr, "gigaflops") == 0)
129 else if (strcmp(ptr, "teraflops") == 0)
131 else if (strcmp(ptr, "petaflops") == 0)
133 else if (strcmp(ptr, "exaflops") == 0)
135 else if (strcmp(ptr, "zettaflops") == 0)
137 else if (strcmp(ptr, "yottaflops") == 0)
139 else if (strcmp(ptr, "flops") == 0)
141 else if (strcmp(ptr, "kf") == 0)
143 else if (strcmp(ptr, "mf") == 0)
145 else if (strcmp(ptr, "gf") == 0)
147 else if (strcmp(ptr, "tf") == 0)
149 else if (strcmp(ptr, "pf") == 0)
151 else if (strcmp(ptr, "ef") == 0)
153 else if (strcmp(ptr, "zf") == 0)
155 else if (strcmp(ptr, "yf") == 0)
157 else if (strcmp(ptr, "f") == 0)
163 * All the callback lists that can be overridden anywhere.
164 * (this list should probably be reduced to the bare minimum to allow the models to work)
167 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
169 /* The default current property receiver. Setup in the corresponding opening callbacks. */
170 xbt_dict_t current_property_set = NULL;
171 xbt_dict_t as_current_property_set = NULL;
173 char* as_name_tab[1024];
174 void* as_dict_tab[1024];
178 /* dictionary of random generator data */
179 xbt_dict_t random_data_list = NULL;
181 YY_BUFFER_STATE surf_input_buffer;
182 FILE *surf_file_to_parse = NULL;
184 static void init_randomness(void);
185 static void add_randomness(void);
188 * Stuff relative to storage
190 void STag_surfxml_storage(void)
193 XBT_DEBUG("STag_surfxml_storage");
194 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
196 void ETag_surfxml_storage(void)
198 s_sg_platf_storage_cbarg_t storage;
199 memset(&storage,0,sizeof(storage));
201 storage.id = A_surfxml_storage_id;
202 storage.type_id = A_surfxml_storage_typeId;
203 storage.content = A_surfxml_storage_content;
204 storage.properties = current_property_set;
205 sg_platf_new_storage(&storage);
206 current_property_set = NULL;
208 void STag_surfxml_storage___type(void)
211 XBT_DEBUG("STag_surfxml_storage___type");
212 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
214 void ETag_surfxml_storage___type(void)
216 s_sg_platf_storage_type_cbarg_t storage_type;
217 memset(&storage_type,0,sizeof(storage_type));
219 storage_type.content = A_surfxml_storage___type_content;
220 storage_type.id = A_surfxml_storage___type_id;
221 storage_type.model = A_surfxml_storage___type_model;
222 storage_type.properties = current_property_set;
223 storage_type.size = surf_parse_get_int(A_surfxml_storage___type_size);
224 sg_platf_new_storage_type(&storage_type);
225 current_property_set = NULL;
227 void STag_surfxml_mstorage(void)
229 XBT_DEBUG("STag_surfxml_mstorage");
231 void ETag_surfxml_mstorage(void)
233 s_sg_platf_mstorage_cbarg_t mstorage;
234 memset(&mstorage,0,sizeof(mstorage));
236 mstorage.name = A_surfxml_mstorage_name;
237 mstorage.type_id = A_surfxml_mstorage_typeId;
238 sg_platf_new_mstorage(&mstorage);
240 void STag_surfxml_mount(void)
242 XBT_DEBUG("STag_surfxml_mount");
244 void ETag_surfxml_mount(void)
246 s_sg_platf_mount_cbarg_t mount;
247 memset(&mount,0,sizeof(mount));
249 mount.name = A_surfxml_mount_name;
250 mount.id = A_surfxml_mount_id;
251 sg_platf_new_mount(&mount);
255 * Stuff relative to the <include> tag
257 static xbt_dynar_t surf_input_buffer_stack = NULL;
258 static xbt_dynar_t surf_file_to_parse_stack = NULL;
259 static xbt_dynar_t surf_parsed_filename_stack = NULL;
261 void STag_surfxml_include(void)
263 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
264 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
265 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
267 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
269 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
270 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
271 A_surfxml_include_file);
272 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
273 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
274 surf_parse_push_buffer_state(surf_input_buffer);
279 void ETag_surfxml_include(void) {
280 /* Nothing to do when done with reading the include tag.
281 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
284 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
286 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
287 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
288 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
289 * error message in that case.
291 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
292 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
293 * on a line. One day maybe, if the maya allow it.
295 int ETag_surfxml_include_state(void)
298 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
300 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
303 // Yeah, we were in an <include> Restore state and proceed.
304 fclose(surf_file_to_parse);
305 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
306 surf_parse_pop_buffer_state();
307 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
309 // Restore the filename for error messages
310 free(surf_parsed_filename);
311 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
317 void surf_parse_init_callbacks(void)
322 void surf_parse_reset_callbacks(void)
324 surf_parse_free_callbacks();
325 surf_parse_init_callbacks();
328 void surf_parse_free_callbacks(void)
333 /* Stag and Etag parse functions */
335 void STag_surfxml_platform(void) {
336 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
338 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
339 "You're using an ancient XML file.\n"
340 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
341 "instead of MBytes, MFlops and seconds.\n"
343 "Use simgrid_update_xml to update your file automatically. "
344 "This program is installed automatically with SimGrid, or "
345 "available in the tools/ directory of the source archive.\n"
347 "Please check also out the SURF section of the ChangeLog for "
348 "the 3.1 version for more information. \n"
350 "Last, do not forget to also update your values for "
351 "the calls to MSG_task_create (if any).");
352 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
353 "You're using an old XML file.\n"
354 "Use simgrid_update_xml to update your file automatically. "
355 "This program is installed automatically with SimGrid, or "
356 "available in the tools/ directory of the source archive.");
360 void ETag_surfxml_platform(void){
364 void STag_surfxml_host(void){
366 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
369 void STag_surfxml_prop(void)
372 if (!as_current_property_set){
373 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
374 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
375 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
376 as_dict_tab[as_prop_nb] = as_current_property_set;
377 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
380 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
383 if (!current_property_set)
384 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
385 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
389 void ETag_surfxml_host(void) {
390 s_sg_platf_host_cbarg_t host;
391 memset(&host,0,sizeof(host));
393 host.properties = current_property_set;
395 host.id = A_surfxml_host_id;
396 host.power_peak = get_cpu_power(A_surfxml_host_power);
397 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
398 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
399 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
400 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
401 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
402 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
403 if (A_surfxml_host_state == A_surfxml_host_state_ON)
404 host.initial_state = SURF_RESOURCE_ON;
405 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
406 host.initial_state = SURF_RESOURCE_OFF;
407 host.coord = A_surfxml_host_coordinates;
409 sg_platf_new_host(&host);
410 current_property_set = NULL;
413 void STag_surfxml_host___link(void){
414 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
415 s_sg_platf_host_link_cbarg_t host_link;
416 memset(&host_link,0,sizeof(host_link));
418 host_link.id = A_surfxml_host___link_id;
419 host_link.link_up = A_surfxml_host___link_up;
420 host_link.link_down = A_surfxml_host___link_down;
421 sg_platf_new_host_link(&host_link);
424 void STag_surfxml_router(void){
425 s_sg_platf_router_cbarg_t router;
426 memset(&router, 0, sizeof(router));
428 router.id = A_surfxml_router_id;
429 router.coord = A_surfxml_router_coordinates;
431 sg_platf_new_router(&router);
434 void STag_surfxml_cluster(void){
435 s_sg_platf_cluster_cbarg_t cluster;
436 memset(&cluster,0,sizeof(cluster));
437 cluster.id = A_surfxml_cluster_id;
438 cluster.prefix = A_surfxml_cluster_prefix;
439 cluster.suffix = A_surfxml_cluster_suffix;
440 cluster.radical = A_surfxml_cluster_radical;
441 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
442 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
443 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
444 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
445 if(strcmp(A_surfxml_cluster_bb___bw,""))
446 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
447 if(strcmp(A_surfxml_cluster_bb___lat,""))
448 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
449 if(strcmp(A_surfxml_cluster_limiter___link,""))
450 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
451 if(strcmp(A_surfxml_cluster_loopback___bw,""))
452 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
453 if(strcmp(A_surfxml_cluster_loopback___lat,""))
454 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
455 cluster.router_id = A_surfxml_cluster_router___id;
457 switch (AX_surfxml_cluster_sharing___policy) {
458 case A_surfxml_cluster_sharing___policy_SHARED:
459 cluster.sharing_policy = SURF_LINK_SHARED;
461 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
462 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
464 case A_surfxml_cluster_sharing___policy_FATPIPE:
465 cluster.sharing_policy = SURF_LINK_FATPIPE;
468 surf_parse_error("Invalid cluster sharing policy for cluster %s",
472 switch (AX_surfxml_cluster_bb___sharing___policy) {
473 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
474 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
476 case A_surfxml_cluster_bb___sharing___policy_SHARED:
477 cluster.bb_sharing_policy = SURF_LINK_SHARED;
480 surf_parse_error("Invalid bb sharing policy in cluster %s",
485 cluster.availability_trace = A_surfxml_cluster_availability___file;
486 cluster.state_trace = A_surfxml_cluster_state___file;
487 sg_platf_new_cluster(&cluster);
490 void STag_surfxml_cabinet(void){
491 s_sg_platf_cabinet_cbarg_t cabinet;
492 memset(&cabinet,0,sizeof(cabinet));
493 cabinet.id = A_surfxml_cabinet_id;
494 cabinet.prefix = A_surfxml_cabinet_prefix;
495 cabinet.suffix = A_surfxml_cabinet_suffix;
496 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
497 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
498 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
499 cabinet.radical = A_surfxml_cabinet_radical;
501 sg_platf_new_cabinet(&cabinet);
504 void STag_surfxml_peer(void){
505 s_sg_platf_peer_cbarg_t peer;
506 memset(&peer,0,sizeof(peer));
507 peer.id = A_surfxml_peer_id;
508 peer.power = surf_parse_get_power(A_surfxml_peer_power);
509 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
510 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
511 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
512 peer.coord = A_surfxml_peer_coordinates;
513 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
514 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
516 sg_platf_new_peer(&peer);
519 void STag_surfxml_link(void){
521 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
524 void ETag_surfxml_link(void){
525 s_sg_platf_link_cbarg_t link;
526 memset(&link,0,sizeof(link));
528 link.properties = current_property_set;
530 link.id = A_surfxml_link_id;
531 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
532 //printf("Link bandwidth [%lg]\n", link.bandwidth);
533 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
534 link.latency = surf_parse_get_time(A_surfxml_link_latency);
535 //printf("Link latency [%lg]\n", link.latency);
536 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
538 switch (A_surfxml_link_state) {
539 case A_surfxml_link_state_ON:
540 link.state = SURF_RESOURCE_ON;
542 case A_surfxml_link_state_OFF:
543 link.state = SURF_RESOURCE_OFF;
546 surf_parse_error("invalid state for link %s", link.id);
549 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
551 switch (A_surfxml_link_sharing___policy) {
552 case A_surfxml_link_sharing___policy_SHARED:
553 link.policy = SURF_LINK_SHARED;
555 case A_surfxml_link_sharing___policy_FATPIPE:
556 link.policy = SURF_LINK_FATPIPE;
558 case A_surfxml_link_sharing___policy_FULLDUPLEX:
559 link.policy = SURF_LINK_FULLDUPLEX;
562 surf_parse_error("Invalid sharing policy in link %s", link.id);
566 sg_platf_new_link(&link);
568 current_property_set = NULL;
571 void STag_surfxml_link___ctn(void){
574 switch (A_surfxml_link___ctn_direction) {
575 case AU_surfxml_link___ctn_direction:
576 case A_surfxml_link___ctn_direction_NONE:
577 link_id = xbt_strdup(A_surfxml_link___ctn_id);
579 case A_surfxml_link___ctn_direction_UP:
580 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
582 case A_surfxml_link___ctn_direction_DOWN:
583 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
587 // FIXME we should push the surf link object but it don't
588 // work because of model rulebased
589 xbt_dynar_push(parsed_link_list, &link_id);
592 void ETag_surfxml_backbone(void){
593 s_sg_platf_link_cbarg_t link;
594 memset(&link,0,sizeof(link));
596 link.properties = NULL;
598 link.id = A_surfxml_backbone_id;
599 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
600 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
601 link.state = SURF_RESOURCE_ON;
602 link.policy = SURF_LINK_SHARED;
604 sg_platf_new_link(&link);
605 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
608 void STag_surfxml_route(void){
609 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
610 "Missing end-points while defining route \"%s\"->\"%s\"",
611 A_surfxml_route_src, A_surfxml_route_dst);
612 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
615 void STag_surfxml_ASroute(void){
616 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
617 || strlen(A_surfxml_ASroute_dst) > 0
618 || strlen(A_surfxml_ASroute_gw___src) > 0
619 || strlen(A_surfxml_ASroute_gw___dst) > 0,
620 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
621 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
622 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
623 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
626 void STag_surfxml_bypassRoute(void){
627 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
628 || strlen(A_surfxml_bypassRoute_dst) > 0,
629 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
630 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
631 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
634 void STag_surfxml_bypassASroute(void){
635 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
636 || strlen(A_surfxml_bypassASroute_dst) > 0
637 || strlen(A_surfxml_bypassASroute_gw___src) > 0
638 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
639 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
640 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
641 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
642 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
645 void ETag_surfxml_route(void){
646 s_sg_platf_route_cbarg_t route;
647 memset(&route,0,sizeof(route));
649 route.src = A_surfxml_route_src;
650 route.dst = A_surfxml_route_dst;
653 route.link_list = parsed_link_list;
655 switch (A_surfxml_route_symmetrical) {
656 case AU_surfxml_route_symmetrical:
657 case A_surfxml_route_symmetrical_YES:
658 route.symmetrical = TRUE;
660 case A_surfxml_route_symmetrical_NO:
661 route.symmetrical = FALSE;;
665 sg_platf_new_route(&route);
666 parsed_link_list = NULL;
669 void ETag_surfxml_ASroute(void){
670 s_sg_platf_route_cbarg_t ASroute;
671 memset(&ASroute,0,sizeof(ASroute));
673 ASroute.src = A_surfxml_ASroute_src;
674 ASroute.dst = A_surfxml_ASroute_dst;
676 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
677 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
678 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
680 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
681 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_ASroute_gw___src;
682 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_ASroute_gw___dst;
684 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
685 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
688 ASroute.link_list = parsed_link_list;
690 switch (A_surfxml_ASroute_symmetrical) {
691 case AU_surfxml_ASroute_symmetrical:
692 case A_surfxml_ASroute_symmetrical_YES:
693 ASroute.symmetrical = TRUE;
695 case A_surfxml_ASroute_symmetrical_NO:
696 ASroute.symmetrical = FALSE;
700 sg_platf_new_ASroute(&ASroute);
701 parsed_link_list = NULL;
704 void ETag_surfxml_bypassRoute(void){
705 s_sg_platf_route_cbarg_t route;
706 memset(&route,0,sizeof(route));
708 route.src = A_surfxml_bypassRoute_src;
709 route.dst = A_surfxml_bypassRoute_dst;
712 route.link_list = parsed_link_list;
713 route.symmetrical = FALSE;
715 sg_platf_new_bypassRoute(&route);
716 parsed_link_list = NULL;
719 void ETag_surfxml_bypassASroute(void){
720 s_sg_platf_route_cbarg_t ASroute;
721 memset(&ASroute,0,sizeof(ASroute));
723 ASroute.src = A_surfxml_bypassASroute_src;
724 ASroute.dst = A_surfxml_bypassASroute_dst;
725 ASroute.link_list = parsed_link_list;
726 ASroute.symmetrical = FALSE;
728 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
729 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
730 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
732 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
733 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_bypassASroute_gw___src;
734 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_bypassASroute_gw___dst;
736 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
737 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
740 sg_platf_new_bypassASroute(&ASroute);
741 parsed_link_list = NULL;
744 void ETag_surfxml_trace(void){
745 s_sg_platf_trace_cbarg_t trace;
746 memset(&trace,0,sizeof(trace));
748 trace.id = A_surfxml_trace_id;
749 trace.file = A_surfxml_trace_file;
750 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
751 trace.pc_data = surfxml_pcdata;
753 sg_platf_new_trace(&trace);
756 void STag_surfxml_trace___connect(void){
757 s_sg_platf_trace_connect_cbarg_t trace_connect;
758 memset(&trace_connect,0,sizeof(trace_connect));
760 trace_connect.element = A_surfxml_trace___connect_element;
761 trace_connect.trace = A_surfxml_trace___connect_trace;
763 switch (A_surfxml_trace___connect_kind) {
764 case AU_surfxml_trace___connect_kind:
765 case A_surfxml_trace___connect_kind_POWER:
766 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
768 case A_surfxml_trace___connect_kind_BANDWIDTH:
769 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
771 case A_surfxml_trace___connect_kind_HOST___AVAIL:
772 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
774 case A_surfxml_trace___connect_kind_LATENCY:
775 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
777 case A_surfxml_trace___connect_kind_LINK___AVAIL:
778 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
781 sg_platf_trace_connect(&trace_connect);
784 void STag_surfxml_AS(void){
786 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
787 AS.id = A_surfxml_AS_id;
788 AS.routing = (int)A_surfxml_AS_routing;
790 as_current_property_set = NULL;
792 sg_platf_new_AS_begin(&AS);
794 void ETag_surfxml_AS(void){
796 char *name = as_name_tab[as_prop_nb-1];
797 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
799 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
800 xbt_lib_set(as_router_lib,
802 ROUTING_PROP_ASR_LEVEL,
806 sg_platf_new_AS_end();
809 extern int _sg_init_status; /* FIXME: find a proper way to export this at some point */
811 void STag_surfxml_config(void){
813 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
814 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
815 if (_sg_init_status == 2) {
816 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
819 void ETag_surfxml_config(void){
820 xbt_dict_cursor_t cursor = NULL;
824 xbt_dict_foreach(current_property_set, cursor, key, elem) {
825 cfg = bprintf("%s:%s",key,elem);
826 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
827 xbt_cfg_set_parse(_sg_cfg_set, cfg);
829 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
832 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
833 xbt_dict_free(¤t_property_set);
834 current_property_set = NULL;
840 void STag_surfxml_process(void){
843 argv = xbt_new(char *, 1);
844 argv[0] = xbt_strdup(A_surfxml_process_function);
845 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
848 void ETag_surfxml_process(void){
849 s_sg_platf_process_cbarg_t process;
850 memset(&process,0,sizeof(process));
853 process.argv = (const char **)argv;
854 process.properties = current_property_set;
855 process.host = A_surfxml_process_host;
856 process.function = A_surfxml_process_function;
857 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
858 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
860 switch (A_surfxml_process_on___failure) {
861 case AU_surfxml_process_on___failure:
862 case A_surfxml_process_on___failure_DIE:
863 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
865 case A_surfxml_process_on___failure_RESTART:
866 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
870 sg_platf_new_process(&process);
871 current_property_set = NULL;
874 void STag_surfxml_argument(void){
876 argv = xbt_realloc(argv, (argc) * sizeof(char *));
877 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
880 /* ***************************************** */
881 /* TUTORIAL: New TAG */
882 void STag_surfxml_gpu(void)
884 XBT_DEBUG("STag_surfxml_gpu");
886 void ETag_surfxml_gpu(void)
888 s_sg_platf_gpu_cbarg_t gpu;
889 memset(&gpu,0,sizeof(gpu));
891 gpu.name = A_surfxml_gpu_name;
893 sg_platf_new_gpu(&gpu);
895 /* ***************************************** */
897 /* nothing to do in those functions */
898 void ETag_surfxml_prop(void){}
899 void STag_surfxml_random(void){}
900 void ETag_surfxml_random(void){}
901 void ETag_surfxml_trace___connect(void){}
902 void STag_surfxml_trace(void){}
903 void ETag_surfxml_router(void){}
904 void ETag_surfxml_host___link(void){}
905 void ETag_surfxml_cluster(void){}
906 void ETag_surfxml_cabinet(void){}
907 void ETag_surfxml_peer(void){}
908 void STag_surfxml_backbone(void){}
909 void ETag_surfxml_link___ctn(void){}
910 void ETag_surfxml_argument(void){}
912 /* Open and Close parse file */
914 void surf_parse_open(const char *file)
916 static int warned = 0; /* warn only once */
920 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
921 "If it is not what you want, go fix your code.");
927 if (!surf_input_buffer_stack)
928 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
929 if (!surf_file_to_parse_stack)
930 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
932 if (!surf_parsed_filename_stack)
933 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
934 surf_parsed_filename = xbt_strdup(file);
936 surf_file_to_parse = surf_fopen(file, "r");
937 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
938 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
939 surf_parse__switch_to_buffer(surf_input_buffer);
940 surf_parse_lineno = 1;
943 void surf_parse_close(void)
945 xbt_dynar_free(&surf_input_buffer_stack);
946 xbt_dynar_free(&surf_file_to_parse_stack);
947 xbt_dynar_free(&surf_parsed_filename_stack);
949 free(surf_parsed_filename);
950 surf_parsed_filename = NULL;
952 if (surf_file_to_parse) {
953 surf_parse__delete_buffer(surf_input_buffer);
954 fclose(surf_file_to_parse);
955 surf_file_to_parse = NULL; //Must be reset for Bypass
959 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
961 static int _surf_parse(void) {
962 return surf_parse_lex();
964 int_f_void_t surf_parse = _surf_parse;
967 /* Prop tag functions */
973 /* Random tag functions */
975 double get_cpu_power(const char *power)
977 double power_scale = 0.0;
980 random_data_t random = NULL;
981 /* randomness is inserted like this: power="$rand(my_random)" */
982 if (((p = strstr(power, "$rand(")) != NULL)
983 && ((q = strstr(power, ")")) != NULL)) {
985 generator = xbt_malloc(q - (p + 6) + 1);
986 memcpy(generator, p + 6, q - (p + 6));
987 generator[q - (p + 6)] = '\0';
988 random = xbt_dict_get_or_null(random_data_list, generator);
989 xbt_assert(random, "Random generator %s undefined", generator);
990 power_scale = random_generate(random);
993 power_scale = surf_parse_get_power(power);
998 double random_min, random_max, random_mean, random_std_deviation;
999 e_random_generator_t random_generator;
1002 static void init_randomness(void)
1004 random_id = A_surfxml_random_id;
1005 random_min = surf_parse_get_double(A_surfxml_random_min);
1006 random_max = surf_parse_get_double(A_surfxml_random_max);
1007 random_mean = surf_parse_get_double(A_surfxml_random_mean);
1008 random_std_deviation = surf_parse_get_double(A_surfxml_random_std___deviation);
1009 switch (A_surfxml_random_generator) {
1010 case AU_surfxml_random_generator:
1011 case A_surfxml_random_generator_NONE:
1012 random_generator = NONE;
1014 case A_surfxml_random_generator_DRAND48:
1015 random_generator = DRAND48;
1017 case A_surfxml_random_generator_RAND:
1018 random_generator = RAND;
1020 case A_surfxml_random_generator_RNGSTREAM:
1021 random_generator = RNGSTREAM;
1024 surf_parse_error("Invalid random generator");
1029 static void add_randomness(void)
1031 /* If needed aditional properties can be added by using the prop tag */
1032 random_data_t random =
1033 random_new(random_generator, 0, random_min, random_max, random_mean,
1034 random_std_deviation);
1035 xbt_dict_set(random_data_list, random_id, (void *) random,
1040 xbt_dict_t get_as_router_properties(const char* name)
1042 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);