memfile_lease_mgr_unittest.cc 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  1. // Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <asiolink/asio_wrapper.h>
  8. #include <asiolink/io_address.h>
  9. #include <dhcp/duid.h>
  10. #include <dhcp/iface_mgr.h>
  11. #include <dhcpsrv/cfgmgr.h>
  12. #include <dhcpsrv/lease_mgr.h>
  13. #include <dhcpsrv/lease_mgr_factory.h>
  14. #include <dhcpsrv/memfile_lease_mgr.h>
  15. #include <dhcpsrv/timer_mgr.h>
  16. #include <dhcpsrv/tests/lease_file_io.h>
  17. #include <dhcpsrv/tests/test_utils.h>
  18. #include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
  19. #include <util/pid_file.h>
  20. #include <util/range_utilities.h>
  21. #include <util/stopwatch.h>
  22. #include <boost/bind.hpp>
  23. #include <gtest/gtest.h>
  24. #include <cstdlib>
  25. #include <iostream>
  26. #include <fstream>
  27. #include <queue>
  28. #include <sstream>
  29. #include <unistd.h>
  30. using namespace std;
  31. using namespace isc;
  32. using namespace isc::asiolink;
  33. using namespace isc::dhcp;
  34. using namespace isc::dhcp::test;
  35. using namespace isc::util;
  36. namespace {
  37. /// @brief Class derived from @c Memfile_LeaseMgr to test LFC timer.
  38. ///
  39. /// This class provides a custom callback function which is invoked
  40. /// when the timer for Lease File Cleanup goes off. It is used to
  41. /// test that the timer is correctly installed.
  42. class LFCMemfileLeaseMgr : public Memfile_LeaseMgr {
  43. public:
  44. /// @brief Constructor.
  45. ///
  46. /// Sets the counter for callbacks to 0.
  47. LFCMemfileLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
  48. : Memfile_LeaseMgr(parameters), lfc_cnt_(0) {
  49. }
  50. /// @brief Returns the number of callback executions.
  51. int getLFCCount() {
  52. return (lfc_cnt_);
  53. }
  54. protected:
  55. /// @brief Custom callback.
  56. ///
  57. /// This callback function increases the counter of callback executions.
  58. /// By examining the counter value a test may verify that the callback
  59. /// was triggered an expected number of times.
  60. virtual void lfcCallback() {
  61. ++lfc_cnt_;
  62. }
  63. private:
  64. /// @brief Counter of callback function executions.
  65. int lfc_cnt_;
  66. };
  67. /// @brief A derivation of the lease manager exposing protected methods.
  68. class NakedMemfileLeaseMgr : public Memfile_LeaseMgr {
  69. public:
  70. /// @brief Constructor.
  71. ///
  72. /// Creates instance of the lease manager.
  73. NakedMemfileLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
  74. : Memfile_LeaseMgr(parameters) {
  75. }
  76. using Memfile_LeaseMgr::lfcCallback;
  77. };
  78. /// @brief Test fixture class for @c Memfile_LeaseMgr
  79. class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
  80. public:
  81. /// @brief memfile lease mgr test constructor
  82. ///
  83. /// Creates memfile and stores it in lmptr_ pointer
  84. MemfileLeaseMgrTest() :
  85. io4_(getLeaseFilePath("leasefile4_0.csv")),
  86. io6_(getLeaseFilePath("leasefile6_0.csv")),
  87. timer_mgr_(TimerMgr::instance()) {
  88. std::ostringstream s;
  89. s << KEA_LFC_BUILD_DIR << "/kea-lfc";
  90. setenv("KEA_LFC_EXECUTABLE", s.str().c_str(), 1);
  91. // Remove lease files and products of Lease File Cleanup.
  92. removeFiles(getLeaseFilePath("leasefile4_0.csv"));
  93. removeFiles(getLeaseFilePath("leasefile6_0.csv"));
  94. }
  95. /// @brief Reopens the connection to the backend.
  96. ///
  97. /// This function is called by unit tests to force reconnection of the
  98. /// backend to check that the leases are stored and can be retrieved
  99. /// from the storage.
  100. ///
  101. /// @param u Universe (V4 or V6)
  102. virtual void reopen(Universe u) {
  103. LeaseMgrFactory::destroy();
  104. startBackend(u);
  105. }
  106. /// @brief destructor
  107. ///
  108. /// destroys lease manager backend.
  109. virtual ~MemfileLeaseMgrTest() {
  110. // Stop TimerMgr worker thread if it is running.
  111. timer_mgr_->stopThread();
  112. // Make sure there are no timers registered.
  113. timer_mgr_->unregisterTimers();
  114. LeaseMgrFactory::destroy();
  115. // Remove lease files and products of Lease File Cleanup.
  116. removeFiles(getLeaseFilePath("leasefile4_0.csv"));
  117. removeFiles(getLeaseFilePath("leasefile6_0.csv"));
  118. }
  119. /// @brief Remove files being products of Lease File Cleanup.
  120. ///
  121. /// @param base_name Path to the lease file name. This file is removed
  122. /// and all files which names are crated from this name (having specific
  123. /// suffixes used by Lease File Cleanup mechanism).
  124. void removeFiles(const std::string& base_name) const {
  125. // Generate suffixes and append them to the base name. The
  126. // resulting file names are the ones that may exist as a
  127. // result of LFC.
  128. for (int i = static_cast<int>(Memfile_LeaseMgr::FILE_CURRENT);
  129. i <= static_cast<int>(Memfile_LeaseMgr::FILE_FINISH);
  130. ++i) {
  131. Memfile_LeaseMgr::LFCFileType type = static_cast<
  132. Memfile_LeaseMgr::LFCFileType>(i);
  133. LeaseFileIO io(Memfile_LeaseMgr::appendSuffix(base_name, type));
  134. io.removeFile();
  135. }
  136. }
  137. /// @brief Return path to the lease file used by unit tests.
  138. ///
  139. /// @param filename Name of the lease file appended to the path to the
  140. /// directory where test data is held.
  141. ///
  142. /// @return Full path to the lease file.
  143. static std::string getLeaseFilePath(const std::string& filename) {
  144. std::ostringstream s;
  145. s << TEST_DATA_BUILDDIR << "/" << filename;
  146. return (s.str());
  147. }
  148. /// @brief Returns the configuration string for the backend.
  149. ///
  150. /// This string configures the @c LeaseMgrFactory to create the memfile
  151. /// backend and use leasefile4_0.csv and leasefile6_0.csv files as
  152. /// storage for leases.
  153. ///
  154. /// @param no_universe Indicates whether universe parameter should be
  155. /// included (false), or not (true).
  156. ///
  157. /// @return Configuration string for @c LeaseMgrFactory.
  158. static std::string getConfigString(Universe u) {
  159. std::ostringstream s;
  160. s << "type=memfile " << (u == V4 ? "universe=4 " : "universe=6 ")
  161. << "name="
  162. << getLeaseFilePath(u == V4 ? "leasefile4_0.csv" : "leasefile6_0.csv");
  163. return (s.str());
  164. }
  165. /// @brief Creates instance of the backend.
  166. ///
  167. /// @param u Universe (v4 or V6).
  168. void startBackend(Universe u) {
  169. try {
  170. LeaseMgrFactory::create(getConfigString(u));
  171. } catch (...) {
  172. std::cerr << "*** ERROR: unable to create instance of the Memfile\n"
  173. " lease database backend.\n";
  174. throw;
  175. }
  176. lmptr_ = &(LeaseMgrFactory::instance());
  177. }
  178. /// @brief Runs @c IfaceMgr::receive6 in a look for a specified time.
  179. ///
  180. /// @param ms Duration in milliseconds.
  181. void setTestTime(const uint32_t ms) {
  182. // Measure test time and exit if timeout hit.
  183. Stopwatch stopwatch;
  184. while (stopwatch.getTotalMilliseconds() < ms) {
  185. // Block for one 1 millisecond.
  186. IfaceMgr::instance().receive6(0, 1000);
  187. }
  188. }
  189. /// @brief Waits for the specified process to finish.
  190. ///
  191. /// @param process An object which started the process.
  192. /// @param timeout Timeout in seconds.
  193. ///
  194. /// @return true if the process ended, false otherwise
  195. bool waitForProcess(const Memfile_LeaseMgr& lease_mgr,
  196. const uint8_t timeout) {
  197. uint32_t iterations = 0;
  198. const uint32_t iterations_max = timeout * 1000;
  199. while (lease_mgr.isLFCRunning() && (iterations < iterations_max)) {
  200. usleep(1000);
  201. ++iterations;
  202. }
  203. return (iterations < iterations_max);
  204. }
  205. /// @brief Generates a DHCPv4 lease with random content.
  206. ///
  207. /// The following lease parameters are randomly generated:
  208. /// - HW address,
  209. /// - client identifier,
  210. /// - hostname,
  211. /// - subnet identifier,
  212. /// - client last transmission time,
  213. ///
  214. /// The following lease parameters are set to constant values:
  215. /// - valid lifetime = 1200,
  216. /// - T1 = 600,
  217. /// - T2 = 900,
  218. /// - DNS update forward flag = false,
  219. /// - DNS update reverse flag = false,
  220. ///
  221. /// The lease address is set to address passed as function
  222. /// argument.
  223. ///
  224. /// @param address Lease address.
  225. ///
  226. /// @return new lease with random content
  227. Lease4Ptr initiateRandomLease4(const IOAddress& address) {
  228. // Randomize HW address.
  229. vector<uint8_t> mac(6);
  230. fillRandom(mac.begin(), mac.end());
  231. HWAddrPtr hwaddr(new HWAddr(mac, HTYPE_ETHER));
  232. // Let's generate clientid of random length
  233. vector<uint8_t> clientid(4 + random()%20);
  234. // And then fill it with random value.
  235. fillRandom(clientid.begin(), clientid.end());
  236. uint32_t valid_lft = 1200;
  237. uint32_t t1 = 600;
  238. uint32_t t2 = 900;
  239. time_t timestamp = time(NULL) - 86400 + random()%86400;
  240. bool fqdn_fwd = false;
  241. bool fqdn_rev = false;
  242. uint32_t subnet_id = 1000 + random()%16;
  243. std::ostringstream hostname;
  244. hostname << "hostname" << (random() % 2048);
  245. // Return created lease.
  246. return (Lease4Ptr(new Lease4(address, hwaddr, &clientid[0],
  247. clientid.size(), valid_lft, t1, t2,
  248. timestamp, subnet_id, fqdn_fwd,
  249. fqdn_rev, hostname.str())));
  250. }
  251. /// @brief Generates a DHCPv6 lease with random content.
  252. ///
  253. /// The following lease parameters are randomly generated:
  254. /// - DUID,
  255. /// - IAID,
  256. /// - hostname,
  257. /// - subnet identifier,
  258. /// - client last transmission time,
  259. ///
  260. /// The following lease parameters are set to constant values:
  261. /// - lease type = IA_NA
  262. /// - valid lifetime = 1200,
  263. /// - preferred lifetime = 1000
  264. /// - T1 = 600,
  265. /// - T2 = 900,
  266. /// - DNS update forward flag = false,
  267. /// - DNS update reverse flag = false,
  268. ///
  269. /// The lease address is set to address passed as function
  270. /// argument.
  271. ///
  272. /// @param address Lease address.
  273. ///
  274. /// @return new lease with random content
  275. Lease6Ptr initiateRandomLease6(const IOAddress& address) {
  276. // Let's generate DUID of random length.
  277. std::vector<uint8_t> duid_vec(8 + random()%20);
  278. // And then fill it with random value.
  279. fillRandom(duid_vec.begin(), duid_vec.end());
  280. DuidPtr duid(new DUID(duid_vec));
  281. Lease::Type lease_type = Lease::TYPE_NA;
  282. uint32_t iaid = 1 + random()%100;
  283. uint32_t valid_lft = 1200;
  284. uint32_t preferred_lft = 1000;
  285. uint32_t t1 = 600;
  286. uint32_t t2 = 900;
  287. time_t timestamp = time(NULL) - 86400 + random()%86400;
  288. bool fqdn_fwd = false;
  289. bool fqdn_rev = false;
  290. uint32_t subnet_id = 1000 + random()%16;
  291. std::ostringstream hostname;
  292. hostname << "hostname" << (random() % 2048);
  293. // Return created lease.
  294. Lease6Ptr lease(new Lease6(lease_type, address, duid, iaid,
  295. preferred_lft, valid_lft, t1, t2,
  296. subnet_id, fqdn_fwd, fqdn_rev,
  297. hostname.str()));
  298. lease->cltt_ = timestamp;
  299. return (lease);
  300. }
  301. /// @brief Object providing access to v4 lease IO.
  302. LeaseFileIO io4_;
  303. /// @brief Object providing access to v6 lease IO.
  304. LeaseFileIO io6_;
  305. /// @brief Pointer to the instance of the @c TimerMgr.
  306. TimerMgrPtr timer_mgr_;
  307. };
  308. // This test checks if the LeaseMgr can be instantiated and that it
  309. // parses parameters string properly.
  310. TEST_F(MemfileLeaseMgrTest, constructor) {
  311. DatabaseConnection::ParameterMap pmap;
  312. pmap["universe"] = "4";
  313. pmap["persist"] = "false";
  314. boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr;
  315. EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
  316. pmap["lfc-interval"] = "10";
  317. pmap["persist"] = "true";
  318. pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
  319. EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
  320. // Expecting that persist parameter is yes or no. Everything other than
  321. // that is wrong.
  322. pmap["persist"] = "bogus";
  323. pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
  324. EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
  325. // The lfc-interval must be an integer.
  326. pmap["persist"] = "true";
  327. pmap["lfc-interval"] = "bogus";
  328. EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
  329. }
  330. // Checks if there is no lease manager NoLeaseManager is thrown.
  331. TEST_F(MemfileLeaseMgrTest, noLeaseManager) {
  332. LeaseMgrFactory::destroy();
  333. EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager);
  334. }
  335. // Checks if the getType() and getName() methods both return "memfile".
  336. TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
  337. startBackend(V4);
  338. EXPECT_EQ(std::string("memfile"), lmptr_->getType());
  339. EXPECT_EQ(std::string("memory"), lmptr_->getName());
  340. }
  341. // Checks if the path to the lease files is initialized correctly.
  342. TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) {
  343. // Initialize IO objects, so as the test csv files get removed after the
  344. // test (when destructors are called).
  345. LeaseFileIO io4(getLeaseFilePath("leasefile4_1.csv"));
  346. LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
  347. DatabaseConnection::ParameterMap pmap;
  348. pmap["universe"] = "4";
  349. pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
  350. boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
  351. EXPECT_EQ(pmap["name"],
  352. lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4));
  353. pmap["persist"] = "false";
  354. lease_mgr.reset(new Memfile_LeaseMgr(pmap));
  355. EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4).empty());
  356. EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6).empty());
  357. }
  358. // Check if the persitLeases correctly checks that leases should not be written
  359. // to disk when disabled through configuration.
  360. TEST_F(MemfileLeaseMgrTest, persistLeases) {
  361. // Initialize IO objects, so as the test csv files get removed after the
  362. // test (when destructors are called).
  363. LeaseFileIO io4(getLeaseFilePath("leasefile4_1.csv"));
  364. LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
  365. DatabaseConnection::ParameterMap pmap;
  366. pmap["universe"] = "4";
  367. // Specify the names of the lease files. Leases will be written.
  368. pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
  369. boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
  370. lease_mgr.reset(new Memfile_LeaseMgr(pmap));
  371. EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
  372. EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
  373. pmap["universe"] = "6";
  374. pmap["name"] = getLeaseFilePath("leasefile6_1.csv");
  375. lease_mgr.reset(new Memfile_LeaseMgr(pmap));
  376. EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
  377. EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
  378. // This should disable writes of leases to disk.
  379. pmap["persist"] = "false";
  380. lease_mgr.reset(new Memfile_LeaseMgr(pmap));
  381. EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
  382. EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
  383. }
  384. // Check if it is possible to schedule the timer to perform the Lease
  385. // File Cleanup periodically.
  386. TEST_F(MemfileLeaseMgrTest, lfcTimer) {
  387. DatabaseConnection::ParameterMap pmap;
  388. pmap["type"] = "memfile";
  389. pmap["universe"] = "4";
  390. // Specify the names of the lease files. Leases will be written.
  391. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  392. pmap["lfc-interval"] = "1";
  393. boost::scoped_ptr<LFCMemfileLeaseMgr>
  394. lease_mgr(new LFCMemfileLeaseMgr(pmap));
  395. // Start worker thread to execute LFC periodically.
  396. ASSERT_NO_THROW(timer_mgr_->startThread());
  397. // Run the test for at most 2.9 seconds.
  398. setTestTime(2900);
  399. // Stop worker thread.
  400. ASSERT_NO_THROW(timer_mgr_->stopThread());
  401. // Within 2.9 we should record two LFC executions.
  402. EXPECT_EQ(2, lease_mgr->getLFCCount());
  403. }
  404. // This test checks if the LFC timer is disabled (doesn't trigger)
  405. // cleanups when the lfc-interval is set to 0.
  406. TEST_F(MemfileLeaseMgrTest, lfcTimerDisabled) {
  407. DatabaseConnection::ParameterMap pmap;
  408. pmap["type"] = "memfile";
  409. pmap["universe"] = "4";
  410. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  411. // Set the LFC interval to 0, which should effectively disable it.
  412. pmap["lfc-interval"] = "0";
  413. boost::scoped_ptr<LFCMemfileLeaseMgr>
  414. lease_mgr(new LFCMemfileLeaseMgr(pmap));
  415. // Start worker thread to execute LFC periodically.
  416. ASSERT_NO_THROW(timer_mgr_->startThread());
  417. // Run the test for at most 1.9 seconds.
  418. setTestTime(1900);
  419. // Stop worker thread to make sure it is not running when lease
  420. // manager is destroyed. The lease manager will be unable to
  421. // unregster timer when the thread is active.
  422. ASSERT_NO_THROW(timer_mgr_->stopThread());
  423. // There should be no LFC execution recorded.
  424. EXPECT_EQ(0, lease_mgr->getLFCCount());
  425. }
  426. // This test checks that the callback function executing the cleanup of the
  427. // DHCPv4 lease file works as expected.
  428. TEST_F(MemfileLeaseMgrTest, leaseFileCleanup4) {
  429. // This string contains the lease file header, which matches
  430. // the contents of the new file in which no leases have been
  431. // stored.
  432. std::string new_file_contents =
  433. "address,hwaddr,client_id,valid_lifetime,expire,"
  434. "subnet_id,fqdn_fwd,fqdn_rev,hostname,state\n";
  435. // This string contains the contents of the lease file with exactly
  436. // one lease, but two entries. One of the entries should be removed
  437. // as a result of lease file cleanup.
  438. std::string current_file_contents = new_file_contents +
  439. "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1\n"
  440. "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1\n";
  441. LeaseFileIO current_file(getLeaseFilePath("leasefile4_0.csv"));
  442. current_file.writeFile(current_file_contents);
  443. std::string previous_file_contents = new_file_contents +
  444. "192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,,1\n"
  445. "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1\n";
  446. LeaseFileIO previous_file(getLeaseFilePath("leasefile4_0.csv.2"));
  447. previous_file.writeFile(previous_file_contents);
  448. // Create the backend.
  449. DatabaseConnection::ParameterMap pmap;
  450. pmap["type"] = "memfile";
  451. pmap["universe"] = "4";
  452. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  453. pmap["lfc-interval"] = "1";
  454. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  455. // Try to run the lease file cleanup.
  456. ASSERT_NO_THROW(lease_mgr->lfcCallback());
  457. // The new lease file should have been created and it should contain
  458. // no leases.
  459. ASSERT_TRUE(current_file.exists());
  460. EXPECT_EQ(new_file_contents, current_file.readFile());
  461. // Wait for the LFC process to complete.
  462. ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
  463. // And make sure it has returned an exit status of 0.
  464. EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
  465. << "Executing the LFC process failed: make sure that"
  466. " the kea-lfc program has been compiled.";
  467. // Check if we can still write to the lease file.
  468. std::vector<uint8_t> hwaddr_vec(6);
  469. HWAddrPtr hwaddr(new HWAddr(hwaddr_vec, HTYPE_ETHER));
  470. Lease4Ptr new_lease(new Lease4(IOAddress("192.0.2.45"), hwaddr, 0, 0,
  471. 100, 50, 60, 0, 1));
  472. ASSERT_NO_THROW(lease_mgr->addLease(new_lease));
  473. std::string updated_file_contents = new_file_contents +
  474. "192.0.2.45,00:00:00:00:00:00,,100,100,1,0,0,,0\n";
  475. EXPECT_EQ(updated_file_contents, current_file.readFile());
  476. // This string contains the contents of the lease file we
  477. // expect after the LFC run. It has two leases with one
  478. // entry each.
  479. std::string result_file_contents = new_file_contents +
  480. "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,1\n"
  481. "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,1\n";
  482. // The LFC should have created a file with the two leases and moved it
  483. // to leasefile4_0.csv.2
  484. LeaseFileIO input_file(getLeaseFilePath("leasefile4_0.csv.2"), false);
  485. ASSERT_TRUE(input_file.exists());
  486. // And this file should contain the contents of the result file.
  487. EXPECT_EQ(result_file_contents, input_file.readFile());
  488. }
  489. // This test checks that the callback function executing the cleanup of the
  490. // DHCPv6 lease file works as expected.
  491. TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) {
  492. // This string contains the lease file header, which matches
  493. // the contents of the new file in which no leases have been
  494. // stored.
  495. std::string new_file_contents =
  496. "address,duid,valid_lifetime,expire,subnet_id,"
  497. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  498. "fqdn_rev,hostname,hwaddr,state\n";
  499. // This string contains the contents of the lease file with exactly
  500. // one lease, but two entries. One of the entries should be removed
  501. // as a result of lease file cleanup.
  502. std::string current_file_contents = new_file_contents +
  503. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
  504. "8,100,0,7,0,1,1,,,1\n"
  505. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  506. "8,100,0,7,0,1,1,,,1\n";
  507. LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
  508. current_file.writeFile(current_file_contents);
  509. std::string previous_file_contents = new_file_contents +
  510. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,200,"
  511. "8,100,0,7,0,1,1,,,1\n"
  512. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  513. "8,100,0,7,0,1,1,,,1\n";
  514. LeaseFileIO previous_file(getLeaseFilePath("leasefile6_0.csv.2"));
  515. previous_file.writeFile(previous_file_contents);
  516. // Create the backend.
  517. DatabaseConnection::ParameterMap pmap;
  518. pmap["type"] = "memfile";
  519. pmap["universe"] = "6";
  520. pmap["name"] = getLeaseFilePath("leasefile6_0.csv");
  521. pmap["lfc-interval"] = "1";
  522. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  523. // Try to run the lease file cleanup.
  524. ASSERT_NO_THROW(lease_mgr->lfcCallback());
  525. // The new lease file should have been created and it should contain
  526. // no leases.
  527. ASSERT_TRUE(current_file.exists());
  528. EXPECT_EQ(new_file_contents, current_file.readFile());
  529. // Wait for the LFC process to complete.
  530. ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
  531. // And make sure it has returned an exit status of 0.
  532. EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
  533. << "Executing the LFC process failed: make sure that"
  534. " the kea-lfc program has been compiled.";
  535. // Check if we can still write to the lease file.
  536. std::vector<uint8_t> duid_vec(13);
  537. DuidPtr duid(new DUID(duid_vec));
  538. Lease6Ptr new_lease(new Lease6(Lease::TYPE_NA, IOAddress("3000::1"),duid,
  539. 123, 300, 400, 100, 300, 2));
  540. new_lease->cltt_ = 0;
  541. ASSERT_NO_THROW(lease_mgr->addLease(new_lease));
  542. std::string update_file_contents = new_file_contents +
  543. "3000::1,00:00:00:00:00:00:00:00:00:00:00:00:00,400,"
  544. "400,2,300,0,123,128,0,0,,,0\n";
  545. EXPECT_EQ(update_file_contents, current_file.readFile());
  546. // This string contains the contents of the lease file we
  547. // expect after the LFC run. It has two leases with one
  548. // entry each.
  549. std::string result_file_contents = new_file_contents +
  550. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  551. "8,100,0,7,0,1,1,,,1\n"
  552. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  553. "8,100,0,7,0,1,1,,,1\n";
  554. // The LFC should have created a file with the two leases and moved it
  555. // to leasefile6_0.csv.2
  556. LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.2"), false);
  557. ASSERT_TRUE(input_file.exists());
  558. // And this file should contain the contents of the result file.
  559. EXPECT_EQ(result_file_contents, input_file.readFile());
  560. }
  561. // This test verifies that EXIT_FAILURE status code is returned when
  562. // the LFC process fails to start.
  563. TEST_F(MemfileLeaseMgrTest, leaseFileCleanupStartFail) {
  564. // This string contains the lease file header, which matches
  565. // the contents of the new file in which no leases have been
  566. // stored.
  567. std::string new_file_contents =
  568. "address,hwaddr,client_id,valid_lifetime,expire,"
  569. "subnet_id,fqdn_fwd,fqdn_rev,hostname,state\n";
  570. // Create the lease file to be used by the backend.
  571. std::string current_file_contents = new_file_contents +
  572. "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1\n";
  573. LeaseFileIO current_file(getLeaseFilePath("leasefile4_0.csv"));
  574. current_file.writeFile(current_file_contents);
  575. // Specify invalid path to the kea-lfc executable. This should result
  576. // in failure status code returned by the child process.
  577. setenv("KEA_LFC_EXECUTABLE", "foobar", 1);
  578. // Create the backend.
  579. DatabaseConnection::ParameterMap pmap;
  580. pmap["type"] = "memfile";
  581. pmap["universe"] = "4";
  582. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  583. pmap["lfc-interval"] = "1";
  584. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  585. // Try to run the lease file cleanup.
  586. ASSERT_NO_THROW(lease_mgr->lfcCallback());
  587. // Wait for the LFC process to complete.
  588. ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
  589. // And make sure it has returned an error.
  590. EXPECT_EQ(EXIT_FAILURE, lease_mgr->getLFCExitStatus())
  591. << "Executing the LFC process failed: make sure that"
  592. " the kea-lfc program has been compiled.";
  593. }
  594. // This test checks that the callback function executing the cleanup of the
  595. // files doesn't move the current file if the finish file exists
  596. TEST_F(MemfileLeaseMgrTest, leaseFileFinish) {
  597. // This string contains the lease file header, which matches
  598. // the contents of the new file in which no leases have been
  599. // stored.
  600. std::string new_file_contents =
  601. "address,duid,valid_lifetime,expire,subnet_id,"
  602. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  603. "fqdn_rev,hostname,hwaddr,state\n";
  604. // This string contains the contents of the current lease file.
  605. // It should not be moved.
  606. std::string current_file_contents = new_file_contents +
  607. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
  608. "8,100,0,7,0,1,1,,,1\n"
  609. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  610. "8,100,0,7,0,1,1,,,1\n";
  611. LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
  612. current_file.writeFile(current_file_contents);
  613. // This string contains the contents of the finish file. It should
  614. // be moved to the previous file.
  615. std::string finish_file_contents = new_file_contents +
  616. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  617. "8,100,0,7,0,1,1,,,1\n";
  618. LeaseFileIO finish_file(getLeaseFilePath("leasefile6_0.csv.completed"));
  619. finish_file.writeFile(finish_file_contents);
  620. // Create the backend.
  621. DatabaseConnection::ParameterMap pmap;
  622. pmap["type"] = "memfile";
  623. pmap["universe"] = "6";
  624. pmap["name"] = getLeaseFilePath("leasefile6_0.csv");
  625. pmap["lfc-interval"] = "1";
  626. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  627. // Try to run the lease file cleanup.
  628. ASSERT_NO_THROW(lease_mgr->lfcCallback());
  629. // The current lease file should not have been touched.
  630. ASSERT_TRUE(current_file.exists());
  631. EXPECT_EQ(current_file_contents, current_file.readFile());
  632. // Wait for the LFC process to complete.
  633. ASSERT_TRUE(waitForProcess(*lease_mgr, 5));
  634. // And make sure it has returned an exit status of 0.
  635. EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
  636. << "Executing the LFC process failed: make sure that"
  637. " the kea-lfc program has been compiled.";
  638. // The LFC should have moved the finish file to the previous file -
  639. // leasefile6_0.csv.2
  640. LeaseFileIO previous_file(getLeaseFilePath("leasefile6_0.csv.2"), false);
  641. ASSERT_TRUE(previous_file.exists());
  642. // And this file should contain the contents of the finish file.
  643. EXPECT_EQ(finish_file_contents, previous_file.readFile());
  644. // The finish file should have been removed
  645. ASSERT_FALSE(finish_file.exists());
  646. }
  647. // This test checks that the callback function executing the cleanup of the
  648. // files doesn't move the current file if the copy file exists
  649. TEST_F(MemfileLeaseMgrTest, leaseFileCopy) {
  650. // This string contains the lease file header, which matches
  651. // the contents of the new file in which no leases have been
  652. // stored.
  653. std::string new_file_contents =
  654. "address,duid,valid_lifetime,expire,subnet_id,"
  655. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  656. "fqdn_rev,hostname,hwaddr,state\n";
  657. // This string contains the contents of the current lease file.
  658. // It should not be moved.
  659. std::string current_file_contents = new_file_contents +
  660. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
  661. "8,100,0,7,0,1,1,,,1\n"
  662. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  663. "8,100,0,7,0,1,1,,,1\n";
  664. LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
  665. current_file.writeFile(current_file_contents);
  666. // This string contains the contents of the copy file. It should
  667. // be processed and moved to the previous file. As there is only
  668. // one lease the processing should result in the previous file being
  669. // the same.
  670. std::string input_file_contents = new_file_contents +
  671. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  672. "8,100,0,7,0,1,1,,,1\n";
  673. LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.1"));
  674. input_file.writeFile(input_file_contents);
  675. // Create the backend.
  676. DatabaseConnection::ParameterMap pmap;
  677. pmap["type"] = "memfile";
  678. pmap["universe"] = "6";
  679. pmap["name"] = getLeaseFilePath("leasefile6_0.csv");
  680. pmap["lfc-interval"] = "1";
  681. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  682. // Try to run the lease file cleanup.
  683. ASSERT_NO_THROW(lease_mgr->lfcCallback());
  684. // The current lease file should not have been touched.
  685. ASSERT_TRUE(current_file.exists());
  686. EXPECT_EQ(current_file_contents, current_file.readFile());
  687. // Wait for the LFC process to complete.
  688. ASSERT_TRUE(waitForProcess(*lease_mgr, 5));
  689. // And make sure it has returned an exit status of 0.
  690. EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
  691. << "Executing the LFC process failed: make sure that"
  692. " the kea-lfc program has been compiled.";
  693. // The LFC should have processed the lease and moved it to the previous
  694. // file - leasefile6_0.csv.2
  695. LeaseFileIO previous_file(getLeaseFilePath("leasefile6_0.csv.2"), false);
  696. ASSERT_TRUE(previous_file.exists());
  697. // And this file should contain the contents of the copy file.
  698. EXPECT_EQ(input_file_contents, previous_file.readFile());
  699. // The input file should have been removed
  700. ASSERT_FALSE(input_file.exists());
  701. }
  702. // Checks that adding/getting/deleting a Lease6 object works.
  703. TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
  704. startBackend(V6);
  705. testAddGetDelete6(true); // true - check T1,T2 values
  706. // memfile is able to preserve those values, but some other
  707. // backends can't do that.
  708. }
  709. /// @brief Basic Lease4 Checks
  710. ///
  711. /// Checks that the addLease, getLease4 (by address) and deleteLease (with an
  712. /// IPv4 address) works.
  713. TEST_F(MemfileLeaseMgrTest, basicLease4) {
  714. startBackend(V4);
  715. testBasicLease4();
  716. }
  717. /// @todo Write more memfile tests
  718. // Simple test about lease4 retrieval through client id method
  719. TEST_F(MemfileLeaseMgrTest, getLease4ClientId) {
  720. startBackend(V4);
  721. testGetLease4ClientId();
  722. }
  723. // Checks that lease4 retrieval client id is null is working
  724. TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
  725. startBackend(V4);
  726. testGetLease4NullClientId();
  727. }
  728. // Checks lease4 retrieval through HWAddr
  729. TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) {
  730. startBackend(V4);
  731. testGetLease4HWAddr1();
  732. }
  733. /// @brief Check GetLease4 methods - access by Hardware Address
  734. ///
  735. /// Adds leases to the database and checks that they can be accessed via
  736. /// a combination of DUID and IAID.
  737. TEST_F(MemfileLeaseMgrTest, getLease4HWAddr2) {
  738. startBackend(V4);
  739. testGetLease4HWAddr2();
  740. }
  741. // Checks lease4 retrieval with clientId, HWAddr and subnet_id
  742. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
  743. startBackend(V4);
  744. testGetLease4ClientIdHWAddrSubnetId();
  745. }
  746. /// @brief Basic Lease4 Checks
  747. ///
  748. /// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
  749. /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
  750. /// (client-id is optional and may not be present)
  751. TEST_F(MemfileLeaseMgrTest, lease4NullClientId) {
  752. startBackend(V4);
  753. testLease4NullClientId();
  754. }
  755. /// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
  756. ///
  757. /// Adds leases to the database and checks that they can be accessed via
  758. /// a combination of hardware address and subnet ID
  759. TEST_F(MemfileLeaseMgrTest, DISABLED_getLease4HwaddrSubnetId) {
  760. /// @todo: fails on memfile. It's probably a memfile bug.
  761. startBackend(V4);
  762. testGetLease4HWAddrSubnetId();
  763. }
  764. /// @brief Check GetLease4 methods - access by Client ID
  765. ///
  766. /// Adds leases to the database and checks that they can be accessed via
  767. /// the Client ID.
  768. TEST_F(MemfileLeaseMgrTest, getLease4ClientId2) {
  769. startBackend(V4);
  770. testGetLease4ClientId2();
  771. }
  772. // @brief Get Lease4 by client ID
  773. //
  774. // Check that the system can cope with a client ID of any size.
  775. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSize) {
  776. startBackend(V4);
  777. testGetLease4ClientIdSize();
  778. }
  779. /// @brief Check GetLease4 methods - access by Client ID & Subnet ID
  780. ///
  781. /// Adds leases to the database and checks that they can be accessed via
  782. /// a combination of client and subnet IDs.
  783. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSubnetId) {
  784. startBackend(V4);
  785. testGetLease4ClientIdSubnetId();
  786. }
  787. /// @brief Basic Lease6 Checks
  788. ///
  789. /// Checks that the addLease, getLease6 (by address) and deleteLease (with an
  790. /// IPv6 address) works.
  791. TEST_F(MemfileLeaseMgrTest, basicLease6) {
  792. startBackend(V6);
  793. testBasicLease6();
  794. }
  795. /// @brief Check GetLease6 methods - access by DUID/IAID
  796. ///
  797. /// Adds leases to the database and checks that they can be accessed via
  798. /// a combination of DUID and IAID.
  799. /// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
  800. /// const DUID& duid, uint32_t iaid) const is not implemented yet.
  801. TEST_F(MemfileLeaseMgrTest, getLeases6DuidIaid) {
  802. startBackend(V6);
  803. testGetLeases6DuidIaid();
  804. }
  805. /// @brief Check that the system can cope with a DUID of allowed size.
  806. TEST_F(MemfileLeaseMgrTest, getLeases6DuidSize) {
  807. startBackend(V6);
  808. testGetLeases6DuidSize();
  809. }
  810. /// @brief Check that the expired DHCPv4 leases can be retrieved.
  811. ///
  812. /// This test adds a number of leases to the lease database and marks
  813. /// some of them as expired. Then it queries for expired leases and checks
  814. /// whether only expired leases are returned, and that they are returned in
  815. /// the order from most to least expired. It also checks that the lease
  816. /// which is marked as 'reclaimed' is not returned.
  817. TEST_F(MemfileLeaseMgrTest, getExpiredLeases4) {
  818. startBackend(V4);
  819. testGetExpiredLeases4();
  820. }
  821. /// @brief Check that the expired DHCPv6 leases can be retrieved.
  822. ///
  823. /// This test adds a number of leases to the lease database and marks
  824. /// some of them as expired. Then it queries for expired leases and checks
  825. /// whether only expired leases are returned, and that they are returned in
  826. /// the order from most to least expired. It also checks that the lease
  827. /// which is marked as 'reclaimed' is not returned.
  828. TEST_F(MemfileLeaseMgrTest, getExpiredLeases6) {
  829. startBackend(V6);
  830. testGetExpiredLeases6();
  831. }
  832. /// @brief Check that expired reclaimed DHCPv6 leases are removed.
  833. TEST_F(MemfileLeaseMgrTest, deleteExpiredReclaimedLeases6) {
  834. startBackend(V6);
  835. testDeleteExpiredReclaimedLeases6();
  836. }
  837. /// @brief Check that expired reclaimed DHCPv4 leases are removed.
  838. TEST_F(MemfileLeaseMgrTest, deleteExpiredReclaimedLeases4) {
  839. startBackend(V4);
  840. testDeleteExpiredReclaimedLeases4();
  841. }
  842. /// @brief Check that getLease6 methods discriminate by lease type.
  843. ///
  844. /// Adds six leases, two per lease type all with the same duid and iad but
  845. /// with alternating subnet_ids.
  846. /// It then verifies that all of getLeases6() method variants correctly
  847. /// discriminate between the leases based on lease type alone.
  848. /// @todo: Disabled, because type parameter in Memfile_LeaseMgr::getLease6
  849. /// (Lease::Type, const isc::asiolink::IOAddress& addr) const is not used.
  850. TEST_F(MemfileLeaseMgrTest, lease6LeaseTypeCheck) {
  851. startBackend(V6);
  852. testLease6LeaseTypeCheck();
  853. }
  854. /// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
  855. ///
  856. /// Adds leases to the database and checks that they can be accessed via
  857. /// a combination of DIUID and IAID.
  858. TEST_F(MemfileLeaseMgrTest, getLease6DuidIaidSubnetId) {
  859. startBackend(V6);
  860. testGetLease6DuidIaidSubnetId();
  861. }
  862. /// Checks that getLease6(type, duid, iaid, subnet-id) works with different
  863. /// DUID sizes
  864. TEST_F(MemfileLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
  865. startBackend(V6);
  866. testGetLease6DuidIaidSubnetIdSize();
  867. }
  868. /// @brief Lease4 update tests
  869. ///
  870. /// Checks that we are able to update a lease in the database.
  871. /// @todo: Disabled, because memfile does not throw when lease is updated.
  872. /// We should reconsider if lease{4,6} structures should have a limit
  873. /// implemented in them.
  874. TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease4) {
  875. startBackend(V4);
  876. testUpdateLease4();
  877. }
  878. /// @brief Lease6 update tests
  879. ///
  880. /// Checks that we are able to update a lease in the database.
  881. /// @todo: Disabled, because memfile does not throw when lease is updated.
  882. /// We should reconsider if lease{4,6} structures should have a limit
  883. /// implemented in them.
  884. TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease6) {
  885. startBackend(V6);
  886. testUpdateLease6();
  887. }
  888. /// @brief DHCPv4 Lease recreation tests
  889. ///
  890. /// Checks that the lease can be created, deleted and recreated with
  891. /// different parameters. It also checks that the re-created lease is
  892. /// correctly stored in the lease database.
  893. TEST_F(MemfileLeaseMgrTest, testRecreateLease4) {
  894. startBackend(V4);
  895. testRecreateLease4();
  896. }
  897. /// @brief DHCPv6 Lease recreation tests
  898. ///
  899. /// Checks that the lease can be created, deleted and recreated with
  900. /// different parameters. It also checks that the re-created lease is
  901. /// correctly stored in the lease database.
  902. TEST_F(MemfileLeaseMgrTest, testRecreateLease6) {
  903. startBackend(V6);
  904. testRecreateLease6();
  905. }
  906. // The following tests are not applicable for memfile. When adding
  907. // new tests to the list here, make sure to provide brief explanation
  908. // why they are not applicable:
  909. //
  910. // testGetLease4HWAddrSubnetIdSize() - memfile just keeps Lease structure
  911. // and does not do any checks of HWAddr content
  912. /// @brief Checks that null DUID is not allowed.
  913. /// Test is disabled as Memfile does not currently defend against a null DUID.
  914. TEST_F(MemfileLeaseMgrTest, DISABLED_nullDuid) {
  915. // Create leases, although we need only one.
  916. vector<Lease6Ptr> leases = createLeases6();
  917. leases[1]->duid_.reset();
  918. ASSERT_THROW(lmptr_->addLease(leases[1]), DbOperationError);
  919. }
  920. /// @brief Tests whether memfile can store and retrieve hardware addresses
  921. TEST_F(MemfileLeaseMgrTest, testLease6Mac) {
  922. startBackend(V6);
  923. testLease6MAC();
  924. }
  925. // Check that memfile reports version correctly.
  926. TEST_F(MemfileLeaseMgrTest, versionCheck) {
  927. // Check that V4 backend reports versions correctly.
  928. startBackend(V4);
  929. testVersion(Memfile_LeaseMgr::MAJOR_VERSION,
  930. Memfile_LeaseMgr::MINOR_VERSION);
  931. LeaseMgrFactory::destroy();
  932. // Check that V6 backends reports them ok, too.
  933. startBackend(V6);
  934. testVersion(Memfile_LeaseMgr::MAJOR_VERSION,
  935. Memfile_LeaseMgr::MINOR_VERSION);
  936. LeaseMgrFactory::destroy();
  937. }
  938. // Checks that declined IPv4 leases can be returned correctly.
  939. TEST_F(MemfileLeaseMgrTest, getDeclined4) {
  940. startBackend(V4);
  941. testGetDeclinedLeases4();
  942. }
  943. // Checks that declined IPv6 leases can be returned correctly.
  944. TEST_F(MemfileLeaseMgrTest, getDeclined6) {
  945. startBackend(V6);
  946. testGetDeclinedLeases6();
  947. }
  948. // This test checks that the backend reads DHCPv4 lease data from multiple
  949. // files.
  950. TEST_F(MemfileLeaseMgrTest, load4MultipleLeaseFiles) {
  951. LeaseFileIO io2(getLeaseFilePath("leasefile4_0.csv.2"));
  952. io2.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  953. "fqdn_fwd,fqdn_rev,hostname,state\n"
  954. "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1\n"
  955. "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1\n");
  956. LeaseFileIO io1(getLeaseFilePath("leasefile4_0.csv.1"));
  957. io1.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  958. "fqdn_fwd,fqdn_rev,hostname,state\n"
  959. "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1\n"
  960. "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1\n"
  961. "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1\n");
  962. LeaseFileIO io(getLeaseFilePath("leasefile4_0.csv"));
  963. io.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  964. "fqdn_fwd,fqdn_rev,hostname,state\n"
  965. "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1\n"
  966. "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1\n");
  967. startBackend(V4);
  968. // This lease only exists in the second file and the cltt should
  969. // be 0.
  970. Lease4Ptr lease = lmptr_->getLease4(IOAddress("192.0.2.1"));
  971. ASSERT_TRUE(lease);
  972. EXPECT_EQ(0, lease->cltt_);
  973. // This lease only exists in the first file and the cltt should
  974. // be 0.
  975. lease = lmptr_->getLease4(IOAddress("192.0.2.2"));
  976. ASSERT_TRUE(lease);
  977. EXPECT_EQ(0, lease->cltt_);
  978. // This lease only exists in the third file and the cltt should
  979. // be 0.
  980. lease = lmptr_->getLease4(IOAddress("192.0.2.10"));
  981. ASSERT_TRUE(lease);
  982. EXPECT_EQ(0, lease->cltt_);
  983. // This lease exists in the first and second file and the cltt
  984. // should be calculated using the expiration time and the
  985. // valid lifetime from the second file.
  986. lease = lmptr_->getLease4(IOAddress("192.0.2.11"));
  987. ASSERT_TRUE(lease);
  988. EXPECT_EQ(200, lease->cltt_);
  989. // This lease exists in the second and third file and the cltt
  990. // should be calculated using the expiration time and the
  991. // valid lifetime from the third file.
  992. lease = lmptr_->getLease4(IOAddress("192.0.2.12"));
  993. ASSERT_TRUE(lease);
  994. EXPECT_EQ(200, lease->cltt_);
  995. }
  996. // This test checks that the lease database backend loads the file with
  997. // the .completed postfix instead of files with postfixes .1 and .2 if
  998. // the file with .completed postfix exists.
  999. TEST_F(MemfileLeaseMgrTest, load4CompletedFile) {
  1000. LeaseFileIO io2(getLeaseFilePath("leasefile4_0.csv.2"));
  1001. io2.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  1002. "fqdn_fwd,fqdn_rev,hostname,state\n"
  1003. "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,1\n"
  1004. "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,1\n");
  1005. LeaseFileIO io1(getLeaseFilePath("leasefile4_0.csv.1"));
  1006. io1.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  1007. "fqdn_fwd,fqdn_rev,hostname,state\n"
  1008. "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,1\n"
  1009. "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,1\n"
  1010. "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,1\n");
  1011. LeaseFileIO io(getLeaseFilePath("leasefile4_0.csv"));
  1012. io.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  1013. "fqdn_fwd,fqdn_rev,hostname,state\n"
  1014. "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,1\n"
  1015. "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,1\n");
  1016. LeaseFileIO ioc(getLeaseFilePath("leasefile4_0.csv.completed"));
  1017. ioc.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
  1018. "fqdn_fwd,fqdn_rev,hostname,state\n"
  1019. "192.0.2.13,ff:ff:ff:ff:ff:ff,,200,200,8,1,1,,1\n");
  1020. startBackend(V4);
  1021. // We expect that this file only holds leases that belong to the
  1022. // lease file or to the file with .completed postfix.
  1023. Lease4Ptr lease = lmptr_->getLease4(IOAddress("192.0.2.10"));
  1024. ASSERT_TRUE(lease);
  1025. EXPECT_EQ(0, lease->cltt_);
  1026. lease = lmptr_->getLease4(IOAddress("192.0.2.12"));
  1027. ASSERT_TRUE(lease);
  1028. EXPECT_EQ(200, lease->cltt_);
  1029. // This lease is in the .completed file.
  1030. lease = lmptr_->getLease4(IOAddress("192.0.2.13"));
  1031. ASSERT_TRUE(lease);
  1032. EXPECT_EQ(0, lease->cltt_);
  1033. // Leases from the .1 and .2 files should not be loaded.
  1034. EXPECT_FALSE(lmptr_->getLease4(IOAddress("192.0.2.11")));
  1035. EXPECT_FALSE(lmptr_->getLease4(IOAddress("192.0.2.1")));
  1036. }
  1037. // This test checks that backend constructor refuses to load leases from the
  1038. // lease files if the LFC is in progress.
  1039. TEST_F(MemfileLeaseMgrTest, load4LFCInProgress) {
  1040. // Create the backend configuration.
  1041. DatabaseConnection::ParameterMap pmap;
  1042. pmap["type"] = "memfile";
  1043. pmap["universe"] = "4";
  1044. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  1045. pmap["lfc-interval"] = "1";
  1046. // Create a pid file holding the PID of the current process. Choosing the
  1047. // pid of the current process guarantees that when the backend starts up
  1048. // the process is alive.
  1049. PIDFile pid_file(Memfile_LeaseMgr::appendSuffix(pmap["name"], Memfile_LeaseMgr::FILE_PID));
  1050. pid_file.write();
  1051. // There is a pid file and the process which pid is in the file is
  1052. // running, so the backend should refuse to start.
  1053. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr;
  1054. ASSERT_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)),
  1055. DbOpenError);
  1056. // Remove the pid file, and retry. The bakckend should be created.
  1057. pid_file.deleteFile();
  1058. ASSERT_NO_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)));
  1059. }
  1060. // This test checks that the backend reads DHCPv6 lease data from multiple
  1061. // files.
  1062. TEST_F(MemfileLeaseMgrTest, load6MultipleLeaseFiles) {
  1063. LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
  1064. io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1065. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1066. "state\n"
  1067. "2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
  1068. "200,200,8,100,0,7,0,1,1,,,1\n"
  1069. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1070. "200,200,8,100,0,7,0,1,1,,,1\n");
  1071. LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
  1072. io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1073. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1074. "state\n"
  1075. "2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
  1076. "200,200,8,100,0,7,0,1,1,,,1\n"
  1077. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1078. "300,800,8,100,0,7,0,1,1,,,1\n"
  1079. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1080. "200,200,8,100,0,7,0,1,1,,,1\n");
  1081. LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
  1082. io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1083. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1084. "state\n"
  1085. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1086. "400,1000,8,100,0,7,0,1,1,,,1\n"
  1087. "2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
  1088. "200,200,8,100,0,7,0,1,1,,,1\n");
  1089. startBackend(V6);
  1090. // This lease only exists in the first file and the cltt should be 0.
  1091. Lease6Ptr lease = lmptr_->getLease6(Lease::TYPE_NA,
  1092. IOAddress("2001:db8:1::1"));
  1093. ASSERT_TRUE(lease);
  1094. EXPECT_EQ(0, lease->cltt_);
  1095. // This lease exists in the first and second file and the cltt should
  1096. // be calculated using the expiration time and the valid lifetime
  1097. // from the second file.
  1098. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2"));
  1099. ASSERT_TRUE(lease);
  1100. EXPECT_EQ(500, lease->cltt_);
  1101. // This lease only exists in the second file and the cltt should be 0.
  1102. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3"));
  1103. ASSERT_TRUE(lease);
  1104. EXPECT_EQ(0, lease->cltt_);
  1105. // This lease exists in the second and third file and the cltt should
  1106. // be calculated using the expiration time and the valid lifetime
  1107. // from the third file.
  1108. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::4"));
  1109. ASSERT_TRUE(lease);
  1110. EXPECT_EQ(600, lease->cltt_);
  1111. // This lease only exists in the third file and the cltt should be 0.
  1112. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::5"));
  1113. ASSERT_TRUE(lease);
  1114. EXPECT_EQ(0, lease->cltt_);
  1115. }
  1116. // This test checks that the backend reads DHCPv6 lease data from the
  1117. // leasefile without the postfix and the file with a .1 postfix when
  1118. // the file with the .2 postfix is missing.
  1119. TEST_F(MemfileLeaseMgrTest, load6MultipleNoSecondFile) {
  1120. LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
  1121. io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1122. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1123. "state\n"
  1124. "2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
  1125. "200,200,8,100,0,7,0,1,1,,,1\n"
  1126. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1127. "300,800,8,100,0,7,0,1,1,,,1\n"
  1128. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1129. "200,200,8,100,0,7,0,1,1,,,1\n");
  1130. LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
  1131. io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1132. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1133. "state\n"
  1134. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1135. "400,1000,8,100,0,7,0,1,1,,,1\n"
  1136. "2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
  1137. "200,200,8,100,0,7,0,1,1,,,1\n");
  1138. startBackend(V6);
  1139. // Check that leases from the leasefile6_0 and leasefile6_0.1 have
  1140. // been loaded.
  1141. Lease6Ptr lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2"));
  1142. ASSERT_TRUE(lease);
  1143. EXPECT_EQ(500, lease->cltt_);
  1144. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3"));
  1145. ASSERT_TRUE(lease);
  1146. EXPECT_EQ(0, lease->cltt_);
  1147. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::4"));
  1148. ASSERT_TRUE(lease);
  1149. EXPECT_EQ(600, lease->cltt_);
  1150. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::5"));
  1151. ASSERT_TRUE(lease);
  1152. EXPECT_EQ(0, lease->cltt_);
  1153. // Make sure that a lease which is not in those files is not loaded.
  1154. EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1")));
  1155. }
  1156. // This test checks that the backend reads DHCPv6 lease data from the
  1157. // leasefile without the postfix and the file with a .2 postfix when
  1158. // the file with the .1 postfix is missing.
  1159. TEST_F(MemfileLeaseMgrTest, load6MultipleNoFirstFile) {
  1160. LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
  1161. io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1162. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1163. "state\n"
  1164. "2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
  1165. "200,200,8,100,0,7,0,1,1,,,1\n"
  1166. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1167. "200,200,8,100,0,7,0,1,1,,,1\n");
  1168. LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
  1169. io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1170. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1171. "state\n"
  1172. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1173. "400,1000,8,100,0,7,0,1,1,,,1\n"
  1174. "2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
  1175. "200,200,8,100,0,7,0,1,1,,,1\n");
  1176. startBackend(V6);
  1177. // Verify that leases which belong to the leasefile6_0.csv and
  1178. // leasefile6_0.2 are loaded.
  1179. Lease6Ptr lease = lmptr_->getLease6(Lease::TYPE_NA,
  1180. IOAddress("2001:db8:1::1"));
  1181. ASSERT_TRUE(lease);
  1182. EXPECT_EQ(0, lease->cltt_);
  1183. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2"));
  1184. ASSERT_TRUE(lease);
  1185. EXPECT_EQ(0, lease->cltt_);
  1186. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::4"));
  1187. ASSERT_TRUE(lease);
  1188. EXPECT_EQ(600, lease->cltt_);
  1189. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::5"));
  1190. ASSERT_TRUE(lease);
  1191. EXPECT_EQ(0, lease->cltt_);
  1192. // A lease which doesn't belong to these files should not be loaded.
  1193. EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3")));
  1194. }
  1195. // This test checks that the lease database backend loads the file with
  1196. // the .completed postfix instead of files with postfixes .1 and .2 if
  1197. // the file with .completed postfix exists.
  1198. TEST_F(MemfileLeaseMgrTest, load6CompletedFile) {
  1199. LeaseFileIO io2(getLeaseFilePath("leasefile6_0.csv.2"));
  1200. io2.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1201. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1202. "state\n"
  1203. "2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
  1204. "200,200,8,100,0,7,0,1,1,,,1\n"
  1205. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1206. "200,200,8,100,0,7,0,1,1,,,1\n");
  1207. LeaseFileIO io1(getLeaseFilePath("leasefile6_0.csv.1"));
  1208. io1.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1209. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1210. "state\n"
  1211. "2001:db8:1::3,03:03:03:03:03:03:03:03:03:03:03:03:03,"
  1212. "200,200,8,100,0,7,0,1,1,,,1\n"
  1213. "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
  1214. "300,800,8,100,0,7,0,1,1,,,1\n"
  1215. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1216. "200,200,8,100,0,7,0,1,1,,,1\n");
  1217. LeaseFileIO io(getLeaseFilePath("leasefile6_0.csv"));
  1218. io.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1219. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1220. "state\n"
  1221. "2001:db8:1::4,04:04:04:04:04:04:04:04:04:04:04:04:04,"
  1222. "400,1000,8,100,0,7,0,1,1,,,1\n"
  1223. "2001:db8:1::5,05:05:05:05:05:05:05:05:05:05:05:05:05,"
  1224. "200,200,8,100,0,7,0,1,1,,,1\n");
  1225. LeaseFileIO ioc(getLeaseFilePath("leasefile6_0.csv.completed"));
  1226. ioc.writeFile("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
  1227. "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
  1228. "state\n"
  1229. "2001:db8:1::125,ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff,"
  1230. "400,1000,8,100,0,7,0,1,1,,,1\n");
  1231. startBackend(V6);
  1232. // We expect that this file only holds leases that belong to the
  1233. // lease file or to the file with .completed postfix.
  1234. Lease6Ptr lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::4"));
  1235. ASSERT_TRUE(lease);
  1236. EXPECT_EQ(600, lease->cltt_);
  1237. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::5"));
  1238. ASSERT_TRUE(lease);
  1239. EXPECT_EQ(0, lease->cltt_);
  1240. lease = lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::125"));
  1241. ASSERT_TRUE(lease);
  1242. EXPECT_EQ(600, lease->cltt_);
  1243. // Leases from the .1 and .2 files should not be loaded.
  1244. EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1")));
  1245. EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2")));
  1246. EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::3")));
  1247. }
  1248. // This test checks that backend constructor refuses to load leases from the
  1249. // lease files if the LFC is in progress.
  1250. TEST_F(MemfileLeaseMgrTest, load6LFCInProgress) {
  1251. // Create the backend configuration.
  1252. DatabaseConnection::ParameterMap pmap;
  1253. pmap["type"] = "memfile";
  1254. pmap["universe"] = "6";
  1255. pmap["name"] = getLeaseFilePath("leasefile6_0.csv");
  1256. pmap["lfc-interval"] = "1";
  1257. // Create a pid file holding the PID of the current process. Choosing the
  1258. // pid of the current process guarantees that when the backend starts up
  1259. // the process is alive.
  1260. PIDFile pid_file(Memfile_LeaseMgr::appendSuffix(pmap["name"], Memfile_LeaseMgr::FILE_PID));
  1261. pid_file.write();
  1262. // There is a pid file and the process which pid is in the file is
  1263. // running, so the backend should refuse to start.
  1264. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr;
  1265. ASSERT_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)),
  1266. DbOpenError);
  1267. // Remove the pid file, and retry. The bakckend should be created.
  1268. pid_file.deleteFile();
  1269. ASSERT_NO_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)));
  1270. }
  1271. // Verifies that LFC is automatically run during MemfileLeasemMgr construction
  1272. // when the lease file(s) being loaded need to be upgraded.
  1273. TEST_F(MemfileLeaseMgrTest, leaseUpgrade4) {
  1274. // Create header strings for each schema
  1275. std::string header_1_0 =
  1276. "address,hwaddr,client_id,valid_lifetime,expire,"
  1277. "subnet_id,fqdn_fwd,fqdn_rev,hostname\n";
  1278. std::string header_2_0 =
  1279. "address,hwaddr,client_id,valid_lifetime,expire,"
  1280. "subnet_id,fqdn_fwd,fqdn_rev,hostname,state\n";
  1281. // Create 1.0 Schema current lease file with two entries for
  1282. // the same lease
  1283. std::string current_file_contents = header_1_0 +
  1284. "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,\n"
  1285. "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,\n";
  1286. LeaseFileIO current_file(getLeaseFilePath("leasefile4_0.csv"));
  1287. current_file.writeFile(current_file_contents);
  1288. // Create 1.0 Schema previous lease file, with two entries for
  1289. // a another lease
  1290. std::string previous_file_contents = header_1_0 +
  1291. "192.0.2.3,03:03:03:03:03:03,,200,200,8,1,1,\n"
  1292. "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,\n";
  1293. LeaseFileIO previous_file(getLeaseFilePath("leasefile4_0.csv.2"));
  1294. previous_file.writeFile(previous_file_contents);
  1295. // Create the backend.
  1296. DatabaseConnection::ParameterMap pmap;
  1297. pmap["type"] = "memfile";
  1298. pmap["universe"] = "4";
  1299. pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
  1300. pmap["lfc-interval"] = "0";
  1301. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  1302. // Since lease files are loaded during lease manager
  1303. // constructor, LFC should get launched automatically.
  1304. // The new lease file should be 2.0 schema and have no entries
  1305. ASSERT_TRUE(current_file.exists());
  1306. EXPECT_EQ(header_2_0, current_file.readFile());
  1307. // Wait for the LFC process to complete and
  1308. // make sure it has returned an exit status of 0.
  1309. ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
  1310. ASSERT_EQ(0, lease_mgr->getLFCExitStatus())
  1311. << "Executing the LFC process failed: make sure that"
  1312. " the kea-lfc program has been compiled.";
  1313. // The LFC should have created a 2.0 schema completion file with the
  1314. // one entry for each lease and moved it to leasefile4_0.csv.2
  1315. LeaseFileIO input_file(getLeaseFilePath("leasefile4_0.csv.2"), false);
  1316. ASSERT_TRUE(input_file.exists());
  1317. // Verify cleaned, converted contents
  1318. std::string result_file_contents = header_2_0 +
  1319. "192.0.2.2,02:02:02:02:02:02,,200,800,8,1,1,,0\n"
  1320. "192.0.2.3,03:03:03:03:03:03,,200,800,8,1,1,,0\n";
  1321. EXPECT_EQ(result_file_contents, input_file.readFile());
  1322. }
  1323. TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) {
  1324. // Create header strings for all three schemas
  1325. std::string header_1_0 =
  1326. "address,duid,valid_lifetime,expire,subnet_id,"
  1327. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  1328. "fqdn_rev,hostname\n";
  1329. std::string header_2_0 =
  1330. "address,duid,valid_lifetime,expire,subnet_id,"
  1331. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  1332. "fqdn_rev,hostname,hwaddr\n";
  1333. std::string header_3_0 =
  1334. "address,duid,valid_lifetime,expire,subnet_id,"
  1335. "pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
  1336. "fqdn_rev,hostname,hwaddr,state\n";
  1337. // The current lease file is schema 1.0 and has two entries for
  1338. // the same lease
  1339. std::string current_file_contents = header_1_0 +
  1340. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,"
  1341. "8,100,0,7,0,1,1,,\n"
  1342. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  1343. "8,100,0,7,0,1,1,,\n";
  1344. LeaseFileIO current_file(getLeaseFilePath("leasefile6_0.csv"));
  1345. current_file.writeFile(current_file_contents);
  1346. // The previous lease file is schema 2.0 and has two entries for
  1347. // a different lease
  1348. std::string previous_file_contents = header_2_0 +
  1349. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,200,"
  1350. "8,100,0,7,0,1,1,,11:22:33:44:55\n"
  1351. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  1352. "8,100,0,7,0,1,1,,11:22:33:44:55\n";
  1353. LeaseFileIO previous_file(getLeaseFilePath("leasefile6_0.csv.2"));
  1354. previous_file.writeFile(previous_file_contents);
  1355. // Create the backend.
  1356. DatabaseConnection::ParameterMap pmap;
  1357. pmap["type"] = "memfile";
  1358. pmap["universe"] = "6";
  1359. pmap["name"] = getLeaseFilePath("leasefile6_0.csv");
  1360. pmap["lfc-interval"] = "0";
  1361. boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
  1362. // Since lease files are loaded during lease manager
  1363. // constructor, LFC should get launched automatically.
  1364. // The new lease file should been 3.0 and contain no leases.
  1365. ASSERT_TRUE(current_file.exists());
  1366. EXPECT_EQ(header_3_0, current_file.readFile());
  1367. // Wait for the LFC process to complete and
  1368. // make sure it has returned an exit status of 0.
  1369. ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
  1370. ASSERT_EQ(0, lease_mgr->getLFCExitStatus())
  1371. << "Executing the LFC process failed: make sure that"
  1372. " the kea-lfc program has been compiled.";
  1373. // The LFC should have created a 3.0 schema cleaned file with one entry
  1374. // for each lease as leasefile6_0.csv.2
  1375. LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.2"), false);
  1376. ASSERT_TRUE(input_file.exists());
  1377. // Verify cleaned, converted contents
  1378. std::string result_file_contents = header_3_0 +
  1379. "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
  1380. "8,100,0,7,0,1,1,,,0\n"
  1381. "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
  1382. "8,100,0,7,0,1,1,,11:22:33:44:55,0\n";
  1383. EXPECT_EQ(result_file_contents, input_file.readFile());
  1384. }
  1385. // This test verifies that the indexes of the container holding
  1386. // DHCPv4 leases are updated correctly when a lease is updated.
  1387. TEST_F(MemfileLeaseMgrTest, lease4ContainerIndexUpdate) {
  1388. const uint32_t seed = 12345678; // Used to initialize the random generator
  1389. const uint32_t leases_cnt = 100; // Number of leases generated per round.
  1390. const uint32_t updates_cnt = 5; // Number of times existing leases are updated
  1391. const string leasefile(getLeaseFilePath("leasefile4_0.csv"));
  1392. // Parameters for the lease file. Make sure the leases are persistent, so they
  1393. // are written to disk.
  1394. DatabaseConnection::ParameterMap pmap;
  1395. pmap["universe"] = "4";
  1396. pmap["name"] = leasefile;
  1397. pmap["persist"] = "true";
  1398. srand(seed);
  1399. IOAddress addr("10.0.0.1"); // Let's generate leases sequentially
  1400. // Recreate Memfile_LeaseMgr.
  1401. LeaseMgrFactory::destroy();
  1402. ASSERT_NO_THROW(lmptr_ = new Memfile_LeaseMgr(pmap));
  1403. // We will store addresses here, so it will be easier to randomly
  1404. // pick a lease.
  1405. std::vector<IOAddress> lease_addresses;
  1406. // Generate random leases. We remember their addresses in
  1407. // lease_addresses.
  1408. for (uint32_t i = 0; i < leases_cnt; ++i) {
  1409. Lease4Ptr lease = initiateRandomLease4(addr);
  1410. lease_addresses.push_back(addr);
  1411. ASSERT_NO_THROW(lmptr_->addLease(lease));
  1412. addr = IOAddress::increase(addr);
  1413. }
  1414. // Check that we inserted correct number of leases.
  1415. ASSERT_EQ(leases_cnt, lease_addresses.size());
  1416. // Now, conduct updates. We call initiateRandomLease4(), so most
  1417. // of the fields are randomly changed. The only constant field
  1418. // is the address.
  1419. for (uint32_t i = 0; i < updates_cnt; ++i) {
  1420. uint32_t offset = random() % lease_addresses.size();
  1421. Lease4Ptr existing(lmptr_->getLease4(lease_addresses[offset]));
  1422. Lease4Ptr updated(initiateRandomLease4(lease_addresses[offset]));
  1423. // Update a lease with new data but preserve lease address.
  1424. // This update should also cause lease container indexes to
  1425. // be updated.
  1426. ASSERT_NO_THROW(lmptr_->updateLease4(updated))
  1427. << "Attempt " << i << " out of " << updates_cnt
  1428. << ":Failed to update lease for address "
  1429. << lease_addresses[offset];
  1430. }
  1431. // Re-create lease manager to cause it to reload leases
  1432. // from a lease file. We want to make sure that lease
  1433. // container is rebuilt correctly and the indexes are
  1434. // consistent with lease information held.
  1435. ASSERT_NO_THROW({
  1436. LeaseMgrFactory::destroy();
  1437. lmptr_ = new Memfile_LeaseMgr(pmap);
  1438. });
  1439. // Ok, let's check if the leases are really accessible.
  1440. // First, build an array of leases. Get them by address.
  1441. // This should work in general, as we haven't updated the addresses.
  1442. std::vector<Lease4Ptr> leases;
  1443. for (uint32_t i = 0; i < lease_addresses.size(); ++i) {
  1444. Lease4Ptr from_mgr = lmptr_->getLease4(lease_addresses[i]);
  1445. ASSERT_TRUE(from_mgr) << "Lease for address " << lease_addresses[i].toText()
  1446. << " not found";
  1447. leases.push_back(from_mgr);
  1448. }
  1449. ASSERT_EQ(leases_cnt, leases.size());
  1450. // Now do the actual checks.
  1451. for (uint32_t i = 0; i < leases.size(); ++i) {
  1452. Lease4Ptr tested = leases[i];
  1453. // Get the lease by different access patterns.
  1454. // In properly working lease manager all queries should return
  1455. // exactly the same lease.
  1456. std::string error_desc = " which indicates that the lease indexes were"
  1457. " not updated correctly when the lease was updated.";
  1458. // Retrieve lease by address.
  1459. Lease4Ptr lease_by_address = lmptr_->getLease4(tested->addr_);
  1460. ASSERT_TRUE(lease_by_address)
  1461. << "Lease " << tested->addr_.toText()
  1462. << " not found by getLease4(addr)"
  1463. << error_desc;
  1464. detailCompareLease(tested, lease_by_address);
  1465. // Retrieve lease by HW address and subnet id.
  1466. Lease4Ptr lease_by_hwaddr_subnet = lmptr_->getLease4(*tested->hwaddr_,
  1467. tested->subnet_id_);
  1468. ASSERT_TRUE(lease_by_hwaddr_subnet)
  1469. << "Lease " << tested->addr_.toText()
  1470. << " not found by getLease4(hwaddr, subnet_id)"
  1471. << error_desc;
  1472. detailCompareLease(tested, lease_by_hwaddr_subnet);
  1473. // Retrieve lease by client identifier and subnet id.
  1474. Lease4Ptr lease_by_clientid_subnet = lmptr_->getLease4(*tested->client_id_,
  1475. tested->subnet_id_);
  1476. ASSERT_TRUE(lease_by_clientid_subnet)
  1477. << "Lease " << tested->addr_.toText()
  1478. << " not found by getLease4(clientid, subnet_id)"
  1479. << error_desc;
  1480. detailCompareLease(tested, lease_by_clientid_subnet);
  1481. // Retrieve lease by client id, HW address and subnet.
  1482. Lease4Ptr lease_by_clientid_hwaddr_subnet = lmptr_->getLease4(*tested->client_id_,
  1483. *tested->hwaddr_,
  1484. tested->subnet_id_);
  1485. ASSERT_TRUE(lease_by_clientid_hwaddr_subnet)
  1486. << "Lease " << tested->addr_.toText()
  1487. << " not found by getLease4(clientid, hwaddr, subnet_id)"
  1488. << error_desc;
  1489. detailCompareLease(tested, lease_by_clientid_hwaddr_subnet);
  1490. // Retrieve lease by HW address.
  1491. Lease4Collection leases_by_hwaddr = lmptr_->getLease4(*tested->hwaddr_);
  1492. ASSERT_EQ(1, leases_by_hwaddr.size());
  1493. detailCompareLease(tested, leases_by_hwaddr[0]);
  1494. // Retrieve lease by client identifier.
  1495. Lease4Collection leases_by_client_id = lmptr_->getLease4(*tested->client_id_);
  1496. ASSERT_EQ(1, leases_by_client_id.size());
  1497. detailCompareLease(tested, leases_by_client_id[0]);
  1498. }
  1499. }
  1500. // This test verifies that the indexes of the container holding
  1501. // DHCPv4 leases are updated correctly when a lease is updated.
  1502. TEST_F(MemfileLeaseMgrTest, lease6ContainerIndexUpdate) {
  1503. const uint32_t seed = 12345678; // Used to initialize the random generator
  1504. const uint32_t leases_cnt = 100; // Number of leases generated per round.
  1505. const uint32_t updates_cnt = 5; // Number of times existing leases are updated
  1506. const string leasefile(getLeaseFilePath("leasefile6_0.csv"));
  1507. // Parameters for the lease file. Make sure the leases are persistent, so they
  1508. // are written to disk.
  1509. DatabaseConnection::ParameterMap pmap;
  1510. pmap["universe"] = "6";
  1511. pmap["name"] = leasefile;
  1512. pmap["persist"] = "true";
  1513. srand(seed);
  1514. IOAddress addr("2001:db8:1::1"); // Let's generate leases sequentially
  1515. // Recreate Memfile_LeaseMgr.
  1516. LeaseMgrFactory::destroy();
  1517. ASSERT_NO_THROW(lmptr_ = new Memfile_LeaseMgr(pmap));
  1518. // We will store addresses here, so it will be easier to randomly
  1519. // pick a lease.
  1520. std::vector<IOAddress> lease_addresses;
  1521. // Generate random leases. We remember their addresses in
  1522. // lease_addresses.
  1523. for (uint32_t i = 0; i < leases_cnt; ++i) {
  1524. Lease6Ptr lease = initiateRandomLease6(addr);
  1525. lease_addresses.push_back(addr);
  1526. ASSERT_NO_THROW(lmptr_->addLease(lease));
  1527. addr = IOAddress::increase(addr);
  1528. }
  1529. // Check that we inserted correct number of leases.
  1530. ASSERT_EQ(leases_cnt, lease_addresses.size());
  1531. // Now, conduct updates. We call initiateRandomLease6(), so most
  1532. // of the fields are randomly changed. The only constant field
  1533. // is the address.
  1534. for (uint32_t i = 0; i < updates_cnt; ++i) {
  1535. uint32_t offset = random() % lease_addresses.size();
  1536. Lease6Ptr existing(lmptr_->getLease6(Lease::TYPE_NA,
  1537. lease_addresses[offset]));
  1538. Lease6Ptr updated(initiateRandomLease6(lease_addresses[offset]));
  1539. // Update a lease with new data but preserve lease address.
  1540. // This update should also cause lease container indexes to
  1541. // be updated.
  1542. ASSERT_NO_THROW(lmptr_->updateLease6(updated))
  1543. << "Attempt " << i << " out of " << updates_cnt
  1544. << ":Failed to update lease for address "
  1545. << lease_addresses[offset];
  1546. }
  1547. // Re-create lease manager to cause it to reload leases
  1548. // from a lease file. We want to make sure that lease
  1549. // container is rebuilt correctly and the indexes are
  1550. // consistent with lease information held.
  1551. ASSERT_NO_THROW({
  1552. LeaseMgrFactory::destroy();
  1553. lmptr_ = new Memfile_LeaseMgr(pmap);
  1554. });
  1555. // Ok, let's check if the leases are really accessible.
  1556. // First, build an array of leases. Get them by address.
  1557. // This should work in general, as we haven't updated the addresses.
  1558. std::vector<Lease6Ptr> leases;
  1559. for (uint32_t i = 0; i < lease_addresses.size(); ++i) {
  1560. Lease6Ptr from_mgr = lmptr_->getLease6(Lease::TYPE_NA,
  1561. lease_addresses[i]);
  1562. ASSERT_TRUE(from_mgr) << "Lease for address " << lease_addresses[i].toText()
  1563. << " not found";
  1564. leases.push_back(from_mgr);
  1565. }
  1566. ASSERT_EQ(leases_cnt, leases.size());
  1567. // Now do the actual checks.
  1568. for (uint32_t i = 0; i < leases.size(); ++i) {
  1569. Lease6Ptr tested = leases[i];
  1570. // Get the lease by different access patterns.
  1571. // In properly working lease manager all queries should return
  1572. // exactly the same lease.
  1573. std::string error_desc = " which indicates that the lease indexes were"
  1574. " not updated correctly when the lease was updated.";
  1575. // Retrieve lease by address.
  1576. Lease6Ptr lease_by_address = lmptr_->getLease6(Lease::TYPE_NA,
  1577. tested->addr_);
  1578. ASSERT_TRUE(lease_by_address)
  1579. << "Lease " << tested->addr_.toText()
  1580. << " not found by getLease6(addr)"
  1581. << error_desc;
  1582. detailCompareLease(tested, lease_by_address);
  1583. // Retrieve lease by type, DUID, IAID.
  1584. Lease6Collection leases_by_duid_iaid = lmptr_->getLeases6(tested->type_,
  1585. *tested->duid_,
  1586. tested->iaid_);
  1587. ASSERT_EQ(1, leases_by_duid_iaid.size());
  1588. ASSERT_TRUE(leases_by_duid_iaid[0])
  1589. << "Lease " << tested->addr_.toText()
  1590. << " not found by getLease6(type, duid, iaid)"
  1591. << error_desc;
  1592. detailCompareLease(tested, leases_by_duid_iaid[0]);
  1593. // Retrieve lease by type, DUID, IAID, subnet identifier.
  1594. Lease6Collection leases_by_duid_iaid_subnet =
  1595. lmptr_->getLeases6(tested->type_, *tested->duid_,
  1596. tested->iaid_, tested->subnet_id_);
  1597. ASSERT_EQ(1, leases_by_duid_iaid_subnet.size());
  1598. ASSERT_TRUE(leases_by_duid_iaid_subnet[0])
  1599. << "Lease " << tested->addr_.toText()
  1600. << " not found by getLease6(type, duid, iaid, subnet_id)"
  1601. << error_desc;
  1602. detailCompareLease(tested, leases_by_duid_iaid_subnet[0]);
  1603. }
  1604. }
  1605. // Verifies that IPv4 lease statistics can be recalculated.
  1606. TEST_F(MemfileLeaseMgrTest, recountLeaseStats4) {
  1607. startBackend(V4);
  1608. testRecountLeaseStats4();
  1609. }
  1610. // Verifies that IPv6 lease statistics can be recalculated.
  1611. TEST_F(MemfileLeaseMgrTest, recountLeaseStats6) {
  1612. startBackend(V6);
  1613. testRecountLeaseStats6();
  1614. }
  1615. }; // end of anonymous namespace