join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicNdpClient< Protocol > Class Template Reference

NDP client, solicits routers and receives their advertisements. More...

#include <ndp.hpp>

Inheritance diagram for join::BasicNdpClient< Protocol >:
Collaboration diagram for join::BasicNdpClient< Protocol >:

Public Types

using RouterAdvertisementNotify = Function<void (const RouterAdvertisement& advert)>
 router advertisement notification callback.
 

Public Member Functions

 BasicNdpClient ()=delete
 create the BasicNdpClient instance.
 
 BasicNdpClient (const std::string &interface, Reactor &reactor=ReactorThread::reactor())
 create the instance bound to the given interface and start receiving advertisements.
 
 ~BasicNdpClient ()
 stop receiving advertisements and destroy the instance.
 
int routerSolicit () noexcept
 send a router solicitation.
 
int routerSolicit (RouterAdvertisement &advert, std::chrono::milliseconds timeout=std::chrono::seconds(1)) noexcept
 send a router solicitation and wait for the first advertisement.
 
int setRouterAdvertisementListener (RouterAdvertisementNotify cb) noexcept
 set the callback called on every router advertisement received, solicited or not.
 
int unsetRouterAdvertisementListener () noexcept
 unset the router advertisement callback, it is no longer called once this returns.
 

Additional Inherited Members

- Protected Types inherited from join::BasicNdp< Protocol >
using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 
using NeighborSolicitationNotify = Function<void (const NeighborSolicitation& solicitation)>
 neighbor solicitation notification callback.
 
using NeighborAdvertisementNotify = Function<void (const NeighborAdvertisement& advert)>
 neighbor advertisement notification callback.
 
- Protected Member Functions inherited from join::BasicNdp< Protocol >
void attach ()
 register with the reactor, to be called by the final class once fully constructed.
 
void detach () noexcept
 unregister from the reactor, to be called by the final class before destruction starts.
 
int applyFilter (uint8_t type, bool pass) noexcept
 pass or block a message type in the ICMPv6 filter.
 
int send (const char *data, size_t size, const IpAddress &destination)
 write a message on the interface.
 
ssize_t receive (char *data, size_t maxSize, IpAddress &from)
 read a message that passed the checks common to every NDP message.
 
bool onNeighborMessage (size_t size, const IpAddress &from) noexcept
 hand a received neighbor message to its listener, and an advertisement to the solicitations waiting for it.
 
 BasicNdp ()=delete
 create the BasicNdp instance.
 
 BasicNdp (const std::string &interface, uint8_t filter, const IpAddress &group, Reactor &reactor)
 create the instance bound to the given interface.
 
 BasicNdp (const BasicNdp &other)=delete
 create instance by copy.
 
BasicNdp & operator= (const BasicNdp &other)=delete
 assign instance by copy.
 
 BasicNdp (BasicNdp &&other)=delete
 create instance by move.
 
BasicNdp & operator= (BasicNdp &&other)=delete
 assign instance by move.
 
virtual ~BasicNdp ()=default
 destroy the instance.
 
int neighborSolicit (const IpAddress &target, NeighborAdvertisement &advert, std::chrono::milliseconds timeout=std::chrono::seconds(1)) noexcept
 send a neighbor solicitation and wait for the advertisement of the target.
 
int neighborAdvertise (const NeighborAdvertisement &advert, const IpAddress &destination=IpAddress::ipv6AllNodes) noexcept
 send a neighbor advertisement, the interface hardware address is used if it carries none.
 
int neighborAdvertise (const NeighborAdvertisement &advert, const NeighborSolicitation &solicitation) noexcept
 answer a neighbor solicitation, to the solicitor or to all the nodes of the link if it has no address.
 
int setNeighborSolicitationListener (NeighborSolicitationNotify cb) noexcept
 set the callback called on every neighbor solicitation received.
 
int unsetNeighborSolicitationListener () noexcept
 unset the neighbor solicitation callback, it is no longer called once this returns.
 
int setNeighborAdvertisementListener (NeighborAdvertisementNotify cb) noexcept
 set the callback called on every neighbor advertisement received, solicited or not.
 
int unsetNeighborAdvertisementListener () noexcept
 unset the neighbor advertisement callback, it is no longer called once this returns.
 
const std::string & interface () const noexcept
 get the name of the interface the instance is bound to.
 
unsigned int index () const noexcept
 get the index of the interface the instance is bound to.
 
const MacAddress & hardware () const noexcept
 get the hardware address of the interface the instance is bound to.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onEvent (int fd, uint32_t revents)
 method called when events are reported on handle.
 
virtual void onWriteable (int fd)
 method called when data are ready to be written on handle.
 
virtual void onClose (int fd)
 method called when handle was closed by the peer.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandler & operator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandler & operator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 
- Static Protected Member Functions inherited from join::BasicNdp< Protocol >
static unsigned int lookup (const std::string &interface)
 get the index of the given interface.
 
- Protected Attributes inherited from join::BasicNdp< Protocol >
Socket _socket
 underlying socket.
 
NdpMessage _message
 NDP message codec.
 
std::unique_ptr< char[]> _buffer
 receive buffer.
 
const std::string _interface
 interface name.
 
const unsigned int _index
 interface index.
 
const MacAddress _hardware
 hardware address of the interface.
 
Reactor & _reactor
 event loop reactor.
 
struct icmp6_filter _filter
 ICMPv6 filter applied to the socket, only accessed from the reactor thread once constructed.
 
std::vector< NeighborRequest * > _neighborPending
 neighbor solicitations waiting for an advertisement, only accessed from the reactor thread.
 
Mutex _neighborMutex
 neighbor solicitations protection mutex.
 
NeighborSolicitationNotify _neighborSolicitationListener
 neighbor solicitation listener, only accessed from the reactor thread.
 
bool _neighborSolicitationCalling = false
 
NeighborAdvertisementNotify _neighborAdvertisementListener
 neighbor advertisement listener, only accessed from the reactor thread.
 
bool _neighborAdvertisementCalling = false
 

Detailed Description

template<class Protocol>
class join::BasicNdpClient< Protocol >

NDP client, solicits routers and receives their advertisements.

Member Typedef Documentation

◆ RouterAdvertisementNotify

template<class Protocol >
using join::BasicNdpClient< Protocol >::RouterAdvertisementNotify = Function<void (const RouterAdvertisement& advert)>

router advertisement notification callback.

Constructor & Destructor Documentation

◆ BasicNdpClient() [1/2]

template<class Protocol >
join::BasicNdpClient< Protocol >::BasicNdpClient ( )
delete

create the BasicNdpClient instance.

◆ BasicNdpClient() [2/2]

template<class Protocol >
join::BasicNdpClient< Protocol >::BasicNdpClient ( const std::string & interface,
Reactor & reactor = ReactorThread::reactor () )
inlineexplicit

create the instance bound to the given interface and start receiving advertisements.

Parameters
interfaceinterface name.
reactorreactor instance.
Exceptions
std::system_errorif the interface is unknown or the socket could not be set up.

◆ ~BasicNdpClient()

template<class Protocol >
join::BasicNdpClient< Protocol >::~BasicNdpClient ( )
inline

stop receiving advertisements and destroy the instance.

Member Function Documentation

◆ routerSolicit() [1/2]

template<class Protocol >
int join::BasicNdpClient< Protocol >::routerSolicit ( )
inlinenoexcept

send a router solicitation.

Returns
0 on success, -1 on failure.

◆ routerSolicit() [2/2]

template<class Protocol >
int join::BasicNdpClient< Protocol >::routerSolicit ( RouterAdvertisement & advert,
std::chrono::milliseconds timeout = std::chrono::seconds (1) )
inlinenoexcept

send a router solicitation and wait for the first advertisement.

Parameters
advertreceives the first advertisement.
timeoutmaximum wait duration.
Returns
0 on success, -1 on failure.

◆ setRouterAdvertisementListener()

template<class Protocol >
int join::BasicNdpClient< Protocol >::setRouterAdvertisementListener ( RouterAdvertisementNotify cb)
inlinenoexcept

set the callback called on every router advertisement received, solicited or not.

Parameters
cbcallback, called from the reactor thread, must not throw nor destroy the instance.
Returns
0 on success, -1 on failure.

◆ unsetRouterAdvertisementListener()

template<class Protocol >
int join::BasicNdpClient< Protocol >::unsetRouterAdvertisementListener ( )
inlinenoexcept

unset the router advertisement callback, it is no longer called once this returns.

Returns
0 on success, -1 on failure.

The documentation for this class was generated from the following files: