1 #include "surf_routing_private.h"
2 #include "surf_routing_full.hpp"
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
10 extern routing_platf_t routing_platf;
11 extern int surf_parse_lineno;
13 #define TO_ROUTE_FULL(i,j) p_routingTable[(i)+(j)*table_size]
15 AS_t model_full_create(void)
20 void model_full_end(AS_t _routing)
23 sg_platf_route_cbarg_t e_route;
26 AsFullPtr routing = ((AsFullPtr) _routing);
27 size_t table_size = xbt_dynar_length(routing->p_indexNetworkElm);
29 /* Create table if necessary */
30 if (!routing->p_routingTable)
31 routing->p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
33 /* Add the loopback if needed */
34 if (routing_platf->p_loopback && routing->p_hierarchy == SURF_ROUTING_BASE) {
35 for (i = 0; i < table_size; i++) {
36 e_route = routing->TO_ROUTE_FULL(i, i);
38 e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
39 e_route->gw_src = NULL;
40 e_route->gw_dst = NULL;
41 e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
42 xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback);
43 routing->TO_ROUTE_FULL(i, i) = e_route;
53 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
55 /* Delete routing table */
56 for (i = 0; i < table_size; i++)
57 for (j = 0; j < table_size; j++)
58 delete TO_ROUTE_FULL(i,j);
59 xbt_free(p_routingTable);
62 xbt_dynar_t AsFull::getOneLinkRoutes()
64 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
67 int table_size = xbt_dynar_length(p_indexNetworkElm);
69 for(src=0; src < table_size; src++) {
70 for(dst=0; dst< table_size; dst++) {
71 sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src,dst);
73 if (xbt_dynar_length(route->link_list) == 1) {
74 void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
75 onelink_t onelink = xbt_new0(s_onelink_t, 1);
76 onelink->link_ptr = link;
77 if (p_hierarchy == SURF_ROUTING_BASE) {
78 onelink->src = xbt_dynar_get_as(p_indexNetworkElm, src, sg_routing_edge_t);
79 onelink->src->m_id = src;
80 onelink->dst = xbt_dynar_get_as(p_indexNetworkElm, dst, sg_routing_edge_t);
81 onelink->dst->m_id = dst;
82 } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
83 onelink->src = route->gw_src;
84 onelink->dst = route->gw_dst;
86 xbt_dynar_push(ret, &onelink);
87 XBT_DEBUG("Push route from '%d' to '%d'",
97 void AsFull::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t res, double *lat)
99 XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]",
106 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
108 sg_platf_route_cbarg_t e_route = NULL;
109 NetworkCm02LinkPtr link;
110 unsigned int cpt = 0;
112 e_route = TO_ROUTE_FULL(src->m_id, dst->m_id);
115 res->gw_src = e_route->gw_src;
116 res->gw_dst = e_route->gw_dst;
117 xbt_dynar_foreach(e_route->link_list, cpt, link) {
118 xbt_dynar_push(res->link_list, &link);
120 *lat += link->getLatency();
125 void AsFull::parseASroute(sg_platf_route_cbarg_t route){
129 static int full_pointer_resource_cmp(const void *a, const void *b)
134 void AsFull::parseRoute(sg_platf_route_cbarg_t route)
137 char *src = (char*)(route->src);
138 char *dst = (char*)(route->dst);
139 RoutingEdgePtr src_net_elm, dst_net_elm;
140 src_net_elm = sg_routing_edge_by_name_or_null(src);
141 dst_net_elm = sg_routing_edge_by_name_or_null(dst);
143 xbt_assert(src_net_elm, "Network elements %s not found", src);
144 xbt_assert(dst_net_elm, "Network elements %s not found", dst);
146 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
148 xbt_assert(!xbt_dynar_is_empty(route->link_list),
149 "Invalid count of links, must be greater than zero (%s,%s)",
153 p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
155 if (TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)) {
158 xbt_dynar_t link_route_to_test =
159 xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
160 xbt_dynar_foreach(route->link_list, i, link_name) {
161 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
162 xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
163 xbt_dynar_push(link_route_to_test, &link);
165 if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list,
166 link_route_to_test, full_pointer_resource_cmp)) {
167 surf_parse_error("A route between \"%s\" and \"%s\" already exists "
168 "with a different content. "
169 "If you are trying to define a reverse route, "
170 "you must set the symmetrical=no attribute to "
171 "your routes tags.", src, dst);
173 surf_parse_warn("Ignoring the identical redefinition of the route "
174 "between \"%s\" and \"%s\"", src, dst);
177 if (!route->gw_dst && !route->gw_dst)
178 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
180 // FIXME We can call a gw which is down the current AS (cf g5k.xml) but not upper.
181 // AS_t subas = xbt_dict_get_or_null(rc->routing_sons, src);
182 // if (subas == NULL)
183 // surf_parse_error("The source of an ASroute must be a sub-AS "
184 // "declared within the current AS, "
185 // "but '%s' is not an AS within '%s'", src, rc->name);
186 // if (subas->to_index
187 // && xbt_dict_get_or_null(subas->to_index, route->src_gateway) == NULL)
188 // surf_parse_error("In an ASroute, source gateway must be part of "
189 // "the source sub-AS (in particular, being in a "
190 // "sub-sub-AS is not allowed), "
191 // "but '%s' is not in '%s'.",
192 // route->src_gateway, subas->name);
194 // subas = xbt_dict_get_or_null(rc->routing_sons, dst);
195 // if (subas == NULL)
196 // surf_parse_error("The destination of an ASroute must be a sub-AS "
197 // "declared within the current AS, "
198 // "but '%s' is not an AS within '%s'", dst, rc->name);
199 // if (subas->to_index
200 // && xbt_dict_get_or_null(subas->to_index, route->dst_gateway) == NULL)
201 // surf_parse_error("In an ASroute, destination gateway must be "
202 // "part of the destination sub-AS (in particular, "
203 // "in a sub-sub-AS is not allowed), "
204 // "but '%s' is not in '%s'.",
205 // route->dst_gateway, subas->name);
207 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
208 src, route->gw_src->p_name, dst, route->gw_dst->p_name);
209 if (route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL)
210 xbt_die("The dst_gateway '%s' does not exist!", route->gw_dst->p_name);
211 if (route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL)
212 xbt_die("The src_gateway '%s' does not exist!", route->gw_src->p_name);
214 TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 1);
215 xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list, 0);
218 if ( (route->symmetrical == TRUE && as_route == 0)
219 || (route->symmetrical == TRUE && as_route == 1)
221 if (route->gw_dst && route->gw_src) {
222 sg_routing_edge_t gw_tmp;
223 gw_tmp = route->gw_src;
224 route->gw_src = route->gw_dst;
225 route->gw_dst = gw_tmp;
227 if (TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)) {
230 xbt_dynar_t link_route_to_test =
231 xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
232 for (i = xbt_dynar_length(route->link_list); i > 0; i--) {
233 link_name = xbt_dynar_get_as(route->link_list, i - 1, char *);
234 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
235 xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
236 xbt_dynar_push(link_route_to_test, &link);
238 xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list,
240 full_pointer_resource_cmp),
241 "The route between \"%s\" and \"%s\" already exists", src,
244 if (!route->gw_dst && !route->gw_src)
245 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
247 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
248 dst, route->gw_src->p_name, src, route->gw_dst->p_name);
249 TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 0);
250 xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list, 0);
253 xbt_dynar_free(&route->link_list);