Kea 2.7.6
|
Provides methods to access CSV file with DHCPv6 leases. More...
#include <csv_lease_file6.h>
Public Member Functions | |
CSVLeaseFile6 (const std::string &filename) | |
Constructor. | |
void | append (const Lease6 &lease) |
Appends the lease record to the CSV file. | |
bool | next (Lease6Ptr &lease) |
Reads next lease from the CSV file. | |
virtual void | open (const bool seek_to_end=false) |
Opens a lease file. | |
Public Member Functions inherited from isc::util::VersionedCSVFile | |
VersionedCSVFile (const std::string &filename) | |
Constructor. | |
virtual | ~VersionedCSVFile () |
Destructor. | |
void | addColumn (const std::string &col_name, const std::string &version, const std::string &default_value="") |
Adds metadata for a single column to the schema. | |
size_t | getInputHeaderCount () const |
Returns the number of columns found in the input header. | |
enum InputSchemaState | getInputSchemaState () const |
Fetches the state of the input file's schema. | |
std::string | getInputSchemaVersion () const |
Returns the schema version of the physical file. | |
size_t | getMinimumValidColumns () const |
Returns the minimum number of columns which must be present for the file to be considered valid. | |
std::string | getSchemaVersion () const |
text version of current schema supported by the file's metadata | |
size_t | getValidColumnCount () const |
Returns the number of valid columns found in the header For newly created files this will always match the number of defined columns (i.e. | |
const VersionedColumnPtr & | getVersionedColumn (const size_t index) const |
Fetch the column descriptor for a given index. | |
bool | needsConversion () const |
Returns true if the input file schema state is not CURRENT. | |
bool | next (CSVRow &row) |
Reads next row from the file file. | |
virtual void | recreate () |
Creates a new CSV file. | |
void | setMinimumValidColumns (const std::string &column_name) |
Sets the minimum number of valid columns based on a given column. | |
Public Member Functions inherited from isc::util::CSVFile | |
CSVFile (const std::string &filename) | |
Constructor. | |
virtual | ~CSVFile () |
Destructor. | |
void | addColumn (const std::string &col_name) |
Adds new column name. | |
void | append (const CSVRow &row) const |
Writes the CSV row into the file. | |
void | close () |
Closes the CSV file. | |
bool | exists () const |
Checks if the CSV file exists and can be opened for reading. | |
void | flush () const |
Flushes a file. | |
size_t | getColumnCount () const |
Returns the number of columns in the file. | |
size_t | getColumnIndex (const std::string &col_name) const |
Returns the index of the column having specified name. | |
std::string | getColumnName (const size_t col_index) const |
Returns the name of the column. | |
std::string | getFilename () const |
Returns the path to the CSV file. | |
std::string | getReadMsg () const |
Returns the description of the last error returned by the CSVFile::next function. | |
bool | next (CSVRow &row, const bool skip_validation=false) |
Reads next row from CSV file. | |
void | setReadMsg (const std::string &read_msg) |
Sets error message after row validation. | |
Public Member Functions inherited from isc::dhcp::LeaseFileStats | |
LeaseFileStats () | |
Constructor. | |
~LeaseFileStats () | |
Destructor. | |
void | clearStatistics () |
Clears the statistics. | |
uint32_t | getReadErrs () const |
Gets the number of errors when reading leases. | |
uint32_t | getReadLeases () const |
Gets the number of leases read. | |
uint32_t | getReads () const |
Gets the number of attempts to read a lease. | |
uint32_t | getWriteErrs () const |
Gets the number of errors when writing leases. | |
uint32_t | getWriteLeases () const |
Gets the number of leases written. | |
uint32_t | getWrites () const |
Gets the number of attempts to write a lease. | |
Additional Inherited Members | |
Public Types inherited from isc::util::VersionedCSVFile | |
enum | InputSchemaState { CURRENT , NEEDS_UPGRADE , NEEDS_DOWNGRADE } |
Possible input file schema states. More... | |
Static Public Member Functions inherited from isc::util::CSVFile | |
static CSVRow | EMPTY_ROW () |
Represents empty row. | |
Protected Member Functions inherited from isc::util::VersionedCSVFile | |
void | columnCountError (const CSVRow &row, const std::string &reason) |
Convenience method for adding an error message. | |
virtual bool | validateHeader (const CSVRow &header) |
Validates the header of a VersionedCSVFile. | |
Protected Member Functions inherited from isc::util::CSVFile | |
void | addColumnInternal (const std::string &col_name) |
Adds a column regardless if the file is open or not. | |
virtual bool | validate (const CSVRow &row) |
Validate the row read from a file. | |
Protected Attributes inherited from isc::dhcp::LeaseFileStats | |
uint32_t | read_errs_ |
Number of errors when reading. | |
uint32_t | read_leases_ |
Number of leases read. | |
uint32_t | reads_ |
Number of attempts to read a lease. | |
uint32_t | write_errs_ |
Number of errors when writing. | |
uint32_t | write_leases_ |
Number of lease written. | |
uint32_t | writes_ |
Number of attempts to write a lease. | |
Provides methods to access CSV file with DHCPv6 leases.
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).
Lease6
is a structure that should be itself responsible for this validation. However, the next
function may need to be updated to use the validation capability of Lease6
. Definition at line 35 of file csv_lease_file6.h.
isc::dhcp::CSVLeaseFile6::CSVLeaseFile6 | ( | const std::string & | filename | ) |
Constructor.
Initializes columns of the lease file.
filename | Name of the lease file. |
Definition at line 21 of file csv_lease_file6.cc.
void isc::dhcp::CSVLeaseFile6::append | ( | const Lease6 & | lease | ) |
Appends the lease record to the CSV file.
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.
lease | Structure representing a DHCPv6 lease. |
BadValue | if the lease to be written has an empty DUID and is whose state is not STATE_DECLINED. |
Definition at line 36 of file csv_lease_file6.cc.
References isc::dhcp::Lease::addr_, isc::dhcp::Lease::basicStatesToText(), isc::dhcp::Lease::cltt_, isc::dhcp::Lease6::duid_, isc::dhcp::DUID::EMPTY(), isc::dhcp::Lease::fqdn_fwd_, isc::dhcp::Lease::fqdn_rev_, isc::util::CSVFile::getColumnCount(), isc::util::CSVFile::getColumnIndex(), isc::data::UserContext::getContext(), isc::dhcp::Lease::hostname_, isc::dhcp::Lease::hwaddr_, isc::dhcp::Lease6::iaid_, isc_throw, isc::dhcp::Lease::pool_id_, isc::dhcp::Lease6::preferred_lft_, isc::dhcp::Lease6::prefixlen_, isc::dhcp::Lease::state_, isc::dhcp::Lease::STATE_DECLINED, isc::dhcp::Lease::subnet_id_, isc::asiolink::IOAddress::toText(), isc::dhcp::Lease6::type_, isc::dhcp::Lease::valid_lft_, isc::dhcp::LeaseFileStats::write_errs_, isc::dhcp::LeaseFileStats::write_leases_, isc::util::CSVRow::writeAt(), isc::util::CSVRow::writeAtEscaped(), and isc::dhcp::LeaseFileStats::writes_.
bool isc::dhcp::CSVLeaseFile6::next | ( | Lease6Ptr & | lease | ) |
Reads next lease from the CSV file.
If this function hits an error during lease read, it sets the error message using CSVFile::setReadMsg
and returns false. The error string may be read using CSVFile::getReadMsg
.
This function is exception safe.
[out] | lease | Pointer to the lease read from CSV file or NULL pointer if lease hasn't been read. |
Lease6
validation mechanism should be used. Definition at line 86 of file csv_lease_file6.cc.
References isc::dhcp::DUID::EMPTY(), isc::util::CSVFile::EMPTY_ROW(), isc_throw, isc::util::VersionedCSVFile::next(), isc::dhcp::LeaseFileStats::read_errs_, isc::dhcp::LeaseFileStats::read_leases_, isc::dhcp::LeaseFileStats::reads_, isc::util::CSVFile::setReadMsg(), isc::dhcp::Lease::STATE_DECLINED, and isc::dhcp::Lease::TYPE_PD.
|
virtual |
Opens a lease file.
This function calls the base class open to do the work of opening a file. It is used to clear any statistics associated with any previous use of the file While it doesn't throw any exceptions of its own the base class may do so.
Reimplemented from isc::util::VersionedCSVFile.
Definition at line 27 of file csv_lease_file6.cc.
References isc::dhcp::LeaseFileStats::clearStatistics(), and isc::util::VersionedCSVFile::open().