Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / include / simgrid / kernel / routing / NetPoint.hpp
1 /* Copyright (c) 2013-2022. 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 KERNEL_ROUTING_NETPOINT_HPP_
7 #define KERNEL_ROUTING_NETPOINT_HPP_
8
9 #include <xbt/Extendable.hpp>
10 #include <xbt/base.h>
11 #include <xbt/signal.hpp>
12
13 #include <simgrid/kernel/routing/NetZoneImpl.hpp>
14
15 namespace simgrid {
16
17 extern template class XBT_PUBLIC xbt::Extendable<kernel::routing::NetPoint>;
18
19 namespace kernel {
20 namespace routing {
21
22 /** @ingroup ROUTING_API
23  *  @brief Network cards are the vertices in the graph representing the network, used to compute paths between nodes.
24  *
25  * @details This represents a position in the network. One can send information between two netpoints
26  */
27 class NetPoint : public xbt::Extendable<NetPoint> {
28 public:
29   enum class Type { Host, Router, NetZone };
30
31   NetPoint(const std::string& name, NetPoint::Type component_type);
32
33   // Our rank in the vertices_ array of the netzone that contains us.
34   unsigned long id() const { return id_; }
35   const std::string& get_name() const { return name_; }
36   const char* get_cname() const { return name_.c_str(); }
37   /** @brief the NetZone in which this NetPoint is included */
38   NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
39   /** @brief Set the NetZone in which this NetPoint is included */
40   NetPoint* set_englobing_zone(NetZoneImpl* netzone_p);
41   NetPoint* set_coordinates(const std::string& coords);
42
43   bool is_netzone() const { return component_type_ == Type::NetZone; }
44   bool is_host() const { return component_type_ == Type::Host; }
45   bool is_router() const { return component_type_ == Type::Router; }
46
47   static xbt::signal<void(NetPoint&)> on_creation;
48
49   bool operator<(const NetPoint& rhs) const { return name_ < rhs.name_; }
50
51 private:
52   unsigned long id_ = -1;
53   std::string name_;
54   NetPoint::Type component_type_;
55   NetZoneImpl* englobing_zone_ = nullptr;
56 };
57 } // namespace routing
58 } // namespace kernel
59 } // namespace simgrid
60
61 XBT_PUBLIC simgrid::kernel::routing::NetPoint* sg_netpoint_by_name_or_null(const char* name);
62
63 #endif /* KERNEL_ROUTING_NETPOINT_HPP_ */