Logo AND Algorithmique Numérique Distribuée

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