40 if (((!lease.hwaddr_) || lease.hwaddr_->hwaddr_.empty()) &&
41 ((!lease.client_id_) || (lease.client_id_->getClientId().empty())) &&
48 <<
" has neither hardware address or client id");
54 row.writeAt(
getColumnIndex(
"hwaddr"), lease.hwaddr_->toText(
false));
58 if (lease.client_id_) {
59 row.writeAt(
getColumnIndex(
"client_id"), lease.client_id_->toText());
63 row.writeAt(
getColumnIndex(
"expire"),
static_cast<uint64_t
>(lease.cltt_) + lease.valid_lft_);
70 if (lease.getContext()) {
71 row.writeAtEscaped(
getColumnIndex(
"user_context"), lease.getContext()->str());
75 VersionedCSVFile::append(row);
76 }
catch (
const std::exception&) {
112 std::vector<uint8_t> client_id_vec;
114 client_id_vec = client_id->getClientId();
116 size_t client_id_len = client_id_vec.size();
120 HWAddr hwaddr = readHWAddr(row);
121 uint32_t state = readState(row);
123 if ((hwaddr.
hwaddr_.empty()) && (client_id_vec.empty()) &&
127 <<
" has neither hardware address or client id");
133 lease.reset(
new Lease4(addr,
135 client_id_vec.empty() ? NULL : &client_id_vec[0],
144 lease->state_ = state;
147 lease->setContext(ctx);
150 lease->pool_id_ = readPoolID(row);
151 }
catch (
const std::exception& ex) {
169CSVLeaseFile4::initColumns() {
188CSVLeaseFile4::readAddress(
const CSVRow& row) {
194CSVLeaseFile4::readHWAddr(
const CSVRow& row) {
200CSVLeaseFile4::readClientId(
const CSVRow& row) {
203 if (client_id.empty()) {
211CSVLeaseFile4::readValid(
const CSVRow& row) {
218CSVLeaseFile4::readCltt(
const CSVRow& row) {
220 static_cast<time_t
>(row.readAndConvertAt<uint64_t>(
getColumnIndex(
"expire"))
226CSVLeaseFile4::readSubnetID(
const CSVRow& row) {
233CSVLeaseFile4::readPoolID(
const CSVRow& row) {
240CSVLeaseFile4::readFqdnFwd(
const CSVRow& row) {
241 bool fqdn_fwd = row.readAndConvertAt<
bool>(
getColumnIndex(
"fqdn_fwd"));
246CSVLeaseFile4::readFqdnRev(
const CSVRow& row) {
247 bool fqdn_rev = row.readAndConvertAt<
bool>(
getColumnIndex(
"fqdn_rev"));
252CSVLeaseFile4::readHostname(
const CSVRow& row) {
253 std::string hostname = row.readAtEscaped(
getColumnIndex(
"hostname"));
259 uint32_t state = row.readAndConvertAt<uint32_t>(
getColumnIndex(
"state"));
265 std::string user_context = row.readAtEscaped(
getColumnIndex(
"user_context"));
266 if (user_context.empty()) {
272 <<
"' is not a JSON map");
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.
void append(const Lease4 &lease)
Appends the lease record to the CSV file.
CSVLeaseFile4(const std::string &filename)
Constructor.
virtual void open(const bool seek_to_end=false)
Opens a lease file.
bool next(Lease4Ptr &lease)
Reads next lease from the CSV file.
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
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.
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.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
std::vector< uint8_t > hwaddr_
Structure that holds a lease for IPv4 address.
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.