74 VersionedCSVFile::append(row);
75 }
catch (
const std::exception&) {
105 uint8_t prefixlen = 128;
107 prefixlen = readPrefixLen(row);
110 lease.reset(
new Lease6(type, readAddress(row), readDUID(row),
111 readIAID(row), readPreferred(row),
117 lease->cltt_ = readCltt(row);
118 lease->fqdn_fwd_ = readFqdnFwd(row);
119 lease->fqdn_rev_ = readFqdnRev(row);
120 lease->hostname_ = readHostname(row);
121 lease->state_ = readState(row);
126 "The Empty DUID is only valid for declined leases");
131 lease->setContext(ctx);
134 lease->pool_id_ = readPoolID(row);
135 }
catch (
const std::exception& ex) {
153CSVLeaseFile6::initColumns() {
182CSVLeaseFile6::readType(
const CSVRow& row) {
188CSVLeaseFile6::readAddress(
const CSVRow& row) {
200CSVLeaseFile6::readIAID(
const CSVRow& row) {
206CSVLeaseFile6::readPreferred(
const CSVRow& row) {
213CSVLeaseFile6::readValid(
const CSVRow& row) {
220CSVLeaseFile6::readCltt(
const CSVRow& row) {
224 return (
static_cast<uint32_t
>(cltt));
228CSVLeaseFile6::readSubnetID(
const CSVRow& row) {
235CSVLeaseFile6::readPoolID(
const CSVRow& row) {
242CSVLeaseFile6::readPrefixLen(
const CSVRow& row) {
244 return (
static_cast<uint8_t
>(prefixlen));
248CSVLeaseFile6::readFqdnFwd(
const CSVRow& row) {
254CSVLeaseFile6::readFqdnRev(
const CSVRow& row) {
260CSVLeaseFile6::readHostname(
const CSVRow& row) {
266CSVLeaseFile6::readHWAddr(
const CSVRow& row) {
269 uint16_t
const hwtype(readHWType(row).valueOr(
HTYPE_ETHER));
272 if (hwaddr.hwaddr_.empty()) {
284 }
catch (
const std::exception& ex) {
303 if (user_context.empty()) {
309 <<
"' is not a JSON map");
315CSVLeaseFile6::readHWType(
const CSVRow& row) {
317 if (row.
readAt(index).empty()) {
324CSVLeaseFile6::readHWAddrSource(
const CSVRow& row) {
326 if (row.
readAt(index).empty()) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
bool next(Lease6Ptr &lease)
Reads next lease from the CSV file.
void append(const Lease6 &lease)
Appends the lease record to the CSV file.
virtual void open(const bool seek_to_end=false)
Opens a lease file.
CSVLeaseFile6(const std::string &filename)
Constructor.
static DUID fromText(const std::string &text)
Create DUID from the textual format.
static const DUID & EMPTY()
Defines the constant "empty" DUID.
uint32_t write_leases_
Number of lease written.
uint32_t read_leases_
Number of leases read.
uint32_t reads_
Number of attempts to read a lease.
void clearStatistics()
Clears the statistics.
uint32_t writes_
Number of attempts to write a lease.
uint32_t write_errs_
Number of errors when writing.
uint32_t read_errs_
Number of errors when reading.
size_t getColumnCount() const
Returns the number of columns in the file.
static CSVRow EMPTY_ROW()
Represents empty row.
void setReadMsg(const std::string &read_msg)
Sets error message after row validation.
size_t getColumnIndex(const std::string &col_name) const
Returns the index of the column having specified name.
Represents a single row of the CSV file.
T readAndConvertAt(const size_t at) const
Retrieves a value from the internal container.
std::string readAtEscaped(const size_t at) const
Retrieves a value from the internal container, free of escaped characters.
void writeAt(const size_t at, const char *value)
Replaces the value at specified index.
std::string readAt(const size_t at) const
Retrieves a value from the internal container.
void writeAtEscaped(const size_t at, const std::string &value)
Replaces the value at the specified index with a value that has had special characters escaped.
A template representing an optional value.
T valueOr(T const &or_value) const
Retrieves the encapsulated value if specified, or the given value otherwise.
Implements a CSV file that supports multiple versions of the file's "schema".
virtual void open(const bool seek_to_end=false)
Opens existing file or creates a new one.
void setMinimumValidColumns(const std::string &column_name)
Sets the minimum number of valid columns based on a given column.
bool next(CSVRow &row)
Reads next row from the file file.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static const uint32_t HWADDR_SOURCE_UNKNOWN
Used when actual origin is not known, e.g.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_MEMFILE_READ_HWADDR_FAIL
boost::shared_ptr< DUID > DuidPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
@ HTYPE_ETHER
Ethernet 10Mbps.
Defines the logger used by the top-level component of kea-lfc.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
Structure that holds a lease for IPv6 address and/or prefix.
Lease::Type type_
Lease type.
uint32_t iaid_
Identity Association Identifier (IAID)
uint32_t preferred_lft_
Preferred lifetime.
DuidPtr duid_
Client identifier.
uint8_t prefixlen_
IPv6 prefix length.
SubnetID subnet_id_
Subnet identifier.
uint32_t pool_id_
The pool id.
uint32_t valid_lft_
Valid lifetime.
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
static const uint32_t STATE_DECLINED
Declined lease.
Type
Type of lease or pool.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
std::string hostname_
Client hostname.
uint32_t state_
Holds the lease state(s).
bool fqdn_fwd_
Forward zone updated?
time_t cltt_
Client last transmission time.
HWAddrPtr hwaddr_
Client's MAC/hardware address.
bool fqdn_rev_
Reverse zone updated?
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.