stats_mgr.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __STATS_MGR_H
  15. #define __STATS_MGR_H
  16. #include <iostream>
  17. #include <map>
  18. #include <boost/noncopyable.hpp>
  19. #include <boost/shared_ptr.hpp>
  20. #include <boost/multi_index_container.hpp>
  21. #include <boost/multi_index/hashed_index.hpp>
  22. #include <boost/multi_index/sequenced_index.hpp>
  23. #include <boost/multi_index/mem_fun.hpp>
  24. #include <boost/multi_index/global_fun.hpp>
  25. #include <boost/date_time/posix_time/posix_time.hpp>
  26. #include <exceptions/exceptions.h>
  27. namespace isc {
  28. namespace perfdhcp {
  29. /// \brief Statistics Manager
  30. ///
  31. /// This class template is a storage for various performance statistics
  32. /// collected during performance tests execution with perfdhcp tool.
  33. ///
  34. /// Statistics Manager holds lists of sent and received packets and
  35. /// groups them into exchanges. For example: DHCPDISCOVER message and
  36. /// corresponding DHCPOFFER messages belong to one exchange, DHCPREQUEST
  37. /// and corresponding DHCPACK message belong to another exchange etc.
  38. /// In order to update statistics for a particular exchange type, client
  39. /// class passes sent and received packets. Internally, Statistics Manager
  40. /// tries to match transaction id of received packet with sent packet
  41. /// stored on the list of sent packets. When packets are matched the
  42. /// round trip time can be calculated.
  43. ///
  44. /// \tparam T class representing DHCPv4 or DHCPv6 packet.
  45. template <class T>
  46. class StatsMgr : public boost::noncopyable {
  47. public:
  48. /// DHCP packet exchange types.
  49. enum ExchangeType {
  50. XCHG_DO, ///< DHCPv4 DISCOVER-OFFER
  51. XCHG_RA, ///< DHCPv4 REQUEST-ACK
  52. XCHG_SA, ///< DHCPv6 SOLICIT-ADVERTISE
  53. XCHG_RR ///< DHCPv6 REQUEST-REPLY
  54. };
  55. /// \brief Exchange Statistics.
  56. ///
  57. /// This class collects statistics for exchanges. Parent class
  58. /// may define number of different packet exchanges like:
  59. /// DHCPv4 DISCOVER-OFFER, DHCPv6 SOLICIT-ADVERTISE etc. Performance
  60. /// statistics will be collected for each of those separately in
  61. /// corresponding instance of ExchangeStats.
  62. class ExchangeStats {
  63. public:
  64. static uint32_t transid_hash(boost::shared_ptr<T> packet) {
  65. return packet->getTransid() & 1023;
  66. }
  67. /// \brief List of packets (sent or received).
  68. ///
  69. /// List of packets based on multi index container allows efficient
  70. /// search of packets based on their sequence (order in which they
  71. /// were inserted) as well as based on packet transaction id.
  72. typedef boost::multi_index_container<
  73. boost::shared_ptr<T>,
  74. boost::multi_index::indexed_by<
  75. boost::multi_index::sequenced<>,
  76. boost::multi_index::hashed_non_unique<
  77. boost::multi_index::global_fun<
  78. boost::shared_ptr<T>,
  79. uint32_t,
  80. &ExchangeStats::transid_hash
  81. >
  82. >
  83. >
  84. > PktList;
  85. /// Packet list iterator for sequencial access to elements.
  86. typedef typename PktList::iterator PktListIterator;
  87. /// Packet list index to search packets using transaction id.
  88. typedef typename PktList::template nth_index<1>::type
  89. PktListTransidIndex;
  90. /// Packet list iterator to access packets using transaction id.
  91. typedef typename PktListTransidIndex::iterator PktListTransidIterator;
  92. /// \brief Constructor
  93. ///
  94. /// \param xchg_type exchange type
  95. ExchangeStats(const ExchangeType xchg_type)
  96. : xchg_type_(xchg_type),
  97. min_delay_(std::numeric_limits<double>::max()),
  98. max_delay_(0.),
  99. sum_delay_(0.),
  100. orphans_(0),
  101. square_sum_delay_(0.),
  102. ordered_lookups_(0),
  103. unordered_lookup_size_sum_(0),
  104. unordered_lookups_(0),
  105. sent_packets_num_(0),
  106. rcvd_packets_num_(0) {
  107. sent_packets_cache_ = sent_packets_.begin();
  108. }
  109. /// \brief Add new packet to list of sent packets.
  110. ///
  111. /// Method adds new packet to list of sent packets.
  112. ///
  113. /// \param packet packet object to be added.
  114. void appendSent(const boost::shared_ptr<T> packet) {
  115. ++sent_packets_num_;
  116. sent_packets_.template get<0>().push_back(packet);
  117. }
  118. /// \brief Add new packet to list of received packets.
  119. ///
  120. /// Method adds new packet to list of received packets.
  121. ///
  122. /// \param packet packet object to be added.
  123. void appendRcvd(const boost::shared_ptr<T> packet) {
  124. ++rcvd_packets_num_;
  125. rcvd_packets_.template get<0>().push_back(packet);
  126. }
  127. /// \brief Update delay counters.
  128. ///
  129. /// Method updates delay counters based on timestamps of
  130. /// sent and received packets.
  131. ///
  132. /// \param sent_packet sent packet
  133. /// \param rcvd_packet received packet
  134. /// \throw isc::Unexpected if failed to calculate timestamps
  135. void updateDelays(const boost::shared_ptr<T> sent_packet,
  136. const boost::shared_ptr<T> rcvd_packet) {
  137. boost::posix_time::ptime sent_time = sent_packet->getTimestamp();
  138. boost::posix_time::ptime rcvd_time = rcvd_packet->getTimestamp();
  139. if (sent_time.is_not_a_date_time() ||
  140. rcvd_time.is_not_a_date_time()) {
  141. isc_throw(Unexpected,
  142. "Timestamp must be set for sent and "
  143. "received packet to measure RTT");
  144. }
  145. boost::posix_time::time_period period(sent_time, rcvd_time);
  146. // We don't bother calculating deltas in nanoseconds. It is much
  147. // more convenient to use seconds instead because we are going to
  148. // sum them up.
  149. double delta =
  150. static_cast<double>(period.length().total_nanoseconds()) / 1e9;
  151. if (delta < 0) {
  152. isc_throw(Unexpected, "Sent packet's timestamp must not be "
  153. "greater than received packet's timestamp");
  154. }
  155. // Record the minimum delay between sent and received packets.
  156. if (delta < min_delay_) {
  157. min_delay_ = delta;
  158. }
  159. // Record the maximum delay between sent and received packets.
  160. if (delta > max_delay_) {
  161. max_delay_ = delta;
  162. }
  163. // Update delay sum and square sum. That will be used to calculate
  164. // mean delays.
  165. sum_delay_ += delta;
  166. square_sum_delay_ += delta * delta;
  167. }
  168. /// \brief Find packet on the list of sent packets.
  169. ///
  170. /// Method finds packet with specified transaction id on the list
  171. /// of sent packets. It is used to match received packet with
  172. /// corresponding sent packet.
  173. /// Since packets from the server most often come in the same order
  174. /// as they were sent by client, this method will first check if
  175. /// next sent packet matches. If it doesn't, function will search
  176. /// the packet using indexing by transaction id. This reduces
  177. /// packet search time significantly.
  178. ///
  179. /// \param transid transaction id of the packet to search
  180. /// \return packet having specified transaction or NULL if packet
  181. /// not found
  182. boost::shared_ptr<T> findSent(const uint32_t transid) {
  183. if (sent_packets_.size() == 0) {
  184. // List of sent packets is empty so there is no sense
  185. // to continue looking fo the packet. It also means
  186. // that the received packet we got has no corresponding
  187. // sent packet so orphans counter has to be updated.
  188. ++orphans_;
  189. return boost::shared_ptr<T>();
  190. } else if (sent_packets_cache_ == sent_packets_.end()) {
  191. // Even if there are still many unmatched packets on the
  192. // list we might hit the end of it because of unordered
  193. // lookups. The next logical step is to reset cache.
  194. sent_packets_cache_ = sent_packets_.begin();
  195. }
  196. // With this variable we will be signalling success or failure
  197. // to find the packet.
  198. bool packet_found = false;
  199. // Most likely responses are sent from the server in the same
  200. // order as client's requests to the server. We are caching
  201. // next sent packet and first try to match with it the next
  202. // incoming packet. We are successful if there is no
  203. // packet drop or out of order packets sent. This is actually
  204. // the fastest way to look for packets.
  205. if ((*sent_packets_cache_)->getTransid() == transid) {
  206. ++ordered_lookups_;
  207. packet_found = true;
  208. } else {
  209. // If we are here, it means that we were unable to match the
  210. // next incoming packet with next sent packet so we need to
  211. // take a little more expensive approach to look packets using
  212. // alternative index (transaction id & 1023).
  213. PktListTransidIndex& idx = sent_packets_.template get<1>();
  214. // Packets are grouped using trasaction id masking with value
  215. // of 1023. For instance, packets with transaction id equal to
  216. // 1, 1024 ... will belong to the same group (a.k.a. bucket).
  217. // When using alternative index we don't find the packet but
  218. // bucket of packets and need to iterate through the bucket
  219. // to find the one that has desired transaction id.
  220. std::pair<PktListTransidIterator,PktListTransidIterator> p =
  221. idx.equal_range(transid & 1023);
  222. // We want to keep statistics of unordered lookups to make
  223. // sure that there is a right balance before number of
  224. // unordered lookups and ordered lookups. If number of unordered
  225. // lookups is high it may mean that many packets are lost or
  226. // sent out of order.
  227. ++unordered_lookups_;
  228. // We also want to keep the mean value of the bucket. The lower
  229. // bucket size the better. If bucket sizes appear to big we
  230. // might want to increase number of buckets.
  231. unordered_lookup_size_sum_ += std::distance(p.first, p.second);
  232. for (PktListTransidIterator it = p.first; it != p.second;
  233. ++it) {
  234. if ((*it)->getTransid() == transid) {
  235. packet_found = true;
  236. sent_packets_cache_ =
  237. sent_packets_.template project<0>(it);
  238. break;
  239. }
  240. }
  241. }
  242. if (!packet_found) {
  243. // If we are here, it means that both ordered lookup and
  244. // unordered lookup failed. Searched packet is not on the list.
  245. ++orphans_;
  246. return boost::shared_ptr<T>();
  247. }
  248. boost::shared_ptr<T> sent_packet(*sent_packets_cache_);
  249. // If packet was found, we assume it will be never searched
  250. // again. We want to delete this packet from the list to
  251. // improve performance of future searches.
  252. sent_packets_cache_ = eraseSent(sent_packets_cache_);
  253. return sent_packet;
  254. }
  255. /// \brief Return minumum delay between sent and received packet.
  256. ///
  257. /// Method returns minimum delay between sent and received packet.
  258. ///
  259. /// \return minimum delay between packets.
  260. double getMinDelay() const { return min_delay_; }
  261. /// \brief Return maxmimum delay between sent and received packet.
  262. ///
  263. /// Method returns maximum delay between sent and received packet.
  264. ///
  265. /// \return maximum delay between packets.
  266. double getMaxDelay() const { return max_delay_; }
  267. /// \brief Return sum of delays between sent and received packets.
  268. ///
  269. /// Method returns sum of delays between sent and received packets.
  270. ///
  271. /// \return sum of delays between sent and received packets.
  272. double getSumDelay() const { return sum_delay_; }
  273. /// \brief Return square sum of delays between sent and received
  274. /// packets.
  275. ///
  276. /// Method returns square sum of delays between sent and received
  277. /// packets.
  278. ///
  279. /// \return square sum of delays between sent and received packets.
  280. double getSquareSumDelay() const { return square_sum_delay_; }
  281. /// \brief Return number of orphant packets.
  282. ///
  283. /// Method returns number of received packets that had no matching
  284. /// sent packet. It is possible that such packet was late or not
  285. /// for us.
  286. ///
  287. /// \return number of orphant received packets.
  288. uint64_t getOrphans() const { return orphans_; }
  289. /// \brief Return average unordered lookup set size.
  290. ///
  291. /// Method returns average unordered lookup set size.
  292. /// This value is changes every time \findSet function uses
  293. /// unordered packet lookup using transaction id.
  294. ///
  295. /// \return average unordered lookup set size.
  296. double getAvgUnorderedLookupSetSize() const {
  297. if (unordered_lookups_ == 0) {
  298. return 0.;
  299. }
  300. return static_cast<double>(unordered_lookup_size_sum_) /
  301. static_cast<double>(unordered_lookups_);
  302. }
  303. /// \brief Return number of unordered sent packets lookups
  304. ///
  305. /// Method returns number of unordered sent packet lookups.
  306. /// Unordered lookup is used when received packet was sent
  307. /// out of order by server - transaction id of received
  308. /// packet does not match transaction id of next sent packet.
  309. ///
  310. /// \return number of unordered lookups.
  311. uint64_t getUnorderedLookups() const { return unordered_lookups_; }
  312. /// \brief Return number of ordered sent packets lookups
  313. ///
  314. /// Method returns number of ordered sent packet lookups.
  315. /// Ordered lookup is used when packets are received in the
  316. /// same order as they were sent to the server.
  317. /// If packets are skipped or received out of order, lookup
  318. /// function will use unordered lookup (with hash table).
  319. ///
  320. /// \return number of ordered lookups.
  321. uint64_t getOrderedLookups() const { return ordered_lookups_; }
  322. /// \brief Return total number of sent packets
  323. ///
  324. /// Method returns total number of sent packets.
  325. ///
  326. /// \return number of sent packets.
  327. uint64_t getSentPacketsNum() const {
  328. return sent_packets_num_;
  329. }
  330. /// \brief Return total number of received packets
  331. ///
  332. /// Method returns total number of received packets.
  333. ///
  334. /// \return number of received packets.
  335. uint64_t getRcvdPacketsNum() const {
  336. return rcvd_packets_num_;
  337. }
  338. private:
  339. /// \brief Private default constructor.
  340. ///
  341. /// Default constructor is private because we want the client
  342. /// class to specify exchange type explicitely.
  343. ExchangeStats();
  344. /// \brief Erase packet from the list of sent packets.
  345. ///
  346. /// Method erases packet from the list of sent packets.
  347. ///
  348. /// \param it iterator pointing to packet to be erased.
  349. /// \return iterator pointing to packet following erased
  350. /// packet or sent_packets_.end() if packet not found.
  351. PktListIterator eraseSent(const PktListIterator it) {
  352. return sent_packets_.template get<0>().erase(it);
  353. }
  354. ExchangeType xchg_type_; ///< Packet exchange type.
  355. PktList sent_packets_; ///< List of sent packets.
  356. /// Iterator pointing to the packet on sent list which will most
  357. /// likely match next received packet. This is based on the
  358. /// assumption that server responds in order to incoming packets.
  359. PktListIterator sent_packets_cache_;
  360. PktList rcvd_packets_; ///< List of received packets.
  361. double min_delay_; ///< Minimum delay between sent
  362. ///< and received packets.
  363. double max_delay_; ///< Maximum delay between sent
  364. ///< and received packets.
  365. double sum_delay_; ///< Sum of delays between sent
  366. ///< and received packets.
  367. double square_sum_delay_; ///< Square sum of delays between
  368. ///< sent and recived packets.
  369. uint64_t orphans_; ///< Number of orphant received packets.
  370. /// Sum of unordered lookup sets. Needed to calculate mean size of
  371. /// lookup set. It is desired that number of unordered lookups is
  372. /// minimal for performance reasons. Tracking number of lookups and
  373. /// mean size of the lookup set should give idea of packets serach
  374. /// complexity.
  375. uint64_t unordered_lookup_size_sum_;
  376. uint64_t unordered_lookups_; ///< Number of unordered sent packets
  377. ///< lookups.
  378. uint64_t ordered_lookups_; ///< Number of ordered sent packets
  379. ///< lookups.
  380. uint64_t sent_packets_num_; ///< Total number of sent packets.
  381. uint64_t rcvd_packets_num_; ///< Total number of received packets.
  382. };
  383. /// Pointer to ExchangeStats.
  384. typedef boost::shared_ptr<ExchangeStats> ExchangeStatsPtr;
  385. /// Map containing all specified exchange types.
  386. typedef typename std::map<ExchangeType, ExchangeStatsPtr> ExchangesMap;
  387. /// Iterator poiting to \ref ExchangesMap
  388. typedef typename ExchangesMap::const_iterator ExchangesMapIterator;
  389. /// \brief Specify new exchange type.
  390. ///
  391. /// This method creates new \ref ExchangeStats object that will
  392. /// collect statistics data from packets exchange of the specified
  393. /// type.
  394. ///
  395. /// \param xchg_type exchange type.
  396. /// \throw isc::BadValue if exchange of specified type exists.
  397. void addExchangeStats(const ExchangeType xchg_type) {
  398. if (exchanges_.find(xchg_type) != exchanges_.end()) {
  399. isc_throw(BadValue, "Exchange of specified type already added.");
  400. }
  401. exchanges_[xchg_type] = ExchangeStatsPtr(new ExchangeStats(xchg_type));
  402. }
  403. /// \brief Adds new packet to the sent packets list.
  404. ///
  405. /// Method adds new packet to the sent packets list.
  406. /// Packets are added to the list sequentially and
  407. /// most often read sequentially.
  408. ///
  409. /// \param xchg_type exchange type.
  410. /// \param packet packet to be added to the list
  411. /// \throw isc::BadValue if invalid exchange type specified.
  412. void passSentPacket(const ExchangeType xchg_type,
  413. const boost::shared_ptr<T> packet) {
  414. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  415. xchg_stats->appendSent(packet);
  416. }
  417. /// \brief Add new received packet and match with sent packet.
  418. ///
  419. /// Method adds new packet to the list of received packets. It
  420. /// also searches for corresponding packet on the list of sent
  421. /// packets. When packets are matched the statistics counters
  422. /// are updated accordingly for the particular exchange type.
  423. ///
  424. /// \param xchg_type exchange type.
  425. /// \param packet received packet
  426. /// \throw isc::BadValue if invalid exchange type specified.
  427. /// \throw isc::Unexpected if corresponding packet was not
  428. /// found on the list of sent packets.
  429. void passRcvdPacket(const ExchangeType xchg_type,
  430. const boost::shared_ptr<T> packet) {
  431. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  432. boost::shared_ptr<T> sent_packet
  433. = xchg_stats->findSent(packet->getTransid());
  434. if (sent_packet) {
  435. xchg_stats->updateDelays(sent_packet, packet);
  436. xchg_stats->appendRcvd(packet);
  437. }
  438. }
  439. /// \brief Return minumum delay between sent and received packet.
  440. ///
  441. /// Method returns minimum delay between sent and received packet
  442. /// for specified exchange type.
  443. ///
  444. /// \param xchg_type exchange type.
  445. /// \throw isc::BadValue if invalid exchange type specified.
  446. /// \return minimum delay between packets.
  447. double getMinDelay(const ExchangeType xchg_type) const {
  448. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  449. return xchg_stats->getMinDelay();
  450. }
  451. /// \brief Return maxmimum delay between sent and received packet.
  452. ///
  453. /// Method returns maximum delay between sent and received packet
  454. /// for specified exchange type.
  455. ///
  456. /// \param xchg_type exchange type.
  457. /// \throw isc::BadValue if invalid exchange type specified.
  458. /// \return maximum delay between packets.
  459. double getMaxDelay(const ExchangeType xchg_type) const {
  460. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  461. return xchg_stats->getMaxDelay();
  462. }
  463. /// \brief Return sum of delays between sent and received packets.
  464. ///
  465. /// Method returns sum of delays between sent and received packets
  466. /// for specified exchange type.
  467. ///
  468. /// \param xchg_type exchange type.
  469. /// \throw isc::BadValue if invalid exchange type specified.
  470. /// \return sum of delays between sent and received packets.
  471. double getSumDelay(const ExchangeType xchg_type) const {
  472. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  473. return xchg_stats->getSumDelay();
  474. }
  475. /// \brief Return square sum of delays between sent and received
  476. /// packets.
  477. ///
  478. /// Method returns square sum of delays between sent and received
  479. /// packets for specified exchange type.
  480. ///
  481. /// \param xchg_type exchange type.
  482. /// \throw isc::BadValue if invalid exchange type specified.
  483. /// \return square sum of delays between sent and received packets.
  484. double getSquareSumDelay(const ExchangeType xchg_type) const {
  485. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  486. return xchg_stats->getSquareSumDelay();
  487. }
  488. /// \brief Return number of orphant packets.
  489. ///
  490. /// Method returns number of orphant packets for specified
  491. /// exchange type.
  492. ///
  493. /// \param xchg_type exchange type.
  494. /// \throw isc::BadValue if invalid exchange type specified.
  495. /// \return number of orphant packets so far.
  496. uint64_t getOrphans(const ExchangeType xchg_type) const {
  497. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  498. return xchg_stats->getOrphans();
  499. }
  500. /// \brief Return average unordered lookup set size.
  501. ///
  502. /// Method returns average unordered lookup set size.
  503. /// This value is changes every time \findSet function uses
  504. /// unordered packet lookup using transaction id.
  505. ///
  506. /// \param xchg_type exchange type.
  507. /// \throw isc::BadValue if invalid exchange type specified.
  508. /// \return average unordered lookup set size.
  509. double getAvgUnorderedLookupSetSize(const ExchangeType xchg_type) const {
  510. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  511. return xchg_stats->getAvgUnorderedLookupSetSize();
  512. }
  513. /// \brief Return number of unordered sent packets lookups
  514. ///
  515. /// Method returns number of unordered sent packet lookups.
  516. /// Unordered lookup is used when received packet was sent
  517. /// out of order by server - transaction id of received
  518. /// packet does not match transaction id of next sent packet.
  519. ///
  520. /// \param xchg_type exchange type.
  521. /// \throw isc::BadValue if invalid exchange type specified.
  522. /// \return number of unordered lookups.
  523. uint64_t getUnorderedLookups(const ExchangeType xchg_type) const {
  524. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  525. return xchg_stats->getUnorderedLookups();
  526. }
  527. /// \brief Return number of ordered sent packets lookups
  528. ///
  529. /// Method returns number of ordered sent packet lookups.
  530. /// Ordered lookup is used when packets are received in the
  531. /// same order as they were sent to the server.
  532. /// If packets are skipped or received out of order, lookup
  533. /// function will use unordered lookup (with hash table).
  534. ///
  535. /// \param xchg_type exchange type.
  536. /// \throw isc::BadValue if invalid exchange type specified.
  537. /// \return number of ordered lookups.
  538. uint64_t getOrderedLookups(const ExchangeType xchg_type) const {
  539. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  540. return xchg_stats->getOrderedLookups();
  541. }
  542. /// \brief Return total number of sent packets
  543. ///
  544. /// Method returns total number of sent packets for specified
  545. /// exchange type.
  546. ///
  547. /// \param xchg_type exchange type.
  548. /// \throw isc::BadValue if invalid exchange type specified.
  549. /// \return number of sent packets.
  550. uint64_t getSentPacketsNum(const ExchangeType xchg_type) const {
  551. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  552. return xchg_stats->getSentPacketsNum();
  553. }
  554. /// \brief Return total number of received packets
  555. ///
  556. /// Method returns total number of received packets for specified
  557. /// exchange type.
  558. ///
  559. /// \param xchg_type exchange type.
  560. /// \throw isc::BadValue if invalid exchange type specified.
  561. /// \return number of received packets.
  562. uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const {
  563. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  564. return xchg_stats->getRcvdPacketsNum();
  565. }
  566. private:
  567. /// \brief Return exchange stats object for given exchange type
  568. ///
  569. /// Method returns exchange stats object for given exchange type.
  570. ///
  571. /// \param xchg_type exchange type.
  572. /// \throw isc::BadValue if invalid exchange type specified.
  573. /// \return exchange stats object.
  574. ExchangeStatsPtr getExchangeStats(const ExchangeType xchg_type) const {
  575. ExchangesMapIterator it = exchanges_.find(xchg_type);
  576. if (it == exchanges_.end()) {
  577. isc_throw(BadValue, "Packets exchange not specified");
  578. }
  579. ExchangeStatsPtr xchg_stats = it->second;
  580. return xchg_stats;
  581. }
  582. ExchangesMap exchanges_; ///< Map of exchange types.
  583. };
  584. } // namespace perfdhcp
  585. } // namespace isc
  586. #endif // __STATS_MGR_H