dhcp6_message_test.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2014-2015 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 <dhcp6/tests/dhcp6_message_test.h>
  8. using namespace isc::asiolink;
  9. namespace isc {
  10. namespace dhcp {
  11. namespace test {
  12. Dhcpv6MessageTest::Dhcpv6MessageTest()
  13. : Dhcpv6SrvTest(),
  14. iface_mgr_test_config_(true) {
  15. }
  16. IOAddress
  17. Dhcpv6MessageTest::bumpAddress(const IOAddress& input_addr) {
  18. return (bumpByteInAddress(input_addr, V6ADDRESS_LEN - 1));
  19. }
  20. IOAddress
  21. Dhcpv6MessageTest::bumpByteInAddress(const IOAddress& input_addr,
  22. const size_t byte_num) {
  23. std::vector<uint8_t> input_addr_buffer = input_addr.toBytes();
  24. if (input_addr_buffer.size() > byte_num) {
  25. ++input_addr_buffer[byte_num];
  26. return (IOAddress::fromBytes(AF_INET6, &input_addr_buffer[0]));
  27. }
  28. return (input_addr);
  29. }
  30. IOAddress
  31. Dhcpv6MessageTest::bumpSubnet(const IOAddress& input_addr) {
  32. return (bumpByteInAddress(input_addr, 0));
  33. }
  34. void
  35. Dhcpv6MessageTest::requestLease(const std::string& config,
  36. const int subnets_num,
  37. Dhcp6Client& client) {
  38. // Configure the server.
  39. configure(config, *client.getServer());
  40. // Make sure we ended-up having expected number of subnets configured.
  41. const Subnet6Collection* subnets =
  42. CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
  43. ASSERT_EQ(subnets_num, subnets->size());
  44. // Do the actual 4-way exchange.
  45. ASSERT_NO_THROW(client.doSARR());
  46. // Simulate aging of leases, by moving their cltt_ back by 1000s.
  47. client.fastFwdTime(1000);
  48. // Make sure that we have obtained a lease that belongs to one of the
  49. // subnets.
  50. ASSERT_EQ(1, client.getLeaseNum());
  51. Lease6 lease_client = client.getLease(0);
  52. // Check if the lease belongs to one of the available pools.
  53. bool pool_found = false;
  54. for (int i = 0; i < subnets_num; ++i) {
  55. if ((*subnets)[i]->getPool(lease_client.type_, lease_client.addr_)) {
  56. pool_found = true;
  57. break;
  58. }
  59. }
  60. ASSERT_TRUE(pool_found);
  61. // Check that the client's lease matches the information on the server
  62. // side.
  63. Lease6Ptr lease_server = checkLease(lease_client);
  64. ASSERT_TRUE(lease_server);
  65. // And that status code was OK.
  66. ASSERT_EQ(STATUS_Success, client.getStatusCode(lease_client.iaid_));
  67. }
  68. }
  69. }
  70. }