SOLA
Loading...
Searching...
No Matches
node_info.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef MINHTON_CORE_NODE_INFO_H_
8#define MINHTON_CORE_NODE_INFO_H_
9
10#include <string>
11
12#include "minhton/core/logical_node_info.h"
13#include "minhton/core/physical_node_info.h"
14#include "solanet/serializer/serialize.h"
15
16namespace minhton {
17
18enum class NodeStatus : uint8_t { kUninit = 0, kRunning = 1, kLeft = 2, kFailed = 3 };
19
24class NodeInfo {
25public:
26 NodeInfo() = default;
27
35 NodeInfo(uint32_t level, uint32_t number, uint16_t fanout);
36
46 NodeInfo(uint32_t level, uint32_t number, uint16_t fanout, const std::string &address,
47 uint16_t port);
48
52
58 void setLogicalNodeInfo(const minhton::LogicalNodeInfo &l_node_info);
59
63
69 void setPhysicalNodeInfo(const minhton::PhysicalNodeInfo &p_node_info);
70
71 std::string getString() const;
72
84 bool isInitialized() const;
85
86 // -------------- LogicalNodeInfo access Helper methods -------------------
87
89 void setPosition(uint32_t level, uint32_t number);
90
92 void setPosition(LogicalNodeInfo other);
93
95 void setFanout(uint16_t fanout);
96
98 uint32_t getLevel() const;
99
101 uint32_t getNumber() const;
102
104 uint16_t getFanout() const;
105
107 NodeStatus getStatus() const;
108
110 void setStatus(NodeStatus status);
111
113 bool isValidPeer() const;
114
115 // -------------- PhysicalNodeInfo access Helper methods -------------------
116
118 void setPort(uint16_t port);
119
121 void setAddress(const std::string &address);
122
124 uint16_t getPort() const;
125
127 std::string getAddress() const;
128
130 uint32_t getAddressValue() const;
131
132 friend bool operator==(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
133 friend bool operator!=(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
134 friend bool operator<(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
135 friend bool operator<=(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
136 friend bool operator>(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
137 friend bool operator>=(const minhton::NodeInfo &n1, const minhton::NodeInfo &n2);
138
139 SERIALIZE(l_node_info_, p_node_info_);
140
141private:
142 minhton::LogicalNodeInfo l_node_info_;
143 minhton::PhysicalNodeInfo p_node_info_;
144
145 NodeStatus status_{NodeStatus::kUninit};
146};
147
149 std::size_t operator()(const minhton::NodeInfo &node) const {
150 using std::hash;
151 using std::size_t;
152
153 std::size_t peer_hash = minhton::LogicalNodeInfoHasher()(node.getLogicalNodeInfo());
154 std::size_t network_hash = minhton::PhysicalNodeInfoHasher()(node.getPhysicalNodeInfo());
155
156 return peer_hash ^ network_hash;
157 }
158};
159
160} // namespace minhton
161#endif
Definition logical_node_info.h:23
Definition node_info.h:24
uint16_t getPort() const
Definition node_info.cpp:59
uint32_t getAddressValue() const
Definition node_info.cpp:63
uint32_t getLevel() const
Definition node_info.cpp:49
uint32_t getNumber() const
Definition node_info.cpp:51
void setPhysicalNodeInfo(const minhton::PhysicalNodeInfo &p_node_info)
Definition node_info.cpp:33
minhton::PhysicalNodeInfo getPhysicalNodeInfo() const
Definition node_info.cpp:32
void setFanout(uint16_t fanout)
Helper method, which sets the fanout for the internal LogicalNodeInfo object.
Definition node_info.cpp:47
std::string getAddress() const
Definition node_info.cpp:61
NodeStatus getStatus() const
Definition node_info.cpp:65
void setLogicalNodeInfo(const minhton::LogicalNodeInfo &l_node_info)
Definition node_info.cpp:28
void setAddress(const std::string &address)
Helper method, which sets the address for PhysicalNodeInfo.
Definition node_info.cpp:57
bool isValidPeer() const
Definition node_info.cpp:68
void setStatus(NodeStatus status)
sets the status of the node
Definition node_info.cpp:66
void setPosition(uint32_t level, uint32_t number)
Helper method, which sets the position for the internal LogicalNodeInfo object.
Definition node_info.cpp:41
minhton::LogicalNodeInfo getLogicalNodeInfo() const
Definition node_info.cpp:26
uint16_t getFanout() const
Definition node_info.cpp:53
bool isInitialized() const
Definition node_info.cpp:37
void setPort(uint16_t port)
Helper method, which sets the port for PhysicalNodeInfo.
Definition node_info.cpp:55
Definition physical_node_info.h:23
Definition minhton_watchdog_ns3.cpp:24
Definition logical_node_info.h:233
Definition node_info.h:148
Definition physical_node_info.h:110