b10_dhcp6_SOURCES = main.cc
b10_dhcp6_SOURCES += ctrl_dhcp6_srv.cc ctrl_dhcp6_srv.h
b10_dhcp6_SOURCES += config_parser.cc config_parser.h
-b10_dhcp6_SOURCES += alloc_engine.cc alloc_engine.h
b10_dhcp6_SOURCES += dhcp6_log.cc dhcp6_log.h
b10_dhcp6_SOURCES += dhcp6_srv.cc dhcp6_srv.h
lib_LTLIBRARIES = libb10-dhcp++.la libb10-dhcpsrv.la
libb10_dhcp___la_SOURCES =
libb10_dhcp___la_SOURCES += libdhcp++.cc libdhcp++.h
-libb10_dhcp___la_SOURCES += lease_mgr.cc lease_mgr.h
libb10_dhcp___la_SOURCES += iface_mgr.cc iface_mgr.h
libb10_dhcp___la_SOURCES += iface_mgr_linux.cc
libb10_dhcp___la_SOURCES += iface_mgr_bsd.cc
libb10_dhcpsrv_la_SOURCES += pool.cc pool.h
libb10_dhcpsrv_la_SOURCES += subnet.cc subnet.h
libb10_dhcpsrv_la_SOURCES += triplet.h
+libb10_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h
libb10_dhcpsrv_la_SOURCES += addr_utilities.cc addr_utilities.h
+libb10_dhcpsrv_la_SOURCES += alloc_engine.cc alloc_engine.h
libb10_dhcpsrv_la_CXXFLAGS = $(AM_CXXFLAGS)
libb10_dhcpsrv_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
libb10_dhcpsrv_la_LIBADD = $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& addr) {
uint8_t packed[V6ADDRESS_LEN];
int len;
+
+ // First we copy the whole address as 16 bytes.
if (addr.getFamily()==AF_INET) {
// IPv4
memcpy(packed, addr.getAddress().to_v4().to_bytes().data(), 4);
len = 16;
}
- // First we copy the whole address as 16 bytes.
- bool carry = false;
for (int i = len; i >=0; --i) {
packed[i]++;
if (packed[i] != 0) {
isc::asiolink::IOAddress
AllocEngine::IterativeAllocator::pickAddress(const Subnet6Ptr& subnet,
- const DuidPtr& duid,
- const IOAddress& hint) {
+ const DuidPtr&,
+ const IOAddress&) {
// Let's get the last allocated address. It is usually be set correctly,
// but there are times when it won't be (like after removing a pool or
AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
const DuidPtr& duid,
uint32_t iaid,
- const IOAddress& hint) {
+ const IOAddress& hint,
+ bool fake /* = false */ ) {
// That check is not necessary. We create allocator in AllocEngine
// constructor
if (!allocator_) {
return (existing);
}
+ // check if the hint is available
+ existing = LeaseMgr::instance().getLease6(hint);
+ if (!existing) {
+ // the hint is good, let's create a lease for it
+ }
+
unsigned int i = attempts_;
do {
IOAddress candidate = allocator_->pickAddress(subnet, duid, hint);
// there's no existing lease for selected candidate, so it is
// free. Let's allocate it.
if (!existing) {
- Lease6Ptr lease = createLease(subnet, duid, iaid, candidate);
+ Lease6Ptr lease = createLease(subnet, duid, iaid, candidate, fake);
if (lease) {
return (lease);
}
Lease6Ptr AllocEngine::createLease(const Subnet6Ptr& subnet,
const DuidPtr& duid,
uint32_t iaid,
- const IOAddress& addr) {
+ const IOAddress& addr,
+ bool fake /*= false */ ) {
Lease6Ptr lease(new Lease6(Lease6::LEASE_IA_NA, addr, duid, iaid,
subnet->getPreferred(), subnet->getValid(),
subnet->getT1(), subnet->getT2(), subnet->getID()));
- bool status = LeaseMgr::instance().addLease(lease);
+ if (!fake) {
+ // That is a real (REQUEST) allocation
+ bool status = LeaseMgr::instance().addLease(lease);
- if (status) {
- return (lease);
+ if (status) {
+
+ return (lease);
+ } else {
+ // One of many failures with LeaseMgr (e.g. lost connection to the
+ // database, database failed etc.). One notable case for that
+ // is that we are working in multi-process mode and we lost a race
+ // (some other process got that address first)
+ return (Lease6Ptr());
+ }
} else {
- // One of many failures with LeaseMgr (e.g. lost connection to the
- // database, database failed etc.). One notable case for that
- // is that we are working in multi-process mode and we lost a race
- // (some other process got that address first)
- return (Lease6Ptr());
+ // That is only fake (SOLICIT without rapid-commit) allocation
+
+ // It is for advertise only. We should not insert the lease into LeaseMgr,
+ // but rather check that we could have inserted it.
+ Lease6Ptr existing = LeaseMgr::instance().getLease6(addr);
+ if (!existing) {
+ return (lease);
+ } else {
+ return (Lease6Ptr());
+ }
}
}
allocateAddress6(const Subnet6Ptr& subnet,
const DuidPtr& duid,
uint32_t iaid,
- const isc::asiolink::IOAddress& hint);
+ const isc::asiolink::IOAddress& hint,
+ bool fake);
/// @brief Destructor. Used during DHCPv6 service shutdown.
virtual ~AllocEngine();
Lease6Ptr createLease(const Subnet6Ptr& subnet,
const DuidPtr& duid,
uint32_t iaid,
- const isc::asiolink::IOAddress& addr);
+ const isc::asiolink::IOAddress& addr,
+ bool fake = false);
Allocator* allocator_;
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#ifndef LEASE_MGR_H
+#define LEASE_MGR_H
+
#include <string>
#include <fstream>
#include <vector>
}; // end of isc::dhcp namespace
}; // end of isc namespace
+
+#endif // LEASE_MGR_H
libdhcpsrv_unittests_SOURCES += cfgmgr_unittest.cc triplet_unittest.cc
libdhcpsrv_unittests_SOURCES += pool_unittest.cc subnet_unittest.cc
libdhcpsrv_unittests_SOURCES += addr_utilities_unittest.cc
+libdhcpsrv_unittests_SOURCES += alloc_engine_unittest.cc
+
libdhcpsrv_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
libdhcpsrv_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
--- /dev/null
+// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <config.h>
+#include <iostream>
+#include <sstream>
+#include <gtest/gtest.h>
+#include <asiolink/io_address.h>
+#include <dhcp/lease_mgr.h>
+#include <dhcp/duid.h>
+#include <dhcp/alloc_engine.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::asiolink;
+using namespace isc::dhcp;
+
+
+namespace {
+// empty class for now, but may be extended once Addr6 becomes bigger
+class AllocEngineTest : public ::testing::Test {
+public:
+ AllocEngineTest() {
+ }
+};
+
+// This test checks if the Allocation Engine can be instantiated and that it
+// parses parameters string properly.
+TEST_F(AllocEngineTest, constructor) {
+
+ AllocEngine* x = NULL;
+
+ // Hashed and random allocators are not supported yet
+ ASSERT_THROW(x = new AllocEngine(AllocEngine::ALLOC_HASHED, 5), BadValue);
+ ASSERT_THROW(x = new AllocEngine(AllocEngine::ALLOC_RANDOM, 5), BadValue);
+
+ ASSERT_NO_THROW(x = new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
+
+ delete x;
+}
+
+}; // end of anonymous namespace