static const size_t LEASE_COLUMNS = 17;
public:
+
+ /// @brief Union for marshalling IAID into and out of the database
+ /// IAID is defined in the RFC as 4 octets, which Kea code handles as
+ /// a uint32_t. Postgresql however, offers only signed integer types
+ /// of sizes 2, 4, and 8 bytes (SMALLINT, INT, and BIGINT respectively).
+ /// IAID is used in several indexes so rather than use the BIGINT, we
+ /// use this union to safely move the value into and out of an INT column.
+ union Uiaid {
+ /// @brief Constructor
+ /// @param val unsigned 32 bit value for the IAID.
+ Uiaid(uint32_t val) : uval_(val){};
+
+ /// @brief Constructor
+ /// @param val signed 32 bit value for the IAID.
+ Uiaid(int32_t val) : ival_(val){};
+
+ /// @brief Return a string representing the signed 32-bit value.
+ std::string dbInputString() {
+ return (boost::lexical_cast<std::string>(ival_));
+ };
+
+ uint32_t uval_;
+ int32_t ival_;
+ };
+
PgSqlLease6Exchange()
: lease_(), duid_length_(0), duid_(), iaid_u_(0), iaid_str_(""),
lease_type_(Lease6::TYPE_NA), lease_type_str_(""), prefix_len_(0),
// lexically cast from an integer version to avoid out of range
// exception failure upon insert.
iaid_u_.uval_ = lease_->iaid_;
- iaid_str_ = boost::lexical_cast<std::string>(iaid_u_.ival_);
+ iaid_str_ = iaid_u_.dbInputString();
bind_array.add(iaid_str_);
prefix_len_str_ = boost::lexical_cast<std::string>
size_t duid_length_;
vector<uint8_t> duid_;
uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
-
- /// @brief Union for marshalling IAID into and out of the database
- /// IAID is defined in the RFC as 4 octets, which Kea code handles as
- /// a uint32_t. Postgresql however, offers only signed integer types
- /// of sizes 2, 4, and 8 bytes (SMALLINT, INT, and BIGINT respectively).
- /// IAID is used in several indexes so rather than use the BIGINT, we
- /// use this union to safely move the value into and out of an INT column.
- union Uiaid {
- Uiaid(uint32_t val) : uval_(val){};
- Uiaid(int32_t val) : ival_(val){};
- uint32_t uval_;
- int32_t ival_;
- } iaid_u_;
-
+ union Uiaid iaid_u_;
std::string iaid_str_;
Lease6::Type lease_type_;
std::string lease_type_str_;
bind_array.add(duid.getDuid());
// IAID
- std::string iaid_str = boost::lexical_cast<std::string>(iaid);
+ std::string iaid_str = PgSqlLease6Exchange::Uiaid(iaid).dbInputString();
bind_array.add(iaid_str);
// LEASE_TYPE
bind_array.add(duid.getDuid());
// IAID
- std::string iaid_str = boost::lexical_cast<std::string>(iaid);
+ std::string iaid_str = PgSqlLease6Exchange::Uiaid(iaid).dbInputString();
bind_array.add(iaid_str);
// SUBNET ID
testLease6InvalidHostname();
}
+/// @brief Verify that large IAID values work correctly.
+///
+/// Adds lease with a large IAID to the database and verifies it can
+/// fetched correclty.
+TEST_F(CqlLeaseMgrTest, leases6LargeIaidCheck) {
+ testLease6LargeIaidCheck();
+}
+
/// @brief Check GetLease6 methods - access by DUID/IAID
///
/// Adds leases to the database and checks that they can be accessed via
}
}
+void
+GenericLeaseMgrTest::testLease6LargeIaidCheck() {
+
+ DuidPtr duid(new DUID(vector<uint8_t>(8, 0x77)));
+ IOAddress addr(std::string("2001:db8:1::111"));
+ SubnetID subnet_id = 8; // radom number
+
+ // Use a value we know is larger than 32-bit signed max.
+ uint32_t large_iaid = 0xFFFFFFFE;
+
+ // We should be able to add with no problems.
+ Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid, large_iaid,
+ 100, 200, 0, 0, subnet_id));
+ ASSERT_TRUE(lmptr_->addLease(lease));
+
+ // Sanity check that we added it.
+ Lease6Ptr found_lease = lmptr_->getLease6(Lease::TYPE_NA, addr);
+ ASSERT_TRUE(found_lease);
+ EXPECT_TRUE(*found_lease == *lease);
+
+ // Verify getLease6() duid/iaid finds it.
+ found_lease = lmptr_->getLease6(Lease::TYPE_NA, *duid, large_iaid, subnet_id);
+ ASSERT_TRUE(found_lease);
+ EXPECT_TRUE(*found_lease == *lease);
+
+ // Verify getLeases6() duid/iaid finds it.
+ Lease6Collection found_leases = lmptr_->getLeases6(Lease::TYPE_NA,
+ *duid, large_iaid);
+ // We should match the lease.
+ ASSERT_EQ(1, found_leases.size());
+ EXPECT_TRUE(*(found_leases[0]) == *lease);
+}
+
void
GenericLeaseMgrTest::testGetLease6DuidIaidSubnetId() {
// Get the leases to be used for the test and add them to the database.
/// @brief Test method which returns all IPv6 leases for Subnet ID.
void testGetLeases6SubnetId();
+ /// @brief Test making/fetching leases with IAIDs > signed 32-bit max.
+ void testLease6LargeIaidCheck();
+
/// @brief Test method which returns all IPv6 leases.
void testGetLeases6();
/// Adds leases to the database and checks that they can be accessed via
/// a combination of DIUID and IAID.
void testGetLease6DuidIaidSubnetId();
-
+
/// @brief verifies getLeases6 method by DUID
///
/// Adds 3 leases to backend and retrieves, verifes empty
testLease6InvalidHostname();
}
+/// @brief Verify that large IAID values work correctly.
+///
+/// Adds lease with a large IAID to the database and verifies it can
+/// fetched correclty.
+TEST_F(MySqlLeaseMgrTest, leases6LargeIaidCheck) {
+ testLease6LargeIaidCheck();
+}
+
/// @brief Check GetLease6 methods - access by DUID/IAID
///
/// Adds leases to the database and checks that they can be accessed via
testLease6InvalidHostname();
}
+/// @brief Verify that large IAID values work correctly.
+///
+/// Adds lease with a large IAID to the database and verifies it can
+/// fetched correclty.
+TEST_F(PgSqlLeaseMgrTest, leases6LargeIaidCheck) {
+ testLease6LargeIaidCheck();
+}
+
/// @brief Check GetLease6 methods - access by DUID/IAID
///
/// Adds leases to the database and checks that they can be accessed via