X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7711e3434875abc7fba905333f93ef83e5e77a59..1195bd43519f612d47fe67f7511dd5d9433ec577:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 46faca1914..0187aa5180 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -8,7 +8,7 @@ #include "xbt/log.h" #include "xbt/str.h" #include "xbt/dict.h" -#include "surf/surfxml_parse_private.h" +#include "surf/surfxml_parse.h" #include "surf/surf_private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, @@ -58,8 +58,6 @@ xbt_dynar_t STag_surfxml_argument_cb_list = NULL; xbt_dynar_t ETag_surfxml_argument_cb_list = NULL; xbt_dynar_t STag_surfxml_prop_cb_list = NULL; xbt_dynar_t ETag_surfxml_prop_cb_list = NULL; -xbt_dynar_t STag_surfxml_cluster_cb_list = NULL; -xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL; xbt_dynar_t STag_surfxml_peer_cb_list = NULL; xbt_dynar_t ETag_surfxml_peer_cb_list = NULL; xbt_dynar_t STag_surfxml_trace_cb_list = NULL; @@ -130,7 +128,7 @@ int ETag_surfxml_include_state(void) { fflush(NULL); XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file); - if(xbt_dynar_length(surf_input_buffer_stack)!= 0) + if(!xbt_dynar_is_empty(surf_input_buffer_stack)) return 1; fclose(surf_file_to_parse); xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse); @@ -176,10 +174,6 @@ void surf_parse_init_callbacks(void) 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_cluster_cb_list = - xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_cluster_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 = @@ -220,8 +214,6 @@ void surf_parse_free_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_cluster_cb_list); - xbt_dynar_free(&ETag_surfxml_cluster_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); @@ -254,36 +246,37 @@ void STag_surfxml_platform(void) { "This program is installed automatically with SimGrid, or " "available in the tools/ directory of the source archive."); - sg_platf_open(); + sg_platf_begin(); } void ETag_surfxml_platform(void){ - sg_platf_close(); + sg_platf_end(); } 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(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); current_property_set = NULL; } @@ -298,32 +291,58 @@ void STag_surfxml_router(void){ } void STag_surfxml_cluster(void){ - struct_cluster = xbt_new0(s_surf_parsing_cluster_arg_t, 1); - struct_cluster->id = A_surfxml_cluster_id; - struct_cluster->prefix = A_surfxml_cluster_prefix; - struct_cluster->suffix = A_surfxml_cluster_suffix; - struct_cluster->radical = A_surfxml_cluster_radical; - struct_cluster->power= surf_parse_get_double(A_surfxml_cluster_power); - struct_cluster->core_amount = surf_parse_get_int(A_surfxml_cluster_core); - struct_cluster->bw = surf_parse_get_double(A_surfxml_cluster_bw); - struct_cluster->lat = surf_parse_get_double(A_surfxml_cluster_lat); + s_sg_platf_cluster_cbarg_t cluster; + memset(&cluster,0,sizeof(cluster)); + cluster.id = A_surfxml_cluster_id; + cluster.prefix = A_surfxml_cluster_prefix; + cluster.suffix = A_surfxml_cluster_suffix; + cluster.radical = A_surfxml_cluster_radical; + cluster.power= surf_parse_get_double(A_surfxml_cluster_power); + cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core); + cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw); + cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat); if(strcmp(A_surfxml_cluster_bb_bw,"")) - struct_cluster->bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw); + cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw); if(strcmp(A_surfxml_cluster_bb_lat,"")) - struct_cluster->bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat); - struct_cluster->router_id = A_surfxml_cluster_router_id; - - struct_cluster->sharing_policy = AX_surfxml_cluster_sharing_policy; - struct_cluster->bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy; - - struct_cluster->availability_trace = A_surfxml_cluster_availability_file; - struct_cluster->state_trace = A_surfxml_cluster_state_file; + cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat); + cluster.router_id = A_surfxml_cluster_router_id; + + switch (AX_surfxml_cluster_sharing_policy) { + case A_surfxml_cluster_sharing_policy_SHARED: + cluster.sharing_policy = SURF_LINK_SHARED; + break; + case A_surfxml_cluster_sharing_policy_FULLDUPLEX: + cluster.sharing_policy = SURF_LINK_FULLDUPLEX; + break; + case A_surfxml_cluster_sharing_policy_FATPIPE: + cluster.sharing_policy = SURF_LINK_FATPIPE; + break; + default: + surf_parse_error(bprintf + ("Invalid cluster sharing policy for cluster %s", + cluster.id)); + break; + } + switch (AX_surfxml_cluster_bb_sharing_policy) { + case A_surfxml_cluster_bb_sharing_policy_FATPIPE: + cluster.bb_sharing_policy = SURF_LINK_FATPIPE; + break; + case A_surfxml_cluster_bb_sharing_policy_SHARED: + cluster.bb_sharing_policy = SURF_LINK_SHARED; + break; + default: + surf_parse_error(bprintf + ("Invalid bb sharing policy in cluster %s", + cluster.id)); + break; + } - surfxml_call_cb_functions(STag_surfxml_cluster_cb_list); + cluster.availability_trace = A_surfxml_cluster_availability_file; + cluster.state_trace = A_surfxml_cluster_state_file; + sg_platf_new_cluster(&cluster); } void ETag_surfxml_cluster(void){ - surfxml_call_cb_functions(ETag_surfxml_cluster_cb_list); - xbt_free(struct_cluster); + /* nothing I can think of */ } void STag_surfxml_peer(void){ @@ -345,47 +364,50 @@ void ETag_surfxml_peer(void){ /* 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(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)); + break; + } + 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)); + break; + } + + sg_platf_new_link(&link); + current_property_set = NULL; } @@ -411,10 +433,10 @@ void STag_surfxml_trace_connect(void){ surfxml_call_cb_functions(STag_surfxml_trace_connect_cb_list); } void STag_surfxml_AS(void){ - sg_platf_new_AS_open(A_surfxml_AS_id,A_surfxml_AS_routing); + sg_platf_new_AS_begin(A_surfxml_AS_id,A_surfxml_AS_routing); } void ETag_surfxml_AS(void){ - sg_platf_new_AS_close(); + sg_platf_new_AS_end(); } void STag_surfxml_ASroute(void){ surfxml_call_cb_functions(STag_surfxml_ASroute_cb_list); @@ -425,8 +447,6 @@ void STag_surfxml_bypassRoute(void){ 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; @@ -541,38 +561,22 @@ static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list) unsigned int iterator; void_f_void_t fun; xbt_dynar_foreach(cb_list, iterator, fun) { - if (fun) (*fun) (); + if (fun) fun(); } } /* 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 - if(!strcmp(prop_id,"coordinates")){ - if(!strcmp(prop_value,"yes") && !COORD_HOST_LEVEL) - { - XBT_INFO("Configuration change: Set '%s' to '%s'", prop_id, prop_value); - COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp); - COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp); - } - if(strcmp(A_surfxml_prop_value,"yes")) - xbt_die("Setting XML prop coordinates must be \"yes\""); - } - else{ - 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); }