From 55633c554b60455d85885816b1b73e9698b73a14 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 29 Feb 2016 10:17:16 +0100 Subject: [PATCH] factorize one method into the superclass --- src/surf/surf_routing_RoutedGraph.cpp | 30 ++++++++++++++++++++ src/surf/surf_routing_RoutedGraph.hpp | 2 ++ src/surf/surf_routing_dijkstra.cpp | 30 -------------------- src/surf/surf_routing_dijkstra.hpp | 1 - src/surf/surf_routing_floyd.cpp | 33 ---------------------- src/surf/surf_routing_floyd.hpp | 1 - src/surf/surf_routing_full.cpp | 40 +-------------------------- src/surf/surf_routing_full.hpp | 1 - src/surf/surf_routing_vivaldi.hpp | 1 + 9 files changed, 34 insertions(+), 105 deletions(-) diff --git a/src/surf/surf_routing_RoutedGraph.cpp b/src/surf/surf_routing_RoutedGraph.cpp index 5c00da327b..cd85779534 100644 --- a/src/surf/surf_routing_RoutedGraph.cpp +++ b/src/surf/surf_routing_RoutedGraph.cpp @@ -91,6 +91,36 @@ xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt namespace simgrid { namespace surf { + xbt_dynar_t AsRoutedGraph::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 = new std::vector(); + + int table_size = (int)xbt_dynar_length(vertices_); + for(int src=0; src < table_size; src++) { + for(int dst=0; dst< table_size; dst++) { + route->link_list->clear(); + 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 (route->link_list->size() == 1) { + Link *link = route->link_list->at(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 AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) { int src, dst; diff --git a/src/surf/surf_routing_RoutedGraph.hpp b/src/surf/surf_routing_RoutedGraph.hpp index 9d5c7db726..5a2feac181 100644 --- a/src/surf/surf_routing_RoutedGraph.hpp +++ b/src/surf/surf_routing_RoutedGraph.hpp @@ -21,6 +21,8 @@ public: AsRoutedGraph(const char*name); ~AsRoutedGraph(); + xbt_dynar_t getOneLinkRoutes() override; + virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override; virtual sg_platf_route_cbarg_t newExtendedRoute(e_surf_routing_hierarchy_t hierarchy, sg_platf_route_cbarg_t routearg, int change_order); protected: diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index fcaac996a2..1c5c486962 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -138,36 +138,6 @@ void AsDijkstra::newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t 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 = new std::vector(); - - int table_size = (int)xbt_dynar_length(vertices_); - for(int src=0; src < table_size; src++) { - for(int dst=0; dst< table_size; dst++) { - route->link_list->clear(); - 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 (route->link_list->size() == 1) { - Link *link = route->link_list->at(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); diff --git a/src/surf/surf_routing_dijkstra.hpp b/src/surf/surf_routing_dijkstra.hpp index 0bf2e1f8d1..849c682382 100644 --- a/src/surf/surf_routing_dijkstra.hpp +++ b/src/surf/surf_routing_dijkstra.hpp @@ -57,7 +57,6 @@ public: * will have a loopback attached to it. */ void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat) override; - xbt_dynar_t getOneLinkRoutes() override; void addRoute(sg_platf_route_cbarg_t route) override; xbt_graph_t routeGraph_ = nullptr; /* xbt_graph */ diff --git a/src/surf/surf_routing_floyd.cpp b/src/surf/surf_routing_floyd.cpp index c902ac3844..5bfe3df28c 100644 --- a/src/surf/surf_routing_floyd.cpp +++ b/src/surf/surf_routing_floyd.cpp @@ -39,41 +39,8 @@ AsFloyd::~AsFloyd(){ xbt_free(costTable_); } -/* Business methods */ -xbt_dynar_t AsFloyd::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 = new std::vector(); - - int table_size = xbt_dynar_length(vertices_); - for(int src=0; src < table_size; src++) { - for(int dst=0; dst< table_size; dst++) { - route->link_list->clear(); - 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 (route->link_list->size() == 1) { - void *link = route->link_list->at(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 AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat) { - size_t table_size = xbt_dynar_length(vertices_); getRouteCheckParams(src, dst); diff --git a/src/surf/surf_routing_floyd.hpp b/src/surf/surf_routing_floyd.hpp index 67f1f6da96..e5258f83bd 100644 --- a/src/surf/surf_routing_floyd.hpp +++ b/src/surf/surf_routing_floyd.hpp @@ -27,7 +27,6 @@ public: ~AsFloyd(); void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; - xbt_dynar_t getOneLinkRoutes() override; void addRoute(sg_platf_route_cbarg_t route) override; void Seal() override; diff --git a/src/surf/surf_routing_full.cpp b/src/surf/surf_routing_full.cpp index 7d52469d64..1180fe0e79 100644 --- a/src/surf/surf_routing_full.cpp +++ b/src/surf/surf_routing_full.cpp @@ -61,48 +61,10 @@ AsFull::~AsFull(){ } } -xbt_dynar_t AsFull::getOneLinkRoutes() -{ - xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f); - - int src, dst; - int table_size = xbt_dynar_length(vertices_); - - for(src=0; src < table_size; src++) { - for(dst=0; dst< table_size; dst++) { - sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src,dst); - if (route) { - if (route->link_list->size() == 1) { - Link *link = route->link_list->at(0); - Onelink *onelink; - if (hierarchy_ == SURF_ROUTING_BASE) { - NetCard *tmp_src = xbt_dynar_get_as(vertices_, src, sg_netcard_t); - tmp_src->setId(src); - NetCard *tmp_dst = xbt_dynar_get_as(vertices_, dst, sg_netcard_t); - tmp_dst->setId(dst); - onelink = new Onelink(link, tmp_src, tmp_dst); - } 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); - XBT_DEBUG("Push route from '%d' to '%d'", - src, - dst); - } - } - } - } - return ret; -} - void AsFull::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t res, double *lat) { XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]", - src->name(), - src->id(), - dst->name(), - dst->id()); + src->name(), src->id(), dst->name(), dst->id()); /* set utils vars */ size_t table_size = xbt_dynar_length(vertices_); diff --git a/src/surf/surf_routing_full.hpp b/src/surf/surf_routing_full.hpp index 30dd1cbefd..0abbae3fa7 100644 --- a/src/surf/surf_routing_full.hpp +++ b/src/surf/surf_routing_full.hpp @@ -28,7 +28,6 @@ public: ~AsFull(); void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; - xbt_dynar_t getOneLinkRoutes() override; void addRoute(sg_platf_route_cbarg_t route) override; sg_platf_route_cbarg_t *routingTable_ = nullptr; diff --git a/src/surf/surf_routing_vivaldi.hpp b/src/surf/surf_routing_vivaldi.hpp index 3ab9c59658..3795d69681 100644 --- a/src/surf/surf_routing_vivaldi.hpp +++ b/src/surf/surf_routing_vivaldi.hpp @@ -28,6 +28,7 @@ public: AsVivaldi(const char *name); ~AsVivaldi() {}; + xbt_dynar_t getOneLinkRoutes() override {return NULL;}; void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override; }; -- 2.20.1