test_control.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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 __TEST_CONTROL_H
  15. #define __TEST_CONTROL_H
  16. #include <string>
  17. #include <vector>
  18. #include <boost/noncopyable.hpp>
  19. #include <boost/shared_ptr.hpp>
  20. #include <boost/function.hpp>
  21. #include <boost/date_time/posix_time/posix_time.hpp>
  22. #include <dhcp/dhcp6.h>
  23. #include <dhcp/pkt4.h>
  24. #include <dhcp/pkt6.h>
  25. #include "stats_mgr.h"
  26. namespace isc {
  27. namespace perfdhcp {
  28. /// \brief Test Control class.
  29. ///
  30. /// This class is responsible for executing DHCP performance
  31. /// test end to end.
  32. ///
  33. /// Option factory functions are registered using
  34. /// \ref LibDHCP::OptionFactoryRegister. Registered factory functions
  35. /// provide a way to create options of the same type in the same way.
  36. /// When new option instance is needed the corresponding factory
  37. /// function is called to create it. This is done by calling
  38. /// \ref Option::factory with DHCP message type specified as one of
  39. /// parameters. Some of the parameters passed to factory function
  40. /// may be ignored (e.g. option buffer).
  41. class TestControl : public boost::noncopyable {
  42. public:
  43. // Statistics Manager for DHCPv4.
  44. typedef StatsMgr<dhcp::Pkt4> StatsMgr4;
  45. // Pointer to Statistics Manager for DHCPv4;
  46. typedef boost::shared_ptr<StatsMgr4> StatsMgr4Ptr;
  47. // Statictics Manager for DHCPv6.
  48. typedef StatsMgr<dhcp::Pkt6> StatsMgr6;
  49. // Pointer to Statistics Manager for DHCPv6.
  50. typedef boost::shared_ptr<StatsMgr6> StatsMgr6Ptr;
  51. // Packet exchange type.
  52. typedef StatsMgr<>::ExchangeType ExchangeType;
  53. // Packet template buffer.
  54. typedef std::vector<uint8_t> TemplateBuffer;
  55. //Packet template buffers list.
  56. typedef std::list<TemplateBuffer> TemplateBufferList;
  57. /// \brief Socket wrapper class.
  58. ///
  59. /// This is wrapper class that holds descriptor of the socket
  60. /// used to run DHCP test. All sockets created with \ref IfaceMgr
  61. /// are closed in the destructor. This ensures that socket is
  62. /// closed when the function that created the socket ends
  63. /// (normally or when exception occurs).
  64. class TestControlSocket {
  65. public:
  66. /// \brief Constructor of socket wrapper class.
  67. ///
  68. /// This constructor uses provided socket descriptor to
  69. /// find the name of the interface where socket has been
  70. /// bound to.
  71. ///
  72. /// \param socket socket descriptor.
  73. /// \throw isc::BadValue if interface for specified
  74. /// socket descriptor does not exist.
  75. TestControlSocket(const int socket);
  76. /// \brief Destriuctor of the socket wrapper class.
  77. ///
  78. /// Destructor closes all open sockets on all interfaces.
  79. /// TODO: close only the socket being wrapped by this class.
  80. ~TestControlSocket();
  81. /// \brief Return name of the interface where socket is bound to.
  82. ///
  83. /// \return name of the interface where socket is bound to.
  84. const std::string& getIface() const { return(iface_); }
  85. /// \brief Return interface index where socket is bound to.
  86. ///
  87. /// \return index fo the interface where sockert is bound to.
  88. int getIfIndex() const { return(ifindex_); }
  89. /// \brief Return address where socket is bound to.
  90. ///
  91. /// \return address where socket is bound to.
  92. const asiolink::IOAddress& getAddress() const { return(addr_); }
  93. private:
  94. /// \brief Private default constructor.
  95. ///
  96. /// Default constructor is private to make sure that valid
  97. /// socket descriptor is passed to create object.
  98. TestControlSocket();
  99. /// \brief Initialize socket data.
  100. ///
  101. /// This method initializes members of the class that Interface
  102. /// Manager holds: interface name, local address.
  103. ///
  104. /// \throw isc::BadValue if interface for specified socket
  105. /// descriptor does not exist.
  106. void initSocketData();
  107. int socket_; ///< Socket descirptor.
  108. std::string iface_; ///< Name of the interface.
  109. int ifindex_; ///< Index of the interface.
  110. asiolink::IOAddress addr_; ///< Address bound.
  111. };
  112. /// \brief Default transaction id generator class.
  113. ///
  114. /// This is default transaction id generator class. The member
  115. /// function is used to generate unique transaction id value.
  116. /// Other generator classes should derive from this one to
  117. /// override the standard generation algorithm (e.g. unit tests
  118. /// override this class wih algorithm that produces more predictable
  119. /// transaction id values).
  120. class TransidGenerator {
  121. public:
  122. /// \brief generate transaction id.
  123. ///
  124. /// \return generated transazction id value.
  125. virtual uint32_t generate() {
  126. return static_cast<uint32_t>(random() % 0x00FFFFFF);
  127. }
  128. };
  129. typedef boost::shared_ptr<TransidGenerator> TransidGeneratorPtr;
  130. /// \brief Length of the Ethernet HW address (MAC) in bytes.
  131. static const uint8_t HW_ETHER_LEN = 6;
  132. /// TestControl is a singleton class. This method returns reference
  133. /// to its sole instance.
  134. ///
  135. /// \return the only existing instance of test control
  136. static TestControl& instance();
  137. /// brief\ Run performance test.
  138. ///
  139. /// Method runs whole performance test. Command line options must
  140. /// be parsed prior to running this function. Othewise function will
  141. /// throw exception.
  142. ///
  143. /// \throw isc::InvalidOperation if command line options are not parsed.
  144. /// \throw isc::Unexpected if internal Test Controler error occured.
  145. void run();
  146. /// \brief Set new transaction id generator.
  147. ///
  148. /// \param generator generator object to be used.
  149. void setTransidGenerator(TransidGeneratorPtr& generator) {
  150. transid_gen_.reset();
  151. transid_gen_ = generator;
  152. }
  153. protected:
  154. // We would really like these methods and members to be private but
  155. // they have to be accessible for unit-testing. Another, possibly better,
  156. // solution is to make this class friend of test class but this is not
  157. // what's followed in other classes.
  158. /// \brief Default constructor.
  159. ///
  160. /// Default constructor is protected as the object can be created
  161. /// only via \ref instance method.
  162. TestControl();
  163. /// \brief Check if test exit condtitions fulfiled.
  164. ///
  165. /// Method checks if test exit conditions are fulfiled.
  166. /// Exit conditions are checked periodically from the
  167. /// main loop. Program should break the main loop when
  168. /// this method returns true. It is calling function
  169. /// responsibility to break main loop gracefully and
  170. /// cleanup after test execution.
  171. ///
  172. /// \return true if any of the exit conditions is fulfiled.
  173. bool checkExitConditions() const;
  174. /// \brief Factory function to create DHCPv6 ELAPSED_TIME option.
  175. ///
  176. /// This factory function creates DHCPv6 ELAPSED_TIME option instance.
  177. /// If empty buffer is passed the option buffer will be initialized
  178. /// to length 2 and values will be initialized to zeros. Otherwise
  179. /// function will initialize option buffer with values in passed buffer.
  180. ///
  181. /// \param u universe (V6 or V4).
  182. /// \param type option-type.
  183. /// \param buf option-buffer.
  184. /// \throw if elapsed time buffer size is neither 2 nor 0.
  185. /// \return instance o the option.
  186. static dhcp::OptionPtr
  187. factoryElapsedTime6(dhcp::Option::Universe u,
  188. uint16_t type,
  189. const dhcp::OptionBuffer& buf);
  190. /// \brief Factory function to create generic option.
  191. ///
  192. /// This factory function creates option with specified universe,
  193. /// type and buf. It does not have any additional logic validating
  194. /// the buffer contents, size etc.
  195. ///
  196. /// \param u universe (V6 or V4).
  197. /// \param type option-type.
  198. /// \param buf option-buffer.
  199. /// \return instance o the option.
  200. static dhcp::OptionPtr factoryGeneric(dhcp::Option::Universe u,
  201. uint16_t type,
  202. const dhcp::OptionBuffer& buf);
  203. /// \brief Factory function to create IA_NA option.
  204. ///
  205. /// This factory function creates DHCPv6 IA_NA option instance.
  206. /// \TODO: add support for IA Address options.
  207. /// \param u universe (V6 or V4).
  208. /// \param type option-type.
  209. /// \param buf option-buffer.
  210. /// \return instance of IA_NA option.
  211. static dhcp::OptionPtr factoryIana6(dhcp::Option::Universe u,
  212. uint16_t type,
  213. const dhcp::OptionBuffer& buf);
  214. /// \brief Factory function to create DHCPv6 ORO option.
  215. ///
  216. /// This factory function creates DHCPv6 Option Request Option instance.
  217. /// The created option will contain the following set of requested options:
  218. /// - D6O_NAME_SERVERS
  219. /// - D6O_DOMAIN_SEARCH
  220. ///
  221. /// \param u universe (V6 or V4).
  222. /// \param type option-type.
  223. /// \param buf option-buffer (ignored and should be empty).
  224. /// \return instance of ORO option.
  225. static dhcp::OptionPtr
  226. factoryOptionRequestOption6(dhcp::Option::Universe u,
  227. uint16_t type,
  228. const dhcp::OptionBuffer& buf);
  229. /// \brief Factory function to create DHCPv6 RAPID_COMMIT option instance.
  230. ///
  231. /// This factory function creates DHCPv6 RAPID_COMMIT option instance.
  232. /// The buffer passed to this option must be empty because option does
  233. /// not have any payload.
  234. ///
  235. /// \param u universe (V6 or V4).
  236. /// \param type option-type.
  237. /// \param buf option-buffer (ignored and should be empty).
  238. /// \return instance of RAPID_COMMIT option..
  239. static dhcp::OptionPtr factoryRapidCommit6(dhcp::Option::Universe u,
  240. uint16_t type,
  241. const dhcp::OptionBuffer& buf);
  242. /// \brief Factory function to create DHCPv4 Request List option.
  243. ///
  244. /// This factory function creayes DHCPv4 PARAMETER_REQUEST_LIST option
  245. /// instance with the following set of requested options:
  246. /// - DHO_SUBNET_MASK,
  247. /// - DHO_BROADCAST_ADDRESS,
  248. /// - DHO_TIME_OFFSET,
  249. /// - DHO_ROUTERS,
  250. /// - DHO_DOMAIN_NAME,
  251. /// - DHO_DOMAIN_NAME_SERVERS,
  252. /// - DHO_HOST_NAME.
  253. ///
  254. /// \param u universe (V6 or V4).
  255. /// \param type option-type.
  256. /// \param buf option-buffer (ignored and should be empty).
  257. /// \return instance o the generic option.
  258. static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u,
  259. uint16_t type,
  260. const dhcp::OptionBuffer& buf);
  261. /// \brief Generate DUID.
  262. ///
  263. /// Method generates unique DUID. The number of DUIDs it can generate
  264. /// depends on the number of simulated clinets, which is specified
  265. /// from the command line. It uses \ref CommandOptions object to retrieve
  266. /// number of clinets. Since the last six octets of DUID are constructed
  267. /// from the MAC address, this function uses \ref generateMacAddress
  268. /// internally to randomize the DUID.
  269. ///
  270. /// \throw isc::BadValue if \ref generateMacAddress throws.
  271. /// \return vector representing DUID.
  272. std::vector<uint8_t> generateDuid() const;
  273. /// \brief Generate MAC address.
  274. ///
  275. /// This method generates MAC address. The number of unique
  276. /// MAC addresses it can generate is determined by the number
  277. /// simulated DHCP clients specified from command line. It uses
  278. /// \ref CommandOptions object to retrieve number of clients.
  279. /// Based on this the random value is generated and added to
  280. /// the MAC address prefix (default MAC address).
  281. ///
  282. /// \throw isc::BadValue if MAC address prefix (default or specified
  283. /// from the command line) has invalid size (expected 6 octets).
  284. /// \return generated MAC address.
  285. std::vector<uint8_t> generateMacAddress() const;
  286. /// \brief generate transaction id.
  287. ///
  288. /// \return generated transaction id.
  289. uint32_t generateTransid() {
  290. return(transid_gen_->generate());
  291. }
  292. /// \brief Returns number of exchanges to be started.
  293. ///
  294. /// Method returns number of new exchanges to be started as soon
  295. /// as possible to satisfy expected rate. Calculation used here
  296. /// is based on current time, due time calculated with
  297. /// \ref updateSendTime function and expected rate.
  298. ///
  299. /// \return number of exchanges to be started immediatelly.
  300. uint64_t getNextExchangesNum() const;
  301. void initPacketTemplates();
  302. /// \brief Initializes Statistics Manager.
  303. ///
  304. /// This function initializes Statistics Manager. If there is
  305. /// the one initialized already it is released.
  306. void initializeStatsMgr();
  307. /// \brief Open socket to communicate with DHCP server.
  308. ///
  309. /// Method opens socket and binds it to local address. Function will
  310. /// can use either interface name, local address or server address
  311. /// to create a socket, depending on what is available (specified
  312. /// from the command line). If socket can't be created for any
  313. /// reason, exception is thrown.
  314. /// If destination address is broadcast (for DHCPv4) or multicast
  315. /// (for DHCPv6) than broadcast or multicast option is set on
  316. /// the socket.
  317. ///
  318. /// \throw isc::BadValue if socket can't be created for given
  319. /// interface, local address or remote address.
  320. /// \throw isc::InvalidOperation if broadcast option can't be
  321. /// set for the v4 socket or if multicast option cat't be set
  322. /// for the v6 socket.
  323. /// \throw isc::Unexpected if interal unexpected error occured.
  324. /// \return socket descriptor.
  325. int openSocket() const;
  326. /// \brief Print intermediate statistics.
  327. ///
  328. /// Print brief statistics regarding number of sent packets,
  329. /// received packets and dropped packets so far.
  330. void printIntermediateStats();
  331. /// \brief Print rate statistics.
  332. ///
  333. /// Method print packet exchange rate statistics.
  334. void printRate() const;
  335. /// \brief Print performance statistics.
  336. ///
  337. /// Method prints performance statistics.
  338. /// \throws isc::InvalidOperation if Statistics Manager was
  339. /// not initialized.
  340. void printStats() const;
  341. /// \brief Receive DHCPv4 packet.
  342. ///
  343. /// Method performs reception of the DHCPv4 packet, updates
  344. /// statistics and responsds to the server if required, e.g.
  345. /// when OFFER packet arrives, this function will initiate
  346. /// REQUEST message to the server.
  347. ///
  348. /// \param socket socket to be used.
  349. /// \param pkt4 object representing DHCPv4 packet received.
  350. /// \throw isc::BadValue if unknown message type received.
  351. /// \throw isc::Unexpected if unexpected error occured.
  352. void receivePacket4(const TestControlSocket& socket,
  353. const dhcp::Pkt4Ptr& pkt4);
  354. /// \brief Receive DHCPv6 packet.
  355. ///
  356. /// Method performs reception of the DHCPv6 packet, updates
  357. /// statistics and responsds to the server if required, e.g.
  358. /// when ADVERTISE packet arrives, this function will initiate
  359. /// REQUEST message to the server.
  360. ///
  361. /// \param socket socket to be used.
  362. /// \param pkt6 object representing DHCPv6 packet received.
  363. /// \throw isc::BadValue if unknown message type received.
  364. /// \throw isc::Unexpected if unexpected error occured.
  365. void receivePacket6(const TestControlSocket& socket,
  366. const dhcp::Pkt6Ptr& pkt6);
  367. /// \brief Receive DHCPv4 or DHCPv6 packets from the server.
  368. ///
  369. /// Method receives DHCPv4 or DHCPv6 packets from the server.
  370. /// This function will call \ref receivePacket4 or
  371. /// \ref receivePacket6 depending if DHCPv4 or DHCPv6 packet
  372. /// has arrived.
  373. ///
  374. /// \param socket socket to be used.
  375. /// \throw::BadValue if unknown message type received.
  376. /// \throw::Unexpected if unexpected error occured.
  377. void receivePackets(const TestControlSocket& socket);
  378. /// \brief Register option factory functions for DHCPv4
  379. ///
  380. /// Method registers option factory functions for DHCPv4.
  381. /// These functions are called to create instances of DHCPv4
  382. /// options. Call \ref Option::factory to invoke factory
  383. /// function for particular option. Don't use this function directly.
  384. /// Use \ref registerOptionFactories instead.
  385. void registerOptionFactories4() const;
  386. /// \brief Register option factory functions for DHCPv6
  387. ///
  388. /// Method registers option factory functions for DHCPv6.
  389. /// These functions are called to create instances of DHCPv6
  390. /// options. Call \ref Option::factory to invoke factory
  391. /// function for particular option. Don't use this function directly.
  392. /// Use \ref registerOptionFactories instead.
  393. void registerOptionFactories6() const;
  394. /// \brief Register option factory functions for DHCPv4 or DHCPv6.
  395. ///
  396. /// Method registers option factory functions for DHCPv4 or DHCPv6,
  397. /// depending in whch mode test is currently running.
  398. void registerOptionFactories() const;
  399. /// \brief Resets internal state of the object.
  400. ///
  401. /// Method resets internal state of the object. It has to be
  402. /// called before new test is started.
  403. void reset();
  404. /// \brief Send DHCPv4 DISCOVER message.
  405. ///
  406. /// Method creates and sends DHCPv4 DISCOVER message to the server
  407. /// with the following options:
  408. /// - MESSAGE_TYPE set to DHCPDISCOVER
  409. /// - PARAMETER_REQUEST_LIST with the same list of requested options
  410. /// as described in \ref factoryRequestList.
  411. /// The transaction id and MAC address are randomly generated for
  412. /// the message. Range of unique MAC addresses generated depends
  413. /// on the number of clients specified from the command line.
  414. ///
  415. /// \param socket socket to be used to send the message.
  416. /// \param preload preload mode, packets not included in statistics.
  417. /// \throw isc::Unexpected if failed to create new packet instance.
  418. /// \throw isc::BadValue if MAC address has invalid length.
  419. void sendDiscover4(const TestControlSocket& socket,
  420. const bool preload = false);
  421. /// \brief Send DHCPv4 REQUEST message.
  422. ///
  423. /// Method creates and sends DHCPv4 REQUEST message to the server.
  424. ///
  425. /// \param socket socket to be used to send message.
  426. /// \param offer_pkt4 OFFER packet object.
  427. /// \throw isc::Unexpected if unexpected error occured.
  428. /// \throw isc::InvalidOperation if Statistics Manager has not been
  429. /// initialized.
  430. void sendRequest4(const TestControlSocket& socket,
  431. const dhcp::Pkt4Ptr& offer_pkt4);
  432. /// \brief Send DHCPv6 REQUEST message.
  433. ///
  434. /// Method creates and sends DHCPv6 REQUEST message to the server
  435. /// with the following options:
  436. /// - D6O_ELAPSED_TIME
  437. /// - D6O_CLIENTID
  438. /// - D6O_SERVERID
  439. /// The elapsed time is calculated based on the duration between
  440. /// sending a SOLICIT and receiving the ADVERTISE packet prior.
  441. /// For this reason both solicit and advertise packet objects have
  442. /// to be passed when calling this function.
  443. ///
  444. /// \param socket socket to be used to send message.
  445. /// \param solicit_pkt6 SOLICIT packet object.
  446. /// \param advertise_pkt6 ADVERTISE packet object.
  447. /// \throw isc::Unexpected if unexpected error occured.
  448. /// \throw isc::InvalidOperation if Statistics Manager has not been
  449. /// initialized.
  450. void sendRequest6(const TestControlSocket& socket,
  451. const dhcp::Pkt6Ptr& solicit_pkt6,
  452. const dhcp::Pkt6Ptr& advertise_pkt6);
  453. /// \brief Send DHCPv6 SOLICIT message.
  454. ///
  455. /// Method creates and sends DHCPv6 SOLICIT message to the server
  456. /// with the following options:
  457. /// - D6O_ELAPSED_TIME,
  458. /// - D6O_RAPID_COMMIT if rapid commit is requested in command line,
  459. /// - D6O_CLIENTID,
  460. /// - D6O_ORO (Option Request Option),
  461. /// - D6O_IA_NA.
  462. ///
  463. /// \param socket socket to be used to send the message.
  464. /// \param preload mode, packets not included in statistics.
  465. /// \throw isc::Unexpected if failed to create new packet instance.
  466. void sendSolicit6(const TestControlSocket& socket,
  467. const bool preload = false);
  468. /// \brief Set default DHCPv4 packet parameters.
  469. ///
  470. /// This method sets default parameters on the DHCPv4 packet:
  471. /// - interface name,
  472. /// - local port = 68 (DHCP client port),
  473. /// - remote port = 67 (DHCP server port),
  474. /// - server's address,
  475. /// - GIADDR = local address where socket is bound to,
  476. /// - hops = 1 (pretending that we are a relay)
  477. ///
  478. /// \param socket socket used to send the packet.
  479. /// \param pkt reference to packet to be configured.
  480. void setDefaults4(const TestControlSocket& socket,
  481. const dhcp::Pkt4Ptr& pkt);
  482. /// \brief Set default DHCPv6 packet parameters.
  483. ///
  484. /// This method sets default parameters on the DHCPv6 packet:
  485. /// - interface name,
  486. /// - interface index,
  487. /// - local port,
  488. /// - remote port,
  489. /// - local address,
  490. /// - remote address (server).
  491. ///
  492. /// \param socket socket used to send the packet.
  493. /// \param pkt reference to packet to be configured.
  494. void setDefaults6(const TestControlSocket& socket,
  495. const dhcp::Pkt6Ptr& pkt);
  496. /// \brief Update due time to initiate next chunk of exchanges.
  497. ///
  498. /// Method updates due time to initiate next chunk of exchanges.
  499. /// Function takes current time, last sent packet's time and
  500. /// expected rate in its calculations.
  501. void updateSendDue();
  502. private:
  503. /// \brief Generate transaction id using random function.
  504. ///
  505. /// \return generated transaction id value.
  506. static uint32_t generateTransidRandom();
  507. /// \brief Get number of received packets.
  508. ///
  509. /// Get the number of received packets from the Statistics Manager.
  510. /// Function may throw if Statistics Manager object is not
  511. /// initialized.
  512. /// \param xchg_type packet exchange type.
  513. /// \return number of received packets.
  514. uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const;
  515. /// \brief Get number of sent packets.
  516. ///
  517. /// Get the number of sent packets from the Statistics Manager.
  518. /// Function may throw if Statistics Manager object is not
  519. /// initialized.
  520. /// \param xchg_type packet exchange type.
  521. /// \return number of sent packets.
  522. uint64_t getSentPacketsNum(const ExchangeType xchg_type) const;
  523. /// \brief Handle interrupt signal.
  524. ///
  525. /// Function sets flag indicating that program has been
  526. /// interupted.
  527. ///
  528. /// \param sig signal (ignored)
  529. static void handleInterrupt(int sig);
  530. boost::posix_time::ptime send_due_; ///< Due time to initiate next chunk
  531. ///< of exchanges.
  532. boost::posix_time::ptime last_sent_; ///< Indicates when the last exchange
  533. /// was initiated.
  534. boost::posix_time::ptime last_report_; ///< Last intermediate report time.
  535. StatsMgr4Ptr stats_mgr4_; ///< Statistics Manager 4.
  536. StatsMgr6Ptr stats_mgr6_; ///< Statistics Manager 6.
  537. TransidGeneratorPtr transid_gen_; ///< Transaction id generator.
  538. /// Buffer holiding server id received in first packet
  539. dhcp::OptionBuffer first_packet_serverid_;
  540. /// Packet template buffers.
  541. TemplateBufferList template_buffers_;
  542. static bool interrupted_;
  543. uint64_t sent_packets_0_;
  544. uint64_t sent_packets_1_;
  545. };
  546. } // namespace perfdhcp
  547. } // namespace isc
  548. #endif // __COMMAND_OPTIONS_H