SOLA
Loading...
Searching...
No Matches
physical_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_PHYSICAL_NODE_INFO_H_
8#define MINHTON_CORE_PHYSICAL_NODE_INFO_H_
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14#include "solanet/serializer/serialize.h"
15
16namespace minhton {
17constexpr uint16_t kPortMin = 1024;
18constexpr uint16_t kPortMax = UINT16_MAX;
19
24public:
28 PhysicalNodeInfo() = default;
29
36 PhysicalNodeInfo(const std::string &address, uint16_t port);
37
39 uint16_t getPort() const;
40
48 void setPort(uint16_t port);
49
51 std::string getAddress() const;
52
58 void setAddress(std::string address);
59
61 uint32_t getAddressValue() const;
62
64 std::string getString() const;
65
75 bool isInitialized() const;
76
78 friend bool operator==(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
79
81 friend bool operator!=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
82
84 friend bool operator<(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
85
87 friend bool operator<=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
88
90 friend bool operator>(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
91
93 friend bool operator>=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2);
94
95 SERIALIZE(address_, port_);
96
97private:
98 uint16_t port_ = 0;
99 std::string address_ = "";
100
101 std::vector<std::string> splitString(const std::string &, char token);
102
104 static bool isIpv4Address(const std::string &str);
105
107 static bool isIpv6Address(const std::string &str);
108};
109
111 std::size_t operator()(const minhton::PhysicalNodeInfo &net) const {
112 using std::hash;
113 using std::size_t;
114 using std::string;
115
116 std::string rep = (net.getAddress().empty() ? "invalidaddress" : net.getAddress()) + ":" +
117 std::to_string(net.getPort()) + ":" +
118 (net.isInitialized() ? "init" : "uninit");
119 std::size_t res = std::hash<std::string>()(rep);
120 return res;
121 }
122};
123
124} // namespace minhton
125#endif
Definition physical_node_info.h:23
void setPort(uint16_t port)
Definition physical_node_info.cpp:38
friend bool operator>(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:129
std::string getAddress() const
Definition physical_node_info.cpp:36
friend bool operator<(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:115
friend bool operator>=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:133
std::string getString() const
Definition physical_node_info.cpp:66
friend bool operator<=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:122
bool isInitialized() const
Definition physical_node_info.cpp:73
uint32_t getAddressValue() const
Definition physical_node_info.cpp:78
uint16_t getPort() const
Definition physical_node_info.cpp:35
friend bool operator!=(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:111
void setAddress(std::string address)
Definition physical_node_info.cpp:43
friend bool operator==(const minhton::PhysicalNodeInfo &n1, const minhton::PhysicalNodeInfo &n2)
Definition physical_node_info.cpp:107
Definition minhton_watchdog_ns3.cpp:24
Definition physical_node_info.h:110