1 /* Copyright (c) 2006-2015. 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. */
9 #include <stdarg.h> /* va_arg */
16 #include "src/surf/surf_private.h"
17 #include "src/surf/network_interface.hpp"
18 #include "simgrid/sg_config.h"
19 #include "simgrid/link.h"
21 #include "src/surf/xml/platf_private.hpp"
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
24 "Logging specific to the SURF parsing module");
26 int ETag_surfxml_include_state(void);
28 #include "simgrid_dtd.c"
30 char* surf_parsed_filename = NULL; // to locate parse error messages
32 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
36 void surf_parse_assert(bool cond, const char *fmt, ...) {
40 int lineno = surf_parse_lineno;
41 char *msg = bvprintf(fmt,va);
44 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
46 xbt_die("Exiting now");
49 void surf_parse_error(const char *fmt, ...) {
52 int lineno = surf_parse_lineno;
53 char *msg = bvprintf(fmt,va);
56 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
58 xbt_die("Exiting now");
60 void surf_parse_warn(const char *fmt, ...) {
63 char *msg = bvprintf(fmt,va);
65 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
69 double surf_parse_get_double(const char *string) {
71 int ret = sscanf(string, "%lg", &res);
73 surf_parse_error("%s is not a double", string);
77 int surf_parse_get_int(const char *string) {
79 int ret = sscanf(string, "%d", &res);
81 surf_parse_error("%s is not an integer", string);
90 /* Note: field `unit' for the last element of parameter `units' should be
92 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
93 const char *entity_kind, const char *name,
94 const char *error_msg, const char *default_unit)
100 res = strtod(string, &ptr);
102 surf_parse_error("value out of range: %s", string);
104 surf_parse_error("cannot parse number: %s", string);
105 if (ptr[0] == '\0') {
107 return res; // Ok, 0 can be unit-less
109 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
110 ptr = (char*)default_unit;
112 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
114 if (units[i].unit != NULL)
115 res *= units[i].scale;
117 surf_parse_error("unknown unit: %s", ptr);
121 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
123 const struct unit_scale units[] = {
124 { "w", 7 * 24 * 60 * 60 },
125 { "d", 24 * 60 * 60 },
135 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
136 "Append 's' to your time to get seconds", "s");
139 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
141 const struct unit_scale units[] = {
142 { "TiB", pow(1024, 4) },
143 { "GiB", pow(1024, 3) },
144 { "MiB", pow(1024, 2) },
151 { "Tib", 0.125 * pow(1024, 4) },
152 { "Gib", 0.125 * pow(1024, 3) },
153 { "Mib", 0.125 * pow(1024, 2) },
154 { "Kib", 0.125 * 1024 },
155 { "Tb", 0.125 * 1e12 },
156 { "Gb", 0.125 * 1e9 },
157 { "Mb", 0.125 * 1e6 },
158 { "kb", 0.125 * 1e3 },
162 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
163 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
166 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
168 const struct unit_scale units[] = {
169 { "TiBps", pow(1024, 4) },
170 { "GiBps", pow(1024, 3) },
171 { "MiBps", pow(1024, 2) },
178 { "Tibps", 0.125 * pow(1024, 4) },
179 { "Gibps", 0.125 * pow(1024, 3) },
180 { "Mibps", 0.125 * pow(1024, 2) },
181 { "Kibps", 0.125 * 1024 },
182 { "Tbps", 0.125 * 1e12 },
183 { "Gbps", 0.125 * 1e9 },
184 { "Mbps", 0.125 * 1e6 },
185 { "kbps", 0.125 * 1e3 },
189 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
190 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
193 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
195 const struct unit_scale units[] = {
196 { "yottaflops", 1e24 },
198 { "zettaflops", 1e21 },
200 { "exaflops", 1e18 },
202 { "petaflops", 1e15 },
204 { "teraflops", 1e12 },
206 { "gigaflops", 1e9 },
208 { "megaflops", 1e6 },
210 { "kiloflops", 1e3 },
216 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
217 "Append 'f' or 'flops' to your speed to get flop per second", "f");
221 * All the callback lists that can be overridden anywhere.
222 * (this list should probably be reduced to the bare minimum to allow the models to work)
225 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
227 /* The default current property receiver. Setup in the corresponding opening callbacks. */
228 xbt_dict_t current_property_set = NULL;
229 xbt_dict_t current_model_property_set = NULL;
230 xbt_dict_t as_current_property_set = NULL;
232 char* as_name_tab[1024];
233 void* as_dict_tab[1024];
237 /* dictionary of random generator data */
238 xbt_dict_t random_data_list = NULL;
240 YY_BUFFER_STATE surf_input_buffer;
241 FILE *surf_file_to_parse = NULL;
244 * Stuff relative to storage
246 void STag_surfxml_storage(void)
249 XBT_DEBUG("STag_surfxml_storage");
250 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
252 void ETag_surfxml_storage(void)
254 s_sg_platf_storage_cbarg_t storage = SG_PLATF_STORAGE_INITIALIZER;
255 memset(&storage,0,sizeof(storage));
257 storage.id = A_surfxml_storage_id;
258 storage.type_id = A_surfxml_storage_typeId;
259 storage.content = A_surfxml_storage_content;
260 storage.content_type = A_surfxml_storage_content___type;
261 storage.properties = current_property_set;
262 storage.attach = A_surfxml_storage_attach;
263 sg_platf_new_storage(&storage);
264 current_property_set = NULL;
266 void STag_surfxml_storage___type(void)
269 XBT_DEBUG("STag_surfxml_storage___type");
270 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
271 xbt_assert(current_model_property_set == NULL, "Someone forgot to reset the model property set to NULL in its closing tag (or XML malformed)");
273 void ETag_surfxml_storage___type(void)
275 s_sg_platf_storage_type_cbarg_t storage_type = SG_PLATF_STORAGE_TYPE_INITIALIZER;
276 memset(&storage_type,0,sizeof(storage_type));
278 storage_type.content = A_surfxml_storage___type_content;
279 storage_type.content_type = A_surfxml_storage___type_content___type;
280 storage_type.id = A_surfxml_storage___type_id;
281 storage_type.model = A_surfxml_storage___type_model;
282 storage_type.properties = current_property_set;
283 storage_type.model_properties = current_model_property_set;
284 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
285 "size of storage type", storage_type.id);
286 sg_platf_new_storage_type(&storage_type);
287 current_property_set = NULL;
288 current_model_property_set = NULL;
290 void STag_surfxml_mstorage(void)
292 XBT_DEBUG("STag_surfxml_mstorage");
294 void ETag_surfxml_mstorage(void)
296 s_sg_platf_mstorage_cbarg_t mstorage = SG_PLATF_MSTORAGE_INITIALIZER;
297 memset(&mstorage,0,sizeof(mstorage));
299 mstorage.name = A_surfxml_mstorage_name;
300 mstorage.type_id = A_surfxml_mstorage_typeId;
301 sg_platf_new_mstorage(&mstorage);
303 void STag_surfxml_mount(void)
305 XBT_DEBUG("STag_surfxml_mount");
307 void ETag_surfxml_mount(void)
309 s_sg_platf_mount_cbarg_t mount = SG_PLATF_MOUNT_INITIALIZER;
310 memset(&mount,0,sizeof(mount));
312 mount.name = A_surfxml_mount_name;
313 mount.storageId = A_surfxml_mount_storageId;
314 sg_platf_new_mount(&mount);
318 * Stuff relative to the <include> tag
320 static xbt_dynar_t surf_input_buffer_stack = NULL;
321 static xbt_dynar_t surf_file_to_parse_stack = NULL;
322 static xbt_dynar_t surf_parsed_filename_stack = NULL;
324 void STag_surfxml_include(void)
326 parse_after_config();
327 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
328 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
329 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
331 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
333 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
334 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
336 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
337 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
338 surf_parse_push_buffer_state(surf_input_buffer);
343 void ETag_surfxml_include(void) {
344 /* Nothing to do when done with reading the include tag.
345 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
348 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
350 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
351 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
352 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
353 * error message in that case.
355 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
356 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
357 * on a line. One day maybe, if the maya allow it.
359 int ETag_surfxml_include_state(void)
362 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
364 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
367 // Yeah, we were in an <include> Restore state and proceed.
368 fclose(surf_file_to_parse);
369 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
370 surf_parse_pop_buffer_state();
371 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
373 // Restore the filename for error messages
374 free(surf_parsed_filename);
375 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
380 /* Stag and Etag parse functions */
382 void STag_surfxml_platform(void) {
383 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
385 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
386 "You're using an ancient XML file.\n"
387 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
388 "instead of MBytes, MFlops and seconds.\n"
390 "Use simgrid_update_xml to update your file automatically. "
391 "This program is installed automatically with SimGrid, or "
392 "available in the tools/ directory of the source archive.\n"
394 "Please check also out the SURF section of the ChangeLog for "
395 "the 3.1 version for more information. \n"
397 "Last, do not forget to also update your values for "
398 "the calls to MSG_task_create (if any).");
399 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
400 "You're using an old XML file.\n"
401 "Use simgrid_update_xml to update your file automatically. "
402 "This program is installed automatically with SimGrid, or "
403 "available in the tools/ directory of the source archive.");
404 xbt_assert((version >= 4.0), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
405 "Changes introduced in SimGrid 3.13:\n"
406 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
407 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
408 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
409 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
411 "Use simgrid_update_xml to update your file automatically. "
412 "This program is installed automatically with SimGrid, or "
413 "available in the tools/ directory of the source archive.",surf_parsed_filename, version);
417 void ETag_surfxml_platform(void){
421 void STag_surfxml_host(void){
423 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
426 void STag_surfxml_prop(void)
429 if (!as_current_property_set){
430 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
431 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
432 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
433 as_dict_tab[as_prop_nb] = as_current_property_set;
434 XBT_DEBUG("PUSH prop set %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
437 XBT_DEBUG("add prop %s=%s into current AS property set", A_surfxml_prop_id, A_surfxml_prop_value);
438 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
441 if (!current_property_set)
442 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
443 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
444 XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
448 void ETag_surfxml_host(void) {
449 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
451 memset(&host,0,sizeof(host));
454 host.properties = current_property_set;
456 host.id = A_surfxml_host_id;
458 buf = A_surfxml_host_speed;
459 XBT_DEBUG("Buffer: %s", buf);
460 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
461 if (strchr(buf, ',') == NULL){
462 double speed = surf_parse_get_speed(A_surfxml_host_speed,"speed of host", host.id);
463 xbt_dynar_push_as(host.speed_peak,double, speed);
466 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
468 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
472 xbt_dynar_get_cpy(pstate_list, i, &speed_str);
473 xbt_str_trim(speed_str, NULL);
474 speed = surf_parse_get_speed(speed_str,"speed of host", host.id);
475 xbt_dynar_push_as(host.speed_peak, double, speed);
476 XBT_DEBUG("Speed value: %f", speed);
478 xbt_dynar_free(&pstate_list);
481 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
482 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
483 host.speed_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
484 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
485 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
486 host.coord = A_surfxml_host_coordinates;
488 sg_platf_new_host(&host);
489 xbt_dynar_free(&host.speed_peak);
490 current_property_set = NULL;
493 void STag_surfxml_host___link(void){
494 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
495 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
496 memset(&host_link,0,sizeof(host_link));
498 host_link.id = A_surfxml_host___link_id;
499 host_link.link_up = A_surfxml_host___link_up;
500 host_link.link_down = A_surfxml_host___link_down;
501 sg_platf_new_hostlink(&host_link);
504 void STag_surfxml_router(void){
505 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
506 memset(&router, 0, sizeof(router));
508 router.id = A_surfxml_router_id;
509 router.coord = A_surfxml_router_coordinates;
511 sg_platf_new_router(&router);
514 void ETag_surfxml_cluster(void){
515 s_sg_platf_cluster_cbarg_t cluster = SG_PLATF_CLUSTER_INITIALIZER;
516 memset(&cluster,0,sizeof(cluster));
517 cluster.properties = as_current_property_set;
519 cluster.id = A_surfxml_cluster_id;
520 cluster.prefix = A_surfxml_cluster_prefix;
521 cluster.suffix = A_surfxml_cluster_suffix;
522 cluster.radical = A_surfxml_cluster_radical;
523 cluster.speed = surf_parse_get_speed(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
524 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
525 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
526 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
527 if(strcmp(A_surfxml_cluster_bb___bw,""))
528 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
529 if(strcmp(A_surfxml_cluster_bb___lat,""))
530 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
531 if(strcmp(A_surfxml_cluster_limiter___link,""))
532 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
533 if(strcmp(A_surfxml_cluster_loopback___bw,""))
534 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
535 if(strcmp(A_surfxml_cluster_loopback___lat,""))
536 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
538 switch(AX_surfxml_cluster_topology){
539 case A_surfxml_cluster_topology_FLAT:
540 cluster.topology= SURF_CLUSTER_FLAT ;
542 case A_surfxml_cluster_topology_TORUS:
543 cluster.topology= SURF_CLUSTER_TORUS ;
545 case A_surfxml_cluster_topology_FAT___TREE:
546 cluster.topology = SURF_CLUSTER_FAT_TREE;
549 surf_parse_error("Invalid cluster topology for cluster %s",
553 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
554 cluster.router_id = A_surfxml_cluster_router___id;
556 switch (AX_surfxml_cluster_sharing___policy) {
557 case A_surfxml_cluster_sharing___policy_SHARED:
558 cluster.sharing_policy = SURF_LINK_SHARED;
560 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
561 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
563 case A_surfxml_cluster_sharing___policy_FATPIPE:
564 cluster.sharing_policy = SURF_LINK_FATPIPE;
567 surf_parse_error("Invalid cluster sharing policy for cluster %s",
571 switch (AX_surfxml_cluster_bb___sharing___policy) {
572 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
573 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
575 case A_surfxml_cluster_bb___sharing___policy_SHARED:
576 cluster.bb_sharing_policy = SURF_LINK_SHARED;
579 surf_parse_error("Invalid bb sharing policy in cluster %s",
584 cluster.availability_trace = A_surfxml_cluster_availability___file;
585 cluster.state_trace = A_surfxml_cluster_state___file;
586 sg_platf_new_cluster(&cluster);
588 current_property_set = NULL;
591 void STag_surfxml_cluster(void){
592 parse_after_config();
593 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
596 void STag_surfxml_cabinet(void){
597 parse_after_config();
598 s_sg_platf_cabinet_cbarg_t cabinet = SG_PLATF_CABINET_INITIALIZER;
599 memset(&cabinet,0,sizeof(cabinet));
600 cabinet.id = A_surfxml_cabinet_id;
601 cabinet.prefix = A_surfxml_cabinet_prefix;
602 cabinet.suffix = A_surfxml_cabinet_suffix;
603 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
604 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
605 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
606 cabinet.radical = A_surfxml_cabinet_radical;
608 sg_platf_new_cabinet(&cabinet);
611 void STag_surfxml_peer(void){
612 parse_after_config();
613 s_sg_platf_peer_cbarg_t peer = SG_PLATF_PEER_INITIALIZER;
614 memset(&peer,0,sizeof(peer));
615 peer.id = A_surfxml_peer_id;
616 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
617 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
618 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
619 peer.lat = surf_parse_get_time(A_surfxml_peer_lat, "lat of peer", peer.id);
620 peer.coord = A_surfxml_peer_coordinates;
621 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
622 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
624 sg_platf_new_peer(&peer);
627 void STag_surfxml_link(void){
629 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
632 void ETag_surfxml_link(void){
633 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
634 memset(&link,0,sizeof(link));
636 link.properties = current_property_set;
637 link.id = A_surfxml_link_id;
638 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id);
639 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
640 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id);
641 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
642 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
644 switch (A_surfxml_link_sharing___policy) {
645 case A_surfxml_link_sharing___policy_SHARED:
646 link.policy = SURF_LINK_SHARED;
648 case A_surfxml_link_sharing___policy_FATPIPE:
649 link.policy = SURF_LINK_FATPIPE;
651 case A_surfxml_link_sharing___policy_FULLDUPLEX:
652 link.policy = SURF_LINK_FULLDUPLEX;
655 surf_parse_error("Invalid sharing policy in link %s", link.id);
659 sg_platf_new_link(&link);
661 current_property_set = NULL;
664 void STag_surfxml_link___ctn(void){
667 switch (A_surfxml_link___ctn_direction) {
668 case AU_surfxml_link___ctn_direction:
669 case A_surfxml_link___ctn_direction_NONE:
670 link_id = xbt_strdup(A_surfxml_link___ctn_id);
672 case A_surfxml_link___ctn_direction_UP:
673 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
675 case A_surfxml_link___ctn_direction_DOWN:
676 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
680 // FIXME we should push the surf link object but it don't
681 // work because of model rulebased
682 xbt_dynar_push(parsed_link_list, &link_id);
685 void ETag_surfxml_backbone(void){
686 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
687 memset(&link,0,sizeof(link));
689 link.properties = NULL;
691 link.id = A_surfxml_backbone_id;
692 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id);
693 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id);
694 link.policy = SURF_LINK_SHARED;
696 sg_platf_new_link(&link);
697 routing_cluster_add_backbone(sg_link_by_name(A_surfxml_backbone_id));
700 void STag_surfxml_route(void){
701 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_src),
702 "Route src='%s' does name a node.", A_surfxml_route_src);
703 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_dst),
704 "Route dst='%s' does name a node.", A_surfxml_route_dst);
705 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
708 void STag_surfxml_ASroute(void){
709 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_src),
710 "ASroute src='%s' does name a node.", A_surfxml_route_src);
711 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_dst),
712 "ASroute dst='%s' does name a node.", A_surfxml_route_dst);
714 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src),
715 "ASroute gw_src='%s' does name a node.", A_surfxml_ASroute_gw___src);
716 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst),
717 "ASroute gw_dst='%s' does name a node.", A_surfxml_ASroute_gw___dst);
719 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
722 void STag_surfxml_bypassRoute(void){
723 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_src),
724 "bypassRoute src='%s' does name a node.", A_surfxml_bypassRoute_src);
725 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_dst),
726 "bypassRoute dst='%s' does name a node.", A_surfxml_bypassRoute_dst);
728 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
731 void STag_surfxml_bypassASroute(void){
732 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_src),
733 "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
734 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_dst),
735 "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
736 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src),
737 "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
738 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
739 "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
741 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
744 void ETag_surfxml_route(void){
745 s_sg_platf_route_cbarg_t route;
746 memset(&route,0,sizeof(route));
748 route.src = A_surfxml_route_src;
749 route.dst = A_surfxml_route_dst;
752 route.link_list = new std::vector<Link*>();
756 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
757 simgrid::surf::Link *link = Link::byName(link_name);
758 route.link_list->push_back(link);
762 switch (A_surfxml_route_symmetrical) {
763 case AU_surfxml_route_symmetrical:
764 case A_surfxml_route_symmetrical_YES:
765 route.symmetrical = TRUE;
767 case A_surfxml_route_symmetrical_NO:
768 route.symmetrical = FALSE;;
772 sg_platf_new_route(&route);
773 parsed_link_list = NULL;
776 void ETag_surfxml_ASroute(void){
777 s_sg_platf_route_cbarg_t ASroute;
778 memset(&ASroute,0,sizeof(ASroute));
780 ASroute.src = A_surfxml_ASroute_src;
781 ASroute.dst = A_surfxml_ASroute_dst;
783 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src);
784 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst);
786 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
787 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
788 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
789 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
790 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
791 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
793 ASroute.link_list = new std::vector<Link*>();
797 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
798 simgrid::surf::Link *link = Link::byName(link_name);
799 ASroute.link_list->push_back(link);
802 switch (A_surfxml_ASroute_symmetrical) {
803 case AU_surfxml_ASroute_symmetrical:
804 case A_surfxml_ASroute_symmetrical_YES:
805 ASroute.symmetrical = TRUE;
807 case A_surfxml_ASroute_symmetrical_NO:
808 ASroute.symmetrical = FALSE;
812 sg_platf_new_route(&ASroute);
813 parsed_link_list = NULL;
816 void ETag_surfxml_bypassRoute(void){
817 s_sg_platf_route_cbarg_t route;
818 memset(&route,0,sizeof(route));
820 route.src = A_surfxml_bypassRoute_src;
821 route.dst = A_surfxml_bypassRoute_dst;
824 route.symmetrical = FALSE;
825 route.link_list = new std::vector<Link*>();
829 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
830 simgrid::surf::Link *link = Link::byName(link_name);
831 route.link_list->push_back(link);
833 xbt_dynar_free(&parsed_link_list);
835 sg_platf_new_bypassRoute(&route);
838 void ETag_surfxml_bypassASroute(void){
839 s_sg_platf_route_cbarg_t ASroute;
840 memset(&ASroute,0,sizeof(ASroute));
842 ASroute.src = A_surfxml_bypassASroute_src;
843 ASroute.dst = A_surfxml_bypassASroute_dst;
844 ASroute.link_list = new std::vector<Link*>();
847 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
848 simgrid::surf::Link *link = Link::byName(link_name);
849 ASroute.link_list->push_back(link);
851 xbt_dynar_free(&parsed_link_list);
852 ASroute.symmetrical = FALSE;
854 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src);
855 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
857 sg_platf_new_bypassRoute(&ASroute);
860 void ETag_surfxml_trace(void){
861 s_sg_platf_trace_cbarg_t trace = SG_PLATF_TRACE_INITIALIZER;
862 memset(&trace,0,sizeof(trace));
864 trace.id = A_surfxml_trace_id;
865 trace.file = A_surfxml_trace_file;
866 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
867 trace.pc_data = surfxml_pcdata;
869 sg_platf_new_trace(&trace);
872 void STag_surfxml_trace___connect(void){
873 parse_after_config();
874 s_sg_platf_trace_connect_cbarg_t trace_connect = SG_PLATF_TRACE_CONNECT_INITIALIZER;
875 memset(&trace_connect,0,sizeof(trace_connect));
877 trace_connect.element = A_surfxml_trace___connect_element;
878 trace_connect.trace = A_surfxml_trace___connect_trace;
880 switch (A_surfxml_trace___connect_kind) {
881 case AU_surfxml_trace___connect_kind:
882 case A_surfxml_trace___connect_kind_SPEED:
883 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
885 case A_surfxml_trace___connect_kind_BANDWIDTH:
886 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
888 case A_surfxml_trace___connect_kind_HOST___AVAIL:
889 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
891 case A_surfxml_trace___connect_kind_LATENCY:
892 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
894 case A_surfxml_trace___connect_kind_LINK___AVAIL:
895 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
898 sg_platf_trace_connect(&trace_connect);
901 void STag_surfxml_AS(void){
902 parse_after_config();
904 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
905 AS.id = A_surfxml_AS_id;
906 AS.routing = (int)A_surfxml_AS_routing;
908 as_current_property_set = NULL;
910 sg_platf_new_AS_begin(&AS);
912 void ETag_surfxml_AS(void){
914 char *name = as_name_tab[as_prop_nb-1];
915 xbt_dict_t dict = (xbt_dict_t) as_dict_tab[as_prop_nb-1];
917 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
918 xbt_lib_set(as_router_lib,
920 ROUTING_PROP_ASR_LEVEL,
924 sg_platf_new_AS_end();
927 void STag_surfxml_config(void){
929 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
930 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
931 if (_sg_cfg_init_status == 2) {
932 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
935 void ETag_surfxml_config(void){
936 xbt_dict_cursor_t cursor = NULL;
940 xbt_dict_foreach(current_property_set, cursor, key, elem) {
941 cfg = bprintf("%s:%s",key,elem);
942 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
943 xbt_cfg_set_parse(_sg_cfg_set, cfg);
945 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
948 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
950 xbt_dict_free(¤t_property_set);
951 current_property_set = NULL;
957 void STag_surfxml_process(void){
960 argv = xbt_new(char *, 1);
961 argv[0] = xbt_strdup(A_surfxml_process_function);
962 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
965 void ETag_surfxml_process(void){
966 s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
967 memset(&process,0,sizeof(process));
970 process.argv = (const char **)argv;
971 process.properties = current_property_set;
972 process.host = A_surfxml_process_host;
973 process.function = A_surfxml_process_function;
974 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
975 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
977 switch (A_surfxml_process_on___failure) {
978 case AU_surfxml_process_on___failure:
979 case A_surfxml_process_on___failure_DIE:
980 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
982 case A_surfxml_process_on___failure_RESTART:
983 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
987 sg_platf_new_process(&process);
988 current_property_set = NULL;
991 void STag_surfxml_argument(void){
993 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
994 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
997 void STag_surfxml_model___prop(void){
998 if (!current_model_property_set)
999 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
1001 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), NULL);
1004 void STag_surfxml_gpu(void) {}
1005 void ETag_surfxml_gpu(void) {}
1007 /* nothing to do in those functions */
1008 void ETag_surfxml_prop(void){}
1009 void STag_surfxml_random(void){}
1010 void ETag_surfxml_random(void){}
1011 void ETag_surfxml_trace___connect(void){}
1012 void STag_surfxml_trace(void){parse_after_config();}
1013 void ETag_surfxml_router(void){}
1014 void ETag_surfxml_host___link(void){}
1015 void ETag_surfxml_cabinet(void){}
1016 void ETag_surfxml_peer(void){}
1017 void STag_surfxml_backbone(void){}
1018 void ETag_surfxml_link___ctn(void){}
1019 void ETag_surfxml_argument(void){}
1020 void ETag_surfxml_model___prop(void){}
1022 /* Open and Close parse file */
1024 void surf_parse_open(const char *file)
1026 static int warned = 0; /* warn only once */
1030 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
1031 "If it is not what you want, go fix your code.");
1037 if (!surf_input_buffer_stack)
1038 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
1039 if (!surf_file_to_parse_stack)
1040 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
1042 if (!surf_parsed_filename_stack)
1043 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1045 surf_parsed_filename = xbt_strdup(file);
1046 char *dir = xbt_dirname(file);
1047 xbt_dynar_push(surf_path, &dir);
1049 surf_file_to_parse = surf_fopen(file, "r");
1050 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1051 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1052 surf_parse__switch_to_buffer(surf_input_buffer);
1053 surf_parse_lineno = 1;
1056 void surf_parse_close(void)
1058 xbt_dynar_free(&surf_input_buffer_stack);
1059 xbt_dynar_free(&surf_file_to_parse_stack);
1060 xbt_dynar_free(&surf_parsed_filename_stack);
1061 if (surf_parsed_filename) {
1063 xbt_dynar_pop(surf_path, &dir);
1067 free(surf_parsed_filename);
1068 surf_parsed_filename = NULL;
1070 if (surf_file_to_parse) {
1071 surf_parse__delete_buffer(surf_input_buffer);
1072 fclose(surf_file_to_parse);
1073 surf_file_to_parse = NULL; //Must be reset for Bypass
1077 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1079 static int _surf_parse(void) {
1080 return surf_parse_lex();
1082 int_f_void_t surf_parse = _surf_parse;
1085 /* Prop tag functions */
1090 xbt_dict_t get_as_router_properties(const char* name)
1092 return (xbt_dict_t)xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);