Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SGpp] make ROUTING_HOST_LEVEL private. That was painful
[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 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 /* Note: As and RoutingEdge are declared 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 class Onelink;
33 typedef Onelink *OnelinkPtr;
34
35 class RoutingPlatf;
36 typedef RoutingPlatf *RoutingPlatfPtr;
37
38 /** @ingroup SURF_routing_interface
39  * @brief The Autonomous System (AS) routing interface
40  * @details [TODO]
41  */
42 struct As {
43 public:
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;
48   char *p_name;
49   AsPtr p_routingFather;
50   xbt_dict_t p_routingSons;
51   RoutingEdgePtr p_netElem;
52   xbt_dynar_t p_linkUpDownList;
53
54   /**
55    * @brief The As constructor
56    */
57   As(){};
58
59   /**
60    * @brief The As destructor
61    */
62   virtual ~As(){
63         xbt_free(p_name);
64   };
65
66   /**
67    * @brief Get the route and latency between two RoutingEdges
68    * @details [long description]
69    * 
70    * @param src [description]
71    * @param dst [description]
72    * @param into [description]
73    * @param latency [description]
74    */
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;
79
80   /* The parser calls the following functions to inform the routing models
81    * that a new element is added to the AS currently built.
82    *
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;
89 };
90
91 /** @ingroup SURF_routing_interface
92  * @brief A routing edge
93  * @details [long description]
94  */
95 struct RoutingEdge {
96 public:
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;
104 };
105
106 struct RoutingEdgeImpl : public RoutingEdge {
107 public:
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);};
111
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;}
118 private:
119   AsPtr p_rcComponent;
120   e_surf_network_element_type_t p_rcType;
121   int m_id;
122   char *p_name;
123 };
124
125 struct RoutingEdgeWrapper : public RoutingEdge {
126 public:
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();}
135 private:
136   RoutingEdge *p_re;
137 };
138
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
141  */
142 class Onelink {
143 public:
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;
148   void *p_link;
149 };
150
151 /** @ingroup SURF_routing_interface
152  * @brief The class representing a whole routing platform
153  */
154 XBT_PUBLIC_CLASS RoutingPlatf {
155 public:
156   ~RoutingPlatf();
157   AsPtr p_root;
158   void *p_loopback;
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);
163 };
164
165 #endif /* NETWORK_ROUTING_HPP_ */