Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
41c34211208fdb7650616dacfedf67e950ed0c5e
[simgrid.git] / src / surf / surf_routing.hpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef NETWORK_ROUTING_HPP_
8 #define NETWORK_ROUTING_HPP_
9
10 #include "surf_interface.hpp"
11 #include <float.h>
12
13 XBT_PUBLIC(void) routing_model_create( void *loopback);
14
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);
19
20 /***********
21  * Classes *
22  ***********/
23
24 class As;
25 class RoutingModelDescription;
26 class Onelink;
27 class RoutingPlatf;
28
29 /** @ingroup SURF_routing_interface
30  * @brief A routing edge
31  * @details [long description]
32  */
33 struct RoutingEdge {
34 public:
35   virtual ~RoutingEdge(){};
36   virtual int getId()=0;
37   virtual int *getIdPtr()=0;
38   virtual void setId(int id)=0;
39   virtual char *getName()=0;
40   virtual As *getRcComponent()=0;
41   virtual e_surf_network_element_type_t getRcType()=0;
42 };
43
44 /** @ingroup SURF_routing_interface
45  * @brief The Autonomous System (AS) routing interface
46  * @details [TODO]
47  */
48 class As {
49 public:
50   xbt_dynar_t p_indexNetworkElm;
51   xbt_dict_t p_bypassRoutes;    /* store bypass routes */
52   routing_model_description_t p_modelDesc;
53   e_surf_routing_hierarchy_t p_hierarchy;
54   char *p_name;
55   As *p_routingFather;
56   xbt_dict_t p_routingSons;
57   RoutingEdge *p_netElem;
58   xbt_dynar_t p_linkUpDownList;
59
60   /**
61    * @brief The As constructor
62    */
63   As(){};
64
65   /**
66    * @brief The As destructor
67    */
68   virtual ~As(){
69         xbt_free(p_name);
70         if (p_netElem)
71                 delete p_netElem;
72   };
73
74   /**
75    * @brief Get the route and latency between two RoutingEdges
76    * @details [long description]
77    * 
78    * @param src [description]
79    * @param dst [description]
80    * @param into [description]
81    * @param latency [description]
82    */
83   virtual void getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_route_cbarg_t into, double *latency)=0;
84   virtual xbt_dynar_t getOneLinkRoutes()=0;
85   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
86   virtual sg_platf_route_cbarg_t getBypassRoute(RoutingEdge *src, RoutingEdge *dst, double *lat)=0;
87
88   /* The parser calls the following functions to inform the routing models
89    * that a new element is added to the AS currently built.
90    *
91    * Of course, only the routing model of this AS is informed, not every ones */
92   virtual int parsePU(RoutingEdge *elm)=0; /* A host or a router, whatever */
93   virtual int parseAS( RoutingEdge *elm)=0;
94   virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
95   virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
96   virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
97 };
98
99 struct RoutingEdgeImpl : public RoutingEdge {
100 public:
101   RoutingEdgeImpl(char *name, int id, e_surf_network_element_type_t rcType, As *rcComponent)
102   : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
103   ~RoutingEdgeImpl() { xbt_free(p_name);};
104
105   int getId() {return m_id;}
106   int *getIdPtr() {return &m_id;}
107   void setId(int id) {m_id = id;}
108   char *getName() {return p_name;}
109   As *getRcComponent() {return p_rcComponent;}
110   e_surf_network_element_type_t getRcType() {return p_rcType;}
111 private:
112   As *p_rcComponent;
113   e_surf_network_element_type_t p_rcType;
114   int m_id;
115   char *p_name;
116 };
117
118 struct RoutingEdgeWrapper : public RoutingEdge {
119 public:
120   RoutingEdgeWrapper(RoutingEdge *re) : p_re(re){}
121   ~RoutingEdgeWrapper(){}
122   int getId() {return p_re->getId();}
123   int *getIdPtr() {return p_re->getIdPtr();}
124   void setId(int id) {p_re->setId(id);}
125   char *getName() {return p_re->getName();}
126   As *getRcComponent() {return p_re->getRcComponent();}
127   e_surf_network_element_type_t getRcType() {return p_re->getRcType();}
128 private:
129   RoutingEdge *p_re;
130 };
131
132 /** @ingroup SURF_routing_interface
133  * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the ns3 bindings
134  */
135 class Onelink {
136 public:
137   Onelink(void *link, RoutingEdge *src, RoutingEdge *dst)
138     : p_src(src), p_dst(dst), p_link(link) {};
139   RoutingEdge *p_src;
140   RoutingEdge *p_dst;
141   void *p_link;
142 };
143
144 /** @ingroup SURF_routing_interface
145  * @brief The class representing a whole routing platform
146  */
147 XBT_PUBLIC_CLASS RoutingPlatf {
148 public:
149   ~RoutingPlatf();
150   As *p_root;
151   void *p_loopback;
152   xbt_dynar_t p_lastRoute;
153   xbt_dynar_t getOneLinkRoutes(void);
154   xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
155   void getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, xbt_dynar_t * links, double *latency);
156 };
157
158 #endif /* NETWORK_ROUTING_HPP_ */