25#ifndef JOIN_FABRIC_NEIGHBOR_HPP
26#define JOIN_FABRIC_NEIGHBOR_HPP
38#include <linux/neighbour.h>
44 class NeighborManager;
66 return lhs._index == rhs._index && lhs._ip == rhs._ip;
77 if (lhs._index != rhs._index)
79 return lhs._index < rhs._index;
81 return lhs._ip < rhs._ip;
98 using Ptr = std::shared_ptr<Neighbor>;
114 uint32_t
index () const noexcept;
132 uint16_t
state () const;
144 bool isStale () const noexcept;
171 int set (const
MacAddress& macAddress, uint16_t
state = NUD_PERMANENT,
bool sync = false) const;
178 int remove (
bool sync = false) const;
194 uint16_t _state = NUD_NONE;
197 mutable
Mutex _mutex;
225 return lhs->_index == rhs->_index && lhs->_ip == rhs->_ip;
244 if (lhs->_index != rhs->_index)
246 return lhs->_index < rhs->_index;
248 return lhs->_ip < rhs->_ip;
265 size_t h = std::hash<uint32_t>{}(
key._index);
266 h ^= std::hash<join::IpAddress>{}(
key._ip) + 0x9e3779b9 + (h << 6) + (h >> 2);
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
MAC address class.
Definition macaddress.hpp:46
class used to protect shared data from being simultaneously accessed by multiple threads.
Definition mutex.hpp:37
ARP / NDP neighbor manager class.
Definition neighbormanager.hpp:138
class representing a single ARP / NDP neighbor cache entry.
Definition neighbor.hpp:88
MacAddress mac() const
get the address resolved for this entry.
Definition neighbor.cpp:67
std::shared_ptr< Neighbor > Ptr
Definition neighbor.hpp:98
bool isPermanent() const noexcept
is the entry in NUD_PERMANENT state (static).
Definition neighbor.cpp:105
bool isIncomplete() const noexcept
is the entry in NUD_INCOMPLETE state (resolution ongoing).
Definition neighbor.cpp:114
friend bool operator<(const Neighbor::Ptr &lhs, const Neighbor::Ptr &rhs) noexcept
compare two neighbor for ordering.
Definition neighbor.hpp:234
uint32_t index() const noexcept
get interface index.
Definition neighbor.cpp:49
Neighbor()=delete
create instance.
uint16_t state() const
get the NUD state bitmask.
Definition neighbor.cpp:77
~Neighbor()=default
destroy instance.
bool isFailed() const noexcept
is the entry in NUD_FAILED state.
Definition neighbor.cpp:123
int set(const MacAddress &macAddress, uint16_t state=NUD_PERMANENT, bool sync=false) const
update or replace this neighbor entry in the kernel table.
Definition neighbor.cpp:132
bool isStale() const noexcept
is the entry in NUD_STALE state.
Definition neighbor.cpp:96
const IpAddress & ip() const noexcept
get the destination address.
Definition neighbor.cpp:58
int remove(bool sync=false) const
remove this neighbor entry from the kernel table.
Definition neighbor.cpp:141
bool isReachable() const noexcept
is the entry in NUD_REACHABLE state.
Definition neighbor.cpp:87
const std::string key(65, 'a')
key.
Definition acceptor.hpp:32
bool operator<(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower.
Definition endpoint.hpp:207
std::vector< Neighbor::Ptr > NeighborList
list of neighbors.
Definition neighbor.hpp:252
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183
key identifying a neighbor cache entry.
Definition neighbor.hpp:50
uint32_t _index
interface index.
Definition neighbor.hpp:52
IpAddress _ip
destination address.
Definition neighbor.hpp:55