Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3650cf8b1adbed9d3a23b48cbb19dfb756720b50
[simgrid.git] / src / surf / surf_routing.hpp
1 /* Copyright (c) 2013-2014. 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 #include "surf_interface.hpp"
8 #include <float.h>
9
10 #ifndef NETWORK_ROUTING_HPP_
11 #define NETWORK_ROUTING_HPP_
12
13 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 /* Note: As and RoutingEdge are declard as struct instead of class, to keep
25    compatibility with C files where they are mentioned. */
26 struct As;
27 typedef As *AsPtr;
28
29 class RoutingModelDescription;
30 typedef RoutingModelDescription *RoutingModelDescriptionPtr;
31
32 struct RoutingEdge;
33 typedef RoutingEdge *RoutingEdgePtr;
34
35 class Onelink;
36 typedef Onelink *OnelinkPtr;
37
38 class RoutingPlatf;
39 typedef RoutingPlatf *RoutingPlatfPtr;
40
41 /** @ingroup SURF_routing_interface
42  * @brief The Autonomous System (AS) routing interface
43  * @details [TODO]
44  */
45 struct As {
46 public:
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;
51   char *p_name;
52   AsPtr p_routingFather;
53   xbt_dict_t p_routingSons;
54   RoutingEdgePtr p_netElem;
55   xbt_dynar_t p_linkUpDownList;
56
57   /**
58    * @brief The As constructor
59    */
60   As(){};
61
62   /**
63    * @brief The As destructor
64    */
65   virtual ~As(){
66         xbt_free(p_name);
67   };
68
69   /**
70    * @brief Get the route and latency between two RoutingEdgs
71    * @details [long description]
72    * 
73    * @param src [description]
74    * @param dst [description]
75    * @param into [description]
76    * @param latency [description]
77    */
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;
82
83   /* The parser calls the following functions to inform the routing models
84    * that a new element is added to the AS currently built.
85    *
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;
92 };
93
94 /** @ingroup SURF_routing_interface
95  * @brief A routing edge
96  * @details [long description]
97  */
98 struct RoutingEdge {
99 public:
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;
107 };
108
109 struct RoutingEdgeImpl : public RoutingEdge {
110 public:
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);};
114
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;}
121 private:
122   AsPtr p_rcComponent;
123   e_surf_network_element_type_t p_rcType;
124   int m_id;
125   char *p_name;
126 };
127
128 struct RoutingEdgeWrapper : public RoutingEdge {
129 public:
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();}
138 private:
139   RoutingEdge *p_re;
140 };
141
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
144  */
145 class Onelink {
146 public:
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;
151   void *p_link;
152 };
153
154 /** @ingroup SURF_routing_interface
155  * @brief The class representing a whole routing platform
156  */
157 class RoutingPlatf {
158 public:
159   ~RoutingPlatf();
160   AsPtr p_root;
161   void *p_loopback;
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);
166 };
167
168 #endif /* NETWORK_ROUTING_HPP_ */