Kea 2.5.8
isc::dhcp::CSVLeaseFile6 Class Reference

Provides methods to access CSV file with DHCPv6 leases. More...

#include <csv_lease_file6.h>

+ Inheritance diagram for isc::dhcp::CSVLeaseFile6:

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 VersionedColumnPtrgetVersionedColumn (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 open (const bool seek_to_end=false)
 Opens existing file or creates a new one.
 
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.
 
virtual void open (const bool seek_to_end=false)
 Opens existing file or creates a new one.
 
virtual void recreate ()
 Creates a new 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.
 
virtual bool validateHeader (const CSVRow &header)
 This function validates the header of the CSV 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.
 

Detailed Description

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).

Todo:
This class doesn't validate the lease values read from the file. The 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.

Constructor & Destructor Documentation

◆ CSVLeaseFile6()

isc::dhcp::CSVLeaseFile6::CSVLeaseFile6 ( const std::string &  filename)

Constructor.

Initializes columns of the lease file.

Parameters
filenameName of the lease file.

Definition at line 21 of file csv_lease_file6.cc.

Member Function Documentation

◆ append()

void isc::dhcp::CSVLeaseFile6::append ( const Lease6 lease)

◆ next()

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.

Parameters
[out]leasePointer to the lease read from CSV file or NULL pointer if lease hasn't been read.
Returns
Boolean value indicating that the new lease has been read from the CSV file (if true), or that the error has occurred (false).
Todo:
Make sure that the values read from the file are correct. The appropriate 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.

+ Here is the call graph for this function:

◆ open()

void isc::dhcp::CSVLeaseFile6::open ( const bool  seek_to_end = false)
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().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: