25#ifndef JOIN_FABRIC_ROUTE_MANAGER_HPP
26#define JOIN_FABRIC_ROUTE_MANAGER_HPP
60 return RouteChangeType (
static_cast<uint32_t
> (a) &
static_cast<uint32_t
> (b));
71 return RouteChangeType (
static_cast<uint32_t
> (a) |
static_cast<uint32_t
> (b));
82 return RouteChangeType (
static_cast<uint32_t
> (a) ^
static_cast<uint32_t
> (b));
250 uint32_t metric = 0,
bool sync =
false);
262 int addRoute (
const std::string& interfaceName,
const IpAddress& dest, uint32_t prefix,
263 const IpAddress& gateway = {}, uint32_t metric = 0,
bool sync =
false);
273 int removeRoute (uint32_t index,
const IpAddress& dest, uint32_t prefix,
bool sync =
false);
283 int removeRoute (
const std::string& interfaceName,
const IpAddress& dest, uint32_t prefix,
bool sync =
false);
291 int flushRoutes (uint32_t index,
bool sync =
false);
299 int flushRoutes (
const std::string& interfaceName,
bool sync =
false);
312 int setRoute (uint32_t index,
const IpAddress& dest, uint32_t prefix,
const IpAddress& gateway, uint32_t metric,
320 int dumpRoutes (
bool sync =
false);
326 void onMessage (
struct nlmsghdr* nlh)
override;
332 void onRouteMessage (
struct nlmsghdr* nlh);
338 void notifyRouteUpdate (
const RouteInfo& info);
348 Route::Ptr acquire (uint32_t index,
const IpAddress& dest, uint32_t prefix, RouteInfo& info);
351 std::unordered_map<RouteKey, Route::Ptr> _routes;
357 std::unordered_map<uint64_t, RouteNotify> _routeListeners;
360 std::atomic<uint64_t> _listenerCounter{0};
IPv6, IPv4 address class.
Definition ip_address.hpp:51
base class for netlink-based managers.
Definition netlink_manager.hpp:51
Reactor & reactor() const noexcept
get the event loop reactor.
Definition netlink_manager.cpp:52
static Reactor & reactor()
get the global Reactor instance.
Definition reactor.cpp:584
Reactor class.
Definition reactor.hpp:156
kernel routing table manager class.
Definition route_manager.hpp:141
uint64_t addRouteListener(const RouteNotify &cb)
register a callback invoked on any route table change.
Definition route_manager.cpp:160
int removeRoute(uint32_t index, const IpAddress &dest, uint32_t prefix, bool sync=false)
remove a route entry from the kernel table.
Definition route_manager.cpp:244
std::function< void(const RouteInfo &info)> RouteNotify
Definition route_manager.hpp:143
RouteManager & operator=(const RouteManager &)=delete
assign instance by copy.
int flushRoutes(uint32_t index, bool sync=false)
flush all route entries for a given interface.
Definition route_manager.cpp:300
RouteList enumerate()
enumerate all cached route entries.
Definition route_manager.cpp:97
static RouteManager & instance()
get the singleton instance.
Definition route_manager.cpp:61
int refresh()
refresh all data.
Definition route_manager.cpp:146
Route::Ptr findByIndex(uint32_t index, const IpAddress &dest, uint32_t prefix)
find a route entry by interface index, destination and prefix.
Definition route_manager.cpp:71
void removeRouteListener(uint64_t id)
unregister a previously registered callback.
Definition route_manager.cpp:176
RouteManager(Reactor &reactor=ReactorThread::reactor())
create instance.
Definition route_manager.cpp:41
RouteManager(RouteManager &&)=delete
create instance by move.
RouteManager(const RouteManager &)=delete
create instance by copy.
int addRoute(uint32_t index, const IpAddress &dest, uint32_t prefix, const IpAddress &gateway={}, uint32_t metric=0, bool sync=false)
add a route entry in the kernel table.
Definition route_manager.cpp:188
Route::Ptr findByName(const std::string &interfaceName, const IpAddress &dest, uint32_t prefix)
find a route entry by interface name, destination and prefix.
Definition route_manager.cpp:88
~RouteManager()
destroy instance.
Definition route_manager.cpp:52
class representing a single kernel routing table entry.
Definition route.hpp:94
std::shared_ptr< Route > Ptr
Definition route.hpp:104
Definition acceptor.hpp:32
IpAddress operator^(const IpAddress &a, const IpAddress &b)
perform XOR operation on IP address.
Definition ip_address.cpp:1719
constexpr const JsonReadMode & operator&=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary AND on JsonReadMode.
Definition json.hpp:919
IpAddress operator&(const IpAddress &a, const IpAddress &b)
perform AND operation on IP address.
Definition ip_address.cpp:1665
InterfaceChangeType operator~(InterfaceChangeType a)
perform binary NOT on InterfaceChangeType.
Definition interface_manager.hpp:95
RouteChangeType
enumeration of route change types.
Definition route_manager.hpp:41
std::vector< Route::Ptr > RouteList
list of routes.
Definition route.hpp:340
constexpr const JsonReadMode & operator|=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary OR on JsonReadMode.
Definition json.hpp:930
const InterfaceChangeType & operator^=(InterfaceChangeType &a, InterfaceChangeType b)
perform binary XOR assignment on InterfaceChangeType.
Definition interface_manager.hpp:128
IpAddress operator|(const IpAddress &a, const IpAddress &b)
perform OR operation on IP address.
Definition ip_address.cpp:1692
route change notification payload.
Definition route_manager.hpp:132
Route::Ptr route
Definition route_manager.hpp:133
RouteChangeType flags
Definition route_manager.hpp:134