/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include "src/surf/surf_routing_private.hpp"
#include "src/surf/surf_routing_dijkstra.hpp"
#include "src/surf/network_interface.hpp"
{
sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t) e;
if (e_route) {
- xbt_dynar_free(&(e_route->link_list));
+ delete e_route->link_list;
xbt_free(e_route);
}
}
graphNodeMap_ = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
/* Add the loopback if needed */
- if (routing_platf->loopback_ && hierarchy_ == SURF_ROUTING_BASE) {
+ if (routing_platf->loopback_ && hierarchy_ == s4u::As::ROUTING_BASE) {
xbt_dynar_foreach(xbt_graph_get_nodes(routeGraph_), cursor, node) {
xbt_edge_t edge = NULL;
if (!found) {
sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
- e_route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
- xbt_dynar_push(e_route->link_list, &routing_platf->loopback_);
+ e_route->link_list = new std::vector<Link*>();
+ e_route->link_list->push_back(routing_platf->loopback_);
xbt_graph_new_edge(routeGraph_, node, node, e_route);
}
}
xbt_graph_new_edge(routeGraph_, src, dst, e_route);
}
-xbt_dynar_t AsDijkstra::getOneLinkRoutes()
-{
- xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
- sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
- route->link_list = xbt_dynar_new(sizeof(Link*),NULL);
-
- int table_size = (int)xbt_dynar_length(vertices_);
- for(int src=0; src < table_size; src++) {
- for(int dst=0; dst< table_size; dst++) {
- xbt_dynar_reset(route->link_list);
- NetCard *src_elm = xbt_dynar_get_as(vertices_, src, NetCard*);
- NetCard *dst_elm = xbt_dynar_get_as(vertices_, dst, NetCard*);
- this->getRouteAndLatency(src_elm, dst_elm,route, NULL);
-
- if (xbt_dynar_length(route->link_list) == 1) {
- void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
- Onelink *onelink;
- if (hierarchy_ == SURF_ROUTING_BASE)
- onelink = new Onelink(link, src_elm, dst_elm);
- else if (hierarchy_ == SURF_ROUTING_RECURSIVE)
- onelink = new Onelink(link, route->gw_src, route->gw_dst);
- else
- onelink = new Onelink(link, NULL, NULL);
- xbt_dynar_push(ret, &onelink);
- }
- }
- }
- return ret;
-}
-
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
{
getRouteCheckParams(src, dst);
int *pred_arr = NULL;
sg_platf_route_cbarg_t e_route;
int size = 0;
- unsigned int cpt;
- void *link;
xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
/* Use the graph_node id mapping set to quickly find the nodes */
e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
- xbt_dynar_foreach(e_route->link_list, cpt, link) {
- xbt_dynar_unshift(route->link_list, &link);
+ for (auto link: *e_route->link_list) {
+ route->link_list->insert(route->link_list->begin(), link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
}
route_cache_element_t elm = NULL;
if (routeCache_) { /* cache mode */
- elm = (route_cache_element_t)
- xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int));
+ elm = (route_cache_element_t) xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int));
}
if (elm) { /* cached mode and cache hit */
graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
int u_id = data->graph_id;
sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
- int cost_v_u = (tmp_e_route->link_list)->used; /* count of links, old model assume 1 */
+ int cost_v_u = tmp_e_route->link_list->size(); /* count of links, old model assume 1 */
if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
pred_arr[u_id] = *v_id;
if (v == dst_node_id)
first_gw = gw_dst;
- if (hierarchy_ == SURF_ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst->name(), prev_gw_src->name())) {
- xbt_dynar_t e_route_as_to_as=NULL;
+ if (hierarchy_ == s4u::As::ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst->name(), prev_gw_src->name())) {
+ std::vector<Link*> *e_route_as_to_as = new std::vector<Link*>();
- routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
- if (edge == NULL)
- THROWF(arg_error,0,"No route from '%s' to '%s'", src->name(), dst->name());
- int pos = 0;
- xbt_dynar_foreach(e_route_as_to_as, cpt, link) {
- xbt_dynar_insert_at(route->link_list, pos, &link);
+ routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, e_route_as_to_as, NULL);
+ auto pos = route->link_list->begin();
+ for (auto link : *e_route_as_to_as) {
+ route->link_list->insert(pos, link);
if (lat)
- *lat += static_cast<Link*>(link)->getLatency();
+ *lat += link->getLatency();
pos++;
}
}
- xbt_dynar_foreach(e_route->link_list, cpt, link) {
- xbt_dynar_unshift(route->link_list, &link);
+ for (auto link: *e_route->link_list) {
+ route->link_list->insert(route->link_list->begin(), link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
}
size++;
}
- if (hierarchy_ == SURF_ROUTING_RECURSIVE) {
+ if (hierarchy_ == s4u::As::ROUTING_RECURSIVE) {
route->gw_src = gw_src;
route->gw_dst = first_gw;
}
sg_platf_route_cbarg_t link_route_back = newExtendedRoute(hierarchy_, route, 0);
newRoute(dst->id(), src->id(), link_route_back);
}
- xbt_dynar_free(&route->link_list);
+ delete route->link_list;
}
}