option6_status_code.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (C) 2015 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 Writes option in wire-format.
  33. ///
  34. /// Writes option in wire-format to buf, returns pointer to first unused
  35. /// byte after stored option.
  36. ///
  37. /// @param [out] buf Pointer to the output buffer.
  38. virtual void pack(isc::util::OutputBuffer& buf) const;
  39. /// @brief Parses received buffer.
  40. ///
  41. /// @param begin Iterator to first byte of option data
  42. /// @param end Iterator to end of option data (first byte after option end)
  43. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end);
  44. /// @brief Returns total length of the option.
  45. ///
  46. /// The returned length is a sum of the option header and data fields.
  47. virtual uint16_t len() const;
  48. /// @brief Returns textual representation of the option.
  49. ///
  50. /// @param indent Number of spaces before printing text.
  51. virtual std::string toText(int indent = 0) const;
  52. /// @brief Returns textual representation of the option data.
  53. ///
  54. /// This method returns only the status code and the status
  55. /// message. It excludes the option header.
  56. std::string dataToText() const;
  57. /// @brief Returns numeric status code.
  58. uint16_t getStatusCode() const {
  59. return (status_code_);
  60. }
  61. /// @brief Returns the name of the status code.
  62. std::string getStatusCodeName() const;
  63. /// @brief Sets new numeric status code.
  64. ///
  65. /// @param status_code New numeric status code.
  66. void setStatusCode(const uint16_t status_code) {
  67. status_code_ = status_code;
  68. }
  69. /// @brief Returns status message.
  70. const std::string& getStatusMessage() const {
  71. return (status_message_);
  72. }
  73. /// @brief Sets new status message.
  74. ///
  75. /// @param status_message New status message (empty string is allowed).
  76. void setStatusMessage(const std::string& status_message) {
  77. status_message_ = status_message;
  78. }
  79. private:
  80. /// @brief Numeric status code.
  81. uint16_t status_code_;
  82. /// @brief Textual message.
  83. std::string status_message_;
  84. };
  85. } // isc::dhcp namespace
  86. } // isc namespace
  87. #endif // OPTION6_STATUS_CODE_H