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;
54 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
56 /* Delete routing table */
57 for (i = 0; i < table_size; i++)
58 for (j = 0; j < table_size; j++)
59 delete TO_ROUTE_FULL(i,j);
60 xbt_free(p_routingTable);
63 xbt_dynar_t AsFull::getOneLinkRoutes()
65 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
68 int table_size = xbt_dynar_length(p_indexNetworkElm);
70 for(src=0; src < table_size; src++) {
71 for(dst=0; dst< table_size; dst++) {
72 sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src,dst);
74 if (xbt_dynar_length(route->link_list) == 1) {
75 void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
76 onelink_t onelink = xbt_new0(s_onelink_t, 1);
77 onelink->link_ptr = link;
78 if (p_hierarchy == SURF_ROUTING_BASE) {
79 onelink->src = xbt_dynar_get_as(p_indexNetworkElm, src, sg_routing_edge_t);
80 onelink->src->m_id = src;
81 onelink->dst = xbt_dynar_get_as(p_indexNetworkElm, dst, sg_routing_edge_t);
82 onelink->dst->m_id = dst;
83 } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
84 onelink->src = route->gw_src;
85 onelink->dst = route->gw_dst;
87 xbt_dynar_push(ret, &onelink);
88 XBT_DEBUG("Push route from '%d' to '%d'",
98 void AsFull::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t res, double *lat)
100 XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]",
107 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
109 sg_platf_route_cbarg_t e_route = NULL;
111 unsigned int cpt = 0;
113 e_route = TO_ROUTE_FULL(src->m_id, dst->m_id);
116 res->gw_src = e_route->gw_src;
117 res->gw_dst = e_route->gw_dst;
118 xbt_dynar_foreach(e_route->link_list, cpt, link) {
119 xbt_dynar_push(res->link_list, &link);
121 *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
126 void AsFull::parseASroute(sg_platf_route_cbarg_t route){
130 static int full_pointer_resource_cmp(const void *a, const void *b)
135 void AsFull::parseRoute(sg_platf_route_cbarg_t route)
138 char *src = (char*)(route->src);
139 char *dst = (char*)(route->dst);
140 RoutingEdgePtr src_net_elm, dst_net_elm;
141 src_net_elm = sg_routing_edge_by_name_or_null(src);
142 dst_net_elm = sg_routing_edge_by_name_or_null(dst);
144 xbt_assert(src_net_elm, "Network elements %s not found", src);
145 xbt_assert(dst_net_elm, "Network elements %s not found", dst);
147 size_t table_size = xbt_dynar_length(p_indexNetworkElm);
149 xbt_assert(!xbt_dynar_is_empty(route->link_list),
150 "Invalid count of links, must be greater than zero (%s,%s)",
154 p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
156 if (TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)) {
159 xbt_dynar_t link_route_to_test =
160 xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
161 xbt_dynar_foreach(route->link_list, i, link_name) {
162 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
163 xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
164 xbt_dynar_push(link_route_to_test, &link);
166 if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list,
167 link_route_to_test, full_pointer_resource_cmp)) {
168 surf_parse_error("A route between \"%s\" and \"%s\" already exists "
169 "with a different content. "
170 "If you are trying to define a reverse route, "
171 "you must set the symmetrical=no attribute to "
172 "your routes tags.", src, dst);
174 surf_parse_warn("Ignoring the identical redefinition of the route "
175 "between \"%s\" and \"%s\"", src, dst);
178 if (!route->gw_dst && !route->gw_dst)
179 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
181 // FIXME We can call a gw which is down the current AS (cf g5k.xml) but not upper.
182 // AS_t subas = xbt_dict_get_or_null(rc->routing_sons, src);
183 // if (subas == NULL)
184 // surf_parse_error("The source of an ASroute must be a sub-AS "
185 // "declared within the current AS, "
186 // "but '%s' is not an AS within '%s'", src, rc->name);
187 // if (subas->to_index
188 // && xbt_dict_get_or_null(subas->to_index, route->src_gateway) == NULL)
189 // surf_parse_error("In an ASroute, source gateway must be part of "
190 // "the source sub-AS (in particular, being in a "
191 // "sub-sub-AS is not allowed), "
192 // "but '%s' is not in '%s'.",
193 // route->src_gateway, subas->name);
195 // subas = xbt_dict_get_or_null(rc->routing_sons, dst);
196 // if (subas == NULL)
197 // surf_parse_error("The destination of an ASroute must be a sub-AS "
198 // "declared within the current AS, "
199 // "but '%s' is not an AS within '%s'", dst, rc->name);
200 // if (subas->to_index
201 // && xbt_dict_get_or_null(subas->to_index, route->dst_gateway) == NULL)
202 // surf_parse_error("In an ASroute, destination gateway must be "
203 // "part of the destination sub-AS (in particular, "
204 // "in a sub-sub-AS is not allowed), "
205 // "but '%s' is not in '%s'.",
206 // route->dst_gateway, subas->name);
208 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
209 src, route->gw_src->p_name, dst, route->gw_dst->p_name);
210 if (route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL)
211 xbt_die("The dst_gateway '%s' does not exist!", route->gw_dst->p_name);
212 if (route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL)
213 xbt_die("The src_gateway '%s' does not exist!", route->gw_src->p_name);
215 TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 1);
216 xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list, 0);
219 if ( (route->symmetrical == TRUE && as_route == 0)
220 || (route->symmetrical == TRUE && as_route == 1)
222 if (route->gw_dst && route->gw_src) {
223 sg_routing_edge_t gw_tmp;
224 gw_tmp = route->gw_src;
225 route->gw_src = route->gw_dst;
226 route->gw_dst = gw_tmp;
228 if (TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)) {
231 xbt_dynar_t link_route_to_test =
232 xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
233 for (i = xbt_dynar_length(route->link_list); i > 0; i--) {
234 link_name = xbt_dynar_get_as(route->link_list, i - 1, char *);
235 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
236 xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
237 xbt_dynar_push(link_route_to_test, &link);
239 xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list,
241 full_pointer_resource_cmp),
242 "The route between \"%s\" and \"%s\" already exists", src,
245 if (!route->gw_dst && !route->gw_src)
246 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
248 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
249 dst, route->gw_src->p_name, src, route->gw_dst->p_name);
250 TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 0);
251 xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list, 0);
254 xbt_dynar_free(&route->link_list);