1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include <simgrid/s4u/host.hpp>
10 #include <simgrid/s4u/As.hpp>
12 #include "src/surf/surf_routing.hpp"
13 #include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
15 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_as,"S4U autonomous systems");
20 As::As(As* father, const char* name) : father_(father), name_(xbt_strdup(name))
29 xbt_dict_cursor_t cursor = nullptr;
32 xbt_dict_foreach(children_, cursor, key, elem) { delete (As*)elem; }
34 xbt_dict_free(&children_);
35 for (auto& kv : bypassRoutes_)
40 xbt_dict_t As::children()
53 xbt_dynar_t As::hosts()
55 xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
57 for (auto card : vertices_) {
58 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
60 xbt_dynar_push(res, &host);
65 int As::addComponent(kernel::routing::NetCard* elm)
67 vertices_.push_back(elm);
68 return vertices_.size() - 1; // The rank of the newly created object
71 void As::addRoute(sg_platf_route_cbarg_t /*route*/)
73 xbt_die("AS %s does not accept new routes (wrong class).", name_);
76 void As::addBypassRoute(sg_platf_route_cbarg_t e_route)
78 /* Argument validity checks */
79 if (e_route->gw_dst) {
80 XBT_DEBUG("Load bypassASroute from %s@%s to %s@%s", e_route->src->name(), e_route->gw_src->name(),
81 e_route->dst->name(), e_route->gw_dst->name());
82 xbt_assert(!e_route->link_list->empty(), "Bypass route between %s@%s and %s@%s cannot be empty.",
83 e_route->src->name(), e_route->gw_src->name(), e_route->dst->name(), e_route->gw_dst->name());
84 xbt_assert(bypassRoutes_.find({e_route->src->name(), e_route->dst->name()}) == bypassRoutes_.end(),
85 "The bypass route between %s@%s and %s@%s already exists.", e_route->src->name(),
86 e_route->gw_src->name(), e_route->dst->name(), e_route->gw_dst->name());
88 XBT_DEBUG("Load bypassRoute from %s to %s", e_route->src->name(), e_route->dst->name());
89 xbt_assert(!e_route->link_list->empty(), "Bypass route between %s and %s cannot be empty.", e_route->src->name(),
90 e_route->dst->name());
91 xbt_assert(bypassRoutes_.find({e_route->src->name(), e_route->dst->name()}) == bypassRoutes_.end(),
92 "The bypass route between %s and %s already exists.", e_route->src->name(), e_route->dst->name());
95 /* Build a copy that will be stored in the dict */
96 std::vector<surf::Link*>* newRoute = new std::vector<surf::Link*>();
97 for (auto link : *e_route->link_list)
98 newRoute->push_back(link);
101 bypassRoutes_.insert({{e_route->src->name(), e_route->dst->name()}, newRoute});
103 } }; // namespace simgrid::s4u