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 "simgrid/sg_config.h"
18 #include "simgrid/link.h"
20 #include "src/surf/xml/platf_private.hpp"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
23 "Logging specific to the SURF parsing module");
25 int ETag_surfxml_include_state(void);
27 #include "simgrid_dtd.c"
29 char* surf_parsed_filename = NULL; // to locate parse error messages
31 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
35 void surf_parse_assert(bool cond, const char *fmt, ...) {
39 int lineno = surf_parse_lineno;
40 char *msg = bvprintf(fmt,va);
43 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
45 xbt_die("Exiting now");
48 void surf_parse_error(const char *fmt, ...) {
51 int lineno = surf_parse_lineno;
52 char *msg = bvprintf(fmt,va);
55 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
57 xbt_die("Exiting now");
59 void surf_parse_warn(const char *fmt, ...) {
62 char *msg = bvprintf(fmt,va);
64 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
68 double surf_parse_get_double(const char *string) {
70 int ret = sscanf(string, "%lg", &res);
72 surf_parse_error("%s is not a double", string);
76 int surf_parse_get_int(const char *string) {
78 int ret = sscanf(string, "%d", &res);
80 surf_parse_error("%s is not an integer", string);
89 /* Note: field `unit' for the last element of parameter `units' should be
91 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
92 const char *entity_kind, const char *name,
93 const char *error_msg, const char *default_unit)
99 res = strtod(string, &ptr);
101 surf_parse_error("value out of range: %s", string);
103 surf_parse_error("cannot parse number: %s", string);
104 if (ptr[0] == '\0') {
106 return res; // Ok, 0 can be unit-less
108 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
109 ptr = (char*)default_unit;
111 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
113 if (units[i].unit != NULL)
114 res *= units[i].scale;
116 surf_parse_error("unknown unit: %s", ptr);
120 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
122 const struct unit_scale units[] = {
123 { "w", 7 * 24 * 60 * 60 },
124 { "d", 24 * 60 * 60 },
134 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
135 "Append 's' to your time to get seconds", "s");
138 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
140 const struct unit_scale units[] = {
141 { "TiB", pow(1024, 4) },
142 { "GiB", pow(1024, 3) },
143 { "MiB", pow(1024, 2) },
150 { "Tib", 0.125 * pow(1024, 4) },
151 { "Gib", 0.125 * pow(1024, 3) },
152 { "Mib", 0.125 * pow(1024, 2) },
153 { "Kib", 0.125 * 1024 },
154 { "Tb", 0.125 * 1e12 },
155 { "Gb", 0.125 * 1e9 },
156 { "Mb", 0.125 * 1e6 },
157 { "kb", 0.125 * 1e3 },
161 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
162 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
165 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
167 const struct unit_scale units[] = {
168 { "TiBps", pow(1024, 4) },
169 { "GiBps", pow(1024, 3) },
170 { "MiBps", pow(1024, 2) },
177 { "Tibps", 0.125 * pow(1024, 4) },
178 { "Gibps", 0.125 * pow(1024, 3) },
179 { "Mibps", 0.125 * pow(1024, 2) },
180 { "Kibps", 0.125 * 1024 },
181 { "Tbps", 0.125 * 1e12 },
182 { "Gbps", 0.125 * 1e9 },
183 { "Mbps", 0.125 * 1e6 },
184 { "kbps", 0.125 * 1e3 },
188 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
189 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
192 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
194 const struct unit_scale units[] = {
195 { "yottaflops", 1e24 },
197 { "zettaflops", 1e21 },
199 { "exaflops", 1e18 },
201 { "petaflops", 1e15 },
203 { "teraflops", 1e12 },
205 { "gigaflops", 1e9 },
207 { "megaflops", 1e6 },
209 { "kiloflops", 1e3 },
215 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
216 "Append 'f' or 'flops' to your speed to get flop per second", "f");
220 * All the callback lists that can be overridden anywhere.
221 * (this list should probably be reduced to the bare minimum to allow the models to work)
224 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
226 /* The default current property receiver. Setup in the corresponding opening callbacks. */
227 xbt_dict_t current_property_set = NULL;
228 xbt_dict_t current_model_property_set = NULL;
229 xbt_dict_t as_current_property_set = NULL;
231 char* as_name_tab[1024];
232 void* as_dict_tab[1024];
236 /* dictionary of random generator data */
237 xbt_dict_t random_data_list = NULL;
239 YY_BUFFER_STATE surf_input_buffer;
240 FILE *surf_file_to_parse = NULL;
243 * Stuff relative to storage
245 void STag_surfxml_storage(void)
248 XBT_DEBUG("STag_surfxml_storage");
249 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
251 void ETag_surfxml_storage(void)
253 s_sg_platf_storage_cbarg_t storage = SG_PLATF_STORAGE_INITIALIZER;
254 memset(&storage,0,sizeof(storage));
256 storage.id = A_surfxml_storage_id;
257 storage.type_id = A_surfxml_storage_typeId;
258 storage.content = A_surfxml_storage_content;
259 storage.content_type = A_surfxml_storage_content___type;
260 storage.properties = current_property_set;
261 storage.attach = A_surfxml_storage_attach;
262 sg_platf_new_storage(&storage);
263 current_property_set = NULL;
265 void STag_surfxml_storage___type(void)
268 XBT_DEBUG("STag_surfxml_storage___type");
269 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
270 xbt_assert(current_model_property_set == NULL, "Someone forgot to reset the model property set to NULL in its closing tag (or XML malformed)");
272 void ETag_surfxml_storage___type(void)
274 s_sg_platf_storage_type_cbarg_t storage_type = SG_PLATF_STORAGE_TYPE_INITIALIZER;
275 memset(&storage_type,0,sizeof(storage_type));
277 storage_type.content = A_surfxml_storage___type_content;
278 storage_type.content_type = A_surfxml_storage___type_content___type;
279 storage_type.id = A_surfxml_storage___type_id;
280 storage_type.model = A_surfxml_storage___type_model;
281 storage_type.properties = current_property_set;
282 storage_type.model_properties = current_model_property_set;
283 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
284 "size of storage type", storage_type.id);
285 sg_platf_new_storage_type(&storage_type);
286 current_property_set = NULL;
287 current_model_property_set = NULL;
289 void STag_surfxml_mstorage(void)
291 XBT_DEBUG("STag_surfxml_mstorage");
293 void ETag_surfxml_mstorage(void)
295 s_sg_platf_mstorage_cbarg_t mstorage = SG_PLATF_MSTORAGE_INITIALIZER;
296 memset(&mstorage,0,sizeof(mstorage));
298 mstorage.name = A_surfxml_mstorage_name;
299 mstorage.type_id = A_surfxml_mstorage_typeId;
300 sg_platf_new_mstorage(&mstorage);
302 void STag_surfxml_mount(void)
304 XBT_DEBUG("STag_surfxml_mount");
306 void ETag_surfxml_mount(void)
308 s_sg_platf_mount_cbarg_t mount = SG_PLATF_MOUNT_INITIALIZER;
309 memset(&mount,0,sizeof(mount));
311 mount.name = A_surfxml_mount_name;
312 mount.storageId = A_surfxml_mount_storageId;
313 sg_platf_new_mount(&mount);
317 * Stuff relative to the <include> tag
319 static xbt_dynar_t surf_input_buffer_stack = NULL;
320 static xbt_dynar_t surf_file_to_parse_stack = NULL;
321 static xbt_dynar_t surf_parsed_filename_stack = NULL;
323 void STag_surfxml_include(void)
325 parse_after_config();
326 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
327 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
328 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
330 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
332 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
333 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
335 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
336 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
337 surf_parse_push_buffer_state(surf_input_buffer);
342 void ETag_surfxml_include(void) {
343 /* Nothing to do when done with reading the include tag.
344 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
347 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
349 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
350 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
351 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
352 * error message in that case.
354 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
355 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
356 * on a line. One day maybe, if the maya allow it.
358 int ETag_surfxml_include_state(void)
361 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
363 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
366 // Yeah, we were in an <include> Restore state and proceed.
367 fclose(surf_file_to_parse);
368 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
369 surf_parse_pop_buffer_state();
370 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
372 // Restore the filename for error messages
373 free(surf_parsed_filename);
374 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
379 /* Stag and Etag parse functions */
381 void STag_surfxml_platform(void) {
382 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
384 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
385 "You're using an ancient XML file.\n"
386 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
387 "instead of MBytes, MFlops and seconds.\n"
389 "Use simgrid_update_xml to update your file automatically. "
390 "This program is installed automatically with SimGrid, or "
391 "available in the tools/ directory of the source archive.\n"
393 "Please check also out the SURF section of the ChangeLog for "
394 "the 3.1 version for more information. \n"
396 "Last, do not forget to also update your values for "
397 "the calls to MSG_task_create (if any).");
398 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
399 "You're using an old XML file.\n"
400 "Use simgrid_update_xml to update your file automatically. "
401 "This program is installed automatically with SimGrid, or "
402 "available in the tools/ directory of the source archive.");
403 xbt_assert((version >= 4.0), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
404 "Changes introduced in SimGrid 3.13:\n"
405 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
406 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
407 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
408 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
410 "Use simgrid_update_xml to update your file automatically. "
411 "This program is installed automatically with SimGrid, or "
412 "available in the tools/ directory of the source archive.",surf_parsed_filename, version);
416 void ETag_surfxml_platform(void){
420 void STag_surfxml_host(void){
422 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
425 void STag_surfxml_prop(void)
428 if (!as_current_property_set){
429 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
430 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
431 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
432 as_dict_tab[as_prop_nb] = as_current_property_set;
433 XBT_DEBUG("PUSH prop set %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
436 XBT_DEBUG("add prop %s=%s into current AS property set", A_surfxml_prop_id, A_surfxml_prop_value);
437 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
440 if (!current_property_set)
441 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
442 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
443 XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
447 void ETag_surfxml_host(void) {
448 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
450 memset(&host,0,sizeof(host));
453 host.properties = current_property_set;
455 host.id = A_surfxml_host_id;
457 buf = A_surfxml_host_speed;
458 XBT_DEBUG("Buffer: %s", buf);
459 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
460 if (strchr(buf, ',') == NULL){
461 double speed = surf_parse_get_speed(A_surfxml_host_speed,"speed of host", host.id);
462 xbt_dynar_push_as(host.speed_peak,double, speed);
465 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
467 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
471 xbt_dynar_get_cpy(pstate_list, i, &speed_str);
472 xbt_str_trim(speed_str, NULL);
473 speed = surf_parse_get_speed(speed_str,"speed of host", host.id);
474 xbt_dynar_push_as(host.speed_peak, double, speed);
475 XBT_DEBUG("Speed value: %f", speed);
477 xbt_dynar_free(&pstate_list);
480 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
481 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
482 host.speed_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
483 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
484 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
485 host.coord = A_surfxml_host_coordinates;
487 sg_platf_new_host(&host);
488 xbt_dynar_free(&host.speed_peak);
489 current_property_set = NULL;
492 void STag_surfxml_host___link(void){
493 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
494 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
495 memset(&host_link,0,sizeof(host_link));
497 host_link.id = A_surfxml_host___link_id;
498 host_link.link_up = A_surfxml_host___link_up;
499 host_link.link_down = A_surfxml_host___link_down;
500 sg_platf_new_hostlink(&host_link);
503 void STag_surfxml_router(void){
504 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
505 memset(&router, 0, sizeof(router));
507 router.id = A_surfxml_router_id;
508 router.coord = A_surfxml_router_coordinates;
510 sg_platf_new_router(&router);
513 void ETag_surfxml_cluster(void){
514 s_sg_platf_cluster_cbarg_t cluster = SG_PLATF_CLUSTER_INITIALIZER;
515 memset(&cluster,0,sizeof(cluster));
516 cluster.properties = as_current_property_set;
518 cluster.id = A_surfxml_cluster_id;
519 cluster.prefix = A_surfxml_cluster_prefix;
520 cluster.suffix = A_surfxml_cluster_suffix;
521 cluster.radical = A_surfxml_cluster_radical;
522 cluster.speed = surf_parse_get_speed(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
523 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
524 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
525 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
526 if(strcmp(A_surfxml_cluster_bb___bw,""))
527 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
528 if(strcmp(A_surfxml_cluster_bb___lat,""))
529 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
530 if(strcmp(A_surfxml_cluster_limiter___link,""))
531 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
532 if(strcmp(A_surfxml_cluster_loopback___bw,""))
533 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
534 if(strcmp(A_surfxml_cluster_loopback___lat,""))
535 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
537 switch(AX_surfxml_cluster_topology){
538 case A_surfxml_cluster_topology_FLAT:
539 cluster.topology= SURF_CLUSTER_FLAT ;
541 case A_surfxml_cluster_topology_TORUS:
542 cluster.topology= SURF_CLUSTER_TORUS ;
544 case A_surfxml_cluster_topology_FAT___TREE:
545 cluster.topology = SURF_CLUSTER_FAT_TREE;
548 surf_parse_error("Invalid cluster topology for cluster %s",
552 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
553 cluster.router_id = A_surfxml_cluster_router___id;
555 switch (AX_surfxml_cluster_sharing___policy) {
556 case A_surfxml_cluster_sharing___policy_SHARED:
557 cluster.sharing_policy = SURF_LINK_SHARED;
559 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
560 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
562 case A_surfxml_cluster_sharing___policy_FATPIPE:
563 cluster.sharing_policy = SURF_LINK_FATPIPE;
566 surf_parse_error("Invalid cluster sharing policy for cluster %s",
570 switch (AX_surfxml_cluster_bb___sharing___policy) {
571 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
572 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
574 case A_surfxml_cluster_bb___sharing___policy_SHARED:
575 cluster.bb_sharing_policy = SURF_LINK_SHARED;
578 surf_parse_error("Invalid bb sharing policy in cluster %s",
583 cluster.availability_trace = A_surfxml_cluster_availability___file;
584 cluster.state_trace = A_surfxml_cluster_state___file;
585 sg_platf_new_cluster(&cluster);
587 current_property_set = NULL;
590 void STag_surfxml_cluster(void){
591 parse_after_config();
592 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
595 void STag_surfxml_cabinet(void){
596 parse_after_config();
597 s_sg_platf_cabinet_cbarg_t cabinet = SG_PLATF_CABINET_INITIALIZER;
598 memset(&cabinet,0,sizeof(cabinet));
599 cabinet.id = A_surfxml_cabinet_id;
600 cabinet.prefix = A_surfxml_cabinet_prefix;
601 cabinet.suffix = A_surfxml_cabinet_suffix;
602 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
603 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
604 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
605 cabinet.radical = A_surfxml_cabinet_radical;
607 sg_platf_new_cabinet(&cabinet);
610 void STag_surfxml_peer(void){
611 parse_after_config();
612 s_sg_platf_peer_cbarg_t peer = SG_PLATF_PEER_INITIALIZER;
613 memset(&peer,0,sizeof(peer));
614 peer.id = A_surfxml_peer_id;
615 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
616 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
617 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
618 peer.lat = surf_parse_get_time(A_surfxml_peer_lat, "lat of peer", peer.id);
619 peer.coord = A_surfxml_peer_coordinates;
620 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
621 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
623 sg_platf_new_peer(&peer);
626 void STag_surfxml_link(void){
628 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
631 void ETag_surfxml_link(void){
632 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
633 memset(&link,0,sizeof(link));
635 link.properties = current_property_set;
636 link.id = A_surfxml_link_id;
637 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id);
638 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
639 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id);
640 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
641 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
643 switch (A_surfxml_link_sharing___policy) {
644 case A_surfxml_link_sharing___policy_SHARED:
645 link.policy = SURF_LINK_SHARED;
647 case A_surfxml_link_sharing___policy_FATPIPE:
648 link.policy = SURF_LINK_FATPIPE;
650 case A_surfxml_link_sharing___policy_FULLDUPLEX:
651 link.policy = SURF_LINK_FULLDUPLEX;
654 surf_parse_error("Invalid sharing policy in link %s", link.id);
658 sg_platf_new_link(&link);
660 current_property_set = NULL;
663 void STag_surfxml_link___ctn(void){
666 switch (A_surfxml_link___ctn_direction) {
667 case AU_surfxml_link___ctn_direction:
668 case A_surfxml_link___ctn_direction_NONE:
669 link_id = xbt_strdup(A_surfxml_link___ctn_id);
671 case A_surfxml_link___ctn_direction_UP:
672 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
674 case A_surfxml_link___ctn_direction_DOWN:
675 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
679 // FIXME we should push the surf link object but it don't
680 // work because of model rulebased
681 xbt_dynar_push(parsed_link_list, &link_id);
684 void ETag_surfxml_backbone(void){
685 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
686 memset(&link,0,sizeof(link));
688 link.properties = NULL;
690 link.id = A_surfxml_backbone_id;
691 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id);
692 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id);
693 link.policy = SURF_LINK_SHARED;
695 sg_platf_new_link(&link);
696 routing_cluster_add_backbone(sg_link_by_name(A_surfxml_backbone_id));
699 void STag_surfxml_route(void){
700 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_src),
701 "Route src='%s' does name a node.", A_surfxml_route_src);
702 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_dst),
703 "Route dst='%s' does name a node.", A_surfxml_route_dst);
704 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
707 void STag_surfxml_ASroute(void){
708 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_src),
709 "ASroute src='%s' does name a node.", A_surfxml_route_src);
710 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_dst),
711 "ASroute dst='%s' does name a node.", A_surfxml_route_dst);
713 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src),
714 "ASroute gw_src='%s' does name a node.", A_surfxml_ASroute_gw___src);
715 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst),
716 "ASroute gw_dst='%s' does name a node.", A_surfxml_ASroute_gw___dst);
718 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
721 void STag_surfxml_bypassRoute(void){
722 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_src),
723 "bypassRoute src='%s' does name a node.", A_surfxml_bypassRoute_src);
724 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_dst),
725 "bypassRoute dst='%s' does name a node.", A_surfxml_bypassRoute_dst);
727 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
730 void STag_surfxml_bypassASroute(void){
731 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_src),
732 "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
733 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_dst),
734 "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
735 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src),
736 "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
737 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
738 "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
740 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
743 void ETag_surfxml_route(void){
744 s_sg_platf_route_cbarg_t route;
745 memset(&route,0,sizeof(route));
747 route.src = A_surfxml_route_src;
748 route.dst = A_surfxml_route_dst;
751 route.link_list = parsed_link_list;
753 switch (A_surfxml_route_symmetrical) {
754 case AU_surfxml_route_symmetrical:
755 case A_surfxml_route_symmetrical_YES:
756 route.symmetrical = TRUE;
758 case A_surfxml_route_symmetrical_NO:
759 route.symmetrical = FALSE;;
763 sg_platf_new_route(&route);
764 parsed_link_list = NULL;
767 void ETag_surfxml_ASroute(void){
768 s_sg_platf_route_cbarg_t ASroute;
769 memset(&ASroute,0,sizeof(ASroute));
771 ASroute.src = A_surfxml_ASroute_src;
772 ASroute.dst = A_surfxml_ASroute_dst;
774 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src);
775 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst);
777 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
778 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
779 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
780 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
781 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
782 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
784 ASroute.link_list = parsed_link_list;
786 switch (A_surfxml_ASroute_symmetrical) {
787 case AU_surfxml_ASroute_symmetrical:
788 case A_surfxml_ASroute_symmetrical_YES:
789 ASroute.symmetrical = TRUE;
791 case A_surfxml_ASroute_symmetrical_NO:
792 ASroute.symmetrical = FALSE;
796 sg_platf_new_route(&ASroute);
797 parsed_link_list = NULL;
800 void ETag_surfxml_bypassRoute(void){
801 s_sg_platf_route_cbarg_t route;
802 memset(&route,0,sizeof(route));
804 route.src = A_surfxml_bypassRoute_src;
805 route.dst = A_surfxml_bypassRoute_dst;
808 route.link_list = parsed_link_list;
809 route.symmetrical = FALSE;
811 sg_platf_new_bypassRoute(&route);
812 xbt_dynar_free(&parsed_link_list);
815 void ETag_surfxml_bypassASroute(void){
816 s_sg_platf_route_cbarg_t ASroute;
817 memset(&ASroute,0,sizeof(ASroute));
819 ASroute.src = A_surfxml_bypassASroute_src;
820 ASroute.dst = A_surfxml_bypassASroute_dst;
821 ASroute.link_list = parsed_link_list;
822 ASroute.symmetrical = FALSE;
824 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src);
825 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
827 sg_platf_new_bypassRoute(&ASroute);
828 xbt_dynar_free(&parsed_link_list);
831 void ETag_surfxml_trace(void){
832 s_sg_platf_trace_cbarg_t trace = SG_PLATF_TRACE_INITIALIZER;
833 memset(&trace,0,sizeof(trace));
835 trace.id = A_surfxml_trace_id;
836 trace.file = A_surfxml_trace_file;
837 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
838 trace.pc_data = surfxml_pcdata;
840 sg_platf_new_trace(&trace);
843 void STag_surfxml_trace___connect(void){
844 parse_after_config();
845 s_sg_platf_trace_connect_cbarg_t trace_connect = SG_PLATF_TRACE_CONNECT_INITIALIZER;
846 memset(&trace_connect,0,sizeof(trace_connect));
848 trace_connect.element = A_surfxml_trace___connect_element;
849 trace_connect.trace = A_surfxml_trace___connect_trace;
851 switch (A_surfxml_trace___connect_kind) {
852 case AU_surfxml_trace___connect_kind:
853 case A_surfxml_trace___connect_kind_SPEED:
854 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
856 case A_surfxml_trace___connect_kind_BANDWIDTH:
857 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
859 case A_surfxml_trace___connect_kind_HOST___AVAIL:
860 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
862 case A_surfxml_trace___connect_kind_LATENCY:
863 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
865 case A_surfxml_trace___connect_kind_LINK___AVAIL:
866 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
869 sg_platf_trace_connect(&trace_connect);
872 void STag_surfxml_AS(void){
873 parse_after_config();
875 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
876 AS.id = A_surfxml_AS_id;
877 AS.routing = (int)A_surfxml_AS_routing;
879 as_current_property_set = NULL;
881 sg_platf_new_AS_begin(&AS);
883 void ETag_surfxml_AS(void){
885 char *name = as_name_tab[as_prop_nb-1];
886 xbt_dict_t dict = (xbt_dict_t) as_dict_tab[as_prop_nb-1];
888 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
889 xbt_lib_set(as_router_lib,
891 ROUTING_PROP_ASR_LEVEL,
895 sg_platf_new_AS_end();
898 void STag_surfxml_config(void){
900 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
901 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
902 if (_sg_cfg_init_status == 2) {
903 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
906 void ETag_surfxml_config(void){
907 xbt_dict_cursor_t cursor = NULL;
911 xbt_dict_foreach(current_property_set, cursor, key, elem) {
912 cfg = bprintf("%s:%s",key,elem);
913 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
914 xbt_cfg_set_parse(_sg_cfg_set, cfg);
916 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
919 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
921 xbt_dict_free(¤t_property_set);
922 current_property_set = NULL;
928 void STag_surfxml_process(void){
931 argv = xbt_new(char *, 1);
932 argv[0] = xbt_strdup(A_surfxml_process_function);
933 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
936 void ETag_surfxml_process(void){
937 s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
938 memset(&process,0,sizeof(process));
941 process.argv = (const char **)argv;
942 process.properties = current_property_set;
943 process.host = A_surfxml_process_host;
944 process.function = A_surfxml_process_function;
945 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
946 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
948 switch (A_surfxml_process_on___failure) {
949 case AU_surfxml_process_on___failure:
950 case A_surfxml_process_on___failure_DIE:
951 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
953 case A_surfxml_process_on___failure_RESTART:
954 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
958 sg_platf_new_process(&process);
959 current_property_set = NULL;
962 void STag_surfxml_argument(void){
964 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
965 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
968 void STag_surfxml_model___prop(void){
969 if (!current_model_property_set)
970 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
972 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), NULL);
975 void STag_surfxml_gpu(void) {}
976 void ETag_surfxml_gpu(void) {}
978 /* nothing to do in those functions */
979 void ETag_surfxml_prop(void){}
980 void STag_surfxml_random(void){}
981 void ETag_surfxml_random(void){}
982 void ETag_surfxml_trace___connect(void){}
983 void STag_surfxml_trace(void){parse_after_config();}
984 void ETag_surfxml_router(void){}
985 void ETag_surfxml_host___link(void){}
986 void ETag_surfxml_cabinet(void){}
987 void ETag_surfxml_peer(void){}
988 void STag_surfxml_backbone(void){}
989 void ETag_surfxml_link___ctn(void){}
990 void ETag_surfxml_argument(void){}
991 void ETag_surfxml_model___prop(void){}
993 /* Open and Close parse file */
995 void surf_parse_open(const char *file)
997 static int warned = 0; /* warn only once */
1001 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
1002 "If it is not what you want, go fix your code.");
1008 if (!surf_input_buffer_stack)
1009 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
1010 if (!surf_file_to_parse_stack)
1011 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
1013 if (!surf_parsed_filename_stack)
1014 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1016 surf_parsed_filename = xbt_strdup(file);
1017 char *dir = xbt_dirname(file);
1018 xbt_dynar_push(surf_path, &dir);
1020 surf_file_to_parse = surf_fopen(file, "r");
1021 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1022 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1023 surf_parse__switch_to_buffer(surf_input_buffer);
1024 surf_parse_lineno = 1;
1027 void surf_parse_close(void)
1029 xbt_dynar_free(&surf_input_buffer_stack);
1030 xbt_dynar_free(&surf_file_to_parse_stack);
1031 xbt_dynar_free(&surf_parsed_filename_stack);
1032 if (surf_parsed_filename) {
1034 xbt_dynar_pop(surf_path, &dir);
1038 free(surf_parsed_filename);
1039 surf_parsed_filename = NULL;
1041 if (surf_file_to_parse) {
1042 surf_parse__delete_buffer(surf_input_buffer);
1043 fclose(surf_file_to_parse);
1044 surf_file_to_parse = NULL; //Must be reset for Bypass
1048 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1050 static int _surf_parse(void) {
1051 return surf_parse_lex();
1053 int_f_void_t surf_parse = _surf_parse;
1056 /* Prop tag functions */
1061 xbt_dict_t get_as_router_properties(const char* name)
1063 return (xbt_dict_t)xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);