csv_lease_file6.h 5.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (C) 2014 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 CSV_LEASE_FILE6_H
#define CSV_LEASE_FILE6_H

18 19
#include <asiolink/io_address.h>
#include <dhcp/duid.h>
20
#include <dhcpsrv/lease.h>
21
#include <dhcpsrv/subnet.h>
22
#include <util/csv_file.h>
23 24
#include <stdint.h>
#include <string>
25 26 27 28

namespace isc {
namespace dhcp {

29
/// @brief Provides methods to access CSV file with DHCPv6 leases.
30
///
31 32 33
/// This class contains methods customized to read and write DHCPv6 leases from
/// and to the CSV file. It expects that the CSV file being parsed contains a
/// set of columns with well known names (initialized in the class constructor).
34 35 36 37 38 39
///
/// @todo This class doesn't validate the lease values read from the file.
/// The @c Lease6 is a structure that should be itself responsible for this
/// validation (see http://bind10.isc.org/ticket/2405). However, when #2405
/// is implemented, the @c next function may need to be updated to use the
/// validation capablity of @c Lease6.
40 41 42
class CSVLeaseFile6 : public isc::util::CSVFile {
public:

43 44 45 46 47
    /// @brief Constructor.
    ///
    /// Initializes columns of the lease file.
    ///
    /// @param filename Name of the lease file.
48 49
    CSVLeaseFile6(const std::string& filename);

50 51
    /// @brief Appends the lease record to the CSV file.
    ///
52 53 54 55 56
    /// This function doesn't throw exceptions itself. In theory, exceptions
    /// are possible when the index of the indexes of the values being written
    /// to the file are invalid. However, this would have been a programming
    /// error.
    ///
57
    /// @param lease Structure representing a DHCPv6 lease.
58 59
    void append(const Lease6& lease) const;

60 61 62 63 64 65
    /// @brief Reads next lease from the CSV file.
    ///
    /// If this function hits an error during lease read, it sets the error
    /// message using @c CSVFile::setReadMsg and returns false. The error
    /// string may be read using @c CSVFile::getReadMsg.
    ///
66 67
    /// This function is exception safe.
    ///
68 69 70 71 72 73
    /// @param [out] lease Pointer to the lease read from CSV file or
    /// NULL pointer if lease hasn't been read.
    ///
    /// @return Boolean value indicating that the new lease has been
    /// read from the CSV file (if true), or that the error has occurred
    /// (false).
74 75 76 77
    ///
    /// @todo Make sure that the values read from the file are correct.
    /// The appropriate @c Lease6 validation mechanism should be used once
    /// ticket http://bind10.isc.org/ticket/2405 is implemented.
78 79
    bool next(Lease6Ptr& lease);

80 81
private:

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    /// @brief Initializes columns of the CSV file holding leases.
    ///
    /// This function initializes the following columns:
    /// - address
    /// - duid
    /// - valid_lifetime
    /// - expire
    /// - subnet_id
    /// - pref_lifetime
    /// - lease_type
    /// - iaid
    /// - prefix_len
    /// - fqdn_fwd
    /// - fqdn_rev
    /// - hostname
97 98
    void initColumns();

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    ///
    /// @name Methods which read specific lease fields from the CSV row.
    ///
    //@{
    ///
    /// @brief Reads lease type from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    Lease::Type readType(const util::CSVRow& row);

    /// @brief Reads lease address from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    asiolink::IOAddress readAddress(const util::CSVRow& row);

    /// @brief Reads DUID from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    DuidPtr readDUID(const util::CSVRow& row);

    /// @brief Reads IAID from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    uint32_t readIAID(const util::CSVRow& row);

    /// @brief Reads preferred lifetime from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    uint32_t readPreferred(const util::CSVRow& row);

    /// @brief Reads valid lifetime from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    uint32_t readValid(const util::CSVRow& row);

    /// @brief Reads cltt value from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    uint32_t readCltt(const util::CSVRow& row);

    /// @brief Reads subnet id from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    SubnetID readSubnetID(const util::CSVRow& row);

    /// @brief Reads prefix length from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    uint8_t readPrefixLen(const util::CSVRow& row);

    /// @brief Reads the FQDN forward flag from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    bool readFqdnFwd(const util::CSVRow& row);

    /// @brief Reads the FQDN reverse flag from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    bool readFqdnRev(const util::CSVRow& row);

    /// @brief Reads hostname from the CSV file row.
    ///
    /// @param row CSV file holding lease values.
    std::string readHostname(const util::CSVRow& row);
    //@}

165 166 167 168 169 170
};

} // namespace isc::dhcp
} // namespace isc

#endif // CSV_LEASE_FILE6_H