From: Marcin Siodelski Date: Mon, 13 Mar 2023 21:13:18 +0000 (+0100) Subject: [#2764] Addressed review comments X-Git-Tag: Kea-2.3.6~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71c812e3c1b1b2096d5920fe7866bfa75763c7cb;p=thirdparty%2Fkea.git [#2764] Addressed review comments --- diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index 244fe355e2..da23ec3a04 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -2230,6 +2230,9 @@ TEST(CfgSubnets4Test, initAllocatorsAfterConfigure) { cfg.add(subnet2); cfg.add(subnet3); + EXPECT_EQ(0, allocator0->callcount_); + EXPECT_EQ(0, allocator2->callcount_); + cfg.initAllocatorsAfterConfigure(); EXPECT_EQ(1, allocator0->callcount_); diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index c6c821af60..c86e190091 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -2152,6 +2152,9 @@ TEST(CfgSubnets6Test, initAllocatorsAfterConfigure) { cfg.add(subnet2); cfg.add(subnet3); + EXPECT_EQ(0, allocator0->callcount_); + EXPECT_EQ(0, allocator2->callcount_); + cfg.initAllocatorsAfterConfigure(); EXPECT_EQ(1, allocator0->callcount_); diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 58a98d0903..c656f34a22 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -4163,12 +4163,12 @@ GenericLeaseMgrTest::testClassLeaseCount6(Lease::Type ltype) { void GenericLeaseMgrTest::testTrackAddLease4(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. It should trigger the callback. @@ -4200,14 +4200,14 @@ GenericLeaseMgrTest::testTrackAddLease4(bool expect_locked, bool expect_mt_safe) } void -GenericLeaseMgrTest::testTrackAddLease6(bool expect_locked, bool expect_mt_safe) { +GenericLeaseMgrTest::testTrackAddLeaseNA(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_NA, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. It should trigger the callback. @@ -4238,15 +4238,55 @@ GenericLeaseMgrTest::testTrackAddLease6(bool expect_locked, bool expect_mt_safe) EXPECT_FALSE(lmptr_->isLocked(lease)); } +void +GenericLeaseMgrTest::testTrackAddLeasePD(bool expect_locked, bool expect_mt_safe) { + // Register a callback for all subnets. + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_PD, + std::bind(&GenericLeaseMgrTest::logCallback, + this, + TrackingLeaseMgr::TRACK_ADD_LEASE, + SUBNET_ID_GLOBAL, + ph::_1, + ph::_2)); + // Add a lease. It should trigger the callback. + Lease6Ptr lease = initializeLease6(straddress6_[2]); + EXPECT_TRUE(lmptr_->addLease(lease)); + + // Make sure that the callback has been invoked. + ASSERT_EQ(1, logs_.size()); + + // This flag should be false for the Memfile backend and true + // for the SQL backends. + if (expect_locked) { + EXPECT_TRUE(logs_[0].locked); + } else { + EXPECT_FALSE(logs_[0].locked); + } + // This flag should be set to true for the Memfile backends. + // It should be false for other backends. If the backends do + // not provide the MT-safe context, the callbacks must protect + // against the concurrent access on their own. + if (expect_mt_safe) { + EXPECT_TRUE(logs_[0].mt_safe); + } else { + EXPECT_FALSE(logs_[0].mt_safe); + } + + // The lease locks should have been released. + EXPECT_FALSE(lmptr_->isLocked(lease)); +} + void GenericLeaseMgrTest::testTrackUpdateLease4(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. @@ -4281,14 +4321,14 @@ GenericLeaseMgrTest::testTrackUpdateLease4(bool expect_locked, bool expect_mt_sa } void -GenericLeaseMgrTest::testTrackUpdateLease6(bool expect_locked, bool expect_mt_safe) { +GenericLeaseMgrTest::testTrackUpdateLeaseNA(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, - Lease::TYPE_NA, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. @@ -4322,15 +4362,57 @@ GenericLeaseMgrTest::testTrackUpdateLease6(bool expect_locked, bool expect_mt_sa EXPECT_FALSE(lmptr_->isLocked(lease)); } +void +GenericLeaseMgrTest::testTrackUpdateLeasePD(bool expect_locked, bool expect_mt_safe) { + // Register a callback for all subnets. + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_PD, + std::bind(&GenericLeaseMgrTest::logCallback, + this, + TrackingLeaseMgr::TRACK_UPDATE_LEASE, + SUBNET_ID_GLOBAL, + ph::_1, + ph::_2)); + // Add a lease. + Lease6Ptr lease = initializeLease6(straddress6_[2]); + EXPECT_TRUE(lmptr_->addLease(lease)); + EXPECT_TRUE(logs_.empty()); + + lmptr_->updateLease6(lease); + + // Make sure that the callback has been invoked. + ASSERT_EQ(1, logs_.size()); + + // This flag should be false for the Memfile backend and true + // for the SQL backends. + if (expect_locked) { + EXPECT_TRUE(logs_[0].locked); + } else { + EXPECT_FALSE(logs_[0].locked); + } + // This flag should be set to true for the Memfile backends. + // It should be false for other backends. If the backends do + // not provide the MT-safe context, the callbacks must protect + // against the concurrent access on their own. + if (expect_mt_safe) { + EXPECT_TRUE(logs_[0].mt_safe); + } else { + EXPECT_FALSE(logs_[0].mt_safe); + } + + // The lease locks should have been released. + EXPECT_FALSE(lmptr_->isLocked(lease)); +} + void GenericLeaseMgrTest::testTrackDeleteLease4(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", 0, - Lease::TYPE_V4, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_DELETE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. @@ -4365,14 +4447,14 @@ GenericLeaseMgrTest::testTrackDeleteLease4(bool expect_locked, bool expect_mt_sa } void -GenericLeaseMgrTest::testTrackDeleteLease6(bool expect_locked, bool expect_mt_safe) { +GenericLeaseMgrTest::testTrackDeleteLeaseNA(bool expect_locked, bool expect_mt_safe) { // Register a callback for all subnets. - lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", 0, - Lease::TYPE_NA, + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&GenericLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_DELETE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)); // Add a lease. @@ -4406,6 +4488,48 @@ GenericLeaseMgrTest::testTrackDeleteLease6(bool expect_locked, bool expect_mt_sa EXPECT_FALSE(lmptr_->isLocked(lease)); } +void +GenericLeaseMgrTest::testTrackDeleteLeasePD(bool expect_locked, bool expect_mt_safe) { + // Register a callback for all subnets. + lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_PD, + std::bind(&GenericLeaseMgrTest::logCallback, + this, + TrackingLeaseMgr::TRACK_DELETE_LEASE, + SUBNET_ID_GLOBAL, + ph::_1, + ph::_2)); + // Add a lease. + Lease6Ptr lease = initializeLease6(straddress6_[2]); + EXPECT_TRUE(lmptr_->addLease(lease)); + EXPECT_TRUE(logs_.empty()); + + lmptr_->deleteLease(lease); + + // Make sure that the callback has been invoked. + ASSERT_EQ(1, logs_.size()); + + // This flag should be false for the Memfile backend and true + // for the SQL backends. + if (expect_locked) { + EXPECT_TRUE(logs_[0].locked); + } else { + EXPECT_FALSE(logs_[0].locked); + } + // This flag should be set to true for the Memfile backends. + // It should be false for other backends. If the backends do + // not provide the MT-safe context, the callbacks must protect + // against the concurrent access on their own. + if (expect_mt_safe) { + EXPECT_TRUE(logs_[0].mt_safe); + } else { + EXPECT_FALSE(logs_[0].mt_safe); + } + + // The lease locks should have been released. + EXPECT_FALSE(lmptr_->isLocked(lease)); +} + void GenericLeaseMgrTest::testRecreateWithCallbacks(const std::string& access) { // Register a callback. diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h index 68545f9af5..3f47baf2ff 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h @@ -584,13 +584,22 @@ public: void testTrackAddLease4(bool expect_locked, bool expect_mt_safe); /// @brief Checks if the backends call the callbacks when an - /// IPv6 lease is added. + /// IPv6 address lease is added. /// /// @param expect_locked a boolean flag indicating if the test should /// expect that the lease is locked before the callback. /// @param expect_mt_safe a boolean flag indicating if the test should /// expect that the callbacks are called in the MT-safe context. - void testTrackAddLease6(bool expect_locked, bool expect_mt_safe); + void testTrackAddLeaseNA(bool expect_locked, bool expect_mt_safe); + + /// @brief Checks if the backends call the callbacks when an + /// IPv6 prefix lease is added. + /// + /// @param expect_locked a boolean flag indicating if the test should + /// expect that the lease is locked before the callback. + /// @param expect_mt_safe a boolean flag indicating if the test should + /// expect that the callbacks are called in the MT-safe context. + void testTrackAddLeasePD(bool expect_locked, bool expect_mt_safe); /// @brief Checks if the backends call the callbacks when an /// IPv4 lease is updated. @@ -602,13 +611,22 @@ public: void testTrackUpdateLease4(bool expect_locked, bool expect_mt_safe); /// @brief Checks if the backends call the callbacks when an - /// IPv6 lease is updated. + /// IPv6 address lease is updated. /// /// @param expect_locked a boolean flag indicating if the test should /// expect that the lease is locked before the callback. /// @param expect_mt_safe a boolean flag indicating if the test should /// expect that the callbacks are called in the MT-safe context. - void testTrackUpdateLease6(bool expect_locked, bool expect_mt_safe); + void testTrackUpdateLeaseNA(bool expect_locked, bool expect_mt_safe); + + /// @brief Checks if the backends call the callbacks when an + /// IPv6 prefix lease is updated. + /// + /// @param expect_locked a boolean flag indicating if the test should + /// expect that the lease is locked before the callback. + /// @param expect_mt_safe a boolean flag indicating if the test should + /// expect that the callbacks are called in the MT-safe context. + void testTrackUpdateLeasePD(bool expect_locked, bool expect_mt_safe); /// @brief Checks if the backends call the callbacks when an /// IPv4 lease is deleted. @@ -620,13 +638,22 @@ public: void testTrackDeleteLease4(bool expect_locked, bool expect_mt_safe); /// @brief Checks if the backends call the callbacks when an - /// IPv6 lease is deleted. + /// IPv6 address lease is deleted. + /// + /// @param expect_locked a boolean flag indicating if the test should + /// expect that the lease is locked before the callback. + /// @param expect_mt_safe a boolean flag indicating if the test should + /// expect that the callbacks are called in the MT-safe context. + void testTrackDeleteLeaseNA(bool expect_locked, bool expect_mt_safe); + + /// @brief Checks if the backends call the callbacks when an + /// IPv6 prefix lease is deleted. /// /// @param expect_locked a boolean flag indicating if the test should /// expect that the lease is locked before the callback. /// @param expect_mt_safe a boolean flag indicating if the test should /// expect that the callbacks are called in the MT-safe context. - void testTrackDeleteLease6(bool expect_locked, bool expect_mt_safe); + void testTrackDeleteLeasePD(bool expect_locked, bool expect_mt_safe); /// @brief Checks that the lease manager can be recreated and its /// registered callbacks preserved, if desired. diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 403aacced9..443e7f4df5 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -4255,20 +4255,37 @@ TEST_F(MemfileLeaseMgrTest, trackAddLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackAddLease6) { +/// IPv6 address lease is added. +TEST_F(MemfileLeaseMgrTest, trackAddLeaseNA) { startBackend(V6); // Expect that lease is not locked and the MT-safe context. - testTrackAddLease6(false, true); + testTrackAddLeaseNA(false, true); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackAddLease6MultiThreading) { +/// IPv6 address lease is added. +TEST_F(MemfileLeaseMgrTest, trackAddLeaseNAMultiThreading) { startBackend(V6); MultiThreadingMgr::instance().setMode(true); // Expect that lease is not locked and the MT-safe context. - testTrackAddLease6(false, true); + testTrackAddLeaseNA(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(MemfileLeaseMgrTest, trackAddLeasePD) { + startBackend(V6); + // Expect that lease is not locked and the MT-safe context. + testTrackAddLeasePD(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(MemfileLeaseMgrTest, trackAddLeasePDMultiThreading) { + startBackend(V6); + MultiThreadingMgr::instance().setMode(true); + // Expect that lease is not locked and the MT-safe context. + testTrackAddLeasePD(false, true); } /// @brief Checks if the backends call the callbacks when an @@ -4289,20 +4306,37 @@ TEST_F(MemfileLeaseMgrTest, trackUpdateLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackUpdateLease6) { +/// IPv6 address lease is updated. +TEST_F(MemfileLeaseMgrTest, trackUpdateLeaseNA) { startBackend(V6); // Expect that lease is not locked and the MT-safe context. - testTrackUpdateLease6(false, true); + testTrackUpdateLeaseNA(false, true); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackUpdateLease6MultiThreading) { +/// IPv6 address lease is updated. +TEST_F(MemfileLeaseMgrTest, trackUpdateLeaseNAMultiThreading) { startBackend(V6); MultiThreadingMgr::instance().setMode(true); // Expect that lease is not locked and the MT-safe context. - testTrackUpdateLease6(false, true); + testTrackUpdateLeaseNA(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(MemfileLeaseMgrTest, trackUpdateLeasePD) { + startBackend(V6); + // Expect that lease is not locked and the MT-safe context. + testTrackUpdateLeasePD(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(MemfileLeaseMgrTest, trackUpdateLeasePDMultiThreading) { + startBackend(V6); + MultiThreadingMgr::instance().setMode(true); + // Expect that lease is not locked and the MT-safe context. + testTrackUpdateLeasePD(false, true); } /// @brief Checks if the backends call the callbacks when an @@ -4323,20 +4357,37 @@ TEST_F(MemfileLeaseMgrTest, trackDeleteLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackDeleteLease6) { +/// IPv6 address lease is deleted. +TEST_F(MemfileLeaseMgrTest, trackDeleteLeaseNA) { + startBackend(V6); + // Expect that lease is not locked and the MT-safe context. + testTrackDeleteLeaseNA(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 addres lease is deleted. +TEST_F(MemfileLeaseMgrTest, trackDeleteLeaseNAMultiThreading) { + startBackend(V6); + MultiThreadingMgr::instance().setMode(true); + // Expect that lease is not locked and the MT-safe context. + testTrackDeleteLeaseNA(false, true); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is deleted. +TEST_F(MemfileLeaseMgrTest, trackDeleteLeasePD) { startBackend(V6); // Expect that lease is not locked and the MT-safe context. - testTrackDeleteLease6(false, true); + testTrackDeleteLeasePD(false, true); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MemfileLeaseMgrTest, trackDeleteLease6MultiThreading) { +/// IPv6 prefix lease is deleted. +TEST_F(MemfileLeaseMgrTest, trackDeleteLeasePDMultiThreading) { startBackend(V6); MultiThreadingMgr::instance().setMode(true); // Expect that lease is not locked and the MT-safe context. - testTrackDeleteLease6(false, true); + testTrackDeleteLeasePD(false, true); } /// @brief Checks that the lease manager can be recreated and its diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index da14ff2baf..87b6b82500 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -1192,20 +1192,37 @@ TEST_F(MySqlLeaseMgrTest, trackAddLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MySqlLeaseMgrTest, trackAddLease6) { +/// IPv6 address lease is added. +TEST_F(MySqlLeaseMgrTest, trackAddLeaseNA) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackAddLease6(false, false); + testTrackAddLeaseNA(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(MySqlLeaseMgrTest, trackAddLease6MultiThreading) { +/// IPv6 address lease is added. +TEST_F(MySqlLeaseMgrTest, trackAddLeaseNAMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackAddLease6(true, false); + testTrackAddLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(MySqlLeaseMgrTest, trackAddLeasePD) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackAddLeasePD(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(MySqlLeaseMgrTest, trackAddLeasePDMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackAddLeasePD(true, false); } /// @brief Checks if the backends call the callbacks when an @@ -1226,20 +1243,37 @@ TEST_F(MySqlLeaseMgrTest, trackUpdateLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is updated. -TEST_F(MySqlLeaseMgrTest, trackUpdateLease6) { +/// IPv6 address lease is updated. +TEST_F(MySqlLeaseMgrTest, trackUpdateLeaseNA) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackUpdateLease6(false, false); + testTrackUpdateLeaseNA(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is updated. -TEST_F(MySqlLeaseMgrTest, trackUpdateLease6MultiThreading) { +/// IPv6 address lease is updated. +TEST_F(MySqlLeaseMgrTest, trackUpdateLeaseNAMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackUpdateLease6(true, false); + testTrackUpdateLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(MySqlLeaseMgrTest, trackUpdateLeasePD) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackUpdateLeasePD(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(MySqlLeaseMgrTest, trackUpdateLeasePDMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackUpdateLeasePD(true, false); } /// @brief Checks if the backends call the callbacks when an @@ -1260,20 +1294,37 @@ TEST_F(MySqlLeaseMgrTest, trackDeleteLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is deleted. -TEST_F(MySqlLeaseMgrTest, trackDeleteLease6) { +/// IPv6 address lease is deleted. +TEST_F(MySqlLeaseMgrTest, trackDeleteLeaseNA) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackDeleteLeaseNA(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 address lease is deleted. +TEST_F(MySqlLeaseMgrTest, trackDeleteLeaseNAMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackDeleteLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is deleted. +TEST_F(MySqlLeaseMgrTest, trackDeleteLeasePD) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackDeleteLease6(false, false); + testTrackDeleteLeasePD(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is deleted. -TEST_F(MySqlLeaseMgrTest, trackDeleteLease6MultiThreading) { +/// IPv6 prefix lease is deleted. +TEST_F(MySqlLeaseMgrTest, trackDeleteLeasePDMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackDeleteLease6(true, false); + testTrackDeleteLeasePD(true, false); } /// @brief Checks that the lease manager can be recreated and its diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index b18cb91715..c5f8464372 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -1181,20 +1181,37 @@ TEST_F(PgSqlLeaseMgrTest, trackAddLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(PgSqlLeaseMgrTest, trackAddLease6) { +/// IPv6 address lease is added. +TEST_F(PgSqlLeaseMgrTest, trackAddLeaseNA) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackAddLease6(false, false); + testTrackAddLeaseNA(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is added. -TEST_F(PgSqlLeaseMgrTest, trackAddLease6MultiThreading) { +/// IPv6 address lease is added. +TEST_F(PgSqlLeaseMgrTest, trackAddLeaseNAMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackAddLease6(true, false); + testTrackAddLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(PgSqlLeaseMgrTest, trackAddLeasePD) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackAddLeasePD(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is added. +TEST_F(PgSqlLeaseMgrTest, trackAddLeasePDMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackAddLeasePD(true, false); } /// @brief Checks if the backends call the callbacks when an @@ -1215,20 +1232,37 @@ TEST_F(PgSqlLeaseMgrTest, trackUpdateLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is updated. -TEST_F(PgSqlLeaseMgrTest, trackUpdateLease6) { +/// IPv6 address lease is updated. +TEST_F(PgSqlLeaseMgrTest, trackUpdateLeaseNA) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackUpdateLease6(false, false); + testTrackUpdateLeaseNA(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is updated. -TEST_F(PgSqlLeaseMgrTest, trackUpdateLease6MultiThreading) { +/// IPv6 address lease is updated. +TEST_F(PgSqlLeaseMgrTest, trackUpdateLeaseNAMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackUpdateLease6(true, false); + testTrackUpdateLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(PgSqlLeaseMgrTest, trackUpdateLeasePD) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackUpdateLeasePD(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is updated. +TEST_F(PgSqlLeaseMgrTest, trackUpdateLeasePDMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackUpdateLeasePD(true, false); } /// @brief Checks if the backends call the callbacks when an @@ -1249,20 +1283,37 @@ TEST_F(PgSqlLeaseMgrTest, trackDeleteLease4MultiThreading) { } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is deleted. -TEST_F(PgSqlLeaseMgrTest, trackDeleteLease6) { +/// IPv6 address lease is deleted. +TEST_F(PgSqlLeaseMgrTest, trackDeleteLeaseNA) { + // It is unnecessary to lock the lease in ST. The backend does not + // provide the MT-safe context for the callbacks. + testTrackDeleteLeaseNA(false, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 address lease is deleted. +TEST_F(PgSqlLeaseMgrTest, trackDeleteLeaseNAMultiThreading) { + MultiThreadingMgr::instance().setMode(true); + // The lease should be locked in the MT mode. The backend does not + // provide an MT-safe context. + testTrackDeleteLeaseNA(true, false); +} + +/// @brief Checks if the backends call the callbacks when an +/// IPv6 prefix lease is deleted. +TEST_F(PgSqlLeaseMgrTest, trackDeleteLeasePD) { // It is unnecessary to lock the lease in ST. The backend does not // provide the MT-safe context for the callbacks. - testTrackDeleteLease6(false, false); + testTrackDeleteLeasePD(false, false); } /// @brief Checks if the backends call the callbacks when an -/// IPv6 lease is deleted. -TEST_F(PgSqlLeaseMgrTest, trackDeleteLease6MultiThreading) { +/// IPv6 prefix lease is deleted. +TEST_F(PgSqlLeaseMgrTest, trackDeleteLeasePDMultiThreading) { MultiThreadingMgr::instance().setMode(true); // The lease should be locked in the MT mode. The backend does not // provide an MT-safe context. - testTrackDeleteLease6(true, false); + testTrackDeleteLeasePD(true, false); } /// @brief Checks that the lease manager can be recreated and its diff --git a/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc index 7c42606e5e..c12140a460 100644 --- a/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc @@ -99,13 +99,13 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacks) { DatabaseConnection::ParameterMap pmap; ConcreteLeaseMgr mgr(pmap); - // Callback for lease add and subnet id 0. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + // Callback for lease add and global subnet id. + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); // Callback for lease add and subnet id 1. EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 1, @@ -123,34 +123,34 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacks) { TrackingLeaseMgr::TRACK_ADD_LEASE, 1, ph::_1, ph::_2))); - // Callback for lease update and subnet id 0. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, - Lease::TYPE_V4, + // Callback for lease update and global subnet id. + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - // Callback for lease delete and subnet id 0. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", 0, - Lease::TYPE_V4, + // Callback for lease delete and global subnet id. + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_DELETE_LEASE, - 1, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); // This call should trigger the lease add callbacks for subnet id 0 and 1. EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_EQ(2, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_V4)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_V4)); EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 1, Lease::TYPE_V4)); // This call should trigger the lease add callback for subnet id 0 only. That's // because we have no callback for the subnet id 3. EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(3, "192.0.2.1"), false)); EXPECT_EQ(3, logs_.size()); - EXPECT_EQ(2, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_V4)); + EXPECT_EQ(2, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_V4)); } /// Test that registering the callbacks of the same type, for the same subnet id by the @@ -160,31 +160,32 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) { ConcreteLeaseMgr mgr(pmap); // Add the callback for lease add and subnet id 0. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_NA, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); // Another attempt should fail. - EXPECT_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_NA, + EXPECT_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2)), InvalidOperation); // It should succeed for a different owner. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "qlf", 0, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "qlf", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); // It should also succeed for a different subnet id. @@ -221,41 +222,41 @@ TEST_F(TrackingLeaseMgrTest, trackAddLeaseDifferentLeaseTypes) { DatabaseConnection::ParameterMap pmap; ConcreteLeaseMgr mgr(pmap); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_NA, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_NA, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_PD, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_PD, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_EQ(1, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_V4)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_V4)); EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(1, Lease::TYPE_NA, "2001:db8:1::1"), false)); EXPECT_EQ(2, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_NA)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_NA)); EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(1, Lease::TYPE_PD, "3000::"), false)); EXPECT_EQ(3, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_PD)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_PD)); } /// Test invoking the registered lease update callbacks. @@ -263,26 +264,27 @@ TEST_F(TrackingLeaseMgrTest, trackUpdateLease) { DatabaseConnection::ParameterMap pmap; ConcreteLeaseMgr mgr(pmap); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_DELETE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); EXPECT_NO_THROW(mgr.trackUpdateLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_EQ(1, logs_.size()); @@ -294,30 +296,30 @@ TEST_F(TrackingLeaseMgrTest, trackDeleteLease) { DatabaseConnection::ParameterMap pmap; ConcreteLeaseMgr mgr(pmap); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_DELETE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); EXPECT_NO_THROW(mgr.trackDeleteLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_EQ(1, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, Lease::TYPE_V4)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_DELETE_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_V4)); } // Test unregistering the callbacks by subnet id. @@ -326,12 +328,12 @@ TEST_F(TrackingLeaseMgrTest, unregisterCallbacksBySubnetID) { ConcreteLeaseMgr mgr(pmap); // Register different callback types for different subnet identifiers. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 1, Lease::TYPE_V4, @@ -384,20 +386,20 @@ TEST_F(TrackingLeaseMgrTest, unregisterCallbacksBySubnetID) { EXPECT_NO_THROW(mgr.trackUpdateLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_NO_THROW(mgr.trackDeleteLease(initializeLease(1, "192.0.2.1"), false)); - // It should only run the callback for the subnet id 0 that is still + // It should only run the callback for the global subnet id that is still // registered. EXPECT_EQ(1, logs_.size()); - EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, Lease::TYPE_V4)); + EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_ADD_LEASE, SUBNET_ID_GLOBAL, Lease::TYPE_V4)); // Unregister this callback. - EXPECT_NO_THROW(mgr.unregisterCallbacks(SubnetID(0), Lease::TYPE_V4)); + EXPECT_NO_THROW(mgr.unregisterCallbacks(SUBNET_ID_GLOBAL, Lease::TYPE_V4)); // Make sure it is no longer invoked. EXPECT_NO_THROW(mgr.trackAddLease(initializeLease(1, "192.0.2.1"), false)); EXPECT_EQ(1, logs_.size()); // Unregistering it again should be no-op. - EXPECT_NO_THROW(mgr.unregisterCallbacks(SubnetID(0), Lease::TYPE_V4)); + EXPECT_NO_THROW(mgr.unregisterCallbacks(SUBNET_ID_GLOBAL, Lease::TYPE_V4)); } /// Test unregistering all callbacks. @@ -406,19 +408,19 @@ TEST_F(TrackingLeaseMgrTest, unregisterAllCallbacks) { ConcreteLeaseMgr mgr(pmap); // Register some callbacks. - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_UPDATE_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); // Make sure they have been registered. EXPECT_TRUE(mgr.hasCallbacks()); @@ -434,12 +436,12 @@ TEST_F(TrackingLeaseMgrTest, hasCallbacks) { ConcreteLeaseMgr mgr(pmap); EXPECT_FALSE(mgr.hasCallbacks()); - EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", 0, - Lease::TYPE_V4, + EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, "flq", + SUBNET_ID_GLOBAL, Lease::TYPE_V4, std::bind(&TrackingLeaseMgrTest::logCallback, this, TrackingLeaseMgr::TRACK_ADD_LEASE, - 0, + SUBNET_ID_GLOBAL, ph::_1, ph::_2))); EXPECT_TRUE(mgr.hasCallbacks()); } diff --git a/src/lib/dhcpsrv/tracking_lease_mgr.cc b/src/lib/dhcpsrv/tracking_lease_mgr.cc index c723d48ddb..a245c138f3 100644 --- a/src/lib/dhcpsrv/tracking_lease_mgr.cc +++ b/src/lib/dhcpsrv/tracking_lease_mgr.cc @@ -85,7 +85,7 @@ TrackingLeaseMgr::registerCallback(TrackingLeaseMgr::CallbackType type, std::string owner, Lease::Type lease_type, TrackingLeaseMgr::CallbackFn callback_fn) { - registerCallback(type, owner, 0, lease_type, callback_fn); + registerCallback(type, owner, SUBNET_ID_GLOBAL, lease_type, callback_fn); } void @@ -126,7 +126,7 @@ TrackingLeaseMgr::callbackTypeToString(CallbackType type) { void TrackingLeaseMgr::runCallbacks(TrackingLeaseMgr::CallbackType type, const LeasePtr& lease, bool mt_safe) { - runCallbacksForSubnetID(type, 0, lease, mt_safe); + runCallbacksForSubnetID(type, SUBNET_ID_GLOBAL, lease, mt_safe); runCallbacksForSubnetID(type, lease->subnet_id_, lease, mt_safe); } diff --git a/src/lib/dhcpsrv/tracking_lease_mgr.h b/src/lib/dhcpsrv/tracking_lease_mgr.h index 88b2740d03..b6f673ccac 100644 --- a/src/lib/dhcpsrv/tracking_lease_mgr.h +++ b/src/lib/dhcpsrv/tracking_lease_mgr.h @@ -232,7 +232,7 @@ public: /// @param type callback type. /// @param owner callback owner identifier. /// @param subnet_id subnet identifier; it can be set to 0 if the callback should be - /// called for subnets. + /// called for all subnets. /// @param lease_type a lease type. /// @param callback_fn callback function instance. /// @throw InvalidOperation when the callback has been already registered for the given owner and