14#include <boost/foreach.hpp>
32 if (!host || (host->getIPv6SubnetID() == SUBNET_ID_UNUSED)) {
36 if (std::distance(resrv.first, resrv.second) == 0) {
40 BOOST_FOREACH(
auto const& it, resrv) {
52 if (!host || (host->getIPv6SubnetID() == SUBNET_ID_UNUSED)) {
56 if (std::distance(resrv.first, resrv.second) == 0) {
60 const SubnetID& subnet_id = host->getIPv6SubnetID();
65 BOOST_FOREACH(
auto const& it, resrv) {
66 const IOAddress& prefix = it.second.getPrefix();
69 make_pair(idx1.lower_bound(boost::make_tuple(subnet_id, prefix)),
70 idx1.upper_bound(boost::make_tuple(subnet_id, prefix)));
71 for (Resv6ContainerSubnetAddressIndex::iterator p = r.first;
73 if (p->host_ != host) {
81 uint8_t prefix_len = it.second.getPrefixLen();
83 make_pair(idx0.lower_bound(prefix), idx0.upper_bound(prefix));
84 for (Resv6ContainerAddressIndex::iterator p = r.first;
86 if (p->resrv_.getPrefixLen() == prefix_len) {
87 if (p->host_ != host) {
103 HostContainerHashedIndex::iterator it = idx.find(host);
104 if (it == idx.end()) {
118 const uint8_t* identifier_begin,
119 const size_t identifier_len) {
120 HostContainerSequencedIndex::iterator host =
122 identifier_begin, identifier_len);
123 if (host == cache_.end()) {
126 cache_.relocate(cache_.end(), host);
133 HostContainerSequencedIndex::iterator host =
135 if (host == cache_.end()) {
138 cache_.relocate(cache_.end(), host);
145 const uint8_t* identifier_begin,
146 const size_t identifier_len) {
147 HostContainerSequencedIndex::iterator host =
149 identifier_begin, identifier_len);
150 if (host == cache_.end()) {
153 cache_.relocate(cache_.end(), host);
159 const uint8_t prefix_len) {
171HostContainerSequencedIndex::iterator
174 const uint8_t* identifier,
175 const size_t identifier_len) {
180 boost::make_tuple(vector<uint8_t>(identifier,
181 identifier + identifier_len),
184 for (HostContainerIdentifierIndex::iterator host = idx.lower_bound(t);
185 host != idx.upper_bound(t); ++host) {
187 SubnetID host_subnet_id = subnet6 ? (*host)->getIPv6SubnetID() :
188 (*host)->getIPv4SubnetID();
190 if (subnet_id == host_subnet_id) {
194 return (cache_.end());
197HostContainerSequencedIndex::iterator
204 for (HostContainerAddress4Index::iterator host = r.first;
205 host != r.second; ++host) {
207 if ((*host)->getIPv4SubnetID() == subnet_id) {
211 return (cache_.end());
216 const uint8_t prefix_len) {
221 idx.upper_bound(prefix));
222 BOOST_FOREACH(
auto const& resrv, r) {
223 if (resrv.resrv_.getPrefixLen() == prefix_len) {
224 return (resrv.host_);
238 make_pair(idx.lower_bound(boost::make_tuple(subnet_id, address)),
239 idx.upper_bound(boost::make_tuple(subnet_id, address)));
241 BOOST_FOREACH(
auto const& resrv, r) {
242 return (resrv.host_);
250 DuidPtr duid = host->getDuid();
251 const vector<uint8_t>&
id = host->getIdentifier();
252 size_t conflicts = 0;
255 if (host->getIPv4SubnetID() != SUBNET_ID_UNUSED) {
258 HostContainerSequencedIndex::iterator dup;
260 host->getIdentifierType(),
275 HostContainerSequencedIndex::iterator dup;
277 address)) != cache_.end()) {
290 if (host->getIPv6SubnetID() != SUBNET_ID_UNUSED) {
293 HostContainerSequencedIndex::iterator dup;
295 host->getIdentifierType(),
309 BOOST_FOREACH(
auto const& it, resrv) {
313 it.second.getPrefix()))) {
324 it.second.getPrefixLen()))) {
338 auto ret = cache_.push_back(host_copy);
365 if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
366 host->getIPv6SubnetID() == SUBNET_ID_UNUSED) {
374 for (
HostPtr const& h : cache_) {
375 if (h->getHostId() == host->getHostId()) {
391 return (
insert(host,
false) == 0);
401 for (HostContainerAddress4Index::iterator host = r.first;
402 host != r.second; ++host) {
404 if ((*host)->getIPv4SubnetID() == subnet_id) {
405 txt = (*host)->toText();
421 Resv6ContainerSubnetAddressIndex::iterator resrv =
422 idx.find(boost::make_tuple(subnet_id, addr));
423 if (resrv == idx.end()) {
426 txt = resrv->host_->toText();
434 const uint8_t* identifier_begin,
435 const size_t identifier_len) {
440 boost::make_tuple(vector<uint8_t>(identifier_begin,
441 identifier_begin + identifier_len),
443 for (HostContainerIdentifierIndex::iterator host = idx.lower_bound(t);
444 host != idx.upper_bound(t); ++host) {
445 SubnetID host_subnet_id = (*host)->getIPv4SubnetID();
446 if (subnet_id == host_subnet_id) {
447 txt = (*host)->toText();
459 const uint8_t* identifier_begin,
460 const size_t identifier_len) {
466 boost::make_tuple(vector<uint8_t>(identifier_begin,
467 identifier_begin + identifier_len),
469 for (HostContainerIdentifierIndex::iterator host = idx.lower_bound(t);
470 host != idx.upper_bound(t); ++host) {
471 SubnetID host_subnet_id = (*host)->getIPv6SubnetID();
472 if (subnet_id == host_subnet_id) {
473 txt = (*host)->toText();
486 HostContainerHashedIndex::iterator host_it = idx.find(host);
489 if (host_it == idx.end()) {
503 HostContainerSequencedIndex::iterator host = idx.begin();
504 while ((host != idx.end()) && (count > 0)) {
518 for (
auto const& host : idx) {
529 const uint8_t* identifier_begin,
530 const size_t identifier_len)
const {
535 boost::make_tuple(vector<uint8_t>(identifier_begin,
536 identifier_begin + identifier_len),
539 for (HostContainerIdentifierIndex::iterator host = idx.lower_bound(t);
540 host != idx.upper_bound(t); ++host) {
541 result.push_back(*host);
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
A generic exception that is thrown when an object can not be found.
The IOAddress class represents an IP addresses (version agnostic)
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
Represents a device with IPv4 and/or IPv6 reservations.
IdentifierType
Type of the host identifier.
void flush(size_t count)
Flush entries.
dhcp::ConstHostPtr get6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Returns a host connected to the IPv6 subnet.
void removeResv6(const dhcp::HostPtr &host)
Remove IPv6 reservations.
HostContainerSequencedIndex::iterator getHostInternal4(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
dhcp::HostPtr relocate(dhcp::HostPtr host)
Relocate an entry to the end of sequenced index.
size_t maximum_
Maximum number of elements (0 means unbound).
virtual dhcp::ConstHostCollection get(const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
virtual ~HostCacheImpl()
Destructor.
void update(isc::dhcp::ConstHostPtr const &host)
Implements isc::dhcp::BaseHostDataSource::update() for HostCacheImpl.
dhcp::HostPtr getHostInternal6(const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Returns a host using the specified IPv6 prefix.
bool add(const dhcp::HostPtr &host)
Adds a new host to the collection.
HostContainerSequencedIndex::iterator getHostInternal(const dhcp::SubnetID &subnet_id, const bool subnet6, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier, const size_t identifier_len)
Returns Host object connected to a subnet.
HostCacheImpl()
Constructor.
std::string del6(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id6, address)
std::string del4(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id4, address)
data::ElementPtr toElement() const
Unparse cache content.
dhcp::ConstHostPtr get4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Returns a host connected to the IPv4 subnet.
bool insertResv6(const dhcp::HostPtr &host)
Insert IPv6 reservations.
bool remove(const dhcp::HostPtr &host)
Remove a host from the cache.
size_t insert(const dhcp::ConstHostPtr &host, bool overwrite)
Insert a host into the cache.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
boost::shared_ptr< DUID > DuidPtr
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
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< const Host > ConstHostPtr
Const pointer to the Host object.
HostContainer::index< HostAddress4IndexTag >::type HostContainerAddress4Index
Reserved Ipv4 address index type in the HostContainer.
std::pair< Resv6ContainerSubnetAddressIndex::iterator, Resv6ContainerSubnetAddressIndex::iterator > Resv6ContainerSubnetAddressIndexRange
Results range returned using the Resv6ContainerSubnetAddressIndex.
HostContainer::index< HostIdentifierIndexTag >::type HostContainerIdentifierIndex
Identifier index type in the HostContainer.
std::pair< HostContainerAddress4Index::iterator, HostContainerAddress4Index::iterator > HostContainerAddress4IndexRange
Results range returned using the HostContainerAddress4Index.
HostContainer::index< HostHashedIndexTag >::type HostContainerHashedIndex
Hashed index type in the HostContainer.
std::pair< Resv6ContainerAddressIndex::iterator, Resv6ContainerAddressIndex::iterator > Resv6ContainerAddressIndexRange
Results range returned using the Resv6ContainerAddressIndex.
ElementPtr toElement(const ConstHostPtr &host)
Unparse a host cache entry.
Resv6Container::index< Resv6AddressIndexTag >::type Resv6ContainerAddressIndex
First index type in the Resv6Container.
HostContainer::index< HostSequencedIndexTag >::type HostContainerSequencedIndex
Sequenced index type in the HostContainer.
Resv6Container::index< Resv6SubnetAddressIndexTag >::type Resv6ContainerSubnetAddressIndex
Second index type in the Resv6Container.
Defines the logger used by the top-level component of kea-lfc.
Tag for the index for searching by reserved IPv4 address.
Tag for the hashed index.
Tag for the index for searching by identifier.
Defines one entry for the Host Container for v6 hosts.
Tag for the sequenced index.
Tag for the index for searching by address.
Tag for the index for searching by subnet and address.