perf_pkt4.h 5.9 KB
 Marcin Siodelski committed Jun 05, 2012 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. #ifndef __PERF_PKT4_H #define __PERF_PKT4_H #include #include #include #include "localized_option.h" namespace isc { namespace perfdhcp { /// \brief PerfPkt4 (DHCPv4 packet) ///  Stephen Morris committed Jun 07, 2012 29 30 31 32 33 34 35 36 37 38 39 40 41 /// This class extends the functionality of \ref isc::dhcp::Pkt4 by adding the /// ability to specify an options offset in the DHCP message and to override /// options' contents. This is particularly useful when we create a packet /// object using a template file (i.e. do not build it dynamically). The client /// class should read data from the template file and pass it to this class in /// a buffer. /// /// The contents of such a packet can be later partially replaced, notably the /// selected options and the transaction ID. (The transaction ID and its /// offset in the template file are passed via the constructor.) /// /// In order to replace contents of the options, the client class has to /// create a collection of \ref LocalizedOption, adding them using  Marcin Siodelski committed Jun 05, 2012 42 /// \ref dhcp::Pkt4::addOption.  Marcin Siodelski committed Jun 05, 2012 43 ///  Stephen Morris committed Jun 07, 2012 44 /// \note If you don't use template files simply use constructors  Marcin Siodelski committed Jun 05, 2012 45 /// inherited from parent class and isc::dhcp::Option type instead  Stephen Morris committed Jun 07, 2012 46   Marcin Siodelski committed Jun 05, 2012 47 48 49 50 51 52 class PerfPkt4 : public dhcp::Pkt4 { public: /// Localized option pointer type. typedef boost::shared_ptr LocalizedOptionPtr;  Marcin Siodelski committed Jun 05, 2012 53 54  /// \brief Constructor, used for outgoing and incoming messages ///  Stephen Morris committed Jun 07, 2012 55  /// This constructor initializes the transaction ID and  Marcin Siodelski committed Jun 05, 2012 56 57 58 59 60 61 62  /// transaction id offset of the packet with default /// values. /// /// \param buf buffer holding contents of the message. /// \param len length of the data in the buffer. PerfPkt4(const uint8_t* buf, size_t len);  Marcin Siodelski committed Jun 05, 2012 63 64  /// \brief Constructor, used for outgoing DHCP messages. ///  Stephen Morris committed Jun 07, 2012 65 66 67 68  /// Creates new DHCPv4 message using the provided buffer. The /// transaction ID and its offset are specified via this /// constructor. The transaction ID is stored in the outgoing message /// when the client class calls \ref PerfPkt4::rawPack.  Marcin Siodelski committed Jun 05, 2012 69 70  /// /// \note This constructor should be used only for outgoing  Marcin Siodelski committed Jun 05, 2012 71  /// messages that are created from template files.  Marcin Siodelski committed Jun 05, 2012 72  ///  Marcin Siodelski committed Jun 05, 2012 73  /// \param buf buffer holding contents of the message (this can  Marcin Siodelski committed Jun 05, 2012 74 75 76 77 78  /// be directly read from template file). /// \param len length of the data in the buffer. /// \param transid_offset transaction id offset in outgoing message. /// \param transid transaction id to be stored in outgoing message. PerfPkt4(const uint8_t* buf,  Marcin Siodelski committed Jun 05, 2012 79  size_t len,  Marcin Siodelski committed Jun 05, 2012 80 81 82 83 84  size_t transid_offset, uint32_t transid); /// Constructor, used for incoming DHCP messages. ///  Stephen Morris committed Jun 07, 2012 85 86 87 88  /// Creates new DHCPv4 message using the provided buffer. /// The client class may indicate which options are to be read /// from the buffer. Such options should be added to the /// options collection using \ref dhcp::Pkt4::addOption: these  Marcin Siodelski committed Jun 05, 2012 89  /// options should be of \ref LocalizedOption class.  Marcin Siodelski committed Jun 05, 2012 90  ///  Stephen Morris committed Jun 07, 2012 91 92 93  /// The transaction ID offset points to the location where the /// transaction ID field is stored. The transaction ID will /// be read from this location when \ref PerfPkt4::rawUnpack is  Marcin Siodelski committed Jun 05, 2012 94 95  /// called. The transid_ class member will be updated accordingly. ///  Stephen Morris committed Jun 07, 2012 96 97 98 99  /// \note Use this constructor only in the case where you want to create /// an incoming DHCPv4 object from the raw buffer /// and you know the options offsets. The options offsets are /// specified on the perfdhcp command line by the user.  Marcin Siodelski committed Jun 05, 2012 100 101 102 103 104  /// /// \param buf pointer to a buffer of received packet content. /// \param len size of buffer of packet content. /// \param transid_offset transaction id offset in a message. PerfPkt4(const uint8_t* buf,  Marcin Siodelski committed Jun 05, 2012 105  size_t len,  Marcin Siodelski committed Jun 05, 2012 106 107 108 109  size_t transid_offset); /// \brief Returns transaction id offset in packet buffer ///  Stephen Morris committed Jun 07, 2012 110  /// \return Transaction ID offset in packet buffer  Marcin Siodelski committed Jun 05, 2012 111 112  size_t getTransIdOffset() const { return transid_offset_; };  Marcin Siodelski committed Jun 05, 2012 113  /// \brief Prepares on-wire format from raw buffer.  Marcin Siodelski committed Jun 05, 2012 114  ///  Stephen Morris committed Jun 07, 2012 115 116  /// The method copies the buffer provided in the constructor to the /// output buffer and replaces the transaction ID and selected  Marcin Siodelski committed Jun 05, 2012 117  /// options with new data.  Marcin Siodelski committed Jun 05, 2012 118  ///  Stephen Morris committed Jun 07, 2012 119  /// \note Use this method to prepare an on-wire DHCPv4 message  Marcin Siodelski committed Jun 05, 2012 120 121 122  /// when you use template packets that require replacement /// of selected options' contents before sending. ///  Stephen Morris committed Jun 07, 2012 123  /// \return false ID pack operation failed.  Marcin Siodelski committed Jun 05, 2012 124 125 126  bool rawPack(); /// \brief Handles limited binary packet parsing for packets with  Stephen Morris committed Jun 07, 2012 127  /// custom offsets of options and transaction ID  Marcin Siodelski committed Jun 05, 2012 128  ///  Stephen Morris committed Jun 07, 2012 129 130  /// This method handles the parsing of packets that have custom offsets /// of options or transaction ID. Use  Marcin Siodelski committed Jun 05, 2012 131  /// \ref isc::dhcp::Pkt4::addOption to specify which options to parse.  Stephen Morris committed Jun 07, 2012 132  /// Options should be of the \ref isc::perfdhcp::LocalizedOption  Marcin Siodelski committed Jun 05, 2012 133 134  /// type with offset values provided. Each added option will /// be updated with actual data read from the binary packet buffer.  Marcin Siodelski committed Jun 05, 2012 135  ///  Stephen Morris committed Jun 07, 2012 136  /// \return false If unpack operation failed.  Marcin Siodelski committed Jun 05, 2012 137 138 139 140 141 142 143 144 145 146 147  bool rawUnpack(); private: size_t transid_offset_; ///< transaction id offset }; } // namespace perfdhcp } // namespace isc #endif // __PERF_PKT4_H