Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cb29f193e5af1791eb0af3162e93cd31d0873de3
[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 <float.h>
16
17 #include <vector>
18 #include <map>
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 surf {
28
29 /***********
30  * Classes *
31  ***********/
32
33 class XBT_PRIVATE RoutingModelDescription;
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(){};
45   virtual int id()=0; // Our rank in the vertices_ array of our containing AS.
46   virtual void setId(int id)=0;
47   virtual char *name()=0;
48   virtual s4u::As *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 };
53
54 struct XBT_PRIVATE NetCardImpl : public NetCard {
55 public:
56   NetCardImpl(const char *name, e_surf_network_element_type_t componentType, s4u::As *as)
57   : name_(xbt_strdup(name)),
58     componentType_(componentType),
59     containingAS_(as)
60   {}
61   ~NetCardImpl() { xbt_free(name_);};
62
63   int id()           override {return id_;}
64   void setId(int id) override {id_ = id;}
65   char *name()       override {return name_;}
66   s4u::As *containingAS() override {return containingAS_;}
67
68   bool isAS()        override {return componentType_ == SURF_NETWORK_ELEMENT_AS;}
69   bool isHost()      override {return componentType_ == SURF_NETWORK_ELEMENT_HOST;}
70   bool isRouter()    override {return componentType_ == SURF_NETWORK_ELEMENT_ROUTER;}
71
72 private:
73   int id_ = -1;
74   char *name_;
75   e_surf_network_element_type_t componentType_;
76   s4u::As *containingAS_;
77 };
78
79 /** @ingroup SURF_routing_interface
80  * @brief Link of length 1, alongside with its source and destination. This is mainly useful in the ns3 bindings
81  */
82 class Onelink {
83 public:
84   Onelink(void *link, NetCard *src, NetCard *dst)
85     : src_(src), dst_(dst), link_(link) {};
86   NetCard *src_;
87   NetCard *dst_;
88   void *link_;
89 };
90
91 /** @ingroup SURF_routing_interface
92  * @brief The class representing a whole routing platform
93  */
94 XBT_PUBLIC_CLASS RoutingPlatf {
95 public:
96   RoutingPlatf(Link *loopback);
97   ~RoutingPlatf();
98   s4u::As *root_ = nullptr;
99   Link *loopback_;
100   xbt_dynar_t getOneLinkRoutes(void);
101   void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
102 };
103
104 /*************
105  * Callbacks *
106  *************/
107
108 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
109 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
110
111 }
112 }
113
114 #endif /* NETWORK_ROUTING_HPP_ */