Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move the rootAS from routing_platf into the EngineImpl
[simgrid.git] / src / surf / surf_routing.hpp
1 /* Copyright (c) 2013-2016. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef NETWORK_ROUTING_HPP_
7 #define NETWORK_ROUTING_HPP_
8
9 #include <xbt/base.h>
10 #include <xbt/signal.hpp>
11
12 #include "surf_interface.hpp"
13 #include "src/kernel/routing/AsImpl.hpp"
14
15 #include <float.h>
16 #include <vector>
17
18 SG_BEGIN_DECL()
19 XBT_PRIVATE xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
20 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);
21 SG_END_DECL()
22
23 namespace simgrid {
24 namespace kernel {
25 namespace routing {
26
27   XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
28   XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
29
30 /***********
31  * Classes *
32  ***********/
33
34 class XBT_PRIVATE Onelink;
35 class RoutingPlatf;
36
37 /** @ingroup SURF_routing_interface
38  * @brief Network cards are the vertices in the graph representing the network, used to compute paths between nodes.
39  *
40  * @details This represents a position in the network. One can route information between two netcards
41  */
42 class NetCard {
43 public:
44   virtual ~NetCard()            = default;
45   virtual unsigned int id()=0; // Our rank in the vertices_ array of our containing AS.
46   virtual std::string name()    = 0;
47   virtual const char* cname()    = 0;
48   virtual AsImpl* containingAS() = 0; // This is the AS in which I am
49   virtual bool isAS()=0;
50   virtual bool isHost()=0;
51   virtual bool isRouter()=0;
52   enum class Type {
53     Host, Router, As
54   };
55 };
56
57 struct XBT_PRIVATE NetCardImpl : public NetCard {
58 public:
59   NetCardImpl(std::string name, NetCard::Type componentType, AsImpl* containingAS)
60       : name_(name), componentType_(componentType), containingAS_(containingAS)
61   {
62     if (containingAS != nullptr)
63       id_ = containingAS->addComponent(this);
64     simgrid::kernel::routing::netcardCreatedCallbacks(this);
65   }
66   ~NetCardImpl() = default;
67
68   unsigned int id()  override {return id_;}
69   std::string name() override { return name_; }
70   const char* cname() override { return name_.c_str(); }
71   AsImpl *containingAS() override {return containingAS_;}
72
73   bool isAS()        override {return componentType_ == Type::As;}
74   bool isHost()      override {return componentType_ == Type::Host;}
75   bool isRouter()    override {return componentType_ == Type::Router;}
76
77 private:
78   unsigned int id_;
79   std::string name_;
80   NetCard::Type componentType_;
81   AsImpl *containingAS_;
82 };
83
84 class AsRoute {
85 public:
86   explicit AsRoute(NetCard* gwSrc, NetCard* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {}
87   const NetCard* gw_src;
88   const NetCard* gw_dst;
89   std::vector<Link*> links;
90 };
91
92 /** @ingroup SURF_routing_interface
93  * @brief Link of length 1, alongside with its source and destination. This is mainly useful in the ns3 bindings
94  */
95 class Onelink {
96 public:
97   Onelink(Link* link, NetCard* src, NetCard* dst) : src_(src), dst_(dst), link_(link){};
98   NetCard* src_;
99   NetCard* dst_;
100   Link* link_;
101 };
102
103 /** @ingroup SURF_routing_interface
104  * @brief The class representing a whole routing platform
105  */
106 XBT_PUBLIC_CLASS RoutingPlatf {
107 public:
108   explicit RoutingPlatf();
109   ~RoutingPlatf();
110 };
111
112 }}}
113
114 #endif /* NETWORK_ROUTING_HPP_ */