Commit 8f21305b authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[4277] IPv6 Reservations now functional

src/lib/dhcpsrv/pgsql_exchange.h
src/lib/dhcpsrv/pgsql_exchange.cc
src/lib/dhcpsrv/pgsql_lease_mgr.cc
    Moved getIPv6Value() from PgSqlLease6Exchange to
    PgSqlExchange and made it static

    PgSqlExchange::dumpRow() gets number of columns
    from result set, not parameter

src/lib/dhcpsrv/pgsql_host_data_source.cc
     PgSqlIPv6ReservationExchange
     PgSqlHostIPv6Exchange - now functional

src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
    TEST_F(PgSqlHostDataSourceTest, get6AddrWithDuid)
    TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithHWAddr)
    TEST_F(PgSqlHostDataSourceTest, optionsReservations6)
    TEST_F(PgSqlHostDataSourceTest, optionsReservations46)
    TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations6)
    TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations46)
    - All included and passing.
parent 3c01633e
......@@ -196,6 +196,19 @@ PgSqlExchange::getColumnValue(const PgSqlResult& r, const int row,
}
}
isc::asiolink::IOAddress
PgSqlExchange::getIPv6Value(const PgSqlResult& r, const int row,
const size_t col) {
const char* data = getRawColumnValue(r, row, col);
try {
return (isc::asiolink::IOAddress(data));
} catch (const std::exception& ex) {
isc_throw(DbOperationError, "Cannot convert data: " << data
<< " for: " << getColumnLabel(r, col) << " row:" << row
<< " : " << ex.what());
}
}
void
PgSqlExchange::convertFromBytea(const PgSqlResult& r, const int row,
const size_t col, uint8_t* buffer,
......@@ -254,8 +267,9 @@ PgSqlExchange::getColumnLabel(const PgSqlResult& r, const size_t column) {
}
std::string
PgSqlExchange::dumpRow(const PgSqlResult& r, int row, size_t columns) {
PgSqlExchange::dumpRow(const PgSqlResult& r, int row) {
std::ostringstream stream;
int columns = PQnfields(r);
for (int col = 0; col < columns; ++col) {
const char* val = getRawColumnValue(r, row, col);
std::string name = getColumnLabel(r, col);
......
......@@ -287,6 +287,10 @@ public:
static void getColumnValue(const PgSqlResult& r, const int row,
const size_t col, uint8_t &value);
static isc::asiolink::IOAddress getIPv6Value(const PgSqlResult& r,
const int row,
const size_t col);
static bool isColumnNull(const PgSqlResult& r, const int row,
const size_t col);
......@@ -337,7 +341,7 @@ public:
size_t &bytes_converted);
static std::string dumpRow(const PgSqlResult& r, int row, size_t columns);
static std::string dumpRow(const PgSqlResult& r, int row);
protected:
/// @brief Stores text labels for columns, currently only used for
......
This diff is collapsed.
......@@ -636,27 +636,6 @@ public:
}
}
/// @brief Converts a column in a row in a result set into IPv6 address.
///
/// @param r the result set containing the query results
/// @param row the row number within the result set
/// @param col the column number within the row
///
/// @return isc::asiolink::IOAddress containing the IPv6 address.
/// @throw DbOperationError if the value cannot be fetched or is
/// invalid.
isc::asiolink::IOAddress getIPv6Value(const PgSqlResult& r, const int row,
const size_t col) const {
const char* data = getRawColumnValue(r, row, col);
try {
return (isc::asiolink::IOAddress(data));
} catch (const std::exception& ex) {
isc_throw(DbOperationError, "Cannot convert data: " << data
<< " for: " << getColumnLabel(r, col) << " row:" << row
<< " : " << ex.what());
}
}
private:
/// @brief Lease6 object currently being sent to the database.
/// Storing this value ensures that it remains in scope while any bindings
......
......@@ -257,7 +257,6 @@ TEST_F(PgSqlHostDataSourceTest, DISABLED_hwaddrOrClientId2) {
/// reservation is returned.
}
#if 0
// Test verifies that host with IPv6 address and DUID can be added and
// later retrieved by IPv6 address.
TEST_F(PgSqlHostDataSourceTest, get6AddrWithDuid) {
......@@ -380,7 +379,6 @@ TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithDUID) {
TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithHWAddr) {
testAddDuplicate6WithSameHWAddr();
}
#endif
// Test if the duplicate IPv4 host instances can't be inserted. The test logic is as
// follows: try to add multiple instances of the same host reservation and
......@@ -394,7 +392,6 @@ TEST_F(PgSqlHostDataSourceTest, addDuplicate4) {
TEST_F(PgSqlHostDataSourceTest, optionsReservations4) {
testOptionsReservations4(false);
}
#if 0
// This test verifies that DHCPv6 options can be inserted in a binary format
/// and retrieved from the PostgreSQL host database.
......@@ -407,7 +404,6 @@ TEST_F(PgSqlHostDataSourceTest, optionsReservations6) {
TEST_F(PgSqlHostDataSourceTest, optionsReservations46) {
testOptionsReservations46(false);
}
#endif
// This test verifies that DHCPv4 options can be inserted in a textual format
/// and retrieved from the PostgreSQL host database.
......@@ -415,7 +411,6 @@ TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations4) {
testOptionsReservations4(true);
}
#if 0
// This test verifies that DHCPv6 options can be inserted in a textual format
/// and retrieved from the PostgreSQL host database.
TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations6) {
......@@ -428,6 +423,7 @@ TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations46) {
testOptionsReservations46(true);
}
#if 0
// This test checks transactional insertion of the host information
// into the database. The failure to insert host information at
// any stage should cause the whole transaction to be rolled back.
......
Supports Markdown
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