Logo AND Algorithmique Numérique Distribuée

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