option6_status_code.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef OPTION6_STATUS_CODE_H
  7. #define OPTION6_STATUS_CODE_H
  8. #include <dhcp/option.h>
  9. #include <boost/shared_ptr.hpp>
  10. #include <stdint.h>
  11. #include <string>
  12. namespace isc {
  13. namespace dhcp {
  14. class Option6StatusCode;
  15. /// @brief Pointer to the @c isc::dhcp::Option6StatusCode.
  16. typedef boost::shared_ptr<Option6StatusCode> Option6StatusCodePtr;
  17. /// @brief This class represents Status Code option (13) from RFC3315.
  18. class Option6StatusCode: public Option {
  19. public:
  20. /// @brief Constructor, used for options constructed (during transmission).
  21. ///
  22. /// @param status_code Numeric status code, e.g. STATUS_NoAddrsAvail.
  23. /// @param status_message Textual message for the statuscode.
  24. Option6StatusCode(const uint16_t status_code, const std::string& status_message);
  25. /// @brief Constructor, used for received options.
  26. ///
  27. /// @throw OutOfRange if specified option is truncated
  28. ///
  29. /// @param begin Iterator to first byte of option data
  30. /// @param end Iterator to end of option data (first byte after option end).
  31. Option6StatusCode(OptionBufferConstIter begin, OptionBufferConstIter end);
  32. /// @brief Copies this option and returns a pointer to the copy.
  33. virtual OptionPtr clone() const;
  34. /// @brief Writes option in wire-format.
  35. ///
  36. /// Writes option in wire-format to buf, returns pointer to first unused
  37. /// byte after stored option.
  38. ///
  39. /// @param [out] buf Pointer to the output buffer.
  40. virtual void pack(isc::util::OutputBuffer& buf) const;
  41. /// @brief Parses received buffer.
  42. ///
  43. /// @param begin Iterator to first byte of option data
  44. /// @param end Iterator to end of option data (first byte after option end)
  45. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end);
  46. /// @brief Returns total length of the option.
  47. ///
  48. /// The returned length is a sum of the option header and data fields.
  49. virtual uint16_t len() const;
  50. /// @brief Returns textual representation of the option.
  51. ///
  52. /// @param indent Number of spaces before printing text.
  53. virtual std::string toText(int indent = 0) const;
  54. /// @brief Returns textual representation of the option data.
  55. ///
  56. /// This method returns only the status code and the status
  57. /// message. It excludes the option header.
  58. std::string dataToText() const;
  59. /// @brief Returns numeric status code.
  60. uint16_t getStatusCode() const {
  61. return (status_code_);
  62. }
  63. /// @brief Returns the name of the status code.
  64. std::string getStatusCodeName() const;
  65. /// @brief Sets new numeric status code.
  66. ///
  67. /// @param status_code New numeric status code.
  68. void setStatusCode(const uint16_t status_code) {
  69. status_code_ = status_code;
  70. }
  71. /// @brief Returns status message.
  72. const std::string& getStatusMessage() const {
  73. return (status_message_);
  74. }
  75. /// @brief Sets new status message.
  76. ///
  77. /// @param status_message New status message (empty string is allowed).
  78. void setStatusMessage(const std::string& status_message) {
  79. status_message_ = status_message;
  80. }
  81. private:
  82. /// @brief Numeric status code.
  83. uint16_t status_code_;
  84. /// @brief Textual message.
  85. std::string status_message_;
  86. };
  87. } // isc::dhcp namespace
  88. } // isc namespace
  89. #endif // OPTION6_STATUS_CODE_H