1 /* Copyright (c) 2009-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/routing/AsFull.hpp"
7 #include "src/surf/network_interface.hpp"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
11 #define TO_ROUTE_FULL(i,j) routingTable_[(i)+(j)*table_size]
16 AsFull::AsFull(As* father, const char* name) : AsRoutedGraph(father, name)
22 sg_platf_route_cbarg_t e_route;
25 int table_size = static_cast<int>(vertices_.size());
27 /* Create table if necessary */
29 routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
31 /* Add the loopback if needed */
32 if (surf_network_model->loopback_ && hierarchy_ == RoutingMode::base) {
33 for (i = 0; i < table_size; i++) {
34 e_route = TO_ROUTE_FULL(i, i);
36 e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
37 e_route->gw_src = nullptr;
38 e_route->gw_dst = nullptr;
39 e_route->link_list = new std::vector<Link*>();
40 e_route->link_list->push_back(surf_network_model->loopback_);
41 TO_ROUTE_FULL(i, i) = e_route;
49 int table_size = static_cast<int>(vertices_.size());
50 /* Delete routing table */
51 for (int i = 0; i < table_size; i++)
52 for (int j = 0; j < table_size; j++) {
53 if (TO_ROUTE_FULL(i,j)){
54 delete TO_ROUTE_FULL(i,j)->link_list;
55 xbt_free(TO_ROUTE_FULL(i,j));
58 xbt_free(routingTable_);
62 void AsFull::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t res, double *lat)
64 XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]", src->name().c_str(), src->id(), dst->name().c_str(),
68 size_t table_size = vertices_.size();
70 sg_platf_route_cbarg_t e_route = nullptr;
72 e_route = TO_ROUTE_FULL(src->id(), dst->id());
75 res->gw_src = e_route->gw_src;
76 res->gw_dst = e_route->gw_dst;
77 for (auto link : *e_route->link_list) {
78 res->link_list->push_back(link);
80 *lat += static_cast<Link*>(link)->latency();
85 void AsFull::addRoute(sg_platf_route_cbarg_t route)
87 NetCard* src = route->src;
88 NetCard* dst = route->dst;
89 const char* srcName = src->name().c_str();
90 const char* dstName = dst->name().c_str();
92 addRouteCheckParams(route);
94 size_t table_size = vertices_.size();
97 routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
99 /* Check that the route does not already exist */
100 if (route->gw_dst) // AS route (to adapt the error message, if any)
101 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
102 "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).", srcName,
103 route->gw_src->name().c_str(), dstName, route->gw_dst->name().c_str());
105 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
106 "The route between %s and %s already exists (Rq: routes are symmetrical by default).", srcName, dstName);
108 /* Add the route to the base */
109 TO_ROUTE_FULL(src->id(), dst->id()) = newExtendedRoute(hierarchy_, route, 1);
110 TO_ROUTE_FULL(src->id(), dst->id())->link_list->shrink_to_fit();
112 if (route->symmetrical == true && src != dst) {
113 if (route->gw_dst && route->gw_src) {
114 NetCard* gw_tmp = route->gw_src;
115 route->gw_src = route->gw_dst;
116 route->gw_dst = gw_tmp;
118 if (route->gw_dst) // AS route (to adapt the error message, if any)
120 nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
121 "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
122 dstName, route->gw_dst->name().c_str(), srcName, route->gw_src->name().c_str());
124 xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
125 "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
128 TO_ROUTE_FULL(dst->id(), src->id()) = newExtendedRoute(hierarchy_, route, 0);
129 TO_ROUTE_FULL(dst->id(), src->id())->link_list->shrink_to_fit();