1 /* Copyright (c) 2009, 2010, 2011. 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. */
6 #include "surf_routing_private.h"
9 extern routing_global_t global_routing;
10 extern routing_component_t current_routing;
11 extern model_type_t current_routing_model;
12 extern xbt_dynar_t link_list;
13 extern xbt_dict_t cluster_host_link;
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
17 /* Routing model structure */
20 s_routing_component_t generic_routing;
21 xbt_dict_t dict_processing_units;
22 xbt_dict_t dict_autonomous_systems;
23 } s_routing_component_cluster_t, *routing_component_cluster_t;
25 /* Parse routing model functions */
27 static void model_cluster_set_processing_unit(routing_component_t rc,
30 routing_component_cluster_t routing =
31 (routing_component_cluster_t) rc;
32 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
35 static void model_cluster_set_autonomous_system(routing_component_t rc,
38 routing_component_cluster_t routing =
39 (routing_component_cluster_t) rc;
40 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
44 static void model_cluster_set_bypassroute(routing_component_t rc,
47 route_extended_t e_route)
49 xbt_die("bypass routing not supported for Route-Based model");
52 static void model_cluster_set_route(routing_component_t rc,
53 const char *src, const char *dst,
54 name_route_extended_t route)
56 xbt_die("routing not supported for Route-Based model");
59 static void model_cluster_set_ASroute(routing_component_t rc,
60 const char *src, const char *dst,
61 name_route_extended_t route)
63 xbt_die("AS routing not supported for Route-Based model");
66 #define BUFFER_SIZE 4096 /* result buffer size */
67 #define OVECCOUNT 30 /* should be a multiple of 3 */
69 static route_extended_t cluster_get_route(routing_component_t rc,
72 static xbt_dynar_t cluster_get_onelink_routes(routing_component_t rc)
74 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
76 //We have already bypass cluster routes with network NS3
77 if(!strcmp(surf_network_model->name,"network NS3"))
80 routing_component_cluster_t routing = (routing_component_cluster_t)rc;
82 xbt_dict_cursor_t c1 = NULL;
87 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
88 if (rc->get_network_element_type(k1) == SURF_NETWORK_ELEMENT_ROUTER){
94 xbt_die ("cluster_get_onelink_routes works only if the AS is a cluster, sorry.");
97 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
98 route_extended_t route = cluster_get_route (rc, router, k1);
100 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
102 if(number_of_links == 1) {
106 if (number_of_links != 2) {
107 xbt_die ("cluster_get_onelink_routes works only if the AS is a cluster, sorry.");
111 xbt_dynar_get_cpy (route->generic_route.link_list, 1, &link_ptr);
112 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
113 onelink->src = xbt_strdup (k1);
114 onelink->dst = xbt_strdup (router);
115 onelink->link_ptr = link_ptr;
116 xbt_dynar_push (ret, &onelink);
122 /* Business methods */
123 static route_extended_t cluster_get_route(routing_component_t rc,
129 "Invalid params for \"get_route\" function at AS \"%s\"",
133 xbt_dynar_t links_list =
134 xbt_dynar_new(global_routing->size_of_link, NULL);
136 char *cluster_is_fd = xbt_dict_get_or_null(cluster_host_link,rc->name);
137 char *link_src,*link_bb,*link_dst,*link_src_up,*link_dst_down;
139 if(!cluster_is_fd){ // NOT FULLDUPLEX
140 link_src = xbt_dict_get_or_null(cluster_host_link,src);
141 if( !link_src && (global_routing->get_network_element_type(src) != SURF_NETWORK_ELEMENT_ROUTER) )
142 xbt_die("No link for '%s' found!",src);
143 if(link_src) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_src, SURF_LINK_LEVEL)); //link_up
145 link_bb = bprintf("%s_backbone",rc->name);
146 xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_bb, SURF_LINK_LEVEL)); //link_bb
149 link_dst = xbt_dict_get_or_null(cluster_host_link,dst);
150 if( !link_dst && (global_routing->get_network_element_type(dst) != SURF_NETWORK_ELEMENT_ROUTER) )
151 xbt_die("No link for '%s' found!",dst);
152 if(link_dst) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_dst, SURF_LINK_LEVEL)); //link_down
156 link_src = xbt_dict_get_or_null(cluster_host_link,src);
157 if( !link_src && (global_routing->get_network_element_type(src) != SURF_NETWORK_ELEMENT_ROUTER) )
158 xbt_die("No link for '%s' found!",src);
159 link_src_up = bprintf("%s_UP",link_src);
160 if(link_src) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_src_up, SURF_LINK_LEVEL)); //link_up
163 link_bb = bprintf("%s_backbone",rc->name);
164 if(link_bb) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_bb, SURF_LINK_LEVEL)); //link_bb
167 link_dst = xbt_dict_get_or_null(cluster_host_link,dst);
168 if(!link_dst && (global_routing->get_network_element_type(dst) != SURF_NETWORK_ELEMENT_ROUTER))
169 xbt_die("No link for '%s' found!",dst);
170 link_dst_down = bprintf("%s_DOWN",link_dst);
171 if(link_dst) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_dst_down, SURF_LINK_LEVEL)); //link_down
175 route_extended_t new_e_route = NULL;
176 new_e_route = xbt_new0(s_route_extended_t, 1);
177 new_e_route->generic_route.link_list = links_list;
182 static route_extended_t cluster_get_bypass_route(routing_component_t rc,
189 static void cluster_finalize(routing_component_t rc)
191 routing_component_cluster_t routing =
192 (routing_component_cluster_t) rc;
194 xbt_dict_free(&routing->dict_processing_units);
195 xbt_dict_free(&routing->dict_autonomous_systems);
196 /* Delete structure */
201 /* Creation routing model functions */
202 void *model_cluster_create(void)
204 routing_component_cluster_t new_component =
205 xbt_new0(s_routing_component_cluster_t, 1);
206 new_component->generic_routing.set_processing_unit =
207 model_cluster_set_processing_unit;
208 new_component->generic_routing.set_autonomous_system =
209 model_cluster_set_autonomous_system;
210 new_component->generic_routing.set_route = model_cluster_set_route;
211 new_component->generic_routing.set_ASroute = model_cluster_set_ASroute;
212 new_component->generic_routing.set_bypassroute = model_cluster_set_bypassroute;
213 new_component->generic_routing.get_onelink_routes = cluster_get_onelink_routes;
214 new_component->generic_routing.get_route = cluster_get_route;
215 new_component->generic_routing.get_latency = generic_get_link_latency;
216 new_component->generic_routing.get_bypass_route = cluster_get_bypass_route;
217 new_component->generic_routing.finalize = cluster_finalize;
218 new_component->generic_routing.get_network_element_type = get_network_element_type;
219 /* initialization of internal structures */
220 new_component->dict_processing_units = xbt_dict_new();
221 new_component->dict_autonomous_systems = xbt_dict_new();
223 return new_component;
226 void model_cluster_load(void)
228 /* use "surfxml_add_callback" to add a parse function call */
231 void model_cluster_unload(void)
233 /* use "surfxml_del_callback" to remove a parse function call */
236 void model_cluster_end(void)