dhcp6_message_test.cc 3.04 KB
Newer Older
1
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15
#include <config.h>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#include <dhcp6/tests/dhcp6_message_test.h>

using namespace isc::asiolink;

namespace isc {
namespace dhcp {
namespace test {

Dhcpv6MessageTest::Dhcpv6MessageTest()
    : Dhcpv6SrvTest(),
      iface_mgr_test_config_(true) {
}

IOAddress
Dhcpv6MessageTest::bumpAddress(const IOAddress& input_addr) {
    return (bumpByteInAddress(input_addr, V6ADDRESS_LEN - 1));
}

IOAddress
Dhcpv6MessageTest::bumpByteInAddress(const IOAddress& input_addr,
                                     const size_t byte_num) {
    std::vector<uint8_t> input_addr_buffer = input_addr.toBytes();
    if (input_addr_buffer.size() > byte_num) {
        ++input_addr_buffer[byte_num];
        return (IOAddress::fromBytes(AF_INET6, &input_addr_buffer[0]));
    }
    return (input_addr);
}

IOAddress
Dhcpv6MessageTest::bumpSubnet(const IOAddress& input_addr) {
    return (bumpByteInAddress(input_addr, 0));
}

void
Dhcpv6MessageTest::requestLease(const std::string& config,
                                const int subnets_num,
                                Dhcp6Client& client) {
    // Configure the server.
    configure(config, *client.getServer());
    // Make sure we ended-up having expected number of subnets configured.
57 58
    const Subnet6Collection* subnets =
        CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
59 60 61 62 63 64 65 66 67
    ASSERT_EQ(subnets_num, subnets->size());
    // Do the actual 4-way exchange.
    ASSERT_NO_THROW(client.doSARR());
    // Simulate aging of leases, by moving their cltt_ back by 1000s.
    client.fastFwdTime(1000);
    // Make sure that we have obtained a lease that belongs to one of the
    // subnets.
    ASSERT_EQ(1, client.getLeaseNum());
    Lease6 lease_client = client.getLease(0);
68 69 70 71 72 73 74 75 76 77 78

    // Check if the lease belongs to one of the available pools.
    bool pool_found = false;
    for (int i = 0; i < subnets_num; ++i) {
        if ((*subnets)[i]->getPool(lease_client.type_, lease_client.addr_)) {
            pool_found = true;
            break;
        }
    }
    ASSERT_TRUE(pool_found);

79 80 81 82 83
    // Check that the client's lease matches the information on the server
    // side.
    Lease6Ptr lease_server = checkLease(lease_client);
    ASSERT_TRUE(lease_server);
    // And that status code was OK.
84
    ASSERT_EQ(STATUS_Success, client.getStatusCode(0));
85 86 87 88 89
}

}
}
}