ndn::net::NetworkMonitorStub Class Reference

a stub NetworkMonitor for unit testing More...

#include <network-monitor-stub.hpp>

+ Inheritance diagram for ndn::net::NetworkMonitorStub:
+ Collaboration diagram for ndn::net::NetworkMonitorStub:

Public Types

enum  Capability : uint32_t {
  CAP_NONE = 0,
  CAP_ENUM = 1 << 0,
  CAP_IF_ADD_REMOVE = 1 << 1,
  CAP_STATE_CHANGE = 1 << 2,
  CAP_MTU_CHANGE = 1 << 3,
  CAP_ADDR_ADD_REMOVE = 1 << 4
}
 

Public Member Functions

 NetworkMonitorStub (uint32_t capabilities)
 constructor More...
 
void addInterface (shared_ptr< NetworkInterface > netif)
 emit the onInterfaceAdded signal and add netif internally More...
 
void emitEnumerationCompleted ()
 emit the onEnumerationCompleted signal More...
 
uint32_t getCapabilities () const
 Returns a bitwise OR'ed set of Capability flags supported on the current platform. More...
 
shared_ptr< const NetworkInterfacegetNetworkInterface (const std::string &ifname) const
 Returns the NetworkInterface with the given name, or nullptr if it does not exist. More...
 
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces () const
 Lists all network interfaces currently available on the system. More...
 
void removeInterface (const std::string &ifname)
 emit the onInterfaceRemoved signal and remove netif internally More...
 

Static Public Member Functions

static shared_ptr< NetworkInterfacemakeNetworkInterface ()
 create a NetworkInterface instance More...
 

Public Attributes

util::Signal< NetworkMonitorImpl > & onEnumerationCompleted
 Fires when network interfaces enumeration is complete. More...
 
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
 Fires when a new interface is added. More...
 
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceRemoved
 Fires when an interface is removed. More...
 
util::Signal< NetworkMonitorImpl > & onNetworkStateChanged
 

Detailed Description

a stub NetworkMonitor for unit testing

Definition at line 34 of file network-monitor-stub.hpp.

Member Enumeration Documentation

enum ndn::net::NetworkMonitor::Capability : uint32_t
inherited
Enumerator
CAP_NONE 

NetworkMonitor is not supported and is a no-op.

CAP_ENUM 

listNetworkInterfaces() and getNetworkInterface() are supported

CAP_IF_ADD_REMOVE 

NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.

CAP_STATE_CHANGE 

NetworkInterface onStateChanged signal is supported.

CAP_MTU_CHANGE 

NetworkInterface onMtuChanged signal is supported.

CAP_ADDR_ADD_REMOVE 

NetworkInterface onAddressAdded and onAddressRemoved signals are supported.

Definition at line 77 of file network-monitor.hpp.

Constructor & Destructor Documentation

ndn::net::NetworkMonitorStub::NetworkMonitorStub ( uint32_t  capabilities)
explicit

constructor

Parameters
capabilitiescapabilities reported by getCapabilities

Definition at line 100 of file network-monitor-stub.cpp.

Member Function Documentation

void ndn::net::NetworkMonitorStub::addInterface ( shared_ptr< NetworkInterface netif)

emit the onInterfaceAdded signal and add netif internally

Parameters
netifnew network interface
Postcondition
getNetworkInterface(netif->getName()) == netif
listNetworkInterface() contains netif
Exceptions
std::invalid_argumenta network interface with same name already exists

Definition at line 118 of file network-monitor-stub.cpp.

void ndn::net::NetworkMonitorStub::emitEnumerationCompleted ( )

emit the onEnumerationCompleted signal

A real NetworkMonitor starts with an "enumerating" state, during which the initial information about network interfaces is collected from the OS. Upon discovering a network interface, it emits the onInterfaceAdded signal. When the initial enumerating completes, it emits the onEnumerationCompleted signal.

To simulate this procedure on a newly constructed MockNetworkMonitor, the caller should invoke addInterface once for each network interface that already exists, and then invoke signalEnumerationCompleted .

Definition at line 130 of file network-monitor-stub.cpp.

uint32_t ndn::net::NetworkMonitor::getCapabilities ( ) const
inherited

Returns a bitwise OR'ed set of Capability flags supported on the current platform.

Definition at line 57 of file network-monitor.cpp.

shared_ptr< const NetworkInterface > ndn::net::NetworkMonitor::getNetworkInterface ( const std::string &  ifname) const
inherited

Returns the NetworkInterface with the given name, or nullptr if it does not exist.

Definition at line 63 of file network-monitor.cpp.

std::vector< shared_ptr< const NetworkInterface > > ndn::net::NetworkMonitor::listNetworkInterfaces ( ) const
inherited

Lists all network interfaces currently available on the system.

Warning
May return incomplete results if called before the onEnumerationCompleted signal has been emitted.

Definition at line 69 of file network-monitor.cpp.

shared_ptr< NetworkInterface > ndn::net::NetworkMonitorStub::makeNetworkInterface ( )
static

create a NetworkInterface instance

Definition at line 112 of file network-monitor-stub.cpp.

void ndn::net::NetworkMonitorStub::removeInterface ( const std::string &  ifname)

emit the onInterfaceRemoved signal and remove netif internally

Parameters
ifnamenetwork interface name
Postcondition
getNetworkInterface(ifname) == nullptr
listNetworkInterface() does not contains an interface with specified name
Note
If specified interface name does not exist, this operation has no effect.

Definition at line 124 of file network-monitor-stub.cpp.

Member Data Documentation

util::Signal<NetworkMonitorImpl>& ndn::net::NetworkMonitor::onEnumerationCompleted
inherited

Fires when network interfaces enumeration is complete.

Definition at line 125 of file network-monitor.hpp.

util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface> >& ndn::net::NetworkMonitor::onInterfaceAdded
inherited

Fires when a new interface is added.

Definition at line 128 of file network-monitor.hpp.

util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface> >& ndn::net::NetworkMonitor::onInterfaceRemoved
inherited

Fires when an interface is removed.

Note
The NetworkInterface object is no longer present in the internal list of network interfaces when this signal is emitted.

Definition at line 135 of file network-monitor.hpp.

util::Signal<NetworkMonitorImpl>& ndn::net::NetworkMonitor::onNetworkStateChanged
inherited
Deprecated:
Only for backward compatibility

Definition at line 138 of file network-monitor.hpp.