Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix for manually crafted clusters.
[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 "src/surf/xml/platf_private.hpp" // FIXME: including this here is pure madness. KILKILKIL XML.
15 #include "src/surf/AsImpl.hpp"
16
17 #include <float.h>
18 #include <vector>
19
20 SG_BEGIN_DECL()
21 XBT_PUBLIC(void) routing_model_create(Link *loopback);
22 XBT_PRIVATE xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
23 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);
24 SG_END_DECL()
25
26 namespace simgrid {
27 namespace routing {
28
29   XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
30   XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
31
32 /***********
33  * Classes *
34  ***********/
35
36 class XBT_PRIVATE Onelink;
37 class RoutingPlatf;
38
39 /** @ingroup SURF_routing_interface
40  * @brief Network cards are the vertices in the graph representing the network, used to compute paths between nodes.
41  *
42  * @details This represents a position in the network. One can route information between two netcards
43  */
44 class NetCard {
45 public:
46   virtual ~NetCard(){};
47   virtual int id()=0; // Our rank in the vertices_ array of our containing AS.
48   virtual char *name()=0;
49   virtual AsImpl *containingAS()=0; // This is the AS in which I am
50   virtual bool isAS()=0;
51   virtual bool isHost()=0;
52   virtual bool isRouter()=0;
53   enum class Type {
54     Host, Router, As
55   };
56 };
57
58 struct XBT_PRIVATE NetCardImpl : public NetCard {
59 public:
60   NetCardImpl(const char *name, NetCard::Type componentType, AsImpl *containingAS)
61   : name_(xbt_strdup(name)),
62     componentType_(componentType),
63     containingAS_(containingAS)
64   {
65     if (containingAS != nullptr)
66       id_ = containingAS->addComponent(this);
67     simgrid::routing::netcardCreatedCallbacks(this);
68   }
69   ~NetCardImpl() { xbt_free(name_);};
70
71   int id()           override {return id_;}
72   char *name()       override {return name_;}
73   AsImpl *containingAS() override {return containingAS_;}
74
75   bool isAS()        override {return componentType_ == Type::As;}
76   bool isHost()      override {return componentType_ == Type::Host;}
77   bool isRouter()    override {return componentType_ == Type::Router;}
78
79 private:
80   int id_ = -1;
81   char *name_;
82   NetCard::Type componentType_;
83   AsImpl *containingAS_;
84 };
85
86 /** @ingroup SURF_routing_interface
87  * @brief Link of length 1, alongside with its source and destination. This is mainly useful in the ns3 bindings
88  */
89 class Onelink {
90 public:
91   Onelink(void *link, NetCard *src, NetCard *dst)
92     : src_(src), dst_(dst), link_(link) {};
93   NetCard *src_;
94   NetCard *dst_;
95   void *link_;
96 };
97
98 /** @ingroup SURF_routing_interface
99  * @brief The class representing a whole routing platform
100  */
101 XBT_PUBLIC_CLASS RoutingPlatf {
102 public:
103   explicit RoutingPlatf(Link *loopback);
104   ~RoutingPlatf();
105   AsImpl *root_ = nullptr;
106   Link *loopback_;
107   xbt_dynar_t getOneLinkRoutes(void);
108   void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
109 };
110
111 }
112 }
113
114 #endif /* NETWORK_ROUTING_HPP_ */