Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1f0589642a00d6e34ae1daa1ba50c70c256ca69b
[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 network card
31  * @details This represents a position in the network. One can route information between two netcards
32  */
33 class NetCard {
34 public:
35   virtual ~NetCard(){};
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   NetCard *p_netElem;
58   xbt_dynar_t p_linkUpDownList;
59
60   /**
61    * @brief The As constructor
62    */
63   As(){xbt_die("FIXME:DEADCODE");};
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     NetCard *src, NetCard *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     NetCard *src, NetCard *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(NetCard *elm)=0; /* A host or a router, whatever */
97   virtual int parseAS(NetCard *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 NetCardImpl : public NetCard {
104 public:
105   NetCardImpl(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   ~NetCardImpl() { 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 /** @ingroup SURF_routing_interface
123  * @brief Link of lenght 1, alongside with its source and destination. This is mainly usefull in the ns3 bindings
124  */
125 class Onelink {
126 public:
127   Onelink(void *link, NetCard *src, NetCard *dst)
128     : p_src(src), p_dst(dst), p_link(link) {};
129   NetCard *p_src;
130   NetCard *p_dst;
131   void *p_link;
132 };
133
134 /** @ingroup SURF_routing_interface
135  * @brief The class representing a whole routing platform
136  */
137 XBT_PUBLIC_CLASS RoutingPlatf {
138 public:
139   ~RoutingPlatf();
140   As *p_root;
141   void *p_loopback;
142   xbt_dynar_t p_lastRoute;
143   xbt_dynar_t getOneLinkRoutes(void);
144   xbt_dynar_t recursiveGetOneLinkRoutes(As *rc);
145   void getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t * links, double *latency);
146 };
147
148 /*************
149  * Callbacks *
150  *************/
151
152 XBT_PUBLIC_DATA(simgrid::surf::signal<void(NetCard*)>) routingEdgeCreatedCallbacks;
153 XBT_PUBLIC_DATA(simgrid::surf::signal<void(As*)>) asCreatedCallbacks;
154
155 }
156 }
157
158 #endif /* NETWORK_ROUTING_HPP_ */