csv_lease_file6.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (C) 2014 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 CSV_LEASE_FILE6_H
  15. #define CSV_LEASE_FILE6_H
  16. #include <asiolink/io_address.h>
  17. #include <dhcp/duid.h>
  18. #include <dhcpsrv/lease.h>
  19. #include <dhcpsrv/subnet.h>
  20. #include <util/csv_file.h>
  21. #include <boost/shared_ptr.hpp>
  22. #include <stdint.h>
  23. #include <string>
  24. namespace isc {
  25. namespace dhcp {
  26. /// @brief Provides methods to access CSV file with DHCPv6 leases.
  27. class CSVLeaseFile6 : public isc::util::CSVFile {
  28. public:
  29. /// @brief Constructor.
  30. ///
  31. /// Initializes columns of the lease file.
  32. ///
  33. /// @param filename Name of the lease file.
  34. CSVLeaseFile6(const std::string& filename);
  35. /// @brief Appends the lease record to the CSV file.
  36. ///
  37. /// @param lease Structure representing a DHCPv6 lease.
  38. void append(const Lease6& lease) const;
  39. /// @brief Reads next lease from the CSV file.
  40. ///
  41. /// If this function hits an error during lease read, it sets the error
  42. /// message using @c CSVFile::setReadMsg and returns false. The error
  43. /// string may be read using @c CSVFile::getReadMsg.
  44. ///
  45. /// @param [out] lease Pointer to the lease read from CSV file or
  46. /// NULL pointer if lease hasn't been read.
  47. ///
  48. /// @return Boolean value indicating that the new lease has been
  49. /// read from the CSV file (if true), or that the error has occurred
  50. /// (false).
  51. bool next(Lease6Ptr& lease);
  52. private:
  53. /// @brief Initializes columns of the CSV file holding leases.
  54. ///
  55. /// This function initializes the following columns:
  56. /// - address
  57. /// - duid
  58. /// - valid_lifetime
  59. /// - expire
  60. /// - subnet_id
  61. /// - pref_lifetime
  62. /// - lease_type
  63. /// - iaid
  64. /// - prefix_len
  65. /// - fqdn_fwd
  66. /// - fqdn_rev
  67. /// - hostname
  68. void initColumns();
  69. ///
  70. /// @name Methods which read specific lease fields from the CSV row.
  71. ///
  72. //@{
  73. ///
  74. /// @brief Reads lease type from the CSV file row.
  75. ///
  76. /// @param row CSV file holding lease values.
  77. Lease::Type readType(const util::CSVRow& row);
  78. /// @brief Reads lease address from the CSV file row.
  79. ///
  80. /// @param row CSV file holding lease values.
  81. asiolink::IOAddress readAddress(const util::CSVRow& row);
  82. /// @brief Reads DUID from the CSV file row.
  83. ///
  84. /// @param row CSV file holding lease values.
  85. DuidPtr readDUID(const util::CSVRow& row);
  86. /// @brief Reads IAID from the CSV file row.
  87. ///
  88. /// @param row CSV file holding lease values.
  89. uint32_t readIAID(const util::CSVRow& row);
  90. /// @brief Reads preferred lifetime from the CSV file row.
  91. ///
  92. /// @param row CSV file holding lease values.
  93. uint32_t readPreferred(const util::CSVRow& row);
  94. /// @brief Reads valid lifetime from the CSV file row.
  95. ///
  96. /// @param row CSV file holding lease values.
  97. uint32_t readValid(const util::CSVRow& row);
  98. /// @brief Reads cltt value from the CSV file row.
  99. ///
  100. /// @param row CSV file holding lease values.
  101. uint32_t readCltt(const util::CSVRow& row);
  102. /// @brief Reads subnet id from the CSV file row.
  103. ///
  104. /// @param row CSV file holding lease values.
  105. SubnetID readSubnetID(const util::CSVRow& row);
  106. /// @brief Reads prefix length from the CSV file row.
  107. ///
  108. /// @param row CSV file holding lease values.
  109. uint8_t readPrefixLen(const util::CSVRow& row);
  110. /// @brief Reads the FQDN forward flag from the CSV file row.
  111. ///
  112. /// @param row CSV file holding lease values.
  113. bool readFqdnFwd(const util::CSVRow& row);
  114. /// @brief Reads the FQDN reverse flag from the CSV file row.
  115. ///
  116. /// @param row CSV file holding lease values.
  117. bool readFqdnRev(const util::CSVRow& row);
  118. /// @brief Reads hostname from the CSV file row.
  119. ///
  120. /// @param row CSV file holding lease values.
  121. std::string readHostname(const util::CSVRow& row);
  122. //@}
  123. };
  124. } // namespace isc::dhcp
  125. } // namespace isc
  126. #endif // CSV_LEASE_FILE6_H