Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start initializing routing fields in the constructors, not with a shotgun
[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   As(const char*name);
52   /** @brief Close that AS: no more content can be added to it */
53   virtual void Seal()=0;
54   virtual ~As();
55
56   char *p_name = nullptr;
57   NetCard *p_netcard = nullptr;
58   As *p_routingFather = nullptr;
59
60   xbt_dynar_t p_indexNetworkElm = xbt_dynar_new(sizeof(char*),NULL);
61   xbt_dict_t p_bypassRoutes = nullptr;
62   e_surf_routing_hierarchy_t p_hierarchy = SURF_ROUTING_NULL;
63   xbt_dict_t p_routingSons = xbt_dict_new_homogeneous(NULL);
64   xbt_dynar_t p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
65
66
67
68   /**
69    * @brief Get the characteristics of the routing path between two points
70    *
71    * This function is used by the networking model to find the information it needs when starting a communication.
72    *
73    * The things are not straightforward because the platform can be routed using several routing models.
74    * 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.
75    * Some ASes may even not have any predefined links and use only coordinate informations to compute the latency.
76    *
77    * So, the path is constructed recursively, with each traversed AS adding its information to the set.
78    * The algorithm for that is explained in http://hal.inria.fr/hal-00650233/
79    * 
80    * @param src Initial point of the routing path
81    * @param dst Final point of the routing path
82    * @param into Container into which the links should be pushed
83    * @param latency Accumulator in which the latencies should be added
84    */
85   virtual void getRouteAndLatency(
86       NetCard *src, NetCard *dst,
87       sg_platf_route_cbarg_t into, double *latency)=0;
88   virtual xbt_dynar_t getOneLinkRoutes()=0;
89   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
90   virtual sg_platf_route_cbarg_t getBypassRoute(
91       NetCard *src, NetCard *dst,
92       double *lat)=0;
93
94   /* The parser calls the following functions to inform the routing models
95    * that a new element is added to the AS currently built.
96    *
97    * Of course, only the routing model of this AS is informed, not every ones */
98   virtual int parsePU(NetCard *elm)=0; /* A host or a router, whatever */
99   virtual int parseAS(NetCard *elm)=0;
100   virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
101   virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
102   virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
103 };
104
105 struct XBT_PRIVATE NetCardImpl : public NetCard {
106 public:
107   NetCardImpl(const char *name, e_surf_network_element_type_t componentType, As *component)
108   : component_(component),
109     componentType_(componentType),
110     name_(xbt_strdup(name)) {}
111   ~NetCardImpl() { xbt_free(name_);};
112
113   int getId() {return id_;}
114   int *getIdPtr() {return &id_;}
115   void setId(int id) {id_ = id;}
116   char *getName() {return name_;}
117   As *getRcComponent() {return component_;}
118   e_surf_network_element_type_t getRcType() {return componentType_;}
119 private:
120   As *component_;
121   e_surf_network_element_type_t componentType_;
122   int id_ = -1;
123   char *name_;
124 };
125
126 /** @ingroup SURF_routing_interface
127  * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the ns3 bindings
128  */
129 class Onelink {
130 public:
131   Onelink(void *link, NetCard *src, NetCard *dst)
132     : p_src(src), p_dst(dst), p_link(link) {};
133   NetCard *p_src;
134   NetCard *p_dst;
135   void *p_link;
136 };
137
138 /** @ingroup SURF_routing_interface
139  * @brief The class representing a whole routing platform
140  */
141 XBT_PUBLIC_CLASS RoutingPlatf {
142 public:
143   RoutingPlatf(void *loopback);
144   ~RoutingPlatf();
145   As *p_root = nullptr;
146   void *p_loopback;
147   xbt_dynar_t p_lastRoute = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
148   xbt_dynar_t getOneLinkRoutes(void);
149   xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
150   void getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t * links, double *latency);
151 };
152
153 /*************
154  * Callbacks *
155  *************/
156
157 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
158 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(As*)>) asCreatedCallbacks;
159
160 }
161 }
162
163 #endif /* NETWORK_ROUTING_HPP_ */