perf_pkt6.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (C) 2011 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 __PERF_PKT6_H
  15. #define __PERF_PKT6_H
  16. #include <time.h>
  17. #include <boost/shared_ptr.hpp>
  18. #include <dhcp/pkt6.h>
  19. #include "localized_option.h"
  20. namespace isc {
  21. namespace perfdhcp {
  22. /// \brief PerfPkt6 (DHCPv6 packet)
  23. ///
  24. /// This class extends the functionality of \ref isc::dhcp::Pkt6 by
  25. /// adding the ability to specify an options offset in the DHCP message
  26. /// and so override the options' contents. This is particularly useful when we
  27. /// create a packet object using a template file (i.e. do not build it
  28. /// dynamically). The client class should read the data from the template file
  29. /// and pass it to this class as a buffer.
  30. ///
  31. /// The contents of such packet can be later partially replaced: in particular,
  32. /// selected options and the transaction ID can be altered. (The transaction
  33. /// ID and its offset in the template file is passed via the constructor.)
  34. ///
  35. /// In order to replace the contents of options, the client class has to
  36. /// create a collection of \ref LocalizedOption by adding them using
  37. /// \ref dhcp::Pkt6::addOption.
  38. ///
  39. /// \note If you don't use template files, simply use constructors
  40. /// inherited from parent class and the \ref isc::dhcp::Option type instead.
  41. class PerfPkt6 : public dhcp::Pkt6 {
  42. public:
  43. /// Localized option pointer type.
  44. typedef boost::shared_ptr<LocalizedOption> LocalizedOptionPtr;
  45. /// \brief Constructor, used for outgoing and incoming messages
  46. ///
  47. /// This constructor initializes the transaction ID and the
  48. /// transaction ID offset of the packet with default
  49. /// values.
  50. ///
  51. /// \param buf buffer holding contents of the message.
  52. /// \param len length of the data in the buffer.
  53. PerfPkt6(const uint8_t* buf, size_t len);
  54. /// \brief Constructor, used for outgoing DHCP messages.
  55. ///
  56. /// Creates a new DHCPv6 message using the provided buffer.
  57. /// The transaction ID and its offset are specified via this
  58. /// constructor. The transaction ID is stored in outgoing message
  59. /// when client class calls \ref PerfPkt6::rawPack.
  60. ///
  61. /// \note This constructor should be used only for outgoing
  62. /// messages that are created from template files.
  63. ///
  64. /// \param buf buffer holding contents of the message (this can
  65. /// be directly read from template file).
  66. /// \param len length of the data in the buffer.
  67. /// \param transid_offset transaction id offset in outgoing message.
  68. /// \param transid transaction id to be stored in outgoing message.
  69. PerfPkt6(const uint8_t* buf,
  70. size_t len,
  71. size_t transid_offset,
  72. uint32_t transid);
  73. /// Constructor, used for incoming DHCP messages.
  74. ///
  75. /// Creates a new DHCPv6 message using the provided buffer. The
  76. /// client class may indicate which options are to be read
  77. /// from the buffer. Such options should be added to the
  78. /// options collection using \ref dhcp::Pkt4::addOption. The
  79. /// options should be of \ref LocalizedOption class.
  80. ///
  81. /// The transaction ID offset points to location where the
  82. /// transaction ID field is stored. The transaction ID will
  83. /// be read from this location when \ref PerfPkt4::rawUnpack is
  84. /// called. The transid_ class member will be updated accordingly.
  85. ///
  86. /// \note Use this constructor only in the case where you want to create
  87. /// incoming DHCPv4 object from the raw buffer
  88. /// and you know the options offsets. Options offsets are
  89. /// specified on the perfdhcp command line by the user.
  90. ///
  91. /// \param buf pointer to a buffer of received packet content.
  92. /// \param len size of buffer of packet content.
  93. /// \param transid_offset transaction id offset in a message.
  94. PerfPkt6(const uint8_t* buf,
  95. size_t len,
  96. size_t transid_offset);
  97. /// \brief Returns transaction id offset in packet buffer
  98. ///
  99. /// \return Transaction ID offset in the packet buffer.
  100. size_t getTransIdOffset() const { return transid_offset_; };
  101. /// \brief Prepares on-wire format from raw buffer
  102. ///
  103. /// The method copies the buffer provided in constructor to the
  104. /// output buffer and replaces the transaction ID and selected
  105. /// options with new data.
  106. ///
  107. /// \note Use this method to prepare an on-wire DHCPv6 message
  108. /// when you use template packets that require replacement
  109. /// of selected options' contents before sending.
  110. ///
  111. /// \return false ID pack operation failed.
  112. bool rawPack();
  113. /// \brief Handles limited binary packet parsing for packets with
  114. /// custom offsets of options and transaction id
  115. ///
  116. /// This methoid handles the parsing of packets that have custom offsets
  117. /// of options or transaction ID. Use
  118. /// \ref isc::dhcp::Pkt4::addOption to specify which options to parse.
  119. /// Options should be of the \ref isc::perfdhcp::LocalizedOption
  120. /// type with offset values provided. Each added option will
  121. /// be updated with actual data read from the binary packet buffer.
  122. ///
  123. /// \return false if unpack operation failed.
  124. bool rawUnpack();
  125. private:
  126. size_t transid_offset_; ///< transaction id offset
  127. };
  128. } // namespace perfdhcp
  129. } // namespace isc
  130. #endif // __PERF_PKT6_H