40 if (((!(lease.duid_)) || (*(lease.duid_) ==
DUID::EMPTY())) &&
51 row.writeAt(
getColumnIndex(
"expire"),
static_cast<uint64_t
>(lease.cltt_) + lease.valid_lft_);
53 row.writeAt(
getColumnIndex(
"pref_lifetime"), lease.preferred_lft_);
57 static_cast<int>(lease.prefixlen_));
63 row.writeAt(
getColumnIndex(
"hwaddr"), lease.hwaddr_->toText(
false));
65 row.writeAt(
getColumnIndex(
"hwaddr_source"), lease.hwaddr_->source_);
69 if (lease.getContext()) {
70 row.writeAtEscaped(
getColumnIndex(
"user_context"), lease.getContext()->str());
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) {
201 uint32_t iaid = row.readAndConvertAt<uint32_t>(
getColumnIndex(
"iaid"));
206CSVLeaseFile6::readPreferred(
const CSVRow& row) {
213CSVLeaseFile6::readValid(
const CSVRow& row) {
220CSVLeaseFile6::readCltt(
const CSVRow& row) {
222 static_cast<time_t
>(row.readAndConvertAt<uint64_t>(
getColumnIndex(
"expire"))
224 return (
static_cast<uint32_t
>(cltt));
228CSVLeaseFile6::readSubnetID(
const CSVRow& row) {
235CSVLeaseFile6::readPoolID(
const CSVRow& row) {
242CSVLeaseFile6::readPrefixLen(
const CSVRow& row) {
243 int prefixlen = row.readAndConvertAt<
int>(
getColumnIndex(
"prefix_len"));
244 return (
static_cast<uint8_t
>(prefixlen));
248CSVLeaseFile6::readFqdnFwd(
const CSVRow& row) {
249 bool fqdn_fwd = row.readAndConvertAt<
bool>(
getColumnIndex(
"fqdn_fwd"));
254CSVLeaseFile6::readFqdnRev(
const CSVRow& row) {
255 bool fqdn_rev = row.readAndConvertAt<
bool>(
getColumnIndex(
"fqdn_rev"));
260CSVLeaseFile6::readHostname(
const CSVRow& row) {
261 std::string hostname = row.readAtEscaped(
getColumnIndex(
"hostname"));
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) {
296 uint32_t state = row.readAndConvertAt<uint32_t>(
getColumnIndex(
"state"));
302 std::string user_context = row.readAtEscaped(
getColumnIndex(
"user_context"));
303 if (user_context.empty()) {
309 <<
"' is not a JSON map");
315CSVLeaseFile6::readHWType(
const CSVRow& row) {
317 if (row.readAt(index).empty()) {
318 return Optional<uint16_t>();
320 return row.readAndConvertAt<uint16_t>(index);
324CSVLeaseFile6::readHWAddrSource(
const CSVRow& row) {
326 if (row.readAt(index).empty()) {
327 return Optional<uint16_t>();
329 return row.readAndConvertAt<uint32_t>(index);
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)
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 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.
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.
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)