- NetPoint* src = route->src;
- NetPoint* dst = route->dst;
- const char* srcName = src->name().c_str();
- const char* dstName = dst->name().c_str();
-
- addRouteCheckParams(route);
-
- /* Create the topology graph */
- if (not routeGraph_)
- routeGraph_ = xbt_graph_new_graph(1, nullptr);
- if (not graphNodeMap_)
- graphNodeMap_ = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
-
- /* we don't check whether the route already exist, because the algorithm may find another path through some other
- * nodes */
-
- /* Add the route to the base */
- sg_platf_route_cbarg_t e_route = newExtendedRoute(hierarchy_, route, 1);
- newRoute(src->id(), dst->id(), e_route);
-
- // Symmetrical YES
- if (route->symmetrical == true) {
-
- xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
- xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src->id(), xbt_node_t);
- xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst->id(), xbt_node_t);
- xbt_edge_t edge = xbt_graph_get_edge(routeGraph_, node_e_v, node_s_v);
-
- if (not route->gw_dst || not route->gw_src){
- XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dstName, srcName);
- if (edge)
- THROWF(arg_error, 0, "Route from %s to %s already exists", dstName, srcName);
- } else {
- XBT_DEBUG("Load NetzoneRoute from %s@%s to %s@%s", dstName, route->gw_dst->name().c_str(), srcName,
- route->gw_src->name().c_str());
- if (edge)
- THROWF(arg_error, 0, "Route from %s@%s to %s@%s already exists", dstName, route->gw_dst->name().c_str(), srcName,
- route->gw_src->name().c_str());
- }
-
- if (route->gw_dst && route->gw_src) {
- NetPoint* gw_tmp = route->gw_src;
- route->gw_src = route->gw_dst;
- route->gw_dst = gw_tmp;
- }
- sg_platf_route_cbarg_t link_route_back = newExtendedRoute(hierarchy_, route, 0);
- newRoute(dst->id(), src->id(), link_route_back);
+ XBT_DEBUG("Create Route from '%lu' to '%lu'", src_id, dst_id);
+
+ // Get the extremities, or create them if they don't exist yet
+ xbt_node_t src = node_map_search(src_id);
+ if (src == nullptr)
+ src = route_graph_new_node(src_id);
+
+ xbt_node_t dst = node_map_search(dst_id);
+ if (dst == nullptr)
+ dst = route_graph_new_node(dst_id);
+
+ // Make sure that this graph edge was not already added to the graph
+ if (xbt_graph_get_edge(route_graph_.get(), src, dst) != nullptr) {
+ if (route->gw_dst_ == nullptr || route->gw_src_ == nullptr)
+ throw std::invalid_argument(
+ xbt::string_printf("Route from %s to %s already exists", route->src_->get_cname(), route->dst_->get_cname()));
+ else
+ throw std::invalid_argument(xbt::string_printf("Route from %s@%s to %s@%s already exists",
+ route->src_->get_cname(), route->gw_src_->get_cname(),
+ route->dst_->get_cname(), route->gw_dst_->get_cname()));