Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more documentation in surf::Routing
[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 #include <xbt/signal.hpp>
12
13 #include "surf_interface.hpp"
14 #include <float.h>
15
16 XBT_PUBLIC(void) routing_model_create( void *loopback);
17
18 namespace simgrid {
19 namespace surf {
20
21 /***********
22  * Classes *
23  ***********/
24
25 class As;
26 class XBT_PRIVATE RoutingModelDescription;
27 class XBT_PRIVATE Onelink;
28 class RoutingPlatf;
29
30 /** @ingroup SURF_routing_interface
31  * @brief A network card
32  * @details This represents a position in the network. One can route information between two netcards
33  */
34 class NetCard {
35 public:
36   virtual ~NetCard(){};
37   virtual int getId()=0;
38   virtual int *getIdPtr()=0;
39   virtual void setId(int id)=0;
40   virtual char *getName()=0;
41   virtual As *getRcComponent()=0;
42   virtual e_surf_network_element_type_t getRcType()=0;
43 };
44
45 /** @ingroup SURF_routing_interface
46  * @brief The Autonomous System (AS) routing interface
47  * @details [TODO]
48  */
49 class As {
50 public:
51   xbt_dynar_t p_indexNetworkElm;
52   xbt_dict_t p_bypassRoutes;    /* store bypass routes */
53   routing_model_description_t p_modelDesc;
54   e_surf_routing_hierarchy_t p_hierarchy;
55   char *p_name;
56   As *p_routingFather;
57   xbt_dict_t p_routingSons;
58   NetCard *p_netElem;
59   xbt_dynar_t p_linkUpDownList;
60
61   /**
62    * @brief The As constructor
63    */
64   As(){};
65
66   /**
67    * @brief The As destructor
68    */
69   virtual ~As(){
70         xbt_free(p_name);
71         if (p_netElem)
72                 delete p_netElem;
73   };
74
75   /**
76    * @brief Get the characteristics of the routing path between two points
77    *
78    * This function is used by the networking model to find the information it needs when starting a communication.
79    *
80    * The things are not straightforward because the platform can be routed using several routing models.
81    * Some ASes may be routed in full, others may have only some connection information and use a shortest path on top of that, and so on.
82    * Some ASes may even not have any predefined links and use only coordinate informations to compute the latency.
83    *
84    * So, the path is constructed recursively, with each traversed AS adding its information to the set.
85    * The algorithm for that is explained in http://hal.inria.fr/hal-00650233/
86    * 
87    * @param src Initial point of the routing path
88    * @param dst Final point of the routing path
89    * @param into Container into which the links should be pushed
90    * @param latency Accumulator in which the latencies should be added
91    */
92   virtual void getRouteAndLatency(
93       NetCard *src, NetCard *dst,
94       sg_platf_route_cbarg_t into, double *latency)=0;
95   virtual xbt_dynar_t getOneLinkRoutes()=0;
96   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
97   virtual sg_platf_route_cbarg_t getBypassRoute(
98       NetCard *src, NetCard *dst,
99       double *lat)=0;
100
101   /* The parser calls the following functions to inform the routing models
102    * that a new element is added to the AS currently built.
103    *
104    * Of course, only the routing model of this AS is informed, not every ones */
105   virtual int parsePU(NetCard *elm)=0; /* A host or a router, whatever */
106   virtual int parseAS(NetCard *elm)=0;
107   virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
108   virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
109   virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
110 };
111
112 struct XBT_PRIVATE NetCardImpl : public NetCard {
113 public:
114   NetCardImpl(char *name, int id, e_surf_network_element_type_t rcType, As *rcComponent)
115   : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
116   ~NetCardImpl() { xbt_free(p_name);};
117
118   int getId() {return m_id;}
119   int *getIdPtr() {return &m_id;}
120   void setId(int id) {m_id = id;}
121   char *getName() {return p_name;}
122   As *getRcComponent() {return p_rcComponent;}
123   e_surf_network_element_type_t getRcType() {return p_rcType;}
124 private:
125   As *p_rcComponent;
126   e_surf_network_element_type_t p_rcType;
127   int m_id;
128   char *p_name;
129 };
130
131 /** @ingroup SURF_routing_interface
132  * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the ns3 bindings
133  */
134 class Onelink {
135 public:
136   Onelink(void *link, NetCard *src, NetCard *dst)
137     : p_src(src), p_dst(dst), p_link(link) {};
138   NetCard *p_src;
139   NetCard *p_dst;
140   void *p_link;
141 };
142
143 /** @ingroup SURF_routing_interface
144  * @brief The class representing a whole routing platform
145  */
146 XBT_PUBLIC_CLASS RoutingPlatf {
147 public:
148   ~RoutingPlatf();
149   As *p_root;
150   void *p_loopback;
151   xbt_dynar_t p_lastRoute;
152   xbt_dynar_t getOneLinkRoutes(void);
153   xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
154   void getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t * links, double *latency);
155 };
156
157 /*************
158  * Callbacks *
159  *************/
160
161 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) routingEdgeCreatedCallbacks;
162 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(As*)>) asCreatedCallbacks;
163
164 }
165 }
166
167 #endif /* NETWORK_ROUTING_HPP_ */