perf_pkt6.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 __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 to create messages from packet
  46. /// template files.
  47. ///
  48. /// Creates a new DHCPv6 message using the provided buffer.
  49. /// The transaction ID and its offset are specified via this
  50. /// constructor. The transaction ID is stored in outgoing message
  51. /// when client class calls \ref PerfPkt6::rawPack. Transaction id
  52. /// offset value is used for incoming and outgoing messages to
  53. /// identify transaction ID field's position in incoming and outgoing
  54. /// messages.
  55. ///
  56. /// \param buf buffer holding contents of the message (this can
  57. /// be directly read from template file).
  58. /// \param len length of the data in the buffer.
  59. /// \param transid_offset transaction id offset in a message.
  60. /// \param transid transaction id to be stored in outgoing message.
  61. PerfPkt6(const uint8_t* buf,
  62. size_t len,
  63. size_t transid_offset = 1,
  64. uint32_t transid = 0);
  65. /// \brief Returns transaction id offset in packet buffer
  66. ///
  67. /// \return Transaction ID offset in the packet buffer.
  68. size_t getTransidOffset() const { return transid_offset_; };
  69. /// \brief Prepares on-wire format from raw buffer
  70. ///
  71. /// The method copies the buffer provided in constructor to the
  72. /// output buffer and replaces the transaction ID and selected
  73. /// options with new data.
  74. ///
  75. /// \note Use this method to prepare an on-wire DHCPv6 message
  76. /// when you use template packets that require replacement
  77. /// of selected options' contents before sending.
  78. ///
  79. /// \return false ID pack operation failed.
  80. bool rawPack();
  81. /// \brief Handles limited binary packet parsing for packets with
  82. /// custom offsets of options and transaction id
  83. ///
  84. /// This methoid handles the parsing of packets that have custom offsets
  85. /// of options or transaction ID. Use
  86. /// \ref isc::dhcp::Pkt4::addOption to specify which options to parse.
  87. /// Options should be of the \ref isc::perfdhcp::LocalizedOption
  88. /// type with offset values provided. Each added option will
  89. /// be updated with actual data read from the binary packet buffer.
  90. ///
  91. /// \return false if unpack operation failed.
  92. bool rawUnpack();
  93. private:
  94. size_t transid_offset_; ///< transaction id offset
  95. };
  96. } // namespace perfdhcp
  97. } // namespace isc
  98. #endif // __PERF_PKT6_H