// We have a lease! Let's wrap its content into IA_PD option
// with IAADDR suboption.
- LOG_INFO(lease6_logger, ctx.fake_allocation ?
+ LOG_INFO(lease6_logger, ctx.fake_allocation_ ?
DHCP6_PD_LEASE_ADVERT : DHCP6_PD_LEASE_ALLOC)
.arg(query->getLabel())
.arg((*l)->addr_.toText())
// cause of that failure. The only thing left is to insert
// status code to pass the sad news to the client.
- LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, ctx.fake_allocation ?
+ LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, ctx.fake_allocation_ ?
DHCP6_PD_LEASE_ADVERT_FAIL : DHCP6_PD_LEASE_ALLOC_FAIL)
.arg(query->getLabel())
.arg(ia->getIAID());
// those prefixes and remove those that we have already processed. We
// don't want to remove them from the context, so we need to copy them
// into temporary container.
- AllocEngine::HintContainer hints = ctx.currentIA().hints_;
+ AllocEngine::ResourceContainer hints = ctx.currentIA().hints_;
// For all leases we have now, add the IAADDR with non-zero lifetimes.
for (Lease6Collection::const_iterator l = leases.begin(); l != leases.end(); ++l) {
.arg(ia_rsp->getIAID());
// Now remove this address from the hints list.
- AllocEngine::HintType hint_type((*l)->addr_, 128);
+ AllocEngine::ResourceType hint_type((*l)->addr_, 128);
hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
hints.end());
}
ia_rsp->addOption(iaaddr);
// Now remove this address from the hints list.
- AllocEngine::HintType hint_type((*l)->addr_, 128);
+ AllocEngine::ResourceType hint_type((*l)->addr_, 128);
hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
// If the new FQDN settings have changed for the lease, we need to
// Finally, if there are any addresses requested that we haven't dealt with
// already, inform the client that he can't have them.
- for (AllocEngine::HintContainer::const_iterator hint = hints.begin();
+ for (AllocEngine::ResourceContainer::const_iterator hint = hints.begin();
hint != hints.end(); ++hint) {
Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR,
hint->first, 0, 0));
// those prefixes and remove those that we have already processed. We
// don't want to remove them from the context, so we need to copy them
// into temporary container.
- AllocEngine::HintContainer hints = ctx.currentIA().hints_;
+ AllocEngine::ResourceContainer hints = ctx.currentIA().hints_;
// For all the leases we have now, add the IAPPREFIX with non-zero lifetimes
for (Lease6Collection::const_iterator l = leases.begin(); l != leases.end(); ++l) {
.arg(ia->getIAID());
// Now remove this address from the hints list.
- AllocEngine::HintType hint_type((*l)->addr_, (*l)->prefixlen_);
+ AllocEngine::ResourceType hint_type((*l)->addr_, (*l)->prefixlen_);
hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
hints.end());
}
// zero lifetimes
// Finally, if there are any addresses requested that we haven't dealt with
// already, inform the client that he can't have them.
- for (AllocEngine::HintContainer::const_iterator prefix = hints.begin();
+ for (AllocEngine::ResourceContainer::const_iterator prefix = hints.begin();
prefix != hints.end(); ++prefix) {
// Send the prefix with the zero lifetimes only if the prefix
// contains non-zero value. A zero value indicates that the hint was
}
AllocEngine::ClientContext6::IAContext::IAContext()
- : iaid_(0), type_(Lease::TYPE_NA), hints_(), old_leases_(),
- changed_leases_(), ia_rsp_() {
+ : iaid_(0), type_(Lease::TYPE_NA), hints_(), allocated_resources_(),
+ old_leases_(), changed_leases_(), ia_rsp_() {
}
void
hints_.push_back(std::make_pair(prefix, prefix_len));
}
+void
+AllocEngine::ClientContext6::
+IAContext::addAllocatedResource(const asiolink::IOAddress& prefix,
+ const uint8_t prefix_len) {
+ allocated_resources_.push_back(std::make_pair(prefix, prefix_len));
+}
+
+
void AllocEngine::findReservation(ClientContext6& ctx) {
findReservationInternal(ctx, boost::bind(&HostMgr::get6,
&HostMgr::instance(),
/// This is an entry that represents what the client had requested,
/// either an address or a prefix. Prefix length is 128 for regular
/// addresses.
- typedef std::pair<isc::asiolink::IOAddress, uint8_t> HintType;
+ typedef std::pair<isc::asiolink::IOAddress, uint8_t> ResourceType;
/// @brief Container for client's hints.
- typedef std::vector<HintType> HintContainer;
+ typedef std::vector<ResourceType> ResourceContainer;
/// @brief A tuple holding host identifier type and value.
typedef std::pair<Host::IdentifierType, std::vector<uint8_t> > IdentifierPair;
///
/// There will typically be just one address, but the protocol
/// allows more than one address or prefix for each IA container.
- HintContainer hints_;
+ ResourceContainer hints_;
+
+ /// @brief Holds addresses or prefixes allocated for this IA.
+ ResourceContainer allocated_resources_;
/// @brief A pointer to any old leases that the client had before
/// update but are no longer valid after the update/allocation.
void addHint(const asiolink::IOAddress& prefix,
const uint8_t prefix_len = 128);
+ /// @brief Convenience method adding allocated prefix or address.
+ ///
+ /// @param prefix Prefix or address.
+ /// @param prefix_len Prefix length. Default is 128 for addresses.
+ void addAllocatedResource(const asiolink::IOAddress& prefix,
+ const uint8_t prefix_len = 128);
+
};
/// @brief Container holding IA specific contexts.
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
namespace dhcp {
namespace test {
+// Test convenience method adding hints to IA context.
+TEST(ClientContext6Test, addHint) {
+ AllocEngine::ClientContext6 ctx;
+ ctx.currentIA().addHint(IOAddress("2001:db8:1::1"));
+ ctx.currentIA().addHint(IOAddress("3000:1::"), 64);
+
+ ASSERT_EQ(2, ctx.currentIA().hints_.size());
+ EXPECT_EQ("2001:db8:1::1", ctx.currentIA().hints_[0].first.toText());
+ EXPECT_EQ("3000:1::", ctx.currentIA().hints_[1].first.toText());
+}
+
+// Test convenience method adding allocated prefixes and addresses to
+// IA context.
+TEST(ClientContext6Test, addAllocatedResource) {
+ AllocEngine::ClientContext6 ctx;
+ ctx.currentIA().addAllocatedResource(IOAddress("2001:db8:1::1"));
+ ctx.currentIA().addAllocatedResource(IOAddress("3000:1::"), 64);
+
+ ASSERT_EQ(2, ctx.currentIA().allocated_resources_.size());
+ EXPECT_EQ("2001:db8:1::1", ctx.currentIA().allocated_resources_[0].first.toText());
+ EXPECT_EQ("3000:1::", ctx.currentIA().allocated_resources_[1].first.toText());
+}
+
// This test checks if the v6 Allocation Engine can be instantiated, parses
// parameters string and allocators are created.
TEST_F(AllocEngine6Test, constructor) {
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(IOAddress("2001:db8:1::15"), 128));
// Client should receive a lease.
AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(IOAddress("2001:db8:1::15"), 128));
// Client should receive a lease.
ASSERT_EQ(1, leases.size());
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
Lease6Collection renewed = renewTest(engine, pool_, hints, true);
ASSERT_EQ("2001:db8:1::1c", leases[0]->addr_.toText());
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
Lease6Collection renewed = renewTest(engine, pool_, hints, true);
ASSERT_NE("2001:db8:1::1c", leases[0]->addr_.toText());
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
// Create reservation for the client. This is in-pool reservation,
ASSERT_EQ(1, leases.size());
// This is what the client will send in his renew message.
- AllocEngine::HintContainer hints;
+ AllocEngine::ResourceContainer hints;
hints.push_back(make_pair(leases[0]->addr_, 128));
// Create reservation for this address, but for another client.
Lease6Collection
AllocEngine6Test::renewTest(AllocEngine& engine, const Pool6Ptr& pool,
- AllocEngine::HintContainer& hints,
+ AllocEngine::ResourceContainer& hints,
bool in_pool) {
Lease::Type type = pool->getType();
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// @param in_pool specifies whether the lease is expected to be in pool
/// @return allocated lease(s) (may be empty)
Lease6Collection renewTest(AllocEngine& engine, const Pool6Ptr& pool,
- AllocEngine::HintContainer& hints,
+ AllocEngine::ResourceContainer& hints,
bool in_pool = true);
/// @brief Checks if the address allocation with a hint that is in range,