subnet_unittest.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. // Copyright (C) 2012-2013 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 <dhcp/option.h>
  17. #include <dhcpsrv/subnet.h>
  18. #include <exceptions/exceptions.h>
  19. #include <boost/scoped_ptr.hpp>
  20. #include <gtest/gtest.h>
  21. // don't import the entire boost namespace. It will unexpectedly hide uint8_t
  22. // for some systems.
  23. using boost::scoped_ptr;
  24. using namespace isc;
  25. using namespace isc::dhcp;
  26. using namespace isc::asiolink;
  27. namespace {
  28. TEST(Subnet4Test, constructor) {
  29. EXPECT_NO_THROW(Subnet4 subnet1(IOAddress("192.0.2.2"), 16,
  30. 1, 2, 3));
  31. EXPECT_THROW(Subnet4 subnet2(IOAddress("192.0.2.0"), 33, 1, 2, 3),
  32. BadValue); // invalid prefix length
  33. EXPECT_THROW(Subnet4 subnet3(IOAddress("2001:db8::1"), 24, 1, 2, 3),
  34. BadValue); // IPv6 addresses are not allowed in Subnet4
  35. }
  36. TEST(Subnet4Test, in_range) {
  37. Subnet4 subnet(IOAddress("192.0.2.1"), 24, 1000, 2000, 3000);
  38. EXPECT_EQ(1000, subnet.getT1());
  39. EXPECT_EQ(2000, subnet.getT2());
  40. EXPECT_EQ(3000, subnet.getValid());
  41. EXPECT_FALSE(subnet.inRange(IOAddress("192.0.0.0")));
  42. EXPECT_TRUE(subnet.inRange(IOAddress("192.0.2.0")));
  43. EXPECT_TRUE(subnet.inRange(IOAddress("192.0.2.1")));
  44. EXPECT_TRUE(subnet.inRange(IOAddress("192.0.2.255")));
  45. EXPECT_FALSE(subnet.inRange(IOAddress("192.0.3.0")));
  46. EXPECT_FALSE(subnet.inRange(IOAddress("0.0.0.0")));
  47. EXPECT_FALSE(subnet.inRange(IOAddress("255.255.255.255")));
  48. }
  49. TEST(Subnet4Test, Pool4InSubnet4) {
  50. Subnet4Ptr subnet(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3));
  51. Pool4Ptr pool1(new Pool4(IOAddress("192.1.2.0"), 25));
  52. Pool4Ptr pool2(new Pool4(IOAddress("192.1.2.128"), 26));
  53. Pool4Ptr pool3(new Pool4(IOAddress("192.1.2.192"), 30));
  54. subnet->addPool4(pool1);
  55. // If there's only one pool, get that pool
  56. Pool4Ptr mypool = subnet->getPool4();
  57. EXPECT_EQ(mypool, pool1);
  58. subnet->addPool4(pool2);
  59. subnet->addPool4(pool3);
  60. // If there are more than one pool and we didn't provide hint, we
  61. // should get the first pool
  62. mypool = subnet->getPool4();
  63. EXPECT_EQ(mypool, pool1);
  64. // If we provide a hint, we should get a pool that this hint belongs to
  65. mypool = subnet->getPool4(IOAddress("192.1.2.195"));
  66. EXPECT_EQ(mypool, pool3);
  67. }
  68. TEST(Subnet4Test, Subnet4_Pool4_checks) {
  69. Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
  70. // this one is in subnet
  71. Pool4Ptr pool1(new Pool4(IOAddress("192.255.0.0"), 16));
  72. subnet->addPool4(pool1);
  73. // this one is larger than the subnet!
  74. Pool4Ptr pool2(new Pool4(IOAddress("193.0.0.0"), 24));
  75. EXPECT_THROW(subnet->addPool4(pool2), BadValue);
  76. // this one is totally out of blue
  77. Pool4Ptr pool3(new Pool4(IOAddress("1.2.3.4"), 16));
  78. EXPECT_THROW(subnet->addPool4(pool3), BadValue);
  79. }
  80. TEST(Subnet4Test, addInvalidOption) {
  81. // Create the V4 subnet.
  82. Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
  83. // Some dummy option code.
  84. uint16_t code = 100;
  85. // Create option with invalid universe (V6 instead of V4).
  86. // Attempt to add this option should result in exception.
  87. OptionPtr option1(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  88. EXPECT_THROW(subnet->addOption(option1, false, "dhcp4"),
  89. isc::BadValue);
  90. // Create NULL pointer option. Attempt to add NULL option
  91. // should result in exception.
  92. OptionPtr option2;
  93. ASSERT_FALSE(option2);
  94. EXPECT_THROW(subnet->addOption(option2, false, "dhcp4"),
  95. isc::BadValue);
  96. }
  97. // This test verifies that inRange() and inPool() methods work properly.
  98. TEST(Subnet4Test, inRangeinPool) {
  99. Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.0.0"), 8, 1, 2, 3));
  100. // this one is in subnet
  101. Pool4Ptr pool1(new Pool4(IOAddress("192.2.0.0"), 16));
  102. subnet->addPool4(pool1);
  103. // 192.1.1.1 belongs to the subnet...
  104. EXPECT_TRUE(subnet->inRange(IOAddress("192.1.1.1")));
  105. // ... but it does not belong to any pool within
  106. EXPECT_FALSE(subnet->inPool(IOAddress("192.1.1.1")));
  107. // the last address that is in range, but out of pool
  108. EXPECT_TRUE(subnet->inRange(IOAddress("192.1.255.255")));
  109. EXPECT_FALSE(subnet->inPool(IOAddress("192.1.255.255")));
  110. // the first address that is in range, in pool
  111. EXPECT_TRUE(subnet->inRange(IOAddress("192.2.0.0")));
  112. EXPECT_TRUE (subnet->inPool(IOAddress("192.2.0.0")));
  113. // let's try something in the middle as well
  114. EXPECT_TRUE(subnet->inRange(IOAddress("192.2.3.4")));
  115. EXPECT_TRUE (subnet->inPool(IOAddress("192.2.3.4")));
  116. // the last address that is in range, in pool
  117. EXPECT_TRUE(subnet->inRange(IOAddress("192.2.255.255")));
  118. EXPECT_TRUE (subnet->inPool(IOAddress("192.2.255.255")));
  119. // the first address that is in range, but out of pool
  120. EXPECT_TRUE(subnet->inRange(IOAddress("192.3.0.0")));
  121. EXPECT_FALSE(subnet->inPool(IOAddress("192.3.0.0")));
  122. }
  123. // This test checks if the toText() method returns text representation
  124. TEST(Subnet4Test, toText) {
  125. Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3));
  126. EXPECT_EQ("192.0.2.0/24", subnet->toText());
  127. }
  128. // This test checks if the get() method returns proper parameters
  129. TEST(Subnet4Test, get) {
  130. Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 28, 1, 2, 3));
  131. EXPECT_EQ("192.0.2.0", subnet->get().first.toText());
  132. EXPECT_EQ(28, subnet->get().second);
  133. }
  134. // Tests for Subnet6
  135. TEST(Subnet6Test, constructor) {
  136. EXPECT_NO_THROW(Subnet6 subnet1(IOAddress("2001:db8:1::"), 64,
  137. 1, 2, 3, 4));
  138. EXPECT_THROW(Subnet6 subnet2(IOAddress("2001:db8:1::"), 129, 1, 2, 3, 4),
  139. BadValue); // invalid prefix length
  140. EXPECT_THROW(Subnet6 subnet3(IOAddress("192.168.0.0"), 32, 1, 2, 3, 4),
  141. BadValue); // IPv4 addresses are not allowed in Subnet6
  142. }
  143. TEST(Subnet6Test, in_range) {
  144. Subnet6 subnet(IOAddress("2001:db8:1::"), 64, 1000, 2000, 3000, 4000);
  145. EXPECT_EQ(1000, subnet.getT1());
  146. EXPECT_EQ(2000, subnet.getT2());
  147. EXPECT_EQ(3000, subnet.getPreferred());
  148. EXPECT_EQ(4000, subnet.getValid());
  149. EXPECT_FALSE(subnet.inRange(IOAddress("2001:db8:0:ffff:ffff:ffff:ffff:ffff")));
  150. EXPECT_TRUE(subnet.inRange(IOAddress("2001:db8:1::0")));
  151. EXPECT_TRUE(subnet.inRange(IOAddress("2001:db8:1::1")));
  152. EXPECT_TRUE(subnet.inRange(IOAddress("2001:db8:1::ffff:ffff:ffff:ffff")));
  153. EXPECT_FALSE(subnet.inRange(IOAddress("2001:db8:1:1::")));
  154. EXPECT_FALSE(subnet.inRange(IOAddress("::")));
  155. }
  156. TEST(Subnet6Test, Pool6InSubnet6) {
  157. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  158. Pool6Ptr pool1(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8:1:1::"), 64));
  159. Pool6Ptr pool2(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8:1:2::"), 64));
  160. Pool6Ptr pool3(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8:1:3::"), 64));
  161. subnet->addPool6(pool1);
  162. // If there's only one pool, get that pool
  163. Pool6Ptr mypool = subnet->getPool6();
  164. EXPECT_EQ(mypool, pool1);
  165. subnet->addPool6(pool2);
  166. subnet->addPool6(pool3);
  167. // If there are more than one pool and we didn't provide hint, we
  168. // should get the first pool
  169. mypool = subnet->getPool6();
  170. EXPECT_EQ(mypool, pool1);
  171. // If we provide a hint, we should get a pool that this hint belongs to
  172. mypool = subnet->getPool6(IOAddress("2001:db8:1:3::dead:beef"));
  173. EXPECT_EQ(mypool, pool3);
  174. }
  175. TEST(Subnet6Test, Subnet6_Pool6_checks) {
  176. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  177. // this one is in subnet
  178. Pool6Ptr pool1(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8:1:1::"), 64));
  179. subnet->addPool6(pool1);
  180. // this one is larger than the subnet!
  181. Pool6Ptr pool2(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8::"), 48));
  182. EXPECT_THROW(subnet->addPool6(pool2), BadValue);
  183. // this one is totally out of blue
  184. Pool6Ptr pool3(new Pool6(Pool6::TYPE_IA, IOAddress("3000::"), 16));
  185. EXPECT_THROW(subnet->addPool6(pool3), BadValue);
  186. Pool6Ptr pool4(new Pool6(Pool6::TYPE_IA, IOAddress("4001:db8:1::"), 80));
  187. EXPECT_THROW(subnet->addPool6(pool4), BadValue);
  188. }
  189. TEST(Subnet6Test, addOptions) {
  190. // Create as subnet to add options to it.
  191. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  192. // Differentiate options by their codes (100-109)
  193. for (uint16_t code = 100; code < 110; ++code) {
  194. OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  195. ASSERT_NO_THROW(subnet->addOption(option, false, "dhcp6"));
  196. }
  197. // Add 7 options to another option space. The option codes partially overlap
  198. // with option codes that we have added to dhcp6 option space.
  199. for (uint16_t code = 105; code < 112; ++code) {
  200. OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  201. ASSERT_NO_THROW(subnet->addOption(option, false, "isc"));
  202. }
  203. // Get options from the Subnet and check if all 10 are there.
  204. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp6");
  205. ASSERT_TRUE(options);
  206. ASSERT_EQ(10, options->size());
  207. // Validate codes of options added to dhcp6 option space.
  208. uint16_t expected_code = 100;
  209. for (Subnet::OptionContainer::const_iterator option_desc = options->begin();
  210. option_desc != options->end(); ++option_desc) {
  211. ASSERT_TRUE(option_desc->option);
  212. EXPECT_EQ(expected_code, option_desc->option->getType());
  213. ++expected_code;
  214. }
  215. options = subnet->getOptionDescriptors("isc");
  216. ASSERT_TRUE(options);
  217. ASSERT_EQ(7, options->size());
  218. // Validate codes of options added to isc option space.
  219. expected_code = 105;
  220. for (Subnet::OptionContainer::const_iterator option_desc = options->begin();
  221. option_desc != options->end(); ++option_desc) {
  222. ASSERT_TRUE(option_desc->option);
  223. EXPECT_EQ(expected_code, option_desc->option->getType());
  224. ++expected_code;
  225. }
  226. // Try to get options from a non-existing option space.
  227. options = subnet->getOptionDescriptors("abcd");
  228. ASSERT_TRUE(options);
  229. EXPECT_TRUE(options->empty());
  230. // Delete options from all spaces.
  231. subnet->delOptions();
  232. // Make sure that all options have been removed.
  233. options = subnet->getOptionDescriptors("dhcp6");
  234. ASSERT_TRUE(options);
  235. EXPECT_TRUE(options->empty());
  236. options = subnet->getOptionDescriptors("isc");
  237. ASSERT_TRUE(options);
  238. EXPECT_TRUE(options->empty());
  239. }
  240. TEST(Subnet6Test, addNonUniqueOptions) {
  241. // Create as subnet to add options to it.
  242. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  243. // Create a set of options with non-unique codes.
  244. for (int i = 0; i < 2; ++i) {
  245. // In the inner loop we create options with unique codes (100-109).
  246. for (uint16_t code = 100; code < 110; ++code) {
  247. OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  248. ASSERT_NO_THROW(subnet->addOption(option, false, "dhcp6"));
  249. }
  250. }
  251. // Sanity check that all options are there.
  252. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp6");
  253. ASSERT_EQ(20, options->size());
  254. // Use container index #1 to get the options by their codes.
  255. Subnet::OptionContainerTypeIndex& idx = options->get<1>();
  256. // Look for the codes 100-109.
  257. for (uint16_t code = 100; code < 110; ++ code) {
  258. // For each code we should get two instances of options->
  259. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  260. Subnet::OptionContainerTypeIndex::const_iterator> range =
  261. idx.equal_range(code);
  262. // Distance between iterators indicates how many options
  263. // have been retured for the particular code.
  264. ASSERT_EQ(2, distance(range.first, range.second));
  265. // Check that returned options actually have the expected option code.
  266. for (Subnet::OptionContainerTypeIndex::const_iterator option_desc = range.first;
  267. option_desc != range.second; ++option_desc) {
  268. ASSERT_TRUE(option_desc->option);
  269. EXPECT_EQ(code, option_desc->option->getType());
  270. }
  271. }
  272. // Let's try to find some non-exiting option.
  273. const uint16_t non_existing_code = 150;
  274. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  275. Subnet::OptionContainerTypeIndex::const_iterator> range =
  276. idx.equal_range(non_existing_code);
  277. // Empty set is expected.
  278. EXPECT_EQ(0, distance(range.first, range.second));
  279. subnet->delOptions();
  280. options = subnet->getOptionDescriptors("dhcp6");
  281. EXPECT_EQ(0, options->size());
  282. }
  283. TEST(Subnet6Test, addInvalidOption) {
  284. // Create as subnet to add options to it.
  285. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  286. // Some dummy option code.
  287. uint16_t code = 100;
  288. // Create option with invalid universe (V4 instead of V6).
  289. // Attempt to add this option should result in exception.
  290. OptionPtr option1(new Option(Option::V4, code, OptionBuffer(10, 0xFF)));
  291. EXPECT_THROW(subnet->addOption(option1, false, "dhcp6"), isc::BadValue);
  292. // Create NULL pointer option. Attempt to add NULL option
  293. // should result in exception.
  294. OptionPtr option2;
  295. ASSERT_FALSE(option2);
  296. EXPECT_THROW(subnet->addOption(option2, false, "dhcp6"), isc::BadValue);
  297. }
  298. TEST(Subnet6Test, addPersistentOption) {
  299. // Create as subnet to add options to it.
  300. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
  301. // Add 10 options to the subnet with option codes 100 - 109.
  302. for (uint16_t code = 100; code < 110; ++code) {
  303. OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  304. // We create 10 options and want some of them to be flagged
  305. // persistent and some non-persistent. Persistent options are
  306. // those that server sends to clients regardless if they ask
  307. // for them or not. We pick 3 out of 10 options and mark them
  308. // non-persistent and 7 other options persistent.
  309. // Code values: 102, 105 and 108 are divisable by 3
  310. // and options with these codes will be flagged non-persistent.
  311. // Options with other codes will be flagged persistent.
  312. bool persistent = (code % 3) ? true : false;
  313. ASSERT_NO_THROW(subnet->addOption(option, persistent, "dhcp6"));
  314. }
  315. // Get added options from the subnet.
  316. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp6");
  317. // options->get<2> returns reference to container index #2. This
  318. // index is used to access options by the 'persistent' flag.
  319. Subnet::OptionContainerPersistIndex& idx = options->get<2>();
  320. // Get all persistent options->
  321. std::pair<Subnet::OptionContainerPersistIndex::const_iterator,
  322. Subnet::OptionContainerPersistIndex::const_iterator> range_persistent =
  323. idx.equal_range(true);
  324. // 3 out of 10 options have been flagged persistent.
  325. ASSERT_EQ(7, distance(range_persistent.first, range_persistent.second));
  326. // Get all non-persistent options->
  327. std::pair<Subnet::OptionContainerPersistIndex::const_iterator,
  328. Subnet::OptionContainerPersistIndex::const_iterator> range_non_persistent =
  329. idx.equal_range(false);
  330. // 7 out of 10 options have been flagged persistent.
  331. ASSERT_EQ(3, distance(range_non_persistent.first, range_non_persistent.second));
  332. subnet->delOptions();
  333. options = subnet->getOptionDescriptors("dhcp6");
  334. EXPECT_EQ(0, options->size());
  335. }
  336. TEST(Subnet6Test, getOptionDescriptor) {
  337. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 56, 1, 2, 3, 4));
  338. // Add 10 options to a "dhcp6" option space in the subnet.
  339. for (uint16_t code = 100; code < 110; ++code) {
  340. OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
  341. ASSERT_NO_THROW(subnet->addOption(option, false, "dhcp6"));
  342. }
  343. // Check that we can get each added option descriptor using
  344. // individually.
  345. for (uint16_t code = 100; code < 110; ++code) {
  346. std::ostringstream stream;
  347. // First, try the invalid option space name.
  348. Subnet::OptionDescriptor desc = subnet->getOptionDescriptor("isc", code);
  349. // Returned descriptor should contain NULL option ptr.
  350. EXPECT_FALSE(desc.option);
  351. // Now, try the valid option space.
  352. desc = subnet->getOptionDescriptor("dhcp6", code);
  353. // Test that the option code matches the expected code.
  354. ASSERT_TRUE(desc.option);
  355. EXPECT_EQ(code, desc.option->getType());
  356. }
  357. }
  358. // This test verifies that inRange() and inPool() methods work properly.
  359. TEST(Subnet6Test, inRangeinPool) {
  360. Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));
  361. // this one is in subnet
  362. Pool6Ptr pool1(new Pool6(Pool6::TYPE_IA, IOAddress("2001:db8::10"),
  363. IOAddress("2001:db8::20")));
  364. subnet->addPool6(pool1);
  365. // 192.1.1.1 belongs to the subnet...
  366. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::1")));
  367. // ... but it does not belong to any pool within
  368. EXPECT_FALSE(subnet->inPool(IOAddress("2001:db8::1")));
  369. // the last address that is in range, but out of pool
  370. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::f")));
  371. EXPECT_FALSE(subnet->inPool(IOAddress("2001:db8::f")));
  372. // the first address that is in range, in pool
  373. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::10")));
  374. EXPECT_TRUE (subnet->inPool(IOAddress("2001:db8::10")));
  375. // let's try something in the middle as well
  376. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::18")));
  377. EXPECT_TRUE (subnet->inPool(IOAddress("2001:db8::18")));
  378. // the last address that is in range, in pool
  379. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::20")));
  380. EXPECT_TRUE (subnet->inPool(IOAddress("2001:db8::20")));
  381. // the first address that is in range, but out of pool
  382. EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::21")));
  383. EXPECT_FALSE(subnet->inPool(IOAddress("2001:db8::21")));
  384. }
  385. // This test checks if the toText() method returns text representation
  386. TEST(Subnet6Test, toText) {
  387. Subnet6 subnet(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
  388. EXPECT_EQ("2001:db8::/32", subnet.toText());
  389. }
  390. // This test checks if the get() method returns proper parameters
  391. TEST(Subnet6Test, get) {
  392. Subnet6 subnet(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
  393. EXPECT_EQ("2001:db8::", subnet.get().first.toText());
  394. EXPECT_EQ(32, subnet.get().second);
  395. }
  396. };