1 /* Copyright (c) 2013-2015. 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. */
7 #ifndef NETWORK_ROUTING_HPP_
8 #define NETWORK_ROUTING_HPP_
11 #include <xbt/signal.hpp>
13 #include "surf_interface.hpp"
14 #include "src/surf/xml/platf_private.hpp" // FIXME: including this here is pure madness. KILKILKIL XML.
15 #include "src/kernel/routing/AsImpl.hpp"
21 XBT_PUBLIC(void) routing_model_create(Link *loopback);
22 XBT_PRIVATE xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
23 XBT_PRIVATE xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges);
30 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
31 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
37 class XBT_PRIVATE Onelink;
40 /** @ingroup SURF_routing_interface
41 * @brief Network cards are the vertices in the graph representing the network, used to compute paths between nodes.
43 * @details This represents a position in the network. One can route information between two netcards
47 virtual ~NetCard() = default;
48 virtual unsigned int id()=0; // Our rank in the vertices_ array of our containing AS.
49 virtual std::string name() = 0;
50 virtual AsImpl *containingAS()=0; // This is the AS in which I am
51 virtual bool isAS()=0;
52 virtual bool isHost()=0;
53 virtual bool isRouter()=0;
59 struct XBT_PRIVATE NetCardImpl : public NetCard {
61 NetCardImpl(std::string name, NetCard::Type componentType, AsImpl* containingAS)
62 : name_(name), componentType_(componentType), containingAS_(containingAS)
64 if (containingAS != nullptr)
65 id_ = containingAS->addComponent(this);
66 simgrid::kernel::routing::netcardCreatedCallbacks(this);
68 ~NetCardImpl() = default;
70 unsigned int id() override {return id_;}
71 std::string name() override { return name_; }
72 AsImpl *containingAS() override {return containingAS_;}
74 bool isAS() override {return componentType_ == Type::As;}
75 bool isHost() override {return componentType_ == Type::Host;}
76 bool isRouter() override {return componentType_ == Type::Router;}
81 NetCard::Type componentType_;
82 AsImpl *containingAS_;
87 explicit AsRoute(NetCard* gwSrc, NetCard* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {}
88 const NetCard* gw_src;
89 const NetCard* gw_dst;
90 std::vector<Link*> links;
93 /** @ingroup SURF_routing_interface
94 * @brief Link of length 1, alongside with its source and destination. This is mainly useful in the ns3 bindings
98 Onelink(void *link, NetCard *src, NetCard *dst)
99 : src_(src), dst_(dst), link_(link) {};
102 void *link_; // FIXME: void* should die just like the death*
105 /** @ingroup SURF_routing_interface
106 * @brief The class representing a whole routing platform
108 XBT_PUBLIC_CLASS RoutingPlatf {
110 explicit RoutingPlatf(Link *loopback);
112 AsImpl *root_ = nullptr;
114 xbt_dynar_t getOneLinkRoutes();
115 void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
120 #endif /* NETWORK_ROUTING_HPP_ */