stats_mgr.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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/global_fun.hpp>
  24. #include <boost/multi_index/mem_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. /// \param T class representing DHCPv4 or DHCPv6 packet.
  45. template <class T = dhcp::Pkt4>
  46. class StatsMgr : public boost::noncopyable {
  47. public:
  48. /// \brief Custom Counter
  49. ///
  50. /// This class represents custom statistics counters. Client class
  51. /// may create unlimited number of counters. Such counters are
  52. /// being stored in map in Statistics Manager and access using
  53. /// unique string key.
  54. class CustomCounter {
  55. public:
  56. /// \brief Constructor.
  57. ///
  58. /// This constructor sets counter name. This name is used in
  59. /// log file to report value of each counter.
  60. ///
  61. /// \param name name of the counter used in log file.
  62. CustomCounter(const std::string& name) :
  63. counter_(0),
  64. name_(name) { };
  65. /// \brief Increment operator.
  66. const CustomCounter& operator++() {
  67. ++counter_;
  68. return(*this);
  69. }
  70. /// \brief Increment operator.
  71. const CustomCounter& operator++(int) {
  72. CustomCounter& this_counter(*this);
  73. operator++();
  74. return(this_counter);
  75. }
  76. /// \brief Return counter value.
  77. ///
  78. /// Method returns counter value.
  79. ///
  80. /// \return counter value.
  81. uint64_t getValue() const { return(counter_); }
  82. /// \brief Return counter name.
  83. ///
  84. /// Method returns counter name.
  85. ///
  86. /// \return counter name.
  87. const std::string& getName() const { return(name_); }
  88. private:
  89. /// \brief Default constructor.
  90. ///
  91. /// Default constrcutor is private because we don't want client
  92. /// class to call it because we want client class to specify
  93. /// counter's name.
  94. CustomCounter() { };
  95. uint64_t counter_; ///< Counter's value.
  96. std::string name_; ///< Counter's name.
  97. };
  98. typedef typename boost::shared_ptr<CustomCounter> CustomCounterPtr;
  99. /// DHCP packet exchange types.
  100. enum ExchangeType {
  101. XCHG_DO, ///< DHCPv4 DISCOVER-OFFER
  102. XCHG_RA, ///< DHCPv4 REQUEST-ACK
  103. XCHG_SA, ///< DHCPv6 SOLICIT-ADVERTISE
  104. XCHG_RR ///< DHCPv6 REQUEST-REPLY
  105. };
  106. /// \brief Exchange Statistics.
  107. ///
  108. /// This class collects statistics for exchanges. Parent class
  109. /// may define number of different packet exchanges like:
  110. /// DHCPv4 DISCOVER-OFFER, DHCPv6 SOLICIT-ADVERTISE etc. Performance
  111. /// statistics will be collected for each of those separately in
  112. /// corresponding instance of ExchangeStats.
  113. class ExchangeStats {
  114. public:
  115. /// \brief Hash transaction id of the packet.
  116. ///
  117. /// Function hashes transaction id of the packet. Hashing is
  118. /// non-unique. Many packets may have the same hash value and thus
  119. /// they belong to the same packet buckets. Packet buckets are
  120. /// used for unordered packets search with multi index container.
  121. ///
  122. /// \param packet packet which transaction id is to be hashed.
  123. /// \throw isc::BadValue if packet is null.
  124. /// \return transaction id hash.
  125. static uint32_t hashTransid(const boost::shared_ptr<T>& packet) {
  126. if (!packet) {
  127. isc_throw(BadValue, "Packet is null");
  128. }
  129. return(packet->getTransid() & 1023);
  130. }
  131. /// \brief List of packets (sent or received).
  132. ///
  133. /// List of packets based on multi index container allows efficient
  134. /// search of packets based on their sequence (order in which they
  135. /// were inserted) as well as based on their hashed transaction id.
  136. /// The first index (sequenced) provides the way to use container
  137. /// as a regular list (including iterators, removal of elements from
  138. /// the middle of the collection etc.). This index is meant to be used
  139. /// more frequently than the latter one and it is based on the
  140. /// assumption that responses from the DHCP server are received in
  141. /// order. In this case, when next packet is received it can be
  142. /// matched with next packet on the list of sent packets. This
  143. /// prevents intensive searches on the list of sent packets every
  144. /// time new packet arrives. In many cases however packets can be
  145. /// dropped by the server or may be sent out of order and we still
  146. /// want to have ability to search packets using transaction id.
  147. /// The second index can be used for this purpose. This index is
  148. /// hashing transaction ids using custom function \ref hashTransid.
  149. /// Note that other possibility would be to simply specify index
  150. /// that uses transaction id directly (instead of hashing with
  151. /// \ref hashTransid). In this case however we have chosen to use
  152. /// hashing function because it shortens the index size to just
  153. /// 1023 values maximum. Search operation on this index generally
  154. /// returns the range of packets that have the same transaction id
  155. /// hash assigned but most often these ranges will be short so further
  156. /// search within a range to find a packet with pacrticular transaction
  157. /// id will not be intensive.
  158. ///
  159. /// Example 1: Add elements to the list
  160. /// \code
  161. /// PktList packets_collection();
  162. /// boost::shared_ptr<Pkt4> pkt1(new Pkt4(...));
  163. /// boost::shared_ptr<Pkt4> pkt2(new Pkt4(...));
  164. /// // Add new packet to the container, it will be available through
  165. /// // both indexes
  166. /// packets_collection.push_back(pkt1);
  167. /// // Here is another way to add packet to the container. The result
  168. /// // is exactly the same as previously.
  169. /// packets_collection.template get<0>().push_back(pkt2);
  170. /// \endcode
  171. ///
  172. /// Example 2: Access elements through sequencial index
  173. /// \code
  174. /// PktList packets_collection();
  175. /// ... # Add elements to the container
  176. /// for (PktListIterator it = packets_collection.begin();
  177. /// it != packets_collection.end();
  178. /// ++it) {
  179. /// boost::shared_ptr<Pkt4> pkt = *it;
  180. /// # Do something with packet;
  181. /// }
  182. /// \endcode
  183. ///
  184. /// Example 3: Access elements through hashed index
  185. /// \code
  186. /// // Get the instance of the second search index.
  187. /// PktListTransidHashIndex& idx = sent_packets_.template get<1>();
  188. /// // Get the range (bucket) of packets sharing the same transaction
  189. /// // id hash.
  190. /// std::pair<PktListTransidHashIterator,PktListTransidHashIterator> p =
  191. /// idx.equal_range(hashTransid(rcvd_packet));
  192. /// // Iterate through the returned bucket.
  193. /// for (PktListTransidHashIterator it = p.first; it != p.second;
  194. /// ++it) {
  195. /// boost::shared_ptr pkt = *it;
  196. /// ... # Do something with the packet (e.g. check transaction id)
  197. /// }
  198. /// \endcode
  199. typedef boost::multi_index_container<
  200. boost::shared_ptr<T>,
  201. boost::multi_index::indexed_by<
  202. boost::multi_index::sequenced<>,
  203. boost::multi_index::hashed_non_unique<
  204. boost::multi_index::global_fun<
  205. const boost::shared_ptr<T>&,
  206. uint32_t,
  207. &ExchangeStats::hashTransid
  208. >
  209. >
  210. >
  211. > PktList;
  212. /// Packet list iterator for sequencial access to elements.
  213. typedef typename PktList::iterator PktListIterator;
  214. /// Packet list index to search packets using transaction id hash.
  215. typedef typename PktList::template nth_index<1>::type
  216. PktListTransidHashIndex;
  217. /// Packet list iterator to access packets using transaction id hash.
  218. typedef typename PktListTransidHashIndex::const_iterator
  219. PktListTransidHashIterator;
  220. /// \brief Constructor
  221. ///
  222. /// \param xchg_type exchange type
  223. /// \param archive_enabled if true packets archive mode is enabled.
  224. /// In this mode all packets are stored throughout the test execution.
  225. ExchangeStats(const ExchangeType xchg_type, const bool archive_enabled)
  226. : xchg_type_(xchg_type),
  227. sent_packets_(),
  228. rcvd_packets_(),
  229. archived_packets_(),
  230. archive_enabled_(archive_enabled),
  231. min_delay_(std::numeric_limits<double>::max()),
  232. max_delay_(0.),
  233. sum_delay_(0.),
  234. sum_delay_squared_(0.),
  235. orphans_(0),
  236. unordered_lookup_size_sum_(0),
  237. unordered_lookups_(0),
  238. ordered_lookups_(0),
  239. sent_packets_num_(0),
  240. rcvd_packets_num_(0)
  241. {
  242. next_sent_ = sent_packets_.begin();
  243. }
  244. /// \brief Add new packet to list of sent packets.
  245. ///
  246. /// Method adds new packet to list of sent packets.
  247. ///
  248. /// \param packet packet object to be added.
  249. /// \throw isc::BadValue if packet is null.
  250. void appendSent(const boost::shared_ptr<T>& packet) {
  251. if (!packet) {
  252. isc_throw(BadValue, "Packet is null");
  253. }
  254. ++sent_packets_num_;
  255. sent_packets_.template get<0>().push_back(packet);
  256. }
  257. /// \brief Add new packet to list of received packets.
  258. ///
  259. /// Method adds new packet to list of received packets.
  260. ///
  261. /// \param packet packet object to be added.
  262. /// \throw isc::BadValue if packet is null.
  263. void appendRcvd(const boost::shared_ptr<T>& packet) {
  264. if (!packet) {
  265. isc_throw(BadValue, "Packet is null");
  266. }
  267. rcvd_packets_.push_back(packet);
  268. }
  269. /// \brief Update delay counters.
  270. ///
  271. /// Method updates delay counters based on timestamps of
  272. /// sent and received packets.
  273. ///
  274. /// \param sent_packet sent packet
  275. /// \param rcvd_packet received packet
  276. /// \throw isc::BadValue if sent or received packet is null.
  277. /// \throw isc::Unexpected if failed to calculate timestamps
  278. void updateDelays(const boost::shared_ptr<T>& sent_packet,
  279. const boost::shared_ptr<T>& rcvd_packet) {
  280. if (!sent_packet) {
  281. isc_throw(BadValue, "Sent packet is null");
  282. }
  283. if (!rcvd_packet) {
  284. isc_throw(BadValue, "Received packet is null");
  285. }
  286. boost::posix_time::ptime sent_time = sent_packet->getTimestamp();
  287. boost::posix_time::ptime rcvd_time = rcvd_packet->getTimestamp();
  288. if (sent_time.is_not_a_date_time() ||
  289. rcvd_time.is_not_a_date_time()) {
  290. isc_throw(Unexpected,
  291. "Timestamp must be set for sent and "
  292. "received packet to measure RTT");
  293. }
  294. boost::posix_time::time_period period(sent_time, rcvd_time);
  295. // We don't bother calculating deltas in nanoseconds. It is much
  296. // more convenient to use seconds instead because we are going to
  297. // sum them up.
  298. double delta =
  299. static_cast<double>(period.length().total_nanoseconds()) / 1e9;
  300. if (delta < 0) {
  301. isc_throw(Unexpected, "Sent packet's timestamp must not be "
  302. "greater than received packet's timestamp");
  303. }
  304. // Record the minimum delay between sent and received packets.
  305. if (delta < min_delay_) {
  306. min_delay_ = delta;
  307. }
  308. // Record the maximum delay between sent and received packets.
  309. if (delta > max_delay_) {
  310. max_delay_ = delta;
  311. }
  312. // Update delay sum and square sum. That will be used to calculate
  313. // mean delays.
  314. sum_delay_ += delta;
  315. sum_delay_squared_ += delta * delta;
  316. }
  317. /// \brief Match received packet with the corresponding sent packet.
  318. ///
  319. /// Method finds packet with specified transaction id on the list
  320. /// of sent packets. It is used to match received packet with
  321. /// corresponding sent packet.
  322. /// Since packets from the server most often come in the same order
  323. /// as they were sent by client, this method will first check if
  324. /// next sent packet matches. If it doesn't, function will search
  325. /// the packet using indexing by transaction id. This reduces
  326. /// packet search time significantly.
  327. ///
  328. /// \param rcvd_packet received packet to be matched with sent packet.
  329. /// \throw isc::BadValue if received packet is null.
  330. /// \return packet having specified transaction or NULL if packet
  331. /// not found
  332. boost::shared_ptr<T>
  333. matchPackets(const boost::shared_ptr<T>& rcvd_packet) {
  334. if (!rcvd_packet) {
  335. isc_throw(BadValue, "Received packet is null");
  336. }
  337. if (sent_packets_.size() == 0) {
  338. // List of sent packets is empty so there is no sense
  339. // to continue looking fo the packet. It also means
  340. // that the received packet we got has no corresponding
  341. // sent packet so orphans counter has to be updated.
  342. ++orphans_;
  343. return(boost::shared_ptr<T>());
  344. } else if (next_sent_ == sent_packets_.end()) {
  345. // Even if there are still many unmatched packets on the
  346. // list we might hit the end of it because of unordered
  347. // lookups. The next logical step is to reset iterator.
  348. next_sent_ = sent_packets_.begin();
  349. }
  350. // With this variable we will be signalling success or failure
  351. // to find the packet.
  352. bool packet_found = false;
  353. // Most likely responses are sent from the server in the same
  354. // order as client's requests to the server. We are caching
  355. // next sent packet and first try to match it with the next
  356. // incoming packet. We are successful if there is no
  357. // packet drop or out of order packets sent. This is actually
  358. // the fastest way to look for packets.
  359. if ((*next_sent_)->getTransid() == rcvd_packet->getTransid()) {
  360. ++ordered_lookups_;
  361. packet_found = true;
  362. } else {
  363. // If we are here, it means that we were unable to match the
  364. // next incoming packet with next sent packet so we need to
  365. // take a little more expensive approach to look packets using
  366. // alternative index (transaction id & 1023).
  367. PktListTransidHashIndex& idx = sent_packets_.template get<1>();
  368. // Packets are grouped using trasaction id masked with value
  369. // of 1023. For instance, packets with transaction id equal to
  370. // 1, 1024 ... will belong to the same group (a.k.a. bucket).
  371. // When using alternative index we don't find the packet but
  372. // bucket of packets and we need to iterate through the bucket
  373. // to find the one that has desired transaction id.
  374. std::pair<PktListTransidHashIterator,PktListTransidHashIterator> p =
  375. idx.equal_range(hashTransid(rcvd_packet));
  376. // We want to keep statistics of unordered lookups to make
  377. // sure that there is a right balance between number of
  378. // unordered lookups and ordered lookups. If number of unordered
  379. // lookups is high it may mean that many packets are lost or
  380. // sent out of order.
  381. ++unordered_lookups_;
  382. // We also want to keep the mean value of the bucket. The lower
  383. // bucket size the better. If bucket sizes appear to big we
  384. // might want to increase number of buckets.
  385. unordered_lookup_size_sum_ += std::distance(p.first, p.second);
  386. for (PktListTransidHashIterator it = p.first; it != p.second;
  387. ++it) {
  388. if ((*it)->getTransid() == rcvd_packet->getTransid()) {
  389. packet_found = true;
  390. next_sent_ =
  391. sent_packets_.template project<0>(it);
  392. break;
  393. }
  394. }
  395. }
  396. if (!packet_found) {
  397. // If we are here, it means that both ordered lookup and
  398. // unordered lookup failed. Searched packet is not on the list.
  399. ++orphans_;
  400. return(boost::shared_ptr<T>());
  401. }
  402. // Packet is matched so we count it. We don't count unmatched packets
  403. // as they are counted as orphans with a separate counter.
  404. ++rcvd_packets_num_;
  405. boost::shared_ptr<T> sent_packet(*next_sent_);
  406. // If packet was found, we assume it will be never searched
  407. // again. We want to delete this packet from the list to
  408. // improve performance of future searches.
  409. next_sent_ = eraseSent(next_sent_);
  410. return(sent_packet);
  411. }
  412. /// \brief Return minumum delay between sent and received packet.
  413. ///
  414. /// Method returns minimum delay between sent and received packet.
  415. ///
  416. /// \return minimum delay between packets.
  417. double getMinDelay() const { return(min_delay_); }
  418. /// \brief Return maxmimum delay between sent and received packet.
  419. ///
  420. /// Method returns maximum delay between sent and received packet.
  421. ///
  422. /// \return maximum delay between packets.
  423. double getMaxDelay() const { return(max_delay_); }
  424. /// \brief Return avarage packet delay.
  425. ///
  426. /// Method returns average packet delay. If no packets have been
  427. /// received for this exchange avg delay can't be calculated and
  428. /// thus method throws exception.
  429. ///
  430. /// \throw isc::InvalidOperation if no packets for this exchange
  431. /// have been received yet.
  432. /// \return average packet delay.
  433. double getAvgDelay() const {
  434. if (rcvd_packets_num_ == 0) {
  435. isc_throw(InvalidOperation, "no packets received");
  436. }
  437. return(sum_delay_ / rcvd_packets_num_);
  438. }
  439. /// \brief Return standard deviation of packet delay.
  440. ///
  441. /// Method returns standard deviation of packet delay. If no
  442. /// packets have been received for this exchange, the standard
  443. /// deviation can't be calculated and thus method throws
  444. /// exception.
  445. ///
  446. /// \throw isc::InvalidOperation if number of received packets
  447. /// for the exchange is equal to zero.
  448. /// \return standard deviation of packet delay.
  449. double getStdDevDelay() const {
  450. if (rcvd_packets_num_ == 0) {
  451. isc_throw(InvalidOperation, "no packets received");
  452. }
  453. return(sqrt(sum_delay_squared_ / rcvd_packets_num_ -
  454. getAvgDelay() * getAvgDelay()));
  455. }
  456. /// \brief Return number of orphant packets.
  457. ///
  458. /// Method returns number of received packets that had no matching
  459. /// sent packet. It is possible that such packet was late or not
  460. /// for us.
  461. ///
  462. /// \return number of orphant received packets.
  463. uint64_t getOrphans() const { return(orphans_); }
  464. /// \brief Return average unordered lookup set size.
  465. ///
  466. /// Method returns average unordered lookup set size.
  467. /// This value changes every time \ref ExchangeStats::matchPackets
  468. /// function performs unordered packet lookup.
  469. ///
  470. /// \throw isc::InvalidOperation if there have been no unordered
  471. /// lookups yet.
  472. /// \return average unordered lookup set size.
  473. double getAvgUnorderedLookupSetSize() const {
  474. if (unordered_lookups_ == 0) {
  475. isc_throw(InvalidOperation, "no unordered lookups");
  476. }
  477. return(static_cast<double>(unordered_lookup_size_sum_) /
  478. static_cast<double>(unordered_lookups_));
  479. }
  480. /// \brief Return number of unordered sent packets lookups
  481. ///
  482. /// Method returns number of unordered sent packet lookups.
  483. /// Unordered lookup is used when received packet was sent
  484. /// out of order by server - transaction id of received
  485. /// packet does not match transaction id of next sent packet.
  486. ///
  487. /// \return number of unordered lookups.
  488. uint64_t getUnorderedLookups() const { return(unordered_lookups_); }
  489. /// \brief Return number of ordered sent packets lookups
  490. ///
  491. /// Method returns number of ordered sent packet lookups.
  492. /// Ordered lookup is used when packets are received in the
  493. /// same order as they were sent to the server.
  494. /// If packets are skipped or received out of order, lookup
  495. /// function will use unordered lookup (with hash table).
  496. ///
  497. /// \return number of ordered lookups.
  498. uint64_t getOrderedLookups() const { return(ordered_lookups_); }
  499. /// \brief Return total number of sent packets
  500. ///
  501. /// Method returns total number of sent packets.
  502. ///
  503. /// \return number of sent packets.
  504. uint64_t getSentPacketsNum() const { return(sent_packets_num_); }
  505. /// \brief Return total number of received packets
  506. ///
  507. /// Method returns total number of received packets.
  508. ///
  509. /// \return number of received packets.
  510. uint64_t getRcvdPacketsNum() const { return(rcvd_packets_num_); }
  511. /// \brief Return number of dropped packets.
  512. ///
  513. /// Method returns number of dropped packets.
  514. ///
  515. /// \return number of dropped packets.
  516. uint64_t getDroppedPacketsNum() const {
  517. uint64_t drops = 0;
  518. if (getSentPacketsNum() > getRcvdPacketsNum()) {
  519. drops = getSentPacketsNum() - getRcvdPacketsNum();
  520. }
  521. return(drops);
  522. }
  523. /// \brief Print main statistics for packet exchange.
  524. ///
  525. /// Method prints main statistics for particular exchange.
  526. /// Statistics includes: number of sent and received packets,
  527. /// number of dropped packets and number of orphans.
  528. void printMainStats() const {
  529. using namespace std;
  530. cout << "sent packets: " << getSentPacketsNum() << endl
  531. << "received packets: " << getRcvdPacketsNum() << endl
  532. << "drops: " << getDroppedPacketsNum() << endl
  533. << "orphans: " << getOrphans() << endl;
  534. }
  535. /// \brief Print round trip time packets statistics.
  536. ///
  537. /// Method prints round trip time packets statistics. Statistics
  538. /// includes minimum packet delay, maximum packet delay, average
  539. /// packet delay and standard deviation of delays. Packet delay
  540. /// is a duration between sending a packet to server and receiving
  541. /// response from server.
  542. void printRTTStats() const {
  543. using namespace std;
  544. try {
  545. cout << fixed << setprecision(3)
  546. << "min delay: " << getMinDelay() * 1e3 << " ms" << endl
  547. << "avg delay: " << getAvgDelay() * 1e3 << " ms" << endl
  548. << "max delay: " << getMaxDelay() * 1e3 << " ms" << endl
  549. << "std deviation: " << getStdDevDelay() * 1e3 << " ms"
  550. << endl;
  551. } catch (const Exception& e) {
  552. cout << "Unavailable! No packets received." << endl;
  553. }
  554. }
  555. //// \brief Print timestamps for sent and received packets.
  556. ///
  557. /// Method prints timestamps for all sent and received packets for
  558. /// packet exchange. In order to run this method the packets
  559. /// archiving mode has to be enabled during object constructions.
  560. /// Otherwise sent packets are not stored during tests execution
  561. /// and this method has no ability to get and print their timestamps.
  562. ///
  563. /// \throw isc::InvalidOperation if found packet with no timestamp or
  564. /// if packets archive mode is disabled.
  565. void printTimestamps() {
  566. // If archive mode is disabled there is no sense to proceed
  567. // because we don't have packets and their timestamps.
  568. if (!archive_enabled_) {
  569. isc_throw(isc::InvalidOperation,
  570. "packets archive mode is disabled");
  571. }
  572. if (rcvd_packets_num_ == 0) {
  573. std::cout << "Unavailable! No packets received." << std::endl;
  574. }
  575. // We will be using boost::posix_time extensivelly here
  576. using namespace boost::posix_time;
  577. // Iterate through all received packets.
  578. for (PktListIterator it = rcvd_packets_.begin();
  579. it != rcvd_packets_.end();
  580. ++it) {
  581. boost::shared_ptr<T> rcvd_packet = *it;
  582. PktListTransidHashIndex& idx =
  583. archived_packets_.template get<1>();
  584. std::pair<PktListTransidHashIterator,
  585. PktListTransidHashIterator> p =
  586. idx.equal_range(hashTransid(rcvd_packet));
  587. for (PktListTransidHashIterator it_archived = p.first;
  588. it_archived != p.second;
  589. ++it) {
  590. if ((*it_archived)->getTransid() ==
  591. rcvd_packet->getTransid()) {
  592. boost::shared_ptr<T> sent_packet = *it_archived;
  593. // Get sent and received packet times.
  594. ptime sent_time = sent_packet->getTimestamp();
  595. ptime rcvd_time = rcvd_packet->getTimestamp();
  596. // All sent and received packets should have timestamps
  597. // set but if there is a bug somewhere and packet does
  598. // not have timestamp we want to catch this here.
  599. if (sent_time.is_not_a_date_time() ||
  600. rcvd_time.is_not_a_date_time()) {
  601. isc_throw(InvalidOperation,
  602. "packet time is not set");
  603. }
  604. // Calculate durations of packets from beginning of epoch.
  605. ptime epoch_time(min_date_time);
  606. time_period sent_period(epoch_time, sent_time);
  607. time_period rcvd_period(epoch_time, rcvd_time);
  608. // Print timestamps for sent and received packet.
  609. std::cout << "sent / received: "
  610. << to_iso_string(sent_period.length())
  611. << " / "
  612. << to_iso_string(rcvd_period.length())
  613. << std::endl;
  614. break;
  615. }
  616. }
  617. }
  618. }
  619. private:
  620. /// \brief Private default constructor.
  621. ///
  622. /// Default constructor is private because we want the client
  623. /// class to specify exchange type explicitely.
  624. ExchangeStats();
  625. /// \brief Erase packet from the list of sent packets.
  626. ///
  627. /// Method erases packet from the list of sent packets.
  628. ///
  629. /// \param it iterator pointing to packet to be erased.
  630. /// \return iterator pointing to packet following erased
  631. /// packet or sent_packets_.end() if packet not found.
  632. PktListIterator eraseSent(const PktListIterator it) {
  633. if (archive_enabled_) {
  634. // We don't want to keep list of all sent packets
  635. // because it will affect packet lookup performance.
  636. // If packet is matched with received packet we
  637. // move it to list of archived packets. List of
  638. // archived packets may be used for diagnostics
  639. // when test is completed.
  640. archived_packets_.push_back(*it);
  641. }
  642. // get<0>() template returns sequencial index to
  643. // container.
  644. return(sent_packets_.template get<0>().erase(it));
  645. }
  646. ExchangeType xchg_type_; ///< Packet exchange type.
  647. PktList sent_packets_; ///< List of sent packets.
  648. /// Iterator pointing to the packet on sent list which will most
  649. /// likely match next received packet. This is based on the
  650. /// assumption that server responds in order to incoming packets.
  651. PktListIterator next_sent_;
  652. PktList rcvd_packets_; ///< List of received packets.
  653. /// List of archived packets. All sent packets that have
  654. /// been matched with received packet are moved to this
  655. /// list for diagnostics purposes.
  656. PktList archived_packets_;
  657. /// Indicates all packets have to be preserved after matching.
  658. /// By default this is disabled which means that when received
  659. /// packet is matched with sent packet both are deleted. This
  660. /// is important when test is executed for extended period of
  661. /// time and high memory usage might be the issue.
  662. /// When timestamps listing is specified from the command line
  663. /// (using diagnostics selector), all packets have to be preserved
  664. /// so as the printing method may read their timestamps and
  665. /// print it to user. In such usage model it will be rare to
  666. /// run test for extended period of time so it should be fine
  667. /// to keep all packets archived throughout the test.
  668. bool archive_enabled_;
  669. double min_delay_; ///< Minimum delay between sent
  670. ///< and received packets.
  671. double max_delay_; ///< Maximum delay between sent
  672. ///< and received packets.
  673. double sum_delay_; ///< Sum of delays between sent
  674. ///< and received packets.
  675. double sum_delay_squared_; ///< Squared sum of delays between
  676. ///< sent and recived packets.
  677. uint64_t orphans_; ///< Number of orphant received packets.
  678. /// Sum of unordered lookup sets. Needed to calculate mean size of
  679. /// lookup set. It is desired that number of unordered lookups is
  680. /// minimal for performance reasons. Tracking number of lookups and
  681. /// mean size of the lookup set should give idea of packets serach
  682. /// complexity.
  683. uint64_t unordered_lookup_size_sum_;
  684. uint64_t unordered_lookups_; ///< Number of unordered sent packets
  685. ///< lookups.
  686. uint64_t ordered_lookups_; ///< Number of ordered sent packets
  687. ///< lookups.
  688. uint64_t sent_packets_num_; ///< Total number of sent packets.
  689. uint64_t rcvd_packets_num_; ///< Total number of received packets.
  690. };
  691. /// Pointer to ExchangeStats.
  692. typedef boost::shared_ptr<ExchangeStats> ExchangeStatsPtr;
  693. /// Map containing all specified exchange types.
  694. typedef typename std::map<ExchangeType, ExchangeStatsPtr> ExchangesMap;
  695. /// Iterator poiting to \ref ExchangesMap
  696. typedef typename ExchangesMap::const_iterator ExchangesMapIterator;
  697. /// Map containing custom counters.
  698. typedef typename std::map<std::string, CustomCounterPtr> CustomCountersMap;
  699. /// Iterator for \ref CustomCountersMap.
  700. typedef typename CustomCountersMap::const_iterator CustomCountersMapIterator;
  701. /// \brief Constructor.
  702. ///
  703. /// This constructor by default disables packets archiving mode.
  704. /// In this mode all packets from the list of sent packets are
  705. /// moved to list of archived packets once they have been matched
  706. /// with received packets. This is required if it has been selected
  707. /// from the command line to print timestamps for all packets after
  708. /// the test. If this is not selected archiving should be disabled
  709. /// for performance reasons and to avoid waste of memory for storing
  710. /// large list of archived packets.
  711. ///
  712. /// \param archive_enabled true indicates that packets
  713. /// archive mode is enabled.
  714. StatsMgr(const bool archive_enabled = false) :
  715. exchanges_(),
  716. custom_counters_(),
  717. archive_enabled_(archive_enabled),
  718. boot_time_(boost::posix_time::microsec_clock::universal_time()) {
  719. }
  720. /// \brief Specify new exchange type.
  721. ///
  722. /// This method creates new \ref ExchangeStats object that will
  723. /// collect statistics data from packets exchange of the specified
  724. /// type.
  725. ///
  726. /// \param xchg_type exchange type.
  727. /// \throw isc::BadValue if exchange of specified type exists.
  728. void addExchangeStats(const ExchangeType xchg_type) {
  729. if (exchanges_.find(xchg_type) != exchanges_.end()) {
  730. isc_throw(BadValue, "Exchange of specified type already added.");
  731. }
  732. exchanges_[xchg_type] =
  733. ExchangeStatsPtr(new ExchangeStats(xchg_type, archive_enabled_));
  734. }
  735. /// \brief Add named custom uint64 counter.
  736. ///
  737. /// Method creates new named counter and stores in counter's map under
  738. /// key specified here as short_name.
  739. ///
  740. /// \param short_name key to use to access counter in the map.
  741. /// \param long_name name of the counter presented in the log file.
  742. void addCustomCounter(const std::string& short_name,
  743. const std::string& long_name) {
  744. if (custom_counters_.find(short_name) != custom_counters_.end()) {
  745. isc_throw(BadValue,
  746. "Custom counter " << short_name << " already added.");
  747. }
  748. custom_counters_[short_name] =
  749. CustomCounterPtr(new CustomCounter(long_name));
  750. }
  751. /// \brief Return specified counter.
  752. ///
  753. /// Method returns specified counter.
  754. ///
  755. /// \param counter_key key poiting to the counter in the counters map.
  756. /// The short counter name has to be used to access counter.
  757. /// \return pointer to specified counter object.
  758. CustomCounterPtr getCounter(const std::string& counter_key) {
  759. CustomCountersMapIterator it = custom_counters_.find(counter_key);
  760. if (it == custom_counters_.end()) {
  761. isc_throw(BadValue,
  762. "Custom counter " << counter_key << "does not exist");
  763. }
  764. return(it->second);
  765. }
  766. /// \brief Increment specified counter.
  767. ///
  768. /// Increement counter value by one.
  769. ///
  770. /// \param counter_key key poitinh to the counter in the counters map.
  771. /// \return pointer to specified counter after incrementation.
  772. const CustomCounter& IncrementCounter(const std::string& counter_key) {
  773. CustomCounterPtr counter = getCounter(counter_key);
  774. return(++(*counter));
  775. }
  776. /// \brief Adds new packet to the sent packets list.
  777. ///
  778. /// Method adds new packet to the sent packets list.
  779. /// Packets are added to the list sequentially and
  780. /// most often read sequentially.
  781. ///
  782. /// \param xchg_type exchange type.
  783. /// \param packet packet to be added to the list
  784. /// \throw isc::BadValue if invalid exchange type specified or
  785. /// packet is null.
  786. void passSentPacket(const ExchangeType xchg_type,
  787. const boost::shared_ptr<T>& packet) {
  788. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  789. xchg_stats->appendSent(packet);
  790. }
  791. /// \brief Add new received packet and match with sent packet.
  792. ///
  793. /// Method adds new packet to the list of received packets. It
  794. /// also searches for corresponding packet on the list of sent
  795. /// packets. When packets are matched the statistics counters
  796. /// are updated accordingly for the particular exchange type.
  797. ///
  798. /// \param xchg_type exchange type.
  799. /// \param packet received packet
  800. /// \throw isc::BadValue if invalid exchange type specified
  801. /// or packet is null.
  802. /// \throw isc::Unexpected if corresponding packet was not
  803. /// found on the list of sent packets.
  804. boost::shared_ptr<T>
  805. passRcvdPacket(const ExchangeType xchg_type,
  806. const boost::shared_ptr<T>& packet) {
  807. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  808. boost::shared_ptr<T> sent_packet
  809. = xchg_stats->matchPackets(packet);
  810. if (sent_packet) {
  811. xchg_stats->updateDelays(sent_packet, packet);
  812. if (archive_enabled_) {
  813. xchg_stats->appendRcvd(packet);
  814. }
  815. }
  816. return(sent_packet);
  817. }
  818. /// \brief Return minumum delay between sent and received packet.
  819. ///
  820. /// Method returns minimum delay between sent and received packet
  821. /// for specified exchange type.
  822. ///
  823. /// \param xchg_type exchange type.
  824. /// \throw isc::BadValue if invalid exchange type specified.
  825. /// \return minimum delay between packets.
  826. double getMinDelay(const ExchangeType xchg_type) const {
  827. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  828. return(xchg_stats->getMinDelay());
  829. }
  830. /// \brief Return maxmimum delay between sent and received packet.
  831. ///
  832. /// Method returns maximum delay between sent and received packet
  833. /// for specified exchange type.
  834. ///
  835. /// \param xchg_type exchange type.
  836. /// \throw isc::BadValue if invalid exchange type specified.
  837. /// \return maximum delay between packets.
  838. double getMaxDelay(const ExchangeType xchg_type) const {
  839. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  840. return(xchg_stats->getMaxDelay());
  841. }
  842. /// \brief Return avarage packet delay.
  843. ///
  844. /// Method returns average packet delay for specified
  845. /// exchange type.
  846. ///
  847. /// \return average packet delay.
  848. double getAvgDelay(const ExchangeType xchg_type) const {
  849. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  850. return(xchg_stats->getAvgDelay());
  851. }
  852. /// \brief Return standard deviation of packet delay.
  853. ///
  854. /// Method returns standard deviation of packet delay
  855. /// for specified exchange type.
  856. ///
  857. /// \return standard deviation of packet delay.
  858. double getStdDevDelay(const ExchangeType xchg_type) const {
  859. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  860. return(xchg_stats->getStdDevDelay());
  861. }
  862. /// \brief Return number of orphant packets.
  863. ///
  864. /// Method returns number of orphant packets for specified
  865. /// exchange type.
  866. ///
  867. /// \param xchg_type exchange type.
  868. /// \throw isc::BadValue if invalid exchange type specified.
  869. /// \return number of orphant packets so far.
  870. uint64_t getOrphans(const ExchangeType xchg_type) const {
  871. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  872. return(xchg_stats->getOrphans());
  873. }
  874. /// \brief Return average unordered lookup set size.
  875. ///
  876. /// Method returns average unordered lookup set size.
  877. /// This value changes every time \ref ExchangeStats::matchPackets
  878. /// function performs unordered packet lookup.
  879. ///
  880. /// \param xchg_type exchange type.
  881. /// \throw isc::BadValue if invalid exchange type specified.
  882. /// \return average unordered lookup set size.
  883. double getAvgUnorderedLookupSetSize(const ExchangeType xchg_type) const {
  884. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  885. return(xchg_stats->getAvgUnorderedLookupSetSize());
  886. }
  887. /// \brief Return number of unordered sent packets lookups
  888. ///
  889. /// Method returns number of unordered sent packet lookups.
  890. /// Unordered lookup is used when received packet was sent
  891. /// out of order by server - transaction id of received
  892. /// packet does not match transaction id of next sent packet.
  893. ///
  894. /// \param xchg_type exchange type.
  895. /// \throw isc::BadValue if invalid exchange type specified.
  896. /// \return number of unordered lookups.
  897. uint64_t getUnorderedLookups(const ExchangeType xchg_type) const {
  898. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  899. return(xchg_stats->getUnorderedLookups());
  900. }
  901. /// \brief Return number of ordered sent packets lookups
  902. ///
  903. /// Method returns number of ordered sent packet lookups.
  904. /// Ordered lookup is used when packets are received in the
  905. /// same order as they were sent to the server.
  906. /// If packets are skipped or received out of order, lookup
  907. /// function will use unordered lookup (with hash table).
  908. ///
  909. /// \param xchg_type exchange type.
  910. /// \throw isc::BadValue if invalid exchange type specified.
  911. /// \return number of ordered lookups.
  912. uint64_t getOrderedLookups(const ExchangeType xchg_type) const {
  913. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  914. return(xchg_stats->getOrderedLookups());
  915. }
  916. /// \brief Return total number of sent packets
  917. ///
  918. /// Method returns total number of sent packets for specified
  919. /// exchange type.
  920. ///
  921. /// \param xchg_type exchange type.
  922. /// \throw isc::BadValue if invalid exchange type specified.
  923. /// \return number of sent packets.
  924. uint64_t getSentPacketsNum(const ExchangeType xchg_type) const {
  925. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  926. return(xchg_stats->getSentPacketsNum());
  927. }
  928. /// \brief Return total number of received packets
  929. ///
  930. /// Method returns total number of received packets for specified
  931. /// exchange type.
  932. ///
  933. /// \param xchg_type exchange type.
  934. /// \throw isc::BadValue if invalid exchange type specified.
  935. /// \return number of received packets.
  936. uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const {
  937. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  938. return(xchg_stats->getRcvdPacketsNum());
  939. }
  940. /// \brief Return total number of dropped packets.
  941. ///
  942. /// Method returns total number of dropped packets for specified
  943. /// exchange type.
  944. ///
  945. /// \param xchg_type exchange type.
  946. /// \throw isc::BadValue if invalid exchange type specified.
  947. /// \return number of dropped packets.
  948. uint64_t getDroppedPacketsNum(const ExchangeType xchg_type) const {
  949. ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
  950. return(xchg_stats->getDroppedPacketsNum());
  951. }
  952. /// \brief Get time period since the start of test.
  953. ///
  954. /// Calculate dna return period since the test start. This
  955. /// can be specifically helpful when calculating packet
  956. /// exchange rates.
  957. ///
  958. /// \return test period so far.
  959. boost::posix_time::time_period getTestPeriod() const {
  960. using namespace boost::posix_time;
  961. time_period test_period(boot_time_,
  962. microsec_clock::universal_time());
  963. return test_period;
  964. }
  965. /// \brief Return name of the exchange.
  966. ///
  967. /// Method returns name of the specified exchange type.
  968. /// This function is mainly for logging purposes.
  969. ///
  970. /// \param xchg_type exchange type.
  971. /// \return string representing name of the exchange.
  972. std::string exchangeToString(ExchangeType xchg_type) const {
  973. switch(xchg_type) {
  974. case XCHG_DO:
  975. return("DISCOVER-OFFER");
  976. case XCHG_RA:
  977. return("REQUEST-ACK");
  978. case XCHG_SA:
  979. return("SOLICIT-ADVERTISE");
  980. case XCHG_RR:
  981. return("REQUEST-REPLY");
  982. default:
  983. return("Unknown exchange type");
  984. }
  985. }
  986. /// \brief Print statistics counters for all exchange types.
  987. ///
  988. /// Method prints statistics for all exchange types.
  989. /// Statistics includes:
  990. /// - number of sent and received packets
  991. /// - number of dropped packets and number of orphans
  992. /// - minimum packets delay,
  993. /// - average packets delay,
  994. /// - maximum packets delay,
  995. /// - standard deviation of packets delay.
  996. ///
  997. /// \throw isc::InvalidOperation if no exchange type added to
  998. /// track statistics.
  999. void printStats() const {
  1000. if (exchanges_.size() == 0) {
  1001. isc_throw(isc::InvalidOperation,
  1002. "no exchange type added for tracking");
  1003. }
  1004. for (ExchangesMapIterator it = exchanges_.begin();
  1005. it != exchanges_.end();
  1006. ++it) {
  1007. ExchangeStatsPtr xchg_stats = it->second;
  1008. std::cout << "***Statistics for: " << exchangeToString(it->first)
  1009. << "***" << std::endl;
  1010. xchg_stats->printMainStats();
  1011. std::cout << std::endl;
  1012. xchg_stats->printRTTStats();
  1013. std::cout << std::endl;
  1014. }
  1015. }
  1016. /// \brief Print timestamps of all packets.
  1017. ///
  1018. /// Method prints timestamps of all sent and received
  1019. /// packets for all defined exchange types.
  1020. ///
  1021. /// \throw isc::InvalidOperation if one of the packets has
  1022. /// no timestamp value set or if packets archive mode is
  1023. /// disabled.
  1024. ///
  1025. /// \throw isc::InvalidOperation if no exchange type added to
  1026. /// track statistics or packets archive mode is disabled.
  1027. void printTimestamps() const {
  1028. if (exchanges_.size() == 0) {
  1029. isc_throw(isc::InvalidOperation,
  1030. "no exchange type added for tracking");
  1031. }
  1032. for (ExchangesMapIterator it = exchanges_.begin();
  1033. it != exchanges_.end();
  1034. ++it) {
  1035. ExchangeStatsPtr xchg_stats = it->second;
  1036. std::cout << "***Timestamps for packets: "
  1037. << exchangeToString(it->first)
  1038. << "***" << std::endl;
  1039. xchg_stats->printTimestamps();
  1040. std::cout << std::endl;
  1041. }
  1042. }
  1043. /// \brief Print names and values of custom counters.
  1044. ///
  1045. /// Method prints names and values of custom counters. Custom counters
  1046. /// are defined by client class for tracking different statistics.
  1047. ///
  1048. /// \throw isc::InvalidOperation if no custom counters added for tracking.
  1049. void printCustomCounters() const {
  1050. if (custom_counters_.size() == 0) {
  1051. isc_throw(isc::InvalidOperation, "no custom counters specified");
  1052. }
  1053. for (CustomCountersMapIterator it = custom_counters_.begin();
  1054. it != custom_counters_.end();
  1055. ++it) {
  1056. CustomCounterPtr counter = it->second;
  1057. std::cout << counter->getName() << ": " << counter->getValue()
  1058. << std::endl;
  1059. }
  1060. }
  1061. private:
  1062. /// \brief Return exchange stats object for given exchange type
  1063. ///
  1064. /// Method returns exchange stats object for given exchange type.
  1065. ///
  1066. /// \param xchg_type exchange type.
  1067. /// \throw isc::BadValue if invalid exchange type specified.
  1068. /// \return exchange stats object.
  1069. ExchangeStatsPtr getExchangeStats(const ExchangeType xchg_type) const {
  1070. ExchangesMapIterator it = exchanges_.find(xchg_type);
  1071. if (it == exchanges_.end()) {
  1072. isc_throw(BadValue, "Packets exchange not specified");
  1073. }
  1074. ExchangeStatsPtr xchg_stats = it->second;
  1075. return(xchg_stats);
  1076. }
  1077. ExchangesMap exchanges_; ///< Map of exchange types.
  1078. CustomCountersMap custom_counters_; ///< Map with custom counters.
  1079. /// Indicates that packets from list of sent packets should be
  1080. /// archived (moved to list of archived packets) once they are
  1081. /// matched with received packets. This is required when it has
  1082. /// been selected from the command line to print packets'
  1083. /// timestamps after test. This may affect performance and
  1084. /// consume large amount of memory when the test is running
  1085. /// for extended period of time and many packets have to be
  1086. /// archived.
  1087. bool archive_enabled_;
  1088. boost::posix_time::ptime boot_time_; ///< Time when test is started.
  1089. };
  1090. } // namespace perfdhcp
  1091. } // namespace isc
  1092. #endif // __STATS_MGR_H