dhcp6_message_test.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (C) 2014 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 <dhcp6/tests/dhcp6_message_test.h>
  15. using namespace isc::asiolink;
  16. namespace isc {
  17. namespace dhcp {
  18. namespace test {
  19. Dhcpv6MessageTest::Dhcpv6MessageTest()
  20. : Dhcpv6SrvTest(),
  21. iface_mgr_test_config_(true) {
  22. }
  23. IOAddress
  24. Dhcpv6MessageTest::bumpAddress(const IOAddress& input_addr) {
  25. return (bumpByteInAddress(input_addr, V6ADDRESS_LEN - 1));
  26. }
  27. IOAddress
  28. Dhcpv6MessageTest::bumpByteInAddress(const IOAddress& input_addr,
  29. const size_t byte_num) {
  30. std::vector<uint8_t> input_addr_buffer = input_addr.toBytes();
  31. if (input_addr_buffer.size() > byte_num) {
  32. ++input_addr_buffer[byte_num];
  33. return (IOAddress::fromBytes(AF_INET6, &input_addr_buffer[0]));
  34. }
  35. return (input_addr);
  36. }
  37. IOAddress
  38. Dhcpv6MessageTest::bumpSubnet(const IOAddress& input_addr) {
  39. return (bumpByteInAddress(input_addr, 0));
  40. }
  41. void
  42. Dhcpv6MessageTest::requestLease(const std::string& config,
  43. const int subnets_num,
  44. Dhcp6Client& client) {
  45. // Configure the server.
  46. configure(config, *client.getServer());
  47. // Make sure we ended-up having expected number of subnets configured.
  48. const Subnet6Collection* subnets =
  49. CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
  50. ASSERT_EQ(subnets_num, subnets->size());
  51. // Do the actual 4-way exchange.
  52. ASSERT_NO_THROW(client.doSARR());
  53. // Simulate aging of leases, by moving their cltt_ back by 1000s.
  54. client.fastFwdTime(1000);
  55. // Make sure that we have obtained a lease that belongs to one of the
  56. // subnets.
  57. ASSERT_EQ(1, client.getLeaseNum());
  58. Lease6 lease_client = client.getLease(0);
  59. ASSERT_TRUE(CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->
  60. selectSubnet(lease_client.addr_, ClientClasses()));
  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(0));
  67. }
  68. }
  69. }
  70. }