Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simgrid::Host instead of xbt_dictelt_t for root main object
[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 namespace simgrid {
18 namespace surf {
19
20 /***********
21  * Classes *
22  ***********/
23
24 class As;
25 class XBT_PRIVATE RoutingModelDescription;
26 class XBT_PRIVATE Onelink;
27 class RoutingPlatf;
28
29 /** @ingroup SURF_routing_interface
30  * @brief A routing edge
31  * @details [long description]
32  */
33 class RoutingEdge {
34 public:
35   virtual ~RoutingEdge(){};
36   virtual int getId()=0;
37   virtual int *getIdPtr()=0;
38   virtual void setId(int id)=0;
39   virtual char *getName()=0;
40   virtual As *getRcComponent()=0;
41   virtual e_surf_network_element_type_t getRcType()=0;
42 };
43
44 /** @ingroup SURF_routing_interface
45  * @brief The Autonomous System (AS) routing interface
46  * @details [TODO]
47  */
48 class As {
49 public:
50   xbt_dynar_t p_indexNetworkElm;
51   xbt_dict_t p_bypassRoutes;    /* store bypass routes */
52   routing_model_description_t p_modelDesc;
53   e_surf_routing_hierarchy_t p_hierarchy;
54   char *p_name;
55   As *p_routingFather;
56   xbt_dict_t p_routingSons;
57   RoutingEdge *p_netElem;
58   xbt_dynar_t p_linkUpDownList;
59
60   /**
61    * @brief The As constructor
62    */
63   As(){};
64
65   /**
66    * @brief The As destructor
67    */
68   virtual ~As(){
69         xbt_free(p_name);
70         if (p_netElem)
71                 delete p_netElem;
72   };
73
74   /**
75    * @brief Get the route and latency between two RoutingEdges
76    * @details [long description]
77    * 
78    * @param src [description]
79    * @param dst [description]
80    * @param into [description]
81    * @param latency [description]
82    */
83   virtual void getRouteAndLatency(
84     RoutingEdge *src, RoutingEdge *dst,
85     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(
89     RoutingEdge *src, RoutingEdge *dst,
90     double *lat)=0;
91
92   /* The parser calls the following functions to inform the routing models
93    * that a new element is added to the AS currently built.
94    *
95    * Of course, only the routing model of this AS is informed, not every ones */
96   virtual int parsePU(RoutingEdge *elm)=0; /* A host or a router, whatever */
97   virtual int parseAS(RoutingEdge *elm)=0;
98   virtual void parseRoute(sg_platf_route_cbarg_t route)=0;
99   virtual void parseASroute(sg_platf_route_cbarg_t route)=0;
100   virtual void parseBypassroute(sg_platf_route_cbarg_t e_route)=0;
101 };
102
103 struct XBT_PRIVATE RoutingEdgeImpl : public RoutingEdge {
104 public:
105   RoutingEdgeImpl(char *name, int id, e_surf_network_element_type_t rcType, As *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   As *getRcComponent() {return p_rcComponent;}
114   e_surf_network_element_type_t getRcType() {return p_rcType;}
115 private:
116   As *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   As *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 ns3 bindings
138  */
139 class Onelink {
140 public:
141   Onelink(void *link, RoutingEdge *src, RoutingEdge *dst)
142     : p_src(src), p_dst(dst), p_link(link) {};
143   RoutingEdge *p_src;
144   RoutingEdge *p_dst;
145   void *p_link;
146 };
147
148 /** @ingroup SURF_routing_interface
149  * @brief The class representing a whole routing platform
150  */
151 XBT_PUBLIC_CLASS RoutingPlatf {
152 public:
153   ~RoutingPlatf();
154   As *p_root;
155   void *p_loopback;
156   xbt_dynar_t p_lastRoute;
157   xbt_dynar_t getOneLinkRoutes(void);
158   xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
159   void getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, xbt_dynar_t * links, double *latency);
160 };
161
162 /*************
163  * Callbacks *
164  *************/
165
166 XBT_PUBLIC_DATA(surf_callback(void, RoutingEdge*)) routingEdgeCreatedCallbacks;
167 XBT_PUBLIC_DATA(surf_callback(void, As*)) asCreatedCallbacks;
168
169 }
170 }
171
172 #endif /* NETWORK_ROUTING_HPP_ */