+/* ************************************************************************** */
+/* ************************* GENERIC AUX FUNCTIONS ************************** */
+
+static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order) {
+
+ char *link_name;
+ route_extended_t e_route, new_e_route;
+ route_t route;
+ unsigned int cpt;
+ xbt_dynar_t links, links_id;
+
+ new_e_route = xbt_new0(s_route_extended_t,1);
+ new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
+ new_e_route->src_gateway = NULL;
+ new_e_route->dst_gateway = NULL;
+
+ xbt_assert0(hierarchy == SURF_ROUTING_BASE || hierarchy == SURF_ROUTING_RECURSIVE,
+ "the hierarchy type is not defined");
+
+ if(hierarchy == SURF_ROUTING_BASE ) {
+
+ route = (route_t)data;
+ links = route->link_list;
+
+ } else if(hierarchy == SURF_ROUTING_RECURSIVE ) {
+
+ e_route = (route_extended_t)data;
+ xbt_assert0(e_route->src_gateway&&e_route->dst_gateway,"bad gateway, is null");
+ links = e_route->generic_route.link_list;
+
+ /* remeber not erase the gateway names */
+ new_e_route->src_gateway = e_route->src_gateway;
+ new_e_route->dst_gateway = e_route->dst_gateway;
+ }
+
+ links_id = new_e_route->generic_route.link_list;
+
+ xbt_dynar_foreach(links, cpt, link_name) {
+
+ void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
+ if (link)
+ {
+ if( order )
+ xbt_dynar_push(links_id,&link);
+ else
+ xbt_dynar_unshift(links_id,&link);
+ }
+ else
+ THROW1(mismatch_error,0,"Link %s not found", link_name);
+ }
+
+ return new_e_route;
+}
+
+static void generic_free_route(route_t route) {
+ if(route) {
+ xbt_dynar_free(&(route->link_list));
+ xbt_free(route);
+ }
+}
+
+static void generic_free_extended_route(route_extended_t e_route) {
+ if(e_route) {
+ xbt_dynar_free(&(e_route->generic_route.link_list));
+ if(e_route->src_gateway) xbt_free(e_route->src_gateway);
+ if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
+ xbt_free(e_route);
+ }
+}
+
+static routing_component_t generic_as_exist(routing_component_t find_from, routing_component_t to_find) {
+ //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
+ xbt_dict_cursor_t cursor = NULL;
+ char *key;
+ int found=0;
+ routing_component_t elem;
+ xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
+ if( to_find == elem || generic_as_exist(elem,to_find) ){
+ found=1;
+ break;
+ }
+ }
+ if(found) return to_find;
+ return NULL;
+}
+
+static routing_component_t generic_autonomous_system_exist(routing_component_t rc, char* element) {
+ //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
+ routing_component_t element_as, result, elem;
+ xbt_dict_cursor_t cursor = NULL;
+ char *key;
+ element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
+ result = ((routing_component_t)-1);
+ if(element_as!=rc)
+ result = generic_as_exist(rc,element_as);
+
+ int found=0;
+ if(result)
+ {
+ xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
+ found = !strcmp(elem->name,element);
+ if( found ) break;
+ }
+ if( found ) return element_as;
+ }
+ return NULL;
+}
+
+static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element) {
+ routing_component_t element_as;
+ element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
+ if(element_as==rc) return element_as;
+ return generic_as_exist(rc,element_as);
+}
+
+static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst) {
+
+ routing_component_t src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
+ routing_component_t dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
+
+ xbt_assert3(src_as != NULL && dst_as != NULL,
+ "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",src,dst,rc->name);
+ xbt_assert4(src_as == dst_as,
+ "The src(%s in %s) and dst(%s in %s) are in differents AS",src,src_as->name,dst,dst_as->name);
+ xbt_assert2(rc == dst_as,
+ "The routing component of src and dst is not the same as the network elements belong (%s==%s)",rc->name,dst_as->name);
+}
+
+static void routing_full_parse_Scluster(void)
+{
+
+ char *cluster_id = A_surfxml_cluster_id;
+ char *cluster_prefix = A_surfxml_cluster_prefix;
+ char *cluster_suffix = A_surfxml_cluster_suffix;
+ char *cluster_radical = A_surfxml_cluster_radical;
+ char *cluster_power = A_surfxml_cluster_power;
+ char *cluster_bw = A_surfxml_cluster_bw;
+ char *cluster_lat = A_surfxml_cluster_lat;
+ char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
+ char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
+ char *host_id, *groups, *link_id;
+ char *router_id, *link_router, *link_backbone, *route_src_dst;
+ unsigned int iter;
+ int start, end, i;
+ xbt_dynar_t radical_elements;
+ xbt_dynar_t radical_ends;
+ static int AX_ptr = 0;
+ static int surfxml_bufferstack_size = 2048;
+
+ /* allocating memory for the buffer, I think 2kB should be enough */
+ surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
+
+// DEBUG4("id='%s' prefix='%s' suffix='%s' radical='%s'",
+// cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
+// DEBUG5("power='%s' bw='%s' lat='%s' bb_bw='%s' bb_lat='%s'",
+// cluster_power,cluster_bw,cluster_lat,cluster_bb_bw,cluster_bb_lat);
+
+ DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
+ SURFXML_BUFFER_SET(AS_id, cluster_id);
+ SURFXML_BUFFER_SET(AS_routing, "RuleBased");
+ SURFXML_START_TAG(AS);
+
+ radical_elements = xbt_str_split(cluster_radical, ",");
+ xbt_dynar_foreach(radical_elements, iter, groups)
+ {
+ radical_ends = xbt_str_split(groups, "-");
+ switch (xbt_dynar_length(radical_ends))
+ {
+ case 1:
+ surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
+ host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
+ link_id = bprintf("%s_link_%d", cluster_id, start);
+
+ DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(host_id, host_id);
+ SURFXML_BUFFER_SET(host_power, cluster_power);
+ SURFXML_BUFFER_SET(host_availability, "1.0");
+ SURFXML_BUFFER_SET(host_availability_file, "");
+ A_surfxml_host_state = A_surfxml_host_state_ON;
+ SURFXML_BUFFER_SET(host_state_file, "");
+ SURFXML_BUFFER_SET(host_interference_send, "1.0");
+ SURFXML_BUFFER_SET(host_interference_recv, "1.0");
+ SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
+ SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
+ SURFXML_START_TAG(host);
+ SURFXML_END_TAG(host);
+
+ DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_id, link_id);
+ SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
+ SURFXML_BUFFER_SET(link_latency, cluster_lat);
+ SURFXML_BUFFER_SET(link_bandwidth_file, "");
+ SURFXML_BUFFER_SET(link_latency_file, "");
+ A_surfxml_link_state = A_surfxml_link_state_ON;
+ SURFXML_BUFFER_SET(link_state_file, "");
+ A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+ SURFXML_START_TAG(link);
+ SURFXML_END_TAG(link);
+
+ break;
+
+ case 2:
+
+ surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
+ surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
+ for (i = start; i <= end; i++)
+ {
+ host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
+ link_id = bprintf("%s_link_%d", cluster_id, i);
+
+ DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(host_id, host_id);
+ SURFXML_BUFFER_SET(host_power, cluster_power);
+ SURFXML_BUFFER_SET(host_availability, "1.0");
+ SURFXML_BUFFER_SET(host_availability_file, "");
+ A_surfxml_host_state = A_surfxml_host_state_ON;
+ SURFXML_BUFFER_SET(host_state_file, "");
+ SURFXML_BUFFER_SET(host_interference_send, "1.0");
+ SURFXML_BUFFER_SET(host_interference_recv, "1.0");
+ SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
+ SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
+ SURFXML_START_TAG(host);
+ SURFXML_END_TAG(host);
+
+ DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_id, link_id);
+ SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
+ SURFXML_BUFFER_SET(link_latency, cluster_lat);
+ SURFXML_BUFFER_SET(link_bandwidth_file, "");
+ SURFXML_BUFFER_SET(link_latency_file, "");
+ A_surfxml_link_state = A_surfxml_link_state_ON;
+ SURFXML_BUFFER_SET(link_state_file, "");
+ A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+ SURFXML_START_TAG(link);
+ SURFXML_END_TAG(link);
+ }
+ break;
+
+ default:
+ DEBUG0("Malformed radical");
+ }
+
+ xbt_dynar_free(&radical_ends);
+ }
+
+ DEBUG0(" ");
+ router_id = bprintf("%srouter%s",cluster_prefix,cluster_suffix);
+ link_router = bprintf("%s_link_router",cluster_id);
+ link_backbone = bprintf("%s_backbone",cluster_id);
+
+ DEBUG1("<router id=\"%s\"\">",router_id);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(router_id, router_id);;
+ SURFXML_START_TAG(router);
+ SURFXML_END_TAG(router);
+
+ DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_router,cluster_bw,cluster_lat);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_id, link_router);
+ SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
+ SURFXML_BUFFER_SET(link_latency, cluster_lat);
+ SURFXML_BUFFER_SET(link_bandwidth_file, "");
+ SURFXML_BUFFER_SET(link_latency_file, "");
+ A_surfxml_link_state = A_surfxml_link_state_ON;
+ SURFXML_BUFFER_SET(link_state_file, "");
+ A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+ SURFXML_START_TAG(link);
+ SURFXML_END_TAG(link);
+
+ DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_backbone,cluster_bb_bw,cluster_bb_lat);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_id, link_backbone);
+ SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
+ SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
+ SURFXML_BUFFER_SET(link_bandwidth_file, "");
+ SURFXML_BUFFER_SET(link_latency_file, "");
+ A_surfxml_link_state = A_surfxml_link_state_ON;
+ SURFXML_BUFFER_SET(link_state_file, "");
+ A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+ SURFXML_START_TAG(link);
+ SURFXML_END_TAG(link);
+
+ char *new_suffix = bprintf("%s","");
+
+ radical_elements = xbt_str_split(cluster_suffix, ".");
+ xbt_dynar_foreach(radical_elements, iter, groups)
+ {
+ if(strcmp(groups,""))
+ {
+ new_suffix = bprintf("%s\\.%s",new_suffix,groups);
+ }
+ }
+ route_src_dst = bprintf("%s(.*)%s",cluster_prefix,new_suffix);
+
+ DEBUG0(" ");
+
+ DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(route_src, route_src_dst);
+ SURFXML_BUFFER_SET(route_dst, route_src_dst);
+ SURFXML_START_TAG(route);
+
+ DEBUG1("<link:ctn\tid=\"%s_link_$1src\"/>",cluster_id);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1src",cluster_id));
+ SURFXML_START_TAG(link_c_ctn);
+ SURFXML_END_TAG(link_c_ctn);
+
+ DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_backbone",cluster_id));
+ SURFXML_START_TAG(link_c_ctn);
+ SURFXML_END_TAG(link_c_ctn);
+
+ DEBUG1("<link:ctn\tid=\"%s_link_$1dst\"/>",cluster_id);
+ SURFXML_BUFFER_RESET();
+ SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1dst",cluster_id));
+ SURFXML_START_TAG(link_c_ctn);
+ SURFXML_END_TAG(link_c_ctn);
+
+ DEBUG0("</route>");
+ SURFXML_END_TAG(route);