11 #include <boost/algorithm/string.hpp> 12 #include <boost/scoped_ptr.hpp> 24 const uint32_t Lease::STATE_DEFAULT = 0x0;
25 const uint32_t Lease::STATE_DECLINED = 0x1;
26 const uint32_t Lease::STATE_EXPIRED_RECLAIMED = 0x2;
29 Lease::lifetimeToText(uint32_t lifetime) {
31 if (lifetime == INFINITY_LFT) {
40 uint32_t valid_lft,
SubnetID subnet_id, time_t cltt,
41 const bool fqdn_fwd,
const bool fqdn_rev,
42 const std::string& hostname,
const HWAddrPtr& hwaddr)
43 : addr_(addr), valid_lft_(valid_lft), current_valid_lft_(valid_lft),
44 reuseable_valid_lft_(0),
45 cltt_(cltt), current_cltt_(cltt), subnet_id_(subnet_id),
46 hostname_(
boost::algorithm::to_lower_copy(hostname)), fqdn_fwd_(fqdn_fwd),
47 fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT),
58 return string(
"IA_NA");
60 return string(
"IA_TA");
62 return string(
"IA_PD");
66 tmp <<
"unknown (" << type <<
")";
77 }
else if (text ==
"IA_NA") {
80 }
else if (text ==
"IA_TA") {
83 }
else if (text ==
"IA_PD") {
98 return (
"expired-reclaimed");
103 std::ostringstream s;
104 s <<
"unknown (" << state <<
")";
154 " or it is not a string");
157 boost::scoped_ptr<asiolink::IOAddress> io_address;
161 }
catch (
const std::exception& ex) {
163 <<
" in the parsed lease");
166 lease->addr_ = *io_address;
172 " or it is not a number");
175 if (subnet_id->intValue() <= 0) {
177 <<
" a positive integer");
178 }
else if (subnet_id->intValue() > numeric_limits<uint32_t>::max()) {
180 <<
" a 32 bit unsigned integer");
183 lease->subnet_id_ =
SubnetID(subnet_id->intValue());
197 }
catch (
const std::exception& ex) {
199 << hw_address->stringValue() <<
" in the parsed lease");
207 " or it is not a number");
210 if (cltt->intValue() <= 0) {
212 " positive integer in the parsed lease");
215 lease->cltt_ =
static_cast<time_t
>(cltt->intValue());
221 " or it is not a number");
224 if (valid_lifetime->intValue() < 0) {
226 <<
" is negative in the parsed lease");
229 lease->valid_lft_ = valid_lifetime->intValue();
235 " or it is not a boolean value");
238 lease->fqdn_fwd_ = fqdn_fwd->boolValue();
244 " or it is not a boolean value");
247 lease->fqdn_rev_ = fqdn_rev->boolValue();
253 " or it is not a string value");
256 lease->hostname_ = hostname->stringValue();
257 boost::algorithm::to_lower(lease->hostname_);
263 " or it is not a number");
268 <<
" must be in range [0.." 269 << Lease::STATE_EXPIRED_RECLAIMED <<
"]");
272 lease->state_ = state->intValue();
280 lease->setContext(ctx);
283 lease->updateCurrentExpirationTime();
328 const uint32_t valid_lifetime,
333 const std::string& hostname)
335 :
Lease(address, valid_lifetime, subnet_id, cltt, fqdn_fwd,
336 fqdn_rev, hostname, hw_address),
345 const std::vector<uint8_t>&
348 static std::vector<uint8_t> empty_vec;
355 const std::vector<uint8_t>&
358 static std::vector<uint8_t> empty_vec;
395 if (
this != &other) {
461 if (!lease->addr_.isV4()) {
466 if (!lease->hwaddr_) {
482 }
catch (
const std::exception& ex) {
484 << client_id->stringValue() <<
" in the parsed lease");
492 DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
494 :
Lease(addr, valid, subnet_id, 0, false, false,
"", hwaddr),
495 type_(type), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
496 preferred_lft_(preferred), reuseable_preferred_lft_(0) {
506 DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
507 SubnetID subnet_id,
const bool fqdn_fwd,
const bool fqdn_rev,
508 const std::string& hostname,
const HWAddrPtr& hwaddr,
510 :
Lease(addr, valid, subnet_id, 0,
511 fqdn_fwd, fqdn_rev, hostname, hwaddr),
533 const std::vector<uint8_t>&
536 static std::vector<uint8_t> empty_vec;
540 return (
duid_->getDuid());
558 ostringstream stream;
562 <<
static_cast<int>(
type_) <<
")\n" 563 <<
"Address: " <<
addr_ <<
"\n" 564 <<
"Prefix length: " << static_cast<int>(
prefixlen_) <<
"\n" 565 <<
"IAID: " <<
iaid_ <<
"\n" 568 <<
"Cltt: " <<
cltt_ <<
"\n" 569 <<
"DUID: " << (
duid_?
duid_->toText():
"(none)") <<
"\n" 570 <<
"Hardware addr: " << (
hwaddr_?
hwaddr_->toText(
false):
"(none)") <<
"\n" 575 stream <<
"User context: " <<
getContext()->str() <<
"\n";
578 return (stream.str());
583 ostringstream stream;
585 stream <<
"Address: " <<
addr_ <<
"\n" 587 <<
"Cltt: " <<
cltt_ <<
"\n" 588 <<
"Hardware addr: " << (
hwaddr_ ?
hwaddr_->toText(
false) :
"(none)") <<
"\n" 589 <<
"Client id: " << (client_id_ ? client_id_->toText() :
"(none)") <<
"\n" 594 stream <<
"User context: " <<
getContext()->str() <<
"\n";
597 return (stream.str());
681 if (!lease->addr_.isV6()) {
689 " or it is not a string value");
692 lease->type_ =
textToType(lease_type->stringValue());
699 " or it is not a number");
702 if ((prefix_len->intValue() < 1) || (prefix_len->intValue() > 128)) {
704 <<
" must be in range of [1..128]");
707 lease->prefixlen_ =
static_cast<uint8_t
>(prefix_len->intValue());
714 " or it is not a number");
717 if (iaid->intValue() < 0) {
721 lease->iaid_ =
static_cast<uint32_t
>(iaid->intValue());
727 " or it is not a string");
734 }
catch (
const std::exception& ex) {
736 << duid->stringValue() <<
" in the parsed lease");
743 " or is not a number");
746 if (preferred_lft->intValue() < 0) {
748 <<
" must not be negative");
751 lease->preferred_lft_ =
static_cast<uint32_t
>(preferred_lft->intValue());
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
uint32_t state_
Holds the lease state(s).
boost::shared_ptr< DUID > DuidPtr
void setContext(const data::ConstElementPtr &ctx)
Sets user context.
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
HWAddrPtr hwaddr_
Client's MAC/hardware address.
uint32_t iaid_
Identity Association Identifier (IAID)
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Structure that holds a lease for IPv4 address.
std::vector< uint8_t > relay_id_
Relay identifier for Bulk Lease Query.
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
bool fqdn_rev_
Reverse zone updated?
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
static std::string typeToText(Type type)
returns text representation of a lease type
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
time_t cltt_
Client last transmission time.
uint32_t preferred_lft_
Preferred lifetime.
static const DUID & EMPTY()
Defines the constant "empty" DUID.
bool fqdn_fwd_
Forward zone updated?
virtual std::string toText() const
Convert Lease to Printable Form.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
the lease contains IPv6 prefix (for prefix delegation)
boost::shared_ptr< Element > ElementPtr
std::vector< uint8_t > hwaddr_
static DUID fromText(const std::string &text)
Create DUID from the textual format.
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
std::string hostname_
Client hostname.
SubnetID subnet_id_
Subnet identifier.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
virtual std::string toText() const =0
Convert Lease to Printable Form.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Holds DUID (DHCPv6 Unique Identifier)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static void syncCurrentExpirationTime(const Lease &from, Lease &to)
Sync lease current expiration time with new value from another lease, so that additional operations c...
int64_t getExpirationTime() const
Returns lease expiration time.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
A generic exception that is thrown when an unexpected error condition occurs.
Lease4()
Default constructor.
bool equalValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are non-null and values are equal.
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
boost::shared_ptr< const Element > ConstElementPtr
DuidPtr duid_
Client identifier.
std::vector< uint8_t > duid_
The actual content of the DUID.
Structure that holds a lease for IPv6 address and/or prefix.
ClientIdPtr client_id_
Client identifier.
Lease::Type type_
Lease type.
bool belongsToClient(const HWAddrPtr &hw_address, const ClientIdPtr &client_id) const
Check if the lease belongs to the client with the given identifiers.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
uint8_t prefixlen_
IPv6 prefix length.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
the lease contains temporary IPv6 address
bool operator==(const Lease4 &other) const
Compare two leases for equality.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
the lease contains non-temporary IPv6 address
bool nullOrEqualValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are both null or both are non-null and they point to equal value...
bool expired() const
returns true if the lease is expired
Lease4 & operator=(const Lease4 &other)
Assignment operator.
time_t current_cltt_
Current client last transmission time.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Defines the logger used by the top-level component of kea-lfc.
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
static Type textToType(const std::string &text)
Converts type name to the actual type.
std::string toText() const
Convert the address to a string.
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
static ElementPtr create(const Position &pos=ZERO_POSITION())
A wrapper interface for the ASIO library.
a common structure for IPv4 and IPv6 leases
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
Type
Type of lease or pool.
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
Holds Client identifier or client IPv4 address.
A generic exception that is thrown if a function is called in a prohibited way.
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Hardware type that represents information from DHCPv4 packet.
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
static const uint32_t STATE_DEFAULT
A lease in the default state.
bool operator==(const Lease6 &other) const
Compare two leases for equality.
static const uint32_t STATE_DECLINED
Declined lease.
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
ExtendedInfoAction
Action on extended info tables.
uint32_t valid_lft_
Valid lifetime.
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
The IOAddress class represents an IP addresses (version agnostic)
static void fromElementCommon(const LeasePtr &lease, const data::ConstElementPtr &element)
Sets common (for v4 and v6) properties of the lease object.
virtual std::string toText() const
Convert lease to printable form.
std::vector< uint8_t > remote_id_
Remote identifier for Bulk Lease Query.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
uint32_t current_valid_lft_
Current valid lifetime.
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.