1 /* Copyright (c) 2013-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. */
7 #include "surf_interface.hpp"
10 #ifndef NETWORK_ROUTING_HPP_
11 #define NETWORK_ROUTING_HPP_
13 XBT_PUBLIC(void) routing_model_create( void *loopback);
15 /* ************************************************************************** */
16 /* ************************* GRAPH EXPORTING FUNCTIONS ********************** */
17 xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
18 xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges);
24 /* Note: As and RoutingEdge are declared as struct instead of class, to keep
25 compatibility with C files where they are mentioned. */
29 class RoutingModelDescription;
30 typedef RoutingModelDescription *RoutingModelDescriptionPtr;
33 typedef Onelink *OnelinkPtr;
36 typedef RoutingPlatf *RoutingPlatfPtr;
38 /** @ingroup SURF_routing_interface
39 * @brief The Autonomous System (AS) routing interface
44 xbt_dynar_t p_indexNetworkElm;
45 xbt_dict_t p_bypassRoutes; /* store bypass routes */
46 routing_model_description_t p_modelDesc;
47 e_surf_routing_hierarchy_t p_hierarchy;
49 AsPtr p_routingFather;
50 xbt_dict_t p_routingSons;
51 RoutingEdgePtr p_netElem;
52 xbt_dynar_t p_linkUpDownList;
55 * @brief The As constructor
60 * @brief The As destructor
67 * @brief Get the route and latency between two RoutingEdges
68 * @details [long description]
70 * @param src [description]
71 * @param dst [description]
72 * @param into [description]
73 * @param latency [description]
75 virtual void getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t into, double *latency)=0;
76 virtual xbt_dynar_t getOneLinkRoutes()=0;
77 virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
78 virtual sg_platf_route_cbarg_t getBypassRoute(RoutingEdgePtr src, RoutingEdgePtr dst, double *lat)=0;
80 /* The parser calls the following functions to inform the routing models
81 * that a new element is added to the AS currently built.
83 * Of course, only the routing model of this AS is informed, not every ones */
84 virtual int parsePU(RoutingEdgePtr elm)=0; /* A host or a router, whatever */
85 virtual int parseAS( RoutingEdgePtr elm)=0;
86 virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
87 virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
88 virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
91 /** @ingroup SURF_routing_interface
92 * @brief A routing edge
93 * @details [long description]
97 virtual ~RoutingEdge(){};
98 virtual int getId()=0;
99 virtual int *getIdPtr()=0;
100 virtual void setId(int id)=0;
101 virtual char *getName()=0;
102 virtual AsPtr getRcComponent()=0;
103 virtual e_surf_network_element_type_t getRcType()=0;
106 struct RoutingEdgeImpl : public RoutingEdge {
108 RoutingEdgeImpl(char *name, int id, e_surf_network_element_type_t rcType, AsPtr rcComponent)
109 : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
110 ~RoutingEdgeImpl() { xbt_free(p_name);};
112 int getId() {return m_id;}
113 int *getIdPtr() {return &m_id;}
114 void setId(int id) {m_id = id;}
115 char *getName() {return p_name;}
116 AsPtr getRcComponent() {return p_rcComponent;}
117 e_surf_network_element_type_t getRcType() {return p_rcType;}
120 e_surf_network_element_type_t p_rcType;
125 struct RoutingEdgeWrapper : public RoutingEdge {
127 RoutingEdgeWrapper(RoutingEdge *re) : p_re(re){}
128 ~RoutingEdgeWrapper(){}
129 int getId() {return p_re->getId();}
130 int *getIdPtr() {return p_re->getIdPtr();}
131 void setId(int id) {p_re->setId(id);}
132 char *getName() {return p_re->getName();}
133 AsPtr getRcComponent() {return p_re->getRcComponent();}
134 e_surf_network_element_type_t getRcType() {return p_re->getRcType();}
139 /** @ingroup SURF_routing_interface
140 * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
144 Onelink(void *link, RoutingEdgePtr src, RoutingEdgePtr dst)
145 : p_src(src), p_dst(dst), p_link(link) {};
146 RoutingEdgePtr p_src;
147 RoutingEdgePtr p_dst;
151 /** @ingroup SURF_routing_interface
152 * @brief The class representing a whole routing platform
154 XBT_PUBLIC_CLASS RoutingPlatf {
159 xbt_dynar_t p_lastRoute;
160 xbt_dynar_t getOneLinkRoutes(void);
161 xbt_dynar_t recursiveGetOneLinkRoutes(AsPtr rc);
162 void getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, xbt_dynar_t * links, double *latency);
165 #endif /* NETWORK_ROUTING_HPP_ */