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 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 declard 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 RoutingEdge *RoutingEdgePtr;
36 typedef Onelink *OnelinkPtr;
39 typedef RoutingPlatf *RoutingPlatfPtr;
41 /** @ingroup SURF_routing_interface
42 * @brief The Autonomous System (AS) routing interface
47 xbt_dynar_t p_indexNetworkElm;
48 xbt_dict_t p_bypassRoutes; /* store bypass routes */
49 routing_model_description_t p_modelDesc;
50 e_surf_routing_hierarchy_t p_hierarchy;
52 AsPtr p_routingFather;
53 xbt_dict_t p_routingSons;
54 RoutingEdgePtr p_netElem;
55 xbt_dynar_t p_linkUpDownList;
58 * @brief The As constructor
63 * @brief The As destructor
70 * @brief Get the route and latency between two RoutingEdgs
71 * @details [long description]
73 * @param src [description]
74 * @param dst [description]
75 * @param into [description]
76 * @param latency [description]
78 virtual void getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t into, double *latency)=0;
79 virtual xbt_dynar_t getOneLinkRoutes()=0;
80 virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
81 virtual sg_platf_route_cbarg_t getBypassRoute(RoutingEdgePtr src, RoutingEdgePtr dst, double *lat)=0;
83 /* The parser calls the following functions to inform the routing models
84 * that a new element is added to the AS currently built.
86 * Of course, only the routing model of this AS is informed, not every ones */
87 virtual int parsePU(RoutingEdgePtr elm)=0; /* A host or a router, whatever */
88 virtual int parseAS( RoutingEdgePtr elm)=0;
89 virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
90 virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
91 virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
94 /** @ingroup SURF_routing_interface
95 * @brief A routing edge
96 * @details [long description]
100 virtual ~RoutingEdge(){};
101 virtual int getId()=0;
102 virtual int *getIdPtr()=0;
103 virtual void setId(int id)=0;
104 virtual char *getName()=0;
105 virtual AsPtr getRcComponent()=0;
106 virtual e_surf_network_element_type_t getRcType()=0;
109 struct RoutingEdgeImpl : public RoutingEdge {
111 RoutingEdgeImpl(char *name, int id, e_surf_network_element_type_t rcType, AsPtr rcComponent)
112 : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
113 ~RoutingEdgeImpl() { xbt_free(p_name);};
115 int getId() {return m_id;}
116 int *getIdPtr() {return &m_id;}
117 void setId(int id) {m_id = id;}
118 char *getName() {return p_name;}
119 AsPtr getRcComponent() {return p_rcComponent;}
120 e_surf_network_element_type_t getRcType() {return p_rcType;}
123 e_surf_network_element_type_t p_rcType;
128 struct RoutingEdgeWrapper : public RoutingEdge {
130 RoutingEdgeWrapper(RoutingEdge *re) : p_re(re){}
131 ~RoutingEdgeWrapper(){}
132 int getId() {return p_re->getId();}
133 int *getIdPtr() {return p_re->getIdPtr();}
134 void setId(int id) {p_re->setId(id);}
135 char *getName() {return p_re->getName();}
136 AsPtr getRcComponent() {return p_re->getRcComponent();}
137 e_surf_network_element_type_t getRcType() {return p_re->getRcType();}
142 /** @ingroup SURF_routing_interface
143 * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
147 Onelink(void *link, RoutingEdgePtr src, RoutingEdgePtr dst)
148 : p_src(src), p_dst(dst), p_link(link) {};
149 RoutingEdgePtr p_src;
150 RoutingEdgePtr p_dst;
154 /** @ingroup SURF_routing_interface
155 * @brief The class representing a whole routing platform
157 XBT_PUBLIC_CLASS RoutingPlatf {
162 xbt_dynar_t p_lastRoute;
163 xbt_dynar_t getOneLinkRoutes(void);
164 xbt_dynar_t recursiveGetOneLinkRoutes(AsPtr rc);
165 void getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, xbt_dynar_t * links, double *latency);
168 #endif /* NETWORK_ROUTING_HPP_ */