14#include <boost/noncopyable.hpp>
15#include <boost/shared_ptr.hpp>
16#include <boost/multi_index_container.hpp>
17#include <boost/multi_index/ordered_index.hpp>
18#include <boost/multi_index/sequenced_index.hpp>
19#include <boost/multi_index/global_fun.hpp>
20#include <boost/multi_index/mem_fun.hpp>
21#include <boost/date_time/posix_time/posix_time.hpp>
89 return (this_counter);
161 return(packet->getTransid() & 1023);
233 typedef boost::multi_index_container<
237 boost::multi_index::indexed_by<
240 boost::multi_index::sequenced<>,
245 boost::multi_index::ordered_non_unique<
249 boost::multi_index::global_fun<
264 typedef typename PktList::template nth_index<1>::type
267 typedef typename PktListTransidHashIndex::const_iterator
270 typedef typename std::queue<PktListTransidHashIterator>
282 const double drop_time,
283 const bool archive_enabled,
284 const boost::posix_time::ptime boot_time);
296 static_cast<void>(sent_packets_.template get<0>().push_back(packet));
310 static_cast<void>(rcvd_packets_.push_back(packet));
366 if (rcvd_packets_num_ == 0) {
369 return(sum_delay_ / rcvd_packets_num_);
383 if (rcvd_packets_num_ == 0) {
386 return(sqrt(sum_delay_squared_ / rcvd_packets_num_ -
420 if (unordered_lookups_ == 0) {
423 return(
static_cast<double>(unordered_lookup_size_sum_) /
424 static_cast<double>(unordered_lookups_));
516 double drops_ratio = 100.0 *
static_cast<double>(drops) /
static_cast<double>(sent);
518 cout <<
"sent packets: " << sent << endl
520 <<
"drops: " << drops << endl
521 <<
"drops ratio: " << drops_ratio <<
" %" << endl
537 cout << fixed << setprecision(3)
538 <<
"min delay: " <<
getMinDelay() * 1e3 <<
" ms" << endl
539 <<
"avg delay: " <<
getAvgDelay() * 1e3 <<
" ms" << endl
540 <<
"max delay: " <<
getMaxDelay() * 1e3 <<
" ms" << endl
546 cout <<
"min delay: n/a" << endl
547 <<
"avg delay: n/a" << endl
548 <<
"max delay: n/a" << endl
549 <<
"std deviation: n/a" << endl
550 <<
"collected packets: 0" << endl;
567 return(std::make_tuple(sent_packets_.begin(), sent_packets_.end()));
602 if (archive_enabled_) {
609 static_cast<void>(archived_packets_.push_back(*it));
613 return(sent_packets_.template get<0>().erase(it));
642 bool archive_enabled_;
654 double sum_delay_squared_;
666 uint64_t unordered_lookup_size_sum_;
668 uint64_t unordered_lookups_;
670 uint64_t ordered_lookups_;
673 uint64_t sent_packets_num_;
674 uint64_t rcvd_packets_num_;
676 uint64_t non_unique_addr_num_;
678 uint64_t rejected_leases_num_;
680 boost::posix_time::ptime boot_time_;
733 const double drop_time = -1) {
734 if (exchanges_.find(xchg_type) != exchanges_.end()) {
737 exchanges_[xchg_type] =
755 return (exchanges_.find(xchg_type) != exchanges_.end());
766 const std::string& long_name) {
767 if (custom_counters_.find(short_name) != custom_counters_.end()) {
769 "Custom counter " << short_name <<
" already added.");
771 custom_counters_[short_name] =
779 for (
auto const& it : exchanges_) {
780 if (it.second->getDroppedPacketsNum() > 0) {
796 if (it == custom_counters_.end()) {
798 "Custom counter " << counter_key <<
"does not exist");
811 const uint64_t value = 1) {
830 xchg_stats->appendSent(packet);
850 dhcp::PktPtr sent_packet = xchg_stats->matchPackets(packet);
853 xchg_stats->updateDelays(sent_packet, packet);
854 if (archive_enabled_) {
855 xchg_stats->appendRcvd(packet);
871 return(xchg_stats->getMinDelay());
884 return(xchg_stats->getMaxDelay());
895 return(xchg_stats->getAvgDelay());
906 return(xchg_stats->getStdDevDelay());
919 return(xchg_stats->getOrphans());
933 return(xchg_stats->getAvgUnorderedLookupSetSize());
948 return(xchg_stats->getUnorderedLookups());
964 return(xchg_stats->getOrderedLookups());
977 return(xchg_stats->getSentPacketsNum());
990 return(xchg_stats->getRcvdPacketsNum());
1003 return(xchg_stats->getDroppedPacketsNum());
1018 return(xchg_stats->getCollectedNum());
1031 return(xchg_stats->getRejLeasesNum());
1040 xchg_stats->updateRejLeases();
1049 xchg_stats->updateNonUniqueAddr();
1062 return(xchg_stats->getNonUniqueAddrNum());
1073 using namespace boost::posix_time;
1074 time_period test_period(boot_time_,
1075 microsec_clock::universal_time());
1093 if (exchanges_.empty()) {
1095 "no exchange type added for tracking");
1097 for (
auto const& it : exchanges_) {
1099 std::cout <<
"***Statistics for: " << it.first
1100 <<
"***" << std::endl;
1101 xchg_stats->printMainStats();
1102 std::cout << std::endl;
1103 xchg_stats->printRTTStats();
1104 std::cout << std::endl;
1118 std::ostringstream stream_sent;
1119 std::ostringstream stream_rcvd;
1120 std::ostringstream stream_drops;
1121 std::ostringstream stream_reject;
1122 std::string sep(
"");
1124 for (
auto const& it : exchanges_) {
1134 stream_sent << sep << it.second->getSentPacketsNum();
1135 stream_rcvd << sep << it.second->getRcvdPacketsNum();
1136 stream_drops << sep << it.second->getDroppedPacketsNum();
1137 stream_reject << sep << it.second->getRejLeasesNum();
1141 std::cout << stream_sent.str()
1142 << clean_sep << stream_rcvd.str()
1143 << clean_sep << stream_drops.str()
1144 << clean_sep << stream_reject.str()
1148 std::cout <<
"sent: " << stream_sent.str()
1149 <<
"; received: " << stream_rcvd.str()
1150 <<
"; drops: " << stream_drops.str()
1151 <<
"; rejected: " << stream_reject.str()
1168 if (exchanges_.empty()) {
1170 "no exchange type added for tracking");
1172 for (
auto const& it : exchanges_) {
1174 std::cout <<
"***Timestamps for packets: "
1176 <<
"***" << std::endl;
1177 xchg_stats->printTimestamps();
1178 std::cout << std::endl;
1192 if (custom_counters_.empty()) {
1195 for (
auto const& it : custom_counters_) {
1197 std::cout << counter->getName() <<
": " << counter->getValue()
1202 std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator>
1205 std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> sent_packets_its =
1206 xchg_stats->getSentPackets();
1207 return (sent_packets_its);
1221 if (it == exchanges_.end()) {
1239 bool archive_enabled_;
1241 boost::posix_time::ptime boot_time_;
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
A generic exception that is thrown if a function is called in a prohibited way.
const CustomCounter & operator+=(int val)
const CustomCounter & operator++(int)
Increment operator.
const CustomCounter & operator++()
Increment operator.
const std::string & getName() const
Return counter name.
CustomCounter(const std::string &name)
Constructor.
uint64_t getValue() const
Return counter value.
std::tuple< PktListIterator, PktListIterator > getSentPackets()
double getAvgUnorderedLookupSetSize() const
Return average unordered lookup set size.
static int malformed_pkts_
void updateRejLeases()
Increase number of rejected leases.
void printMainStats() const
Print main statistics for packet exchange.
static uint32_t hashTransid(const dhcp::PktPtr &packet)
Hash transaction id of the packet.
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).
uint64_t getDroppedPacketsNum() const
Return number of dropped packets.
double getAvgDelay() const
Return average packet delay.
uint64_t getUnorderedLookups() const
Return number of unordered sent packets lookups.
uint64_t getOrphans() const
Return number of orphan packets.
std::string receivedLeases() const
Return the list of received leases in CSV format as string.
uint64_t getRcvdPacketsNum() const
Return total number of received packets.
void appendSent(const dhcp::PktPtr &packet)
Add new packet to list of sent packets.
uint64_t getCollectedNum() const
Return number of garbage collected packets.
std::queue< PktListTransidHashIterator > PktListRemovalQueue
Packet list iterator queue for removal.
uint64_t getSentPacketsNum() const
Return total number of sent packets.
double getStdDevDelay() const
Return standard deviation of packet delay.
void updateNonUniqueAddr()
Increase number of non unique addresses.
void appendRcvd(const dhcp::PktPtr &packet)
Add new packet to list of received packets.
uint64_t getOrderedLookups() const
Return number of ordered sent packets lookups.
double getMinDelay() const
Return minimum delay between sent and received packet.
void printLeases() const
Print the list of received leases.
void printTimestamps()
Print timestamps for sent and received packets.
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.
void printRTTStats() const
Print round trip time packets statistics.
dhcp::PktPtr matchPackets(const dhcp::PktPtr &rcvd_packet)
Match received packet with the corresponding sent packet.
uint64_t getRejLeasesNum() const
Return total number of rejected leases.
uint64_t getNonUniqueAddrNum() const
Return total number of non unique addresses.
double getMaxDelay() const
Return maximum delay between sent and received packet.
void updateDelays(const dhcp::PktPtr &sent_packet, const dhcp::PktPtr &rcvd_packet)
Update delay counters.
PktList::iterator PktListIterator
Packet list iterator for sequential access to elements.
void addCustomCounter(const std::string &short_name, const std::string &long_name)
Add named custom uint64 counter.
std::tuple< typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator > getSentPackets(const ExchangeType xchg_type) const
void updateRejLeases(const ExchangeType xchg_type)
Increase total number of rejected leases.
void printStats() const
Print statistics counters for all exchange types.
void printLeases() const
Delegate to all exchanges to print their leases.
double getAvgDelay(const ExchangeType xchg_type) const
Return average packet delay.
void printCustomCounters() const
Print names and values of custom counters.
uint64_t getDroppedPacketsNum(const ExchangeType xchg_type) const
Return total number of dropped packets.
const CustomCounter & incrementCounter(const std::string &counter_key, const uint64_t value=1)
Increment specified counter.
void printTimestamps() const
Print timestamps of all packets.
double getAvgUnorderedLookupSetSize(const ExchangeType xchg_type) const
Return average unordered lookup set size.
void updateNonUniqueAddrNum(const ExchangeType xchg_type)
Increase total number of non unique addresses.
CustomCounterPtr getCounter(const std::string &counter_key)
Return specified counter.
uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const
Return total number of received packets.
uint64_t getSentPacketsNum(const ExchangeType xchg_type) const
Return total number of sent packets.
uint64_t getCollectedNum(const ExchangeType xchg_type) const
Return number of garbage collected packets.
bool hasExchangeStats(const ExchangeType xchg_type) const
Check if the exchange type has been specified.
StatsMgr(CommandOptions &options)
Constructor.
void printIntermediateStats(bool clean_report, std::string clean_sep) const
Print intermediate statistics.
boost::posix_time::time_period getTestPeriod() const
Get time period since the start of test.
uint64_t getOrphans(const ExchangeType xchg_type) const
Return number of orphan packets.
bool droppedPackets() const
Check if any packet drops occurred.
void passSentPacket(const ExchangeType xchg_type, const dhcp::PktPtr &packet)
Adds new packet to the sent packets list.
dhcp::PktPtr passRcvdPacket(const ExchangeType xchg_type, const dhcp::PktPtr &packet)
Add new received packet and match with sent packet.
double getMinDelay(const ExchangeType xchg_type) const
Return minimum delay between sent and received packet.
double getMaxDelay(const ExchangeType xchg_type) const
Return maximum delay between sent and received packet.
uint64_t getOrderedLookups(const ExchangeType xchg_type) const
Return number of ordered sent packets lookups.
uint64_t getRejLeasesNum(const ExchangeType xchg_type) const
Return total number of rejected leases.
void addExchangeStats(const ExchangeType xchg_type, const double drop_time=-1)
Specify new exchange type.
uint64_t getNonUniqueAddrNum(const ExchangeType xchg_type) const
Return total number of non unique addresses.
uint64_t getUnorderedLookups(const ExchangeType xchg_type) const
Return number of unordered sent packets lookups.
double getStdDevDelay(const ExchangeType xchg_type) const
Return standard deviation of packet delay.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
ExchangesMap::const_iterator ExchangesMapIterator
Iterator pointing to ExchangesMap.
boost::shared_ptr< StatsMgr > StatsMgrPtr
Pointer to Statistics Manager;.
CustomCountersMap::const_iterator CustomCountersMapIterator
Iterator for CustomCountersMap.
std::map< ExchangeType, ExchangeStatsPtr > ExchangesMap
Map containing all specified exchange types.
boost::shared_ptr< ExchangeStats > ExchangeStatsPtr
Pointer to ExchangeStats.
int dhcpVersion(ExchangeType const exchange_type)
Get the DHCP version that fits the exchange type.
ExchangeType
DHCP packet exchange types.
@ SA
DHCPv6 SOLICIT-ADVERTISE.
@ RNA
DHCPv4 REQUEST-ACK (renewal)
@ RL
DHCPv6 RELEASE-REPLY.
@ DO
DHCPv4 DISCOVER-OFFER.
@ RR
DHCPv6 REQUEST-REPLY.
std::map< std::string, CustomCounterPtr > CustomCountersMap
Map containing custom counters.
boost::shared_ptr< CustomCounter > CustomCounterPtr
std::ostream & operator<<(std::ostream &os, ExchangeType xchg_type)
Return name of the exchange.
Defines the logger used by the top-level component of kea-lfc.