lease_mgr_unittest.cc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <asiolink/io_address.h>
  16. #include <dhcpsrv/lease_mgr.h>
  17. #include <gtest/gtest.h>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <time.h>
  21. using namespace std;
  22. using namespace isc;
  23. using namespace isc::asiolink;
  24. using namespace isc::dhcp;
  25. // This is a concrete implementation of a Lease database. It does not do
  26. // anything useful and is used for abstract LeaseMgr class testing.
  27. class ConcreteLeaseMgr : public LeaseMgr {
  28. public:
  29. /// @brief The sole lease manager constructor
  30. ///
  31. /// dbconfig is a generic way of passing parameters. Parameters
  32. /// are passed in the "name=value" format, separated by spaces.
  33. /// Values may be enclosed in double quotes, if needed.
  34. ///
  35. /// @param parameters A data structure relating keywords and values
  36. /// concerned with the database.
  37. ConcreteLeaseMgr(const LeaseMgr::ParameterMap& parameters)
  38. : LeaseMgr(parameters)
  39. {}
  40. /// @brief Destructor
  41. virtual ~ConcreteLeaseMgr()
  42. {}
  43. /// @brief Adds an IPv4 lease.
  44. ///
  45. /// @param lease lease to be added
  46. virtual bool addLease(const Lease4Ptr&) {
  47. return (false);
  48. }
  49. /// @brief Adds an IPv6 lease.
  50. ///
  51. /// @param lease lease to be added
  52. virtual bool addLease(const Lease6Ptr&) {
  53. return (false);
  54. }
  55. /// @brief Returns existing IPv4 lease for specified IPv4 address.
  56. ///
  57. /// @param addr address of the searched lease
  58. ///
  59. /// @return smart pointer to the lease (or NULL if a lease is not found)
  60. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress&) const {
  61. return (Lease4Ptr());
  62. }
  63. /// @brief Returns existing IPv4 lease for specific address and subnet
  64. /// @param addr address of the searched lease
  65. /// @param subnet_id ID of the subnet the lease must belong to
  66. ///
  67. /// @return smart pointer to the lease (or NULL if a lease is not found)
  68. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress&,
  69. SubnetID) const {
  70. return (Lease4Ptr());
  71. }
  72. /// @brief Returns existing IPv4 leases for specified hardware address.
  73. ///
  74. /// Although in the usual case there will be only one lease, for mobile
  75. /// clients or clients with multiple static/fixed/reserved leases there
  76. /// can be more than one. Thus return type is a container, not a single
  77. /// pointer.
  78. ///
  79. /// @param hwaddr hardware address of the client
  80. ///
  81. /// @return lease collection
  82. virtual Lease4Collection getLease4(const HWAddr&) const {
  83. return (Lease4Collection());
  84. }
  85. /// @brief Returns existing IPv4 leases for specified hardware address
  86. /// and a subnet
  87. ///
  88. /// There can be at most one lease for a given HW address in a single
  89. /// pool, so this method with either return a single lease or NULL.
  90. ///
  91. /// @param hwaddr hardware address of the client
  92. /// @param subnet_id identifier of the subnet that lease must belong to
  93. ///
  94. /// @return a pointer to the lease (or NULL if a lease is not found)
  95. virtual Lease4Ptr getLease4(const HWAddr&, SubnetID) const {
  96. return (Lease4Ptr());
  97. }
  98. /// @brief Returns existing IPv4 lease for specified client-id
  99. ///
  100. /// @param clientid client identifier
  101. ///
  102. /// @return lease collection
  103. virtual Lease4Collection getLease4(const ClientId&) const {
  104. return (Lease4Collection());
  105. }
  106. /// @brief Returns existing IPv4 lease for specified client-id
  107. ///
  108. /// There can be at most one lease for a given HW address in a single
  109. /// pool, so this method with either return a single lease or NULL.
  110. ///
  111. /// @param clientid client identifier
  112. /// @param subnet_id identifier of the subnet that lease must belong to
  113. ///
  114. /// @return a pointer to the lease (or NULL if a lease is not found)
  115. virtual Lease4Ptr getLease4(const ClientId&, SubnetID) const {
  116. return (Lease4Ptr());
  117. }
  118. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  119. ///
  120. /// @param addr address of the searched lease
  121. ///
  122. /// @return smart pointer to the lease (or NULL if a lease is not found)
  123. virtual Lease6Ptr getLease6(const isc::asiolink::IOAddress&) const {
  124. return (Lease6Ptr());
  125. }
  126. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  127. ///
  128. /// @param duid client DUID
  129. /// @param iaid IA identifier
  130. ///
  131. /// @return collection of IPv6 leases
  132. virtual Lease6Collection getLease6(const DUID&, uint32_t) const {
  133. return (Lease6Collection());
  134. }
  135. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  136. ///
  137. /// @param duid client DUID
  138. /// @param iaid IA identifier
  139. /// @param subnet_id identifier of the subnet the lease must belong to
  140. ///
  141. /// @return smart pointer to the lease (or NULL if a lease is not found)
  142. virtual Lease6Ptr getLease6(const DUID&, uint32_t, SubnetID) const {
  143. return (Lease6Ptr());
  144. }
  145. /// @brief Updates IPv4 lease.
  146. ///
  147. /// @param lease4 The lease to be updated.
  148. ///
  149. /// If no such lease is present, an exception will be thrown.
  150. virtual void updateLease4(const Lease4Ptr&) {}
  151. /// @brief Updates IPv4 lease.
  152. ///
  153. /// @param lease4 The lease to be updated.
  154. ///
  155. /// If no such lease is present, an exception will be thrown.
  156. virtual void updateLease6(const Lease6Ptr&) {}
  157. /// @brief Deletes a lease.
  158. ///
  159. /// @param addr IPv4 address of the lease to be deleted.
  160. ///
  161. /// @return true if deletion was successful, false if no such lease exists
  162. virtual bool deleteLease4(const isc::asiolink::IOAddress&) {
  163. return (false);
  164. }
  165. /// @brief Deletes a lease.
  166. ///
  167. /// @param addr IPv4 address of the lease to be deleted.
  168. ///
  169. /// @return true if deletion was successful, false if no such lease exists
  170. virtual bool deleteLease6(const isc::asiolink::IOAddress&) {
  171. return (false);
  172. }
  173. /// @brief Returns backend type.
  174. ///
  175. /// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
  176. ///
  177. /// @return Type of the backend.
  178. virtual std::string getType() const {
  179. return (std::string("concrete"));
  180. }
  181. /// @brief Returns backend name.
  182. ///
  183. /// If the backend is a database, this is the name of the database or the
  184. /// file. Otherwise it is just the same as the type.
  185. ///
  186. /// @return Name of the backend.
  187. virtual std::string getName() const {
  188. return (std::string("concrete"));
  189. }
  190. /// @brief Returns description of the backend.
  191. ///
  192. /// This description may be multiline text that describes the backend.
  193. ///
  194. /// @return Description of the backend.
  195. virtual std::string getDescription() const {
  196. return (std::string("This is a dummy concrete backend implementation."));
  197. }
  198. /// @brief Returns backend version.
  199. virtual std::pair<uint32_t, uint32_t> getVersion() const {
  200. return (make_pair(uint32_t(0), uint32_t(0)));
  201. }
  202. /// @brief Commit transactions
  203. virtual void commit() {
  204. }
  205. /// @brief Rollback transactions
  206. virtual void rollback() {
  207. }
  208. };
  209. namespace {
  210. /// @brief getParameter test
  211. ///
  212. /// This test checks if the LeaseMgr can be instantiated and that it
  213. /// parses parameters string properly.
  214. TEST(LeaseMgr, getParameter) {
  215. LeaseMgr::ParameterMap pmap;
  216. pmap[std::string("param1")] = std::string("value1");
  217. pmap[std::string("param2")] = std::string("value2");
  218. ConcreteLeaseMgr leasemgr(pmap);
  219. EXPECT_EQ("value1", leasemgr.getParameter("param1"));
  220. EXPECT_EQ("value2", leasemgr.getParameter("param2"));
  221. EXPECT_THROW(leasemgr.getParameter("param3"), BadValue);
  222. }
  223. // There's no point in calling any other methods in LeaseMgr, as they
  224. // are purely virtual, so we would only call ConcreteLeaseMgr methods.
  225. // Those methods are just stubs that do not return anything.
  226. /// @brief Lease4 Constructor Test
  227. ///
  228. /// Lease4 is also defined in lease_mgr.h, so is tested in this file as well.
  229. // This test checks if the Lease4 structure can be instantiated correctly
  230. TEST(Lease4, Lease4Constructor) {
  231. // Random values for the tests
  232. const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
  233. std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
  234. const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
  235. std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
  236. ClientId clientid(clientid_vec);
  237. // ...and a time
  238. const time_t current_time = time(NULL);
  239. // Other random constants.
  240. const uint32_t SUBNET_ID = 42;
  241. const uint32_t VALID_LIFETIME = 500;
  242. // We want to check that various addresses work, so let's iterate over
  243. // these.
  244. const uint32_t ADDRESS[] = {
  245. 0x00000000, 0x01020304, 0x7fffffff, 0x80000000, 0x80000001, 0xffffffff
  246. };
  247. for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
  248. // Create the lease
  249. Lease4 lease(ADDRESS[i], HWADDR, sizeof(HWADDR),
  250. CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time,
  251. SUBNET_ID);
  252. EXPECT_EQ(ADDRESS[i], static_cast<uint32_t>(lease.addr_));
  253. EXPECT_EQ(0, lease.ext_);
  254. EXPECT_TRUE(hwaddr == lease.hwaddr_);
  255. EXPECT_TRUE(clientid == *lease.client_id_);
  256. EXPECT_EQ(0, lease.t1_);
  257. EXPECT_EQ(0, lease.t2_);
  258. EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
  259. EXPECT_EQ(current_time, lease.cltt_);
  260. EXPECT_EQ(SUBNET_ID, lease.subnet_id_);
  261. EXPECT_FALSE(lease.fixed_);
  262. EXPECT_TRUE(lease.hostname_.empty());
  263. EXPECT_FALSE(lease.fqdn_fwd_);
  264. EXPECT_FALSE(lease.fqdn_rev_);
  265. EXPECT_TRUE(lease.comments_.empty());
  266. }
  267. }
  268. /// @brief Lease4 Equality Test
  269. ///
  270. /// Checks that the operator==() correctly compares two leases for equality.
  271. /// As operator!=() is also defined for this class, every check on operator==()
  272. /// is followed by the reverse check on operator!=().
  273. TEST(Lease4, OperatorEquals) {
  274. // Random values for the tests
  275. const uint32_t ADDRESS = 0x01020304;
  276. const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
  277. std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
  278. const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
  279. std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
  280. ClientId clientid(clientid_vec);
  281. const time_t current_time = time(NULL);
  282. const uint32_t SUBNET_ID = 42;
  283. const uint32_t VALID_LIFETIME = 500;
  284. // Check when the leases are equal.
  285. Lease4 lease1(ADDRESS, HWADDR, sizeof(HWADDR),
  286. CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time,
  287. SUBNET_ID);
  288. Lease4 lease2(ADDRESS, HWADDR, sizeof(HWADDR),
  289. CLIENTID, sizeof(CLIENTID), VALID_LIFETIME, current_time,
  290. SUBNET_ID);
  291. EXPECT_TRUE(lease1 == lease2);
  292. EXPECT_FALSE(lease1 != lease2);
  293. // Now vary individual fields in a lease and check that the leases compare
  294. // not equal in every case.
  295. lease1.addr_ = IOAddress(ADDRESS + 1);
  296. EXPECT_FALSE(lease1 == lease2);
  297. EXPECT_TRUE(lease1 != lease2);
  298. lease1.addr_ = lease2.addr_;
  299. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  300. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  301. ++lease1.ext_;
  302. EXPECT_FALSE(lease1 == lease2);
  303. EXPECT_TRUE(lease1 != lease2);
  304. lease1.ext_ = lease2.ext_;
  305. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  306. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  307. ++lease1.hwaddr_[0];
  308. EXPECT_FALSE(lease1 == lease2);
  309. EXPECT_TRUE(lease1 != lease2);
  310. lease1.hwaddr_ = lease2.hwaddr_;
  311. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  312. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  313. ++clientid_vec[0];
  314. lease1.client_id_.reset(new ClientId(clientid_vec));
  315. EXPECT_FALSE(lease1 == lease2);
  316. EXPECT_TRUE(lease1 != lease2);
  317. --clientid_vec[0];
  318. lease1.client_id_.reset(new ClientId(clientid_vec));
  319. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  320. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  321. ++lease1.t1_;
  322. EXPECT_FALSE(lease1 == lease2);
  323. EXPECT_TRUE(lease1 != lease2);
  324. lease1.t1_ = lease2.t1_;
  325. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  326. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  327. ++lease1.t2_;
  328. EXPECT_FALSE(lease1 == lease2);
  329. EXPECT_TRUE(lease1 != lease2);
  330. lease1.t2_ = lease2.t2_;
  331. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  332. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  333. ++lease1.valid_lft_;
  334. EXPECT_FALSE(lease1 == lease2);
  335. EXPECT_TRUE(lease1 != lease2);
  336. lease1.valid_lft_ = lease2.valid_lft_;
  337. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  338. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  339. ++lease1.cltt_;
  340. EXPECT_FALSE(lease1 == lease2);
  341. EXPECT_TRUE(lease1 != lease2);
  342. lease1.cltt_ = lease2.cltt_;
  343. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  344. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  345. ++lease1.subnet_id_;
  346. EXPECT_FALSE(lease1 == lease2);
  347. EXPECT_TRUE(lease1 != lease2);
  348. lease1.subnet_id_ = lease2.subnet_id_;
  349. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  350. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  351. lease1.fixed_ = !lease1.fixed_;
  352. EXPECT_FALSE(lease1 == lease2);
  353. EXPECT_TRUE(lease1 != lease2);
  354. lease1.fixed_ = lease2.fixed_;
  355. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  356. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  357. lease1.hostname_ += string("Something random");
  358. EXPECT_FALSE(lease1 == lease2);
  359. EXPECT_TRUE(lease1 != lease2);
  360. lease1.hostname_ = lease2.hostname_;
  361. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  362. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  363. lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
  364. EXPECT_FALSE(lease1 == lease2);
  365. EXPECT_TRUE(lease1 != lease2);
  366. lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
  367. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  368. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  369. lease1.fqdn_rev_ = !lease1.fqdn_rev_;
  370. EXPECT_FALSE(lease1 == lease2);
  371. EXPECT_TRUE(lease1 != lease2);
  372. lease1.fqdn_rev_ = lease2.fqdn_rev_;
  373. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  374. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  375. lease1.comments_ += string("Something random");
  376. EXPECT_FALSE(lease1 == lease2);
  377. EXPECT_TRUE(lease1 != lease2);
  378. lease1.comments_ = lease2.comments_;
  379. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  380. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  381. }
  382. // Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
  383. // This test checks if the Lease6 structure can be instantiated correctly
  384. TEST(Lease6, Lease6Constructor) {
  385. // check a variety of addresses with different bits set.
  386. const char* ADDRESS[] = {
  387. "::", "::1", "2001:db8:1::456",
  388. "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
  389. "8000::", "8000::1",
  390. "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
  391. };
  392. // Other values
  393. uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
  394. DuidPtr duid(new DUID(llt, sizeof(llt)));
  395. uint32_t iaid = 7; // just a number
  396. SubnetID subnet_id = 8; // just another number
  397. for (int i = 0; i < sizeof(ADDRESS) / sizeof(ADDRESS[0]); ++i) {
  398. IOAddress addr(ADDRESS[i]);
  399. Lease6Ptr lease(new Lease6(Lease6::LEASE_IA_NA, addr,
  400. duid, iaid, 100, 200, 50, 80,
  401. subnet_id));
  402. EXPECT_TRUE(lease->addr_ == addr);
  403. EXPECT_TRUE(*lease->duid_ == *duid);
  404. EXPECT_TRUE(lease->iaid_ == iaid);
  405. EXPECT_TRUE(lease->subnet_id_ == subnet_id);
  406. EXPECT_TRUE(lease->type_ == Lease6::LEASE_IA_NA);
  407. EXPECT_TRUE(lease->preferred_lft_ == 100);
  408. EXPECT_TRUE(lease->valid_lft_ == 200);
  409. EXPECT_TRUE(lease->t1_ == 50);
  410. EXPECT_TRUE(lease->t2_ == 80);
  411. }
  412. // Lease6 must be instantiated with a DUID, not with NULL pointer
  413. IOAddress addr(ADDRESS[0]);
  414. EXPECT_THROW(new Lease6(Lease6::LEASE_IA_NA, addr,
  415. DuidPtr(), iaid, 100, 200, 50, 80,
  416. subnet_id), InvalidOperation);
  417. }
  418. /// @brief Lease6 Equality Test
  419. ///
  420. /// Checks that the operator==() correctly compares two leases for equality.
  421. /// As operator!=() is also defined for this class, every check on operator==()
  422. /// is followed by the reverse check on operator!=().
  423. TEST(Lease6, OperatorEquals) {
  424. // check a variety of addressemas with different bits set.
  425. const IOAddress addr("2001:db8:1::456");
  426. uint8_t duid_array[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
  427. DuidPtr duid(new DUID(duid_array, sizeof(duid_array)));
  428. uint32_t iaid = 7; // just a number
  429. SubnetID subnet_id = 8; // just another number
  430. // Check for equality.
  431. Lease6 lease1(Lease6::LEASE_IA_NA, addr, duid, iaid, 100, 200, 50, 80,
  432. subnet_id);
  433. Lease6 lease2(Lease6::LEASE_IA_NA, addr, duid, iaid, 100, 200, 50, 80,
  434. subnet_id);
  435. EXPECT_TRUE(lease1 == lease2);
  436. EXPECT_FALSE(lease1 != lease2);
  437. // Go through and alter all the fields one by one
  438. lease1.addr_ = IOAddress("::1");
  439. EXPECT_FALSE(lease1 == lease2);
  440. EXPECT_TRUE(lease1 != lease2);
  441. lease1.addr_ = lease2.addr_;
  442. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  443. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  444. lease1.type_ = Lease6::LEASE_IA_PD;
  445. EXPECT_FALSE(lease1 == lease2);
  446. EXPECT_TRUE(lease1 != lease2);
  447. lease1.type_ = lease2.type_;
  448. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  449. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  450. ++lease1.prefixlen_;
  451. EXPECT_FALSE(lease1 == lease2);
  452. EXPECT_TRUE(lease1 != lease2);
  453. lease1.prefixlen_ = lease2.prefixlen_;
  454. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  455. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  456. ++lease1.iaid_;
  457. EXPECT_FALSE(lease1 == lease2);
  458. EXPECT_TRUE(lease1 != lease2);
  459. lease1.iaid_ = lease2.iaid_;
  460. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  461. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  462. ++duid_array[0];
  463. lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
  464. EXPECT_FALSE(lease1 == lease2);
  465. EXPECT_TRUE(lease1 != lease2);
  466. --duid_array[0];
  467. lease1.duid_.reset(new DUID(duid_array, sizeof(duid_array)));
  468. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  469. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  470. ++lease1.preferred_lft_;
  471. EXPECT_FALSE(lease1 == lease2);
  472. EXPECT_TRUE(lease1 != lease2);
  473. lease1.preferred_lft_ = lease2.preferred_lft_;
  474. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  475. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  476. ++lease1.valid_lft_;
  477. EXPECT_FALSE(lease1 == lease2);
  478. EXPECT_TRUE(lease1 != lease2);
  479. lease1.valid_lft_ = lease2.valid_lft_;
  480. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  481. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  482. ++lease1.t1_;
  483. EXPECT_FALSE(lease1 == lease2);
  484. EXPECT_TRUE(lease1 != lease2);
  485. lease1.t1_ = lease2.t1_;
  486. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  487. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  488. ++lease1.t2_;
  489. EXPECT_FALSE(lease1 == lease2);
  490. EXPECT_TRUE(lease1 != lease2);
  491. lease1.t2_ = lease2.t2_;
  492. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  493. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  494. ++lease1.cltt_;
  495. EXPECT_FALSE(lease1 == lease2);
  496. EXPECT_TRUE(lease1 != lease2);
  497. lease1.cltt_ = lease2.cltt_;
  498. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  499. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  500. ++lease1.subnet_id_;
  501. EXPECT_FALSE(lease1 == lease2);
  502. EXPECT_TRUE(lease1 != lease2);
  503. lease1.subnet_id_ = lease2.subnet_id_;
  504. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  505. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  506. lease1.fixed_ = !lease1.fixed_;
  507. EXPECT_FALSE(lease1 == lease2);
  508. EXPECT_TRUE(lease1 != lease2);
  509. lease1.fixed_ = lease2.fixed_;
  510. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  511. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  512. lease1.hostname_ += string("Something random");
  513. EXPECT_FALSE(lease1 == lease2);
  514. EXPECT_TRUE(lease1 != lease2);
  515. lease1.hostname_ = lease2.hostname_;
  516. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  517. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  518. lease1.fqdn_fwd_ = !lease1.fqdn_fwd_;
  519. EXPECT_FALSE(lease1 == lease2);
  520. EXPECT_TRUE(lease1 != lease2);
  521. lease1.fqdn_fwd_ = lease2.fqdn_fwd_;
  522. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  523. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  524. lease1.fqdn_rev_ = !lease1.fqdn_rev_;
  525. EXPECT_FALSE(lease1 == lease2);
  526. EXPECT_TRUE(lease1 != lease2);
  527. lease1.fqdn_rev_ = lease2.fqdn_rev_;
  528. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  529. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  530. lease1.comments_ += string("Something random");
  531. EXPECT_FALSE(lease1 == lease2);
  532. EXPECT_TRUE(lease1 != lease2);
  533. lease1.comments_ = lease2.comments_;
  534. EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
  535. EXPECT_FALSE(lease1 != lease2); // ... leases equal
  536. }
  537. }; // end of anonymous namespace