/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include <stdarg.h> /* va_arg */
+
#include "xbt/misc.h"
#include "xbt/log.h"
#include "xbt/str.h"
#include "simgrid_dtd.c"
+char* surf_parsed_filename = NULL; // to locate parse error messages
+
/*
* Helping functions
*/
-void surf_parse_error(const char *msg) {
- xbt_die("Parse error on line %d: %s\n", surf_parse_lineno, msg);
+void surf_parse_error(const char *fmt, ...) {
+ va_list va;
+ va_start(va,fmt);
+ char *msg = bvprintf(fmt,va);
+ va_end(va);
+ xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
+}
+void surf_parse_warn(const char *fmt, ...) {
+ va_list va;
+ va_start(va,fmt);
+ char *msg = bvprintf(fmt,va);
+ va_end(va);
+ XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
+ free(msg);
}
double surf_parse_get_double(const char *string) {
double res;
int ret = sscanf(string, "%lg", &res);
if (ret != 1)
- surf_parse_error(bprintf("%s is not a double", string));
+ surf_parse_error("%s is not a double", string);
return res;
}
int res;
int ret = sscanf(string, "%d", &res);
if (ret != 1)
- surf_parse_error(bprintf("%s is not an integer", string));
+ surf_parse_error("%s is not an integer", string);
return res;
}
/*
- * All the callback lists that can be overiden anywhere.
+ * All the callback lists that can be overridden anywhere.
* (this list should probably be reduced to the bare minimum to allow the models to work)
*/
xbt_dynar_t ETag_surfxml_ASroute_cb_list = NULL;
xbt_dynar_t STag_surfxml_bypassRoute_cb_list = NULL;
xbt_dynar_t ETag_surfxml_bypassRoute_cb_list = NULL;
+xbt_dynar_t STag_surfxml_bypassASroute_cb_list = NULL;
+xbt_dynar_t ETag_surfxml_bypassASroute_cb_list = NULL;
xbt_dynar_t STag_surfxml_include_cb_list = NULL;
xbt_dynar_t ETag_surfxml_include_cb_list = NULL;
+xbt_dynar_t STag_surfxml_storage_cb_list = NULL;
+xbt_dynar_t ETag_surfxml_storage_cb_list = NULL;
+xbt_dynar_t STag_surfxml_storage_type_cb_list = NULL;
+xbt_dynar_t ETag_surfxml_storage_type_cb_list = NULL;
+xbt_dynar_t STag_surfxml_mount_cb_list = NULL;
+xbt_dynar_t ETag_surfxml_mount_cb_list = NULL;
+xbt_dynar_t STag_surfxml_mstorage_cb_list = NULL;
+xbt_dynar_t ETag_surfxml_mstorage_cb_list = NULL;
+
/* The default current property receiver. Setup in the corresponding opening callbacks. */
xbt_dict_t current_property_set = NULL;
/* dictionary of random generator data */
static void add_randomness(void);
/*
- * Stuff relative to the <include> tag
+ * Stuff relative to storage
*/
+void STag_surfxml_storage(void)
+{
+ XBT_DEBUG("STag_surfxml_storage");
+}
+void ETag_surfxml_storage(void)
+{
+ s_sg_platf_storage_cbarg_t storage;
+ memset(&storage,0,sizeof(storage));
+
+ storage.id = A_surfxml_storage_id;
+ storage.type_id = A_surfxml_storage_typeId;
+ sg_platf_new_storage(&storage);
+}
+void STag_surfxml_storage_type(void)
+{
+ XBT_DEBUG("STag_surfxml_storage_type");
+ xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
+}
+void ETag_surfxml_storage_type(void)
+{
+ s_sg_platf_storage_type_cbarg_t storage_type;
+ memset(&storage_type,0,sizeof(storage_type));
+
+ storage_type.content = A_surfxml_storage_type_content;
+ storage_type.id = A_surfxml_storage_type_id;
+ storage_type.model = A_surfxml_storage_type_model;
+ storage_type.properties = current_property_set;
+ sg_platf_new_storage_type(&storage_type);
+ current_property_set = NULL;
+}
+void STag_surfxml_mstorage(void)
+{
+ XBT_DEBUG("STag_surfxml_mstorage");
+}
+void ETag_surfxml_mstorage(void)
+{
+ s_sg_platf_mstorage_cbarg_t mstorage;
+ memset(&mstorage,0,sizeof(mstorage));
+ mstorage.name = A_surfxml_mstorage_name;
+ mstorage.type_id = A_surfxml_mstorage_typeId;
+ sg_platf_new_mstorage(&mstorage);
+}
+void STag_surfxml_mount(void)
+{
+ XBT_DEBUG("STag_surfxml_mount");
+}
+void ETag_surfxml_mount(void)
+{
+ s_sg_platf_mount_cbarg_t mount;
+ memset(&mount,0,sizeof(mount));
+
+ mount.name = A_surfxml_mount_name;
+ mount.id = A_surfxml_mount_id;
+ sg_platf_new_mount(&mount);
+}
+
+/*
+ * Stuff relative to the <include> tag
+ */
static xbt_dynar_t surf_input_buffer_stack = NULL;
static xbt_dynar_t surf_file_to_parse_stack = NULL;
+static xbt_dynar_t surf_parsed_filename_stack = NULL;
void STag_surfxml_include(void)
{
- XBT_INFO("STag_surfxml_include '%s'",A_surfxml_include_file);
- xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old filename
+ XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
+ xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
+ surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
- surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new filename
+ xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
+
+ surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
A_surfxml_include_file);
xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
surf_parse_push_buffer_state(surf_input_buffer);
+
fflush(NULL);
}
*
* Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
* directly: a command line flag could instruct it to do the correct thing when #include is encountered
- * on a line.
+ * on a line. One day maybe, if the maya allow it.
*/
int ETag_surfxml_include_state(void)
{
fflush(NULL);
- XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
- if(!xbt_dynar_is_empty(surf_input_buffer_stack))
- return 1;
+ XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
+
+ if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
+ return 0;
+
+ // Yeah, we were in an <include> Restore state and proceed.
fclose(surf_file_to_parse);
xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
surf_parse_pop_buffer_state();
- xbt_dynar_pop(surf_input_buffer_stack,surf_input_buffer);
- return 0;
+ xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
+
+ // Restore the filename for error messages
+ free(surf_parsed_filename);
+ xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
+
+ return 1;
}
xbt_dynar_new(sizeof(void_f_void_t), NULL);
ETag_surfxml_bypassRoute_cb_list =
xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_bypassASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_bypassASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
STag_surfxml_peer_cb_list =
xbt_dynar_new(sizeof(void_f_void_t), NULL);
ETag_surfxml_peer_cb_list =
xbt_dynar_new(sizeof(void_f_void_t), NULL);
ETag_surfxml_include_cb_list =
xbt_dynar_new(sizeof(void_f_void_t), NULL);
+
+ STag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
}
void surf_parse_reset_callbacks(void)
xbt_dynar_free(&ETag_surfxml_ASroute_cb_list);
xbt_dynar_free(&STag_surfxml_bypassRoute_cb_list);
xbt_dynar_free(&ETag_surfxml_bypassRoute_cb_list);
+ xbt_dynar_free(&STag_surfxml_bypassASroute_cb_list);
+ xbt_dynar_free(&ETag_surfxml_bypassASroute_cb_list);
xbt_dynar_free(&STag_surfxml_peer_cb_list);
xbt_dynar_free(&ETag_surfxml_peer_cb_list);
xbt_dynar_free(&STag_surfxml_include_cb_list);
xbt_dynar_free(&ETag_surfxml_include_cb_list);
+
+ xbt_dynar_free(&STag_surfxml_storage_cb_list);
+ xbt_dynar_free(&ETag_surfxml_storage_cb_list);
+ xbt_dynar_free(&STag_surfxml_mstorage_cb_list);
+ xbt_dynar_free(&ETag_surfxml_mstorage_cb_list);
+ xbt_dynar_free(&STag_surfxml_mount_cb_list);
+ xbt_dynar_free(&ETag_surfxml_mount_cb_list);
+ xbt_dynar_free(&STag_surfxml_storage_type_cb_list);
+ xbt_dynar_free(&ETag_surfxml_storage_type_cb_list);
}
/* Stag and Etag parse functions */
}
void STag_surfxml_host(void){
- s_sg_platf_host_cbarg_t host;
- memset(&host,0,sizeof(host));
-
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- host.properties = current_property_set = xbt_dict_new();
-
- host.id = A_surfxml_host_id;
- host.power_peak = get_cpu_power(A_surfxml_host_power);
- host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
- host.core_amount = surf_parse_get_int(A_surfxml_host_core);
- host.power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
- host.state_trace = tmgr_trace_new(A_surfxml_host_state_file);
- xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
- (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
- if (A_surfxml_host_state == A_surfxml_host_state_ON)
- host.initial_state = SURF_RESOURCE_ON;
- if (A_surfxml_host_state == A_surfxml_host_state_OFF)
- host.initial_state = SURF_RESOURCE_OFF;
- host.coord = A_surfxml_host_coordinates;
-
- sg_platf_new_host(&host);
}
+
void ETag_surfxml_host(void) {
+ s_sg_platf_host_cbarg_t host;
+ memset(&host,0,sizeof(host));
+
+ host.properties = current_property_set;
+
+ host.id = A_surfxml_host_id;
+ host.power_peak = get_cpu_power(A_surfxml_host_power);
+ host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
+ host.core_amount = surf_parse_get_int(A_surfxml_host_core);
+ host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
+ host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
+ xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
+ (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
+ if (A_surfxml_host_state == A_surfxml_host_state_ON)
+ host.initial_state = SURF_RESOURCE_ON;
+ if (A_surfxml_host_state == A_surfxml_host_state_OFF)
+ host.initial_state = SURF_RESOURCE_OFF;
+ host.coord = A_surfxml_host_coordinates;
+
+ sg_platf_new_host(&host);
current_property_set = NULL;
}
cluster.sharing_policy = SURF_LINK_FATPIPE;
break;
default:
- surf_parse_error(bprintf
- ("Invalid cluster sharing policy for cluster %s",
- cluster.id));
+ surf_parse_error("Invalid cluster sharing policy for cluster %s",
+ cluster.id);
break;
}
switch (AX_surfxml_cluster_bb_sharing_policy) {
cluster.bb_sharing_policy = SURF_LINK_SHARED;
break;
default:
- surf_parse_error(bprintf
- ("Invalid bb sharing policy in cluster %s",
- cluster.id));
+ surf_parse_error("Invalid bb sharing policy in cluster %s",
+ cluster.id);
break;
}
peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
peer.coord = A_surfxml_peer_coordinates;
- peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
- peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
+ peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
+ peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
sg_platf_new_peer(&peer);
/* nothing to do here */
}
void STag_surfxml_link(void){
- s_sg_platf_link_cbarg_t link;
- memset(&link,0,sizeof(link));
-
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- link.properties = current_property_set = xbt_dict_new();
-
- link.id = A_surfxml_link_id;
- link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
- link.bandwidth_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
- link.latency = surf_parse_get_double(A_surfxml_link_latency);
- link.latency_trace = tmgr_trace_new(A_surfxml_link_latency_file);
-
- switch (A_surfxml_link_state) {
- case A_surfxml_link_state_ON:
- link.state = SURF_RESOURCE_ON;
- break;
- case A_surfxml_link_state_OFF:
- link.state = SURF_RESOURCE_OFF;
- break;
- default:
- surf_parse_error(bprintf("invalid state for link %s",link.id));
- }
- link.state_trace = tmgr_trace_new(A_surfxml_link_state_file);
-
- switch (A_surfxml_link_sharing_policy) {
- case A_surfxml_link_sharing_policy_SHARED:
- link.policy = SURF_LINK_SHARED;
- break;
- case A_surfxml_link_sharing_policy_FATPIPE:
- link.policy = SURF_LINK_FATPIPE;
- break;
- case A_surfxml_link_sharing_policy_FULLDUPLEX:
- link.policy = SURF_LINK_FULLDUPLEX;
- break;
- default:
- surf_parse_error(bprintf("Invalid sharing policy in link %s",link.id));
- }
-
- sg_platf_new_link(&link);
}
void ETag_surfxml_link(void){
+ s_sg_platf_link_cbarg_t link;
+ memset(&link,0,sizeof(link));
+
+ link.properties = current_property_set;
+
+ link.id = A_surfxml_link_id;
+ link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
+ link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
+ link.latency = surf_parse_get_double(A_surfxml_link_latency);
+ link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
+
+ switch (A_surfxml_link_state) {
+ case A_surfxml_link_state_ON:
+ link.state = SURF_RESOURCE_ON;
+ break;
+ case A_surfxml_link_state_OFF:
+ link.state = SURF_RESOURCE_OFF;
+ break;
+ default:
+ surf_parse_error("invalid state for link %s", link.id);
+ break;
+ }
+ link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
+
+ switch (A_surfxml_link_sharing_policy) {
+ case A_surfxml_link_sharing_policy_SHARED:
+ link.policy = SURF_LINK_SHARED;
+ break;
+ case A_surfxml_link_sharing_policy_FATPIPE:
+ link.policy = SURF_LINK_FATPIPE;
+ break;
+ case A_surfxml_link_sharing_policy_FULLDUPLEX:
+ link.policy = SURF_LINK_FULLDUPLEX;
+ break;
+ default:
+ surf_parse_error("Invalid sharing policy in link %s", link.id);
+ break;
+ }
+
+ sg_platf_new_link(&link);
+
current_property_set = NULL;
}
void STag_surfxml_bypassRoute(void){
surfxml_call_cb_functions(STag_surfxml_bypassRoute_cb_list);
}
+void STag_surfxml_bypassASroute(void){
+ surfxml_call_cb_functions(STag_surfxml_bypassASroute_cb_list);
+}
void STag_surfxml_config(void){
XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- current_property_set = xbt_dict_new();
-
}
void ETag_surfxml_config(void){
xbt_dict_cursor_t cursor = NULL;
#define parse_method(type,name) \
void type##Tag_surfxml_##name(void) \
{ surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
-parse_method(E, route);
-parse_method(E, link_ctn);
-parse_method(E, process);
-parse_method(E, argument);
-parse_method(E, prop);
-parse_method(E, trace);
-parse_method(E, trace_connect);
-parse_method(E, random);
-parse_method(E, ASroute);
-parse_method(E, bypassRoute);
+parse_method(E, route)
+parse_method(E, link_ctn)
+parse_method(E, process)
+parse_method(E, argument)
+parse_method(E, prop)
+parse_method(E, trace)
+parse_method(E, trace_connect)
+parse_method(E, random)
+parse_method(E, ASroute)
+parse_method(E, bypassRoute)
+parse_method(E, bypassASroute)
/* Open and Close parse file */
if (!surf_file_to_parse_stack)
surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
+ if (!surf_parsed_filename_stack)
+ surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
+ surf_parsed_filename = xbt_strdup(file);
+
surf_file_to_parse = surf_fopen(file, "r");
xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
{
xbt_dynar_free(&surf_input_buffer_stack);
xbt_dynar_free(&surf_file_to_parse_stack);
+ xbt_dynar_free(&surf_parsed_filename_stack);
+
+ free(surf_parsed_filename);
if (surf_file_to_parse) {
surf_parse__delete_buffer(surf_input_buffer);
/* Prop tag functions */
-void parse_properties(const char* prop_id, const char* prop_value)
-{
- if (!current_property_set)
- current_property_set = xbt_dict_new(); // Maybe, it should raise an error
- xbt_dict_set(current_property_set, prop_id, xbt_strdup(prop_value), free);
-}
-
/**
* With XML parser
*/
-void parse_properties_XML(void)
+void parse_properties(void)
{
- parse_properties(A_surfxml_prop_id, A_surfxml_prop_value);
+ if (!current_property_set)
+ current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
+
+ xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
}
return power_scale;
}
-double random_min, random_max, random_mean, random_std_deviation,
- random_generator;
+double random_min, random_max, random_mean, random_std_deviation;
+e_random_generator_t random_generator;
char *random_id;
static void init_randomness(void)
random_max = surf_parse_get_double(A_surfxml_random_max);
random_mean = surf_parse_get_double(A_surfxml_random_mean);
random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
- random_generator = A_surfxml_random_generator;
+ switch (A_surfxml_random_generator) {
+ case AU_surfxml_random_generator:
+ case A_surfxml_random_generator_NONE:
+ random_generator = NONE;
+ break;
+ case A_surfxml_random_generator_DRAND48:
+ random_generator = DRAND48;
+ break;
+ case A_surfxml_random_generator_RAND:
+ random_generator = RAND;
+ break;
+ case A_surfxml_random_generator_RNGSTREAM:
+ random_generator = RNGSTREAM;
+ break;
+ default:
+ surf_parse_error("Invalid random generator");
+ break;
+ }
}
static void add_randomness(void)