libDwm-0.6.0
Dwm::HostPinger Class Reference

Encapsulates a 'pinger', which can 'ping' one or more hosts using TCP or ICMP. More...

#include <DwmHostPinger.hh>

Collaboration diagram for Dwm::HostPinger:

Classes

class  Receiver
 Data callback interface. More...
 

Public Member Functions

 HostPinger (uint16_t identifier, const std::string &device="lo0")
 Construct with the given identifier (normally getpid() & 0xFFFF).
 
bool AddDestination (const PingDestination &destination)
 Adds a destination. Returns true on success.
 
uint16_t PacketRate () const
 Returns the packet rate. More...
 
uint16_t PacketRate (uint16_t pps)
 Sets and returns the packet rate in packets/sec. More...
 
uint32_t PacketsSent (const PingDestination &destination) const
 Returns the number of packets sent to the given destination.
 
uint32_t PacketsReceived (const PingDestination &destination) const
 Returns the number of packets received from the given destination. More...
 
float PacketLoss (const PingDestination &destination) const
 Returns the percent packet loss for the given destination.
 
bool Start (int count=0)
 Starts the pinger. Returns true on success.
 
bool Stop ()
 Stops the pinger. Returns true on success.
 
bool Outstanding () const
 Returns true if we have not yet received replies for some of the packets we sent. More...
 

Static Public Member Functions

static ReceiverGetReceiver ()
 Returns the Receiver registered to receive ping data.
 
static ReceiverSetReceiver (Receiver *receiver)
 Registers receiver to receive ping data.
 

Protected Types

typedef std::map< PingDestination, PingDestinationEntryDestinationMap
 

Protected Member Functions

bool StopWatcher ()
 
bool StopSender ()
 
void GetTcpPacket (const PingDestination &destination, uint16_t seq, std::string &s)
 
void RunWatcher ()
 
void RunSender ()
 

Static Protected Member Functions

static void PcapCallback (uint8_t *user, const struct pcap_pkthdr *pchdr, const uint8_t *pkt)
 

Protected Attributes

std::string _device
 
Ipv4Address _myAddress
 
std::thread _watcherThread
 
std::thread _senderThread
 
std::mutex _watcherReadyMutex
 
std::unique_lock< std::mutex > _watcherReadyLock
 
std::condition_variable _watcherReady
 
bool _runSender
 
bool _runWatcher
 
uint16_t _identifier
 
Socket _socket
 
uint16_t _packetRate
 
Pcap _pcap
 
int _count
 
bool _forever
 
DestinationMap _destinations
 

Static Protected Attributes

static Receiver_receiver
 

Detailed Description

Encapsulates a 'pinger', which can 'ping' one or more hosts using TCP or ICMP.

Member Function Documentation

◆ Outstanding()

bool Dwm::HostPinger::Outstanding ( ) const

Returns true if we have not yet received replies for some of the packets we sent.

◆ PacketRate() [1/2]

uint16_t Dwm::HostPinger::PacketRate ( ) const

Returns the packet rate.

This is divided across all destinations; if the packet rate is 10 and there are 5 destinations, each destination will get 10/5 == 2 packets/sec.

◆ PacketRate() [2/2]

uint16_t Dwm::HostPinger::PacketRate ( uint16_t  pps)

Sets and returns the packet rate in packets/sec.

This is divided across all destinations; if the packet rate is 10 and there are 5 destinations, each destination will get 10/5 == 2 packets/sec.

◆ PacketsReceived()

uint32_t Dwm::HostPinger::PacketsReceived ( const PingDestination destination) const

Returns the number of packets received from the given destination.


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