: query_(query), fake_allocation_(fake_allocation), subnet_(subnet),
duid_(duid), hwaddr_(), host_identifiers_(), host_(),
fwd_dns_update_(fwd_dns), rev_dns_update_(rev_dns),
- hostname_(hostname), callout_handle_(callout_handle), ias_() {
+ hostname_(hostname), callout_handle_(callout_handle),
+ allocated_resources_(), ias_() {
// Initialize host identifiers.
if (duid) {
}
AllocEngine::ClientContext6::IAContext::IAContext()
- : iaid_(0), type_(Lease::TYPE_NA), hints_(), allocated_resources_(),
- old_leases_(), changed_leases_(), ia_rsp_() {
+ : iaid_(0), type_(Lease::TYPE_NA), hints_(), old_leases_(),
+ changed_leases_(), ia_rsp_() {
}
void
void
AllocEngine::ClientContext6::
-IAContext::addAllocatedResource(const asiolink::IOAddress& prefix,
- const uint8_t prefix_len) {
- allocated_resources_.push_back(std::make_pair(prefix, prefix_len));
+addAllocatedResource(const asiolink::IOAddress& prefix,
+ const uint8_t prefix_len) {
+ static_cast<void>(allocated_resources_.insert(std::make_pair(prefix,
+ prefix_len)));
+}
+
+bool
+AllocEngine::ClientContext6::
+isAllocated(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const {
+ return (static_cast<bool>
+ (allocated_resources_.count(std::make_pair(prefix, prefix_len))));
}
// IA context so as they are available when we process subsequent
// IAs.
BOOST_FOREACH(Lease6Ptr lease, leases) {
- ctx.currentIA().addAllocatedResource(lease->addr_,
- lease->prefixlen_);
+ ctx.addAllocatedResource(lease->addr_, lease->prefixlen_);
}
return (leases);
}
// IA context so as they are available when we process subsequent
// IAs.
BOOST_FOREACH(Lease6Ptr lease, leases) {
- ctx.currentIA().addAllocatedResource(lease->addr_,
- lease->prefixlen_);
+ ctx.addAllocatedResource(lease->addr_, lease->prefixlen_);
}
}
/// @brief Container for client's hints.
typedef std::vector<ResourceType> HintContainer;
+ /// @brief Container holding allocated prefixes or addresses.
+ typedef std::set<ResourceType> ResourceContainer;
+
/// @brief A tuple holding host identifier type and value.
typedef std::pair<Host::IdentifierType, std::vector<uint8_t> > IdentifierPair;
/// @brief Callout handle associated with the client's message.
hooks::CalloutHandlePtr callout_handle_;
+ /// @brief Holds addresses and prefixes allocated for all IAs.
+ ResourceContainer allocated_resources_;
+
//@}
/// @brief Parameters pertaining to individual IAs.
/// allows more than one address or prefix for each IA container.
HintContainer hints_;
- /// @brief Holds addresses or prefixes allocated for this IA.
- HintContainer allocated_resources_;
-
/// @brief A pointer to any old leases that the client had before
/// update but are no longer valid after the update/allocation.
///
/// @param prefix_len Prefix length. Default is 128 for addresses.
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.
std::vector<IAContext> ias_;
+ /// @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 Checks if specified address or prefix was allocated.
+ ///
+ /// @param prefix Prefix or address.
+ /// @param prefix_len Prefix length. Default is 128 for addresses.
+ bool isAllocated(const asiolink::IOAddress& prefix,
+ const uint8_t prefix_len = 128) const;
+
/// @brief Conveniece function adding host identifier into
/// @ref host_identifiers_ list.
///
}
// Test convenience method adding allocated prefixes and addresses to
-// IA context.
+// a context.
TEST(ClientContext6Test, addAllocatedResource) {
AllocEngine::ClientContext6 ctx;
- ctx.currentIA().addAllocatedResource(IOAddress("2001:db8:1::1"));
- ctx.currentIA().addAllocatedResource(IOAddress("3000:1::"), 64);
+ ctx.addAllocatedResource(IOAddress("2001:db8:1::1"));
+ ctx.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());
+ ASSERT_EQ(2, ctx.allocated_resources_.size());
+ EXPECT_TRUE(ctx.isAllocated(IOAddress("2001:db8:1::1")));
+ EXPECT_TRUE(ctx.isAllocated(IOAddress("3000:1::"), 64));
}
// This test checks if the v6 Allocation Engine can be instantiated, parses
#include <boost/scoped_ptr.hpp>
#include <iostream>
-#include <iterator>
#include <sstream>
#include <algorithm>
#include <set>
// Do all checks on the lease
checkLease6(*it, type, expected_len, in_pool, in_pool);
- checkAllocatedResources(*it, ctx, std::distance(leases.begin(), it));
+ // Check that context has been updated with allocated addresses or
+ // prefixes.
+ checkAllocatedResources(*it, ctx);
// Check that the lease is indeed in LeaseMgr
Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(type,
// Check that context has been updated with allocated addresses or
// prefixes.
- checkAllocatedResources(*it, ctx, std::distance(leases.begin(), it));
+ checkAllocatedResources(*it, ctx);
// Check that the lease is indeed in LeaseMgr
Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(type,
/// @todo: check cltt
}
- /// @brief Checks if context has been updated with allocated addresses
- /// or prefixes.
+ /// @brief Checks if specified address or prefix has been recorded as
+ /// allocated to the client.
///
/// @param lease Allocated lease.
/// @param ctx Context structure in which this function should check if
/// leased address is stored as allocated resource.
- /// @param lease_index Index of the lease within IA.
void checkAllocatedResources(const Lease6Ptr& lease,
- AllocEngine::ClientContext6& ctx,
- const size_t lease_index) {
- ASSERT_GE(ctx.currentIA().allocated_resources_.size(), lease_index + 1);
- EXPECT_EQ(lease->addr_, ctx.currentIA().allocated_resources_[lease_index].first);
- EXPECT_EQ(static_cast<int>(lease->prefixlen_),
- static_cast<int>(ctx.currentIA().allocated_resources_[lease_index].second));
+ AllocEngine::ClientContext6& ctx) {
+ EXPECT_TRUE(ctx.isAllocated(lease->addr_, lease->prefixlen_));
}
/// @brief Checks if specified address is increased properly