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"
16 XBT_PUBLIC(void) routing_model_create( void *loopback);
26 class XBT_PRIVATE RoutingModelDescription;
27 class XBT_PRIVATE Onelink;
30 /** @ingroup SURF_routing_interface
31 * @brief A network card
32 * @details This represents a position in the network. One can route information between two netcards
37 virtual int getId()=0;
38 virtual int *getIdPtr()=0;
39 virtual void setId(int id)=0;
40 virtual char *getName()=0;
41 virtual As *getRcComponent()=0;
42 virtual e_surf_network_element_type_t getRcType()=0;
45 /** @ingroup SURF_routing_interface
46 * @brief The Autonomous System (AS) routing interface
51 xbt_dynar_t p_indexNetworkElm = xbt_dynar_new(sizeof(char*),NULL);
52 xbt_dict_t p_bypassRoutes; /* store bypass routes */
53 routing_model_description_t p_modelDesc;
54 e_surf_routing_hierarchy_t p_hierarchy;
55 char *p_name = nullptr;
56 As *p_routingFather = nullptr;
57 xbt_dict_t p_routingSons = xbt_dict_new_homogeneous(NULL);
59 xbt_dynar_t p_linkUpDownList = NULL;
62 * @brief The As constructor
67 * @brief The As destructor
70 xbt_dict_free(&p_routingSons);
71 xbt_dynar_free(&p_indexNetworkElm);
72 xbt_dynar_free(&p_linkUpDownList);
79 * @brief Get the characteristics of the routing path between two points
81 * This function is used by the networking model to find the information it needs when starting a communication.
83 * The things are not straightforward because the platform can be routed using several routing models.
84 * Some ASes may be routed in full, others may have only some connection information and use a shortest path on top of that, and so on.
85 * Some ASes may even not have any predefined links and use only coordinate informations to compute the latency.
87 * So, the path is constructed recursively, with each traversed AS adding its information to the set.
88 * The algorithm for that is explained in http://hal.inria.fr/hal-00650233/
90 * @param src Initial point of the routing path
91 * @param dst Final point of the routing path
92 * @param into Container into which the links should be pushed
93 * @param latency Accumulator in which the latencies should be added
95 virtual void getRouteAndLatency(
96 NetCard *src, NetCard *dst,
97 sg_platf_route_cbarg_t into, double *latency)=0;
98 virtual xbt_dynar_t getOneLinkRoutes()=0;
99 virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
100 virtual sg_platf_route_cbarg_t getBypassRoute(
101 NetCard *src, NetCard *dst,
104 /* The parser calls the following functions to inform the routing models
105 * that a new element is added to the AS currently built.
107 * Of course, only the routing model of this AS is informed, not every ones */
108 virtual int parsePU(NetCard *elm)=0; /* A host or a router, whatever */
109 virtual int parseAS(NetCard *elm)=0;
110 virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
111 virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
112 virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
115 struct XBT_PRIVATE NetCardImpl : public NetCard {
117 NetCardImpl(char *name, int id, e_surf_network_element_type_t rcType, As *rcComponent)
118 : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
119 ~NetCardImpl() { xbt_free(p_name);};
121 int getId() {return m_id;}
122 int *getIdPtr() {return &m_id;}
123 void setId(int id) {m_id = id;}
124 char *getName() {return p_name;}
125 As *getRcComponent() {return p_rcComponent;}
126 e_surf_network_element_type_t getRcType() {return p_rcType;}
129 e_surf_network_element_type_t p_rcType;
134 /** @ingroup SURF_routing_interface
135 * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the ns3 bindings
139 Onelink(void *link, NetCard *src, NetCard *dst)
140 : p_src(src), p_dst(dst), p_link(link) {};
146 /** @ingroup SURF_routing_interface
147 * @brief The class representing a whole routing platform
149 XBT_PUBLIC_CLASS RoutingPlatf {
154 xbt_dynar_t p_lastRoute;
155 xbt_dynar_t getOneLinkRoutes(void);
156 xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
157 void getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t * links, double *latency);
164 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
165 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(As*)>) asCreatedCallbacks;
170 #endif /* NETWORK_ROUTING_HPP_ */