Commit 01ee67bc authored by Stephen Morris's avatar Stephen Morris

[2404] Add another Lease4 constructor

This constructore is for use by the MySQL code.  By passing buffer
addresses and lengths, the need for the creation of intermediate
std::vectors is avoided.
parent d135a0e1
......@@ -101,6 +101,33 @@ public:
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct Lease4 {
/// @brief Constructor
/// @param addr IPv4 address as unsigned 32-bit integer in network byte
/// order.
/// @param hwaddr Hardware address buffer
/// @param hwaddr_len Length of hardware address buffer
/// @param clientid Client identification buffer
/// @param clientid_len Length of client identification buffer
/// @param valid_lft Lifetime of the lease
/// @param cltt Client last transmission time
/// @param subnet_id Subnet identification
Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len,
const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
time_t cltt, uint32_t subnet_id)
: addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len),
client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0),
valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id),
fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false),
/// @brief Default Constructor
/// Initialize fields that don't have a default constructor.
Lease4() : addr_(0) {}
/// IPv4 address
isc::asiolink::IOAddress addr_;
......@@ -175,12 +202,6 @@ struct Lease4 {
std::string comments_;
/// @todo: Add DHCPv4 failover related fields here
/// @brief Constructor
/// Initialize fields that don't have a default constructor.
/// @todo Remove this
Lease4() : addr_(0) {}
/// @brief Pointer to a Lease4 structure.
......@@ -202,6 +223,7 @@ struct Lease6 {
LEASE_IA_PD /// the lease contains IPv6 prefix (for prefix delegation)
} LeaseType;
/// @brief Constructor
Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
......@@ -22,6 +22,8 @@
#include <iostream>
#include <sstream>
#include <time.h>
using namespace std;
using namespace isc;
using namespace isc::asiolink;
......@@ -261,6 +263,46 @@ TEST_F(LeaseMgrTest, getParameter) {
// are purely virtual, so we would only call ConcreteLeaseMgr methods.
// Those methods are just stubs that do not return anything.
// Lease4 is also defined in lease_mgr.h, so is tested in this file as well.
// This test checks if the Lease4 structure can be instantiated correctly
TEST(Lease4, Lease4Constructor) {
// Random values for the tests
const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
ClientId clientid(clientid_vec);
// ...and a time
const time_t current_time = time(NULL);
// Other random constants
const uint32_t ADDRESS = 103478;
const uint32_t VALID_LIFETIME = 10986;
const uint32_t SUBNET_ID = 42;
// Create the lease
Lease4 lease(ADDRESS, HWADDR, sizeof(HWADDR), CLIENTID, sizeof(CLIENTID),
EXPECT_EQ(ADDRESS, static_cast<uint32_t>(lease.addr_));
EXPECT_EQ(0, lease.ext_);
EXPECT_TRUE(hwaddr == lease.hwaddr_);
EXPECT_TRUE(clientid == *lease.client_id_);
EXPECT_EQ(0, lease.t1_);
EXPECT_EQ(0, lease.t2_);
EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
EXPECT_EQ(current_time, lease.cltt_);
EXPECT_EQ(SUBNET_ID, lease.subnet_id_);
// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
// This test checks if the Lease6 structure can be instantiated correctly
TEST(Lease6, Lease6Constructor) {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment