Kea 2.5.8
isc::perfdhcp::ExchangeStats Class Reference

Exchange Statistics. More...

#include <stats_mgr.h>

Public Types

typedef boost::multi_index_container< dhcp::PktPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_non_unique< boost::multi_index::global_fun< const dhcp::PktPtr &, uint32_t, &ExchangeStats::hashTransid > > > > PktList
 List of packets (sent or received).
 
typedef PktList::iterator PktListIterator
 Packet list iterator for sequential access to elements.
 
typedef std::queue< PktListTransidHashIteratorPktListRemovalQueue
 Packet list iterator queue for removal.
 
typedef PktList::template nth_index< 1 >::type PktListTransidHashIndex
 Packet list index to search packets using transaction id hash.
 
typedef PktListTransidHashIndex::const_iterator PktListTransidHashIterator
 Packet list iterator to access packets using transaction id hash.
 

Public Member Functions

 ExchangeStats (const ExchangeType xchg_type, const double drop_time, const bool archive_enabled, const boost::posix_time::ptime boot_time)
 Constructor.
 
void appendRcvd (const dhcp::PktPtr &packet)
 Add new packet to list of received packets.
 
void appendSent (const dhcp::PktPtr &packet)
 Add new packet to list of sent packets.
 
double getAvgDelay () const
 Return average packet delay.
 
double getAvgUnorderedLookupSetSize () const
 Return average unordered lookup set size.
 
uint64_t getCollectedNum () const
 Return number of garbage collected packets.
 
uint64_t getDroppedPacketsNum () const
 Return number of dropped packets.
 
double getMaxDelay () const
 Return maximum delay between sent and received packet.
 
double getMinDelay () const
 Return minimum delay between sent and received packet.
 
uint64_t getNonUniqueAddrNum () const
 Return total number of non unique addresses.
 
uint64_t getOrderedLookups () const
 Return number of ordered sent packets lookups.
 
uint64_t getOrphans () const
 Return number of orphan packets.
 
uint64_t getRcvdPacketsNum () const
 Return total number of received packets.
 
uint64_t getRejLeasesNum () const
 Return total number of rejected leases.
 
std::tuple< PktListIterator, PktListIteratorgetSentPackets ()
 
uint64_t getSentPacketsNum () const
 Return total number of sent packets.
 
double getStdDevDelay () const
 Return standard deviation of packet delay.
 
uint64_t getUnorderedLookups () const
 Return number of unordered sent packets lookups.
 
dhcp::PktPtr matchPackets (const dhcp::PktPtr &rcvd_packet)
 Match received packet with the corresponding sent packet.
 
void printLeases () const
 Print the list of received leases.
 
void printMainStats () const
 Print main statistics for packet exchange.
 
void printRTTStats () const
 Print round trip time packets statistics.
 
void printTimestamps ()
 Print timestamps for sent and received packets.
 
std::string receivedLeases () const
 Return the list of received leases in CSV format as string.
 
void updateDelays (const dhcp::PktPtr &sent_packet, const dhcp::PktPtr &rcvd_packet)
 Update delay counters.
 
void updateNonUniqueAddr ()
 Increase number of non unique addresses.
 
void updateRejLeases ()
 Increase number of rejected leases.
 

Static Public Member Functions

static uint32_t hashTransid (const dhcp::PktPtr &packet)
 Hash transaction id of the packet.
 

Static Public Attributes

static int malformed_pkts_ {0}
 

Detailed Description

Exchange Statistics.

This class collects statistics for exchanges. Parent class may define number of different packet exchanges like: DHCPv4 DISCOVER-OFFER, DHCPv6 SOLICIT-ADVERTISE etc. Performance statistics will be collected for each of those separately in corresponding instance of ExchangeStats.

Definition at line 144 of file bin/perfdhcp/stats_mgr.h.

Member Typedef Documentation

◆ PktList

typedef boost::multi_index_container< dhcp::PktPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_non_unique< boost::multi_index::global_fun< const dhcp::PktPtr&, uint32_t, &ExchangeStats::hashTransid > > > > isc::perfdhcp::ExchangeStats::PktList

List of packets (sent or received).

List of packets based on multi index container allows efficient search of packets based on their sequence (order in which they were inserted) as well as based on their hashed transaction id. The first index (sequenced) provides the way to use container as a regular list (including iterators, removal of elements from the middle of the collection etc.). This index is meant to be used more frequently than the latter one and it is based on the assumption that responses from the DHCP server are received in order. In this case, when next packet is received it can be matched with next packet on the list of sent packets. This prevents intensive searches on the list of sent packets every time new packet arrives. In many cases however packets can be dropped by the server or may be sent out of order and we still want to have ability to search packets using transaction id. The second index can be used for this purpose. This index is hashing transaction ids using custom function hashTransid. Note that other possibility would be to simply specify index that uses transaction id directly (instead of hashing with hashTransid). In this case however we have chosen to use hashing function because it shortens the index size to just 1023 values maximum. Search operation on this index generally returns the range of packets that have the same transaction id hash assigned but most often these ranges will be short so further search within a range to find a packet with particular transaction id will not be intensive.

Example 1: Add elements to the list

PktList packets_collection();
boost::shared_ptr<Pkt4> pkt1(new Pkt4(...));
boost::shared_ptr<Pkt4> pkt2(new Pkt4(...));
// Add new packet to the container, it will be available through
// both indexes
static_cast<void>(packets_collection.push_back(pkt1));
// Here is another way to add packet to the container. The result
// is exactly the same as previously.
static_cast<void>(packets_collection.template get<0>().push_back(pkt2));
boost::multi_index_container< dhcp::PktPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_non_unique< boost::multi_index::global_fun< const dhcp::PktPtr &, uint32_t, &ExchangeStats::hashTransid > > > > PktList
List of packets (sent or received).
Note
The multi index has no unique index so insertion should never fail and there is no need to check the return of push_back().

Example 2: Access elements through sequential index

PktList packets_collection();
... # Add elements to the container
for (auto const& it : packets_collection) {
boost::shared_ptr<Pkt4> pkt = it;
# Do something with packet;
}

Example 3: Access elements through ordered index by hash

// Get the instance of the second search index.
PktListTransidHashIndex& idx = sent_packets_.template get<1>();
// Get the range (bucket) of packets sharing the same transaction
// id hash.
std::pair<PktListTransidHashIterator,PktListTransidHashIterator> p =
idx.equal_range(hashTransid(rcvd_packet));
// Iterate through the returned bucket.
for (PktListTransidHashIterator it = p.first; it != p.second;
++it) {
boost::shared_ptr pkt = *it;
... # Do something with the packet (e.g. check transaction id)
}
static uint32_t hashTransid(const dhcp::PktPtr &packet)
Hash transaction id of the packet.
PktListTransidHashIndex::const_iterator PktListTransidHashIterator
Packet list iterator to access packets using transaction id hash.
PktList::template nth_index< 1 >::type PktListTransidHashIndex
Packet list index to search packets using transaction id hash.

Definition at line 259 of file bin/perfdhcp/stats_mgr.h.

◆ PktListIterator

Packet list iterator for sequential access to elements.

Definition at line 262 of file bin/perfdhcp/stats_mgr.h.

◆ PktListRemovalQueue

Packet list iterator queue for removal.

Definition at line 271 of file bin/perfdhcp/stats_mgr.h.

◆ PktListTransidHashIndex

typedef PktList::template nth_index<1>::type isc::perfdhcp::ExchangeStats::PktListTransidHashIndex

Packet list index to search packets using transaction id hash.

Definition at line 265 of file bin/perfdhcp/stats_mgr.h.

◆ PktListTransidHashIterator

typedef PktListTransidHashIndex::const_iterator isc::perfdhcp::ExchangeStats::PktListTransidHashIterator

Packet list iterator to access packets using transaction id hash.

Definition at line 268 of file bin/perfdhcp/stats_mgr.h.

Constructor & Destructor Documentation

◆ ExchangeStats()

isc::perfdhcp::ExchangeStats::ExchangeStats ( const ExchangeType  xchg_type,
const double  drop_time,
const bool  archive_enabled,
const boost::posix_time::ptime  boot_time 
)

Constructor.

Parameters
xchg_typeexchange type
drop_timemaximum time elapsed before packet is assumed dropped. Negative value disables it.
archive_enabledif true packets archive mode is enabled. In this mode all packets are stored throughout the test execution.
boot_timeHolds the timestamp when perfdhcp has been started.

Definition at line 76 of file bin/perfdhcp/stats_mgr.cc.

Member Function Documentation

◆ appendRcvd()

void isc::perfdhcp::ExchangeStats::appendRcvd ( const dhcp::PktPtr packet)
inline

Add new packet to list of received packets.

Method adds new packet to list of received packets.

Parameters
packetpacket object to be added.
Exceptions
isc::BadValueif packet is null.

Definition at line 306 of file bin/perfdhcp/stats_mgr.h.

References isc_throw.

◆ appendSent()

void isc::perfdhcp::ExchangeStats::appendSent ( const dhcp::PktPtr packet)
inline

Add new packet to list of sent packets.

Method adds new packet to list of sent packets.

Parameters
packetpacket object to be added.
Exceptions
isc::BadValueif packet is null.

Definition at line 292 of file bin/perfdhcp/stats_mgr.h.

References isc_throw.

◆ getAvgDelay()

double isc::perfdhcp::ExchangeStats::getAvgDelay ( ) const
inline

Return average packet delay.

Method returns average packet delay. If no packets have been received for this exchange avg delay can't be calculated and thus method throws exception.

Exceptions
isc::InvalidOperationif no packets for this exchange have been received yet.
Returns
average packet delay.

Definition at line 365 of file bin/perfdhcp/stats_mgr.h.

References isc_throw.

Referenced by getStdDevDelay(), and printRTTStats().

◆ getAvgUnorderedLookupSetSize()

double isc::perfdhcp::ExchangeStats::getAvgUnorderedLookupSetSize ( ) const
inline

Return average unordered lookup set size.

Method returns average unordered lookup set size. This value changes every time ExchangeStats::matchPackets function performs unordered packet lookup.

Exceptions
isc::InvalidOperationif there have been no unordered lookups yet.
Returns
average unordered lookup set size.

Definition at line 419 of file bin/perfdhcp/stats_mgr.h.

References isc_throw.

◆ getCollectedNum()

uint64_t isc::perfdhcp::ExchangeStats::getCollectedNum ( ) const
inline

Return number of garbage collected packets.

Method returns number of garbage collected timed out packets. Packet is assumed timed out when duration between sending it to server and receiving server's response is greater than value specified with -d<value> command line argument.

Returns
number of garbage collected packets.

Definition at line 408 of file bin/perfdhcp/stats_mgr.h.

Referenced by printRTTStats().

◆ getDroppedPacketsNum()

uint64_t isc::perfdhcp::ExchangeStats::getDroppedPacketsNum ( ) const
inline

Return number of dropped packets.

Method returns number of dropped packets.

Returns
number of dropped packets.

Definition at line 467 of file bin/perfdhcp/stats_mgr.h.

References getRcvdPacketsNum(), and getSentPacketsNum().

Referenced by printMainStats().

+ Here is the call graph for this function:

◆ getMaxDelay()

double isc::perfdhcp::ExchangeStats::getMaxDelay ( ) const
inline

Return maximum delay between sent and received packet.

Method returns maximum delay between sent and received packet.

Returns
maximum delay between packets.

Definition at line 354 of file bin/perfdhcp/stats_mgr.h.

Referenced by printRTTStats().

◆ getMinDelay()

double isc::perfdhcp::ExchangeStats::getMinDelay ( ) const
inline

Return minimum delay between sent and received packet.

Method returns minimum delay between sent and received packet.

Returns
minimum delay between packets.

Definition at line 347 of file bin/perfdhcp/stats_mgr.h.

Referenced by printRTTStats().

◆ getNonUniqueAddrNum()

uint64_t isc::perfdhcp::ExchangeStats::getNonUniqueAddrNum ( ) const
inline

Return total number of non unique addresses.

Method returns total number of non unique addresses.

Returns
number of non unique addresses.

Definition at line 487 of file bin/perfdhcp/stats_mgr.h.

Referenced by printMainStats().

◆ getOrderedLookups()

uint64_t isc::perfdhcp::ExchangeStats::getOrderedLookups ( ) const
inline

Return number of ordered sent packets lookups.

Method returns number of ordered sent packet lookups. Ordered lookup is used when packets are received in the same order as they were sent to the server. If packets are skipped or received out of order, lookup function will use unordered lookup (with hash table).

Returns
number of ordered lookups.

Definition at line 446 of file bin/perfdhcp/stats_mgr.h.

◆ getOrphans()

uint64_t isc::perfdhcp::ExchangeStats::getOrphans ( ) const
inline

Return number of orphan packets.

Method returns number of received packets that had no matching sent packet. It is possible that such packet was late or not for us.

Returns
number of orphan received packets.

Definition at line 397 of file bin/perfdhcp/stats_mgr.h.

Referenced by printMainStats().

◆ getRcvdPacketsNum()

uint64_t isc::perfdhcp::ExchangeStats::getRcvdPacketsNum ( ) const
inline

Return total number of received packets.

Method returns total number of received packets.

Returns
number of received packets.

Definition at line 460 of file bin/perfdhcp/stats_mgr.h.

Referenced by getDroppedPacketsNum(), and printMainStats().

◆ getRejLeasesNum()

uint64_t isc::perfdhcp::ExchangeStats::getRejLeasesNum ( ) const
inline

Return total number of rejected leases.

Method returns total number of rejected leases.

Returns
number of rejected leases.

Definition at line 480 of file bin/perfdhcp/stats_mgr.h.

Referenced by printMainStats().

◆ getSentPackets()

std::tuple< PktListIterator, PktListIterator > isc::perfdhcp::ExchangeStats::getSentPackets ( )
inline

Definition at line 566 of file bin/perfdhcp/stats_mgr.h.

◆ getSentPacketsNum()

uint64_t isc::perfdhcp::ExchangeStats::getSentPacketsNum ( ) const
inline

Return total number of sent packets.

Method returns total number of sent packets.

Returns
number of sent packets.

Definition at line 453 of file bin/perfdhcp/stats_mgr.h.

Referenced by getDroppedPacketsNum(), and printMainStats().

◆ getStdDevDelay()

double isc::perfdhcp::ExchangeStats::getStdDevDelay ( ) const
inline

Return standard deviation of packet delay.

Method returns standard deviation of packet delay. If no packets have been received for this exchange, the standard deviation can't be calculated and thus method throws exception.

Exceptions
isc::InvalidOperationif number of received packets for the exchange is equal to zero.
Returns
standard deviation of packet delay.

Definition at line 382 of file bin/perfdhcp/stats_mgr.h.

References getAvgDelay(), and isc_throw.

Referenced by printRTTStats().

+ Here is the call graph for this function:

◆ getUnorderedLookups()

uint64_t isc::perfdhcp::ExchangeStats::getUnorderedLookups ( ) const
inline

Return number of unordered sent packets lookups.

Method returns number of unordered sent packet lookups. Unordered lookup is used when received packet was sent out of order by server - transaction id of received packet does not match transaction id of next sent packet.

Returns
number of unordered lookups.

Definition at line 435 of file bin/perfdhcp/stats_mgr.h.

◆ hashTransid()

static uint32_t isc::perfdhcp::ExchangeStats::hashTransid ( const dhcp::PktPtr packet)
inlinestatic

Hash transaction id of the packet.

Function hashes transaction id of the packet. Hashing is non-unique. Many packets may have the same hash value and thus they belong to the same packet buckets. Packet buckets are used for unordered packets search with multi index container.

Parameters
packetpacket which transaction id is to be hashed.
Exceptions
isc::BadValueif packet is null.
Returns
transaction id hash.

Definition at line 157 of file bin/perfdhcp/stats_mgr.h.

References isc_throw.

Referenced by matchPackets(), and printTimestamps().

◆ matchPackets()

PktPtr isc::perfdhcp::ExchangeStats::matchPackets ( const dhcp::PktPtr rcvd_packet)

Match received packet with the corresponding sent packet.

Method finds packet with specified transaction id on the list of sent packets. It is used to match received packet with corresponding sent packet. Since packets from the server most often come in the same order as they were sent by client, this method will first check if next sent packet matches. If it doesn't, function will search the packet using indexing by transaction id. This reduces packet search time significantly.

Parameters
rcvd_packetreceived packet to be matched with sent packet.
Exceptions
isc::BadValueif received packet is null.
Returns
packet having specified transaction or NULL if packet not found

Definition at line 156 of file bin/perfdhcp/stats_mgr.cc.

References hashTransid(), and isc_throw.

+ Here is the call graph for this function:

◆ printLeases()

void isc::perfdhcp::ExchangeStats::printLeases ( ) const

Print the list of received leases.

Definition at line 453 of file bin/perfdhcp/stats_mgr.cc.

References receivedLeases().

+ Here is the call graph for this function:

◆ printMainStats()

void isc::perfdhcp::ExchangeStats::printMainStats ( ) const
inline

Print main statistics for packet exchange.

Method prints main statistics for particular exchange. Statistics includes: number of sent and received packets, number of dropped packets and number of orphans.

Todo:
Currently the number of orphans is not displayed because Reply messages received for Renew and Releases are counted as orphans for the 4-way exchanges, which is wrong. We will need to move the orphans counting out of the Statistics Manager so as orphans counter is increased only if the particular message is not identified as a response to any of the messages sent by perfdhcp.

Definition at line 512 of file bin/perfdhcp/stats_mgr.h.

References getDroppedPacketsNum(), getNonUniqueAddrNum(), getOrphans(), getRcvdPacketsNum(), getRejLeasesNum(), and getSentPacketsNum().

+ Here is the call graph for this function:

◆ printRTTStats()

void isc::perfdhcp::ExchangeStats::printRTTStats ( ) const
inline

Print round trip time packets statistics.

Method prints round trip time packets statistics. Statistics includes minimum packet delay, maximum packet delay, average packet delay and standard deviation of delays. Packet delay is a duration between sending a packet to server and receiving response from server.

Definition at line 534 of file bin/perfdhcp/stats_mgr.h.

References getAvgDelay(), getCollectedNum(), getMaxDelay(), getMinDelay(), and getStdDevDelay().

+ Here is the call graph for this function:

◆ printTimestamps()

void isc::perfdhcp::ExchangeStats::printTimestamps ( )

Print timestamps for sent and received packets.

Method prints timestamps for all sent and received packets for packet exchange. In order to run this method the packets archiving mode has to be enabled during object constructions. Otherwise sent packets are not stored during tests execution and this method has no ability to get and print their timestamps.

Exceptions
isc::InvalidOperationif found packet with no timestamp or if packets archive mode is disabled.

Definition at line 303 of file bin/perfdhcp/stats_mgr.cc.

References hashTransid(), and isc_throw.

+ Here is the call graph for this function:

◆ receivedLeases()

std::string isc::perfdhcp::ExchangeStats::receivedLeases ( ) const

Return the list of received leases in CSV format as string.

Depending exchange type, it can apply to potential leases received in offers and advertisements, committed leases received in acknowledgements and replies, renewed or released leases.

Returns
multiline string of received leases in CSV format

Definition at line 391 of file bin/perfdhcp/stats_mgr.cc.

References D6O_CLIENTID, D6O_IA_NA, D6O_IA_PD, D6O_IAADDR, D6O_IAPREFIX, isc::perfdhcp::dhcpVersion(), isc_throw, isc::dhcp::IdentifierType< min_size, max_size >::toText(), and isc::perfdhcp::TestControl::vector2Hex().

Referenced by printLeases().

+ Here is the call graph for this function:

◆ updateDelays()

void isc::perfdhcp::ExchangeStats::updateDelays ( const dhcp::PktPtr sent_packet,
const dhcp::PktPtr rcvd_packet 
)

Update delay counters.

Method updates delay counters based on timestamps of sent and received packets.

Parameters
sent_packetsent packet
rcvd_packetreceived packet
Exceptions
isc::BadValueif sent or received packet is null.
isc::Unexpectedif failed to calculate timestamps

Definition at line 105 of file bin/perfdhcp/stats_mgr.cc.

References isc_throw.

◆ updateNonUniqueAddr()

void isc::perfdhcp::ExchangeStats::updateNonUniqueAddr ( )
inline

Increase number of non unique addresses.

Method increases total number of non unique addresses by one.

Definition at line 497 of file bin/perfdhcp/stats_mgr.h.

◆ updateRejLeases()

void isc::perfdhcp::ExchangeStats::updateRejLeases ( )
inline

Increase number of rejected leases.

Method increases total number of rejected leases by one.

Definition at line 492 of file bin/perfdhcp/stats_mgr.h.

Member Data Documentation

◆ malformed_pkts_

int isc::perfdhcp::ExchangeStats::malformed_pkts_ {0}
static

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