Logo AND Algorithmique Numérique Distribuée

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