Logo AND Algorithmique Numérique Distribuée

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