dhcp6_srv_unittest.cc 80.5 KB
Newer Older
Stephen Morris's avatar
Stephen Morris committed
1
// Copyright (C) 2011-2013  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
#include <asiolink/io_address.h>
18
#include <dhcp_ddns/ncr_msg.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
19
#include <dhcp/dhcp6.h>
20
#include <dhcp/duid.h>
21
#include <dhcp/option.h>
22
#include <dhcp/option_custom.h>
23
#include <dhcp/option6_addrlst.h>
24
#include <dhcp/option6_client_fqdn.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
25
#include <dhcp/option6_ia.h>
26
#include <dhcp/option6_iaaddr.h>
27
#include <dhcp/option_int_array.h>
28
#include <dhcp/iface_mgr.h>
29
#include <dhcp6/config_parser.h>
30
#include <dhcp/dhcp6.h>
31 32 33
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
34
#include <dhcpsrv/utils.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
35
#include <util/buffer.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
36
#include <util/range_utilities.h>
37
#include <hooks/server_hooks.h>
38

39
#include <dhcp6/tests/dhcp6_test_utils.h>
40
#include <boost/pointer_cast.hpp>
41
#include <boost/scoped_ptr.hpp>
42
#include <gtest/gtest.h>
43
#include <unistd.h>
44 45 46 47
#include <fstream>
#include <iostream>
#include <sstream>

48
using namespace isc;
49
using namespace isc::test;
50
using namespace isc::asiolink;
51
using namespace isc::dhcp;
52
using namespace isc::dhcp_ddns;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
53
using namespace isc::util;
54
using namespace isc::hooks;
55
using namespace std;
56 57 58

// namespace has to be named, because friends are defined in Dhcpv6Srv class
// Maybe it should be isc::test?
59
namespace {
60

61 62
// This is a test fixture class for testing the processing of the DHCPv6 Client
// FQDN Option.
63
class FqdnDhcpv6SrvTest : public Dhcpv6SrvTest {
64
public:
65
    // Constructor
66 67 68 69 70 71 72 73
    FqdnDhcpv6SrvTest()
        : Dhcpv6SrvTest() {
        // generateClientId assigns DUID to duid_.
        generateClientId();
        lease_.reset(new Lease6(Lease6::LEASE_IA_NA, IOAddress("2001:db8:1::1"),
                                duid_, 1234, 501, 502, 503,
                                504, 1, 0));

74 75
    }

76
    // Destructor
77 78 79
    virtual ~FqdnDhcpv6SrvTest() {
    }

80
    // Construct the DHCPv6 Client FQDN Option using flags and domain-name.
81 82 83 84 85 86 87 88 89 90
    Option6ClientFqdnPtr
    createClientFqdn(const uint8_t flags,
                     const std::string& fqdn_name,
                     const Option6ClientFqdn::DomainNameType fqdn_type) {
        return (Option6ClientFqdnPtr(new Option6ClientFqdn(flags,
                                                           fqdn_name,
                                                           fqdn_type)));
    }

    // Create a message holding DHCPv6 Client FQDN Option.
91 92 93 94 95 96 97 98 99
    Pkt6Ptr generatePktWithFqdn(uint8_t msg_type,
                                const uint8_t fqdn_flags,
                                const std::string& fqdn_domain_name,
                                const Option6ClientFqdn::DomainNameType
                                fqdn_type,
                                const bool include_oro,
                                OptionPtr srvid = OptionPtr()) {
        Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(msg_type, 1234));
        pkt->setRemoteAddr(IOAddress("fe80::abcd"));
100 101 102 103 104 105 106 107 108
        Option6IAPtr ia = generateIA(234, 1500, 3000);

        if (msg_type != DHCPV6_REPLY) {
            IOAddress hint("2001:db8:1:1::dead:beef");
            OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
            ia->addOption(hint_opt);
            pkt->addOption(ia);
        }

109 110 111 112 113 114
        OptionPtr clientid = generateClientId();
        pkt->addOption(clientid);
        if (srvid && (msg_type != DHCPV6_SOLICIT)) {
            pkt->addOption(srvid);
        }

115 116
        pkt->addOption(createClientFqdn(fqdn_flags, fqdn_domain_name,
                                        fqdn_type));
117 118 119 120 121 122 123 124 125 126 127

        if (include_oro) {
            OptionUint16ArrayPtr oro(new OptionUint16Array(Option::V6,
                                                           D6O_ORO));
            oro->addValue(D6O_CLIENT_FQDN);
            pkt->addOption(oro);
        }

        return (pkt);
    }

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    // Creates instance of the DHCPv6 message with client id and server id.
    Pkt6Ptr generateMessageWithIds(const uint8_t msg_type,
                                   NakedDhcpv6Srv& srv) {
        Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(msg_type, 1234));
        // Generate client-id.
        OptionPtr opt_clientid = generateClientId();
        pkt->addOption(opt_clientid);

        if (msg_type != DHCPV6_SOLICIT) {
            // Generate server-id.
            pkt->addOption(srv.getServerID());
        }

        return (pkt);
    }

144 145 146 147 148 149
    // Returns an instance of the option carrying FQDN.
    Option6ClientFqdnPtr getClientFqdnOption(const Pkt6Ptr& pkt) {
        return (boost::dynamic_pointer_cast<Option6ClientFqdn>
                (pkt->getOption(D6O_CLIENT_FQDN)));
    }

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    // Adds IA option to the message. Option holds an address.
    void addIA(const uint32_t iaid, const IOAddress& addr, Pkt6Ptr& pkt) {
        Option6IAPtr opt_ia = generateIA(iaid, 1500, 3000);
        Option6IAAddrPtr opt_iaaddr(new Option6IAAddr(D6O_IAADDR, addr,
                                                      300, 500));
        opt_ia->addOption(opt_iaaddr);
        pkt->addOption(opt_ia);
    }

    // Adds IA option to the message. Option holds status code.
    void addIA(const uint32_t iaid, const uint16_t status_code, Pkt6Ptr& pkt) {
        Option6IAPtr opt_ia = generateIA(iaid, 1500, 3000);
        addStatusCode(status_code, "", opt_ia);
        pkt->addOption(opt_ia);
    }

    // Creates status code with the specified code and message.
    OptionCustomPtr createStatusCode(const uint16_t code,
                                     const std::string& msg) {
        OptionDefinition def("status-code", D6O_STATUS_CODE, "record");
        def.addRecordField("uint16");
        def.addRecordField("string");
        OptionCustomPtr opt_status(new OptionCustom(def, Option::V6));
        opt_status->writeInteger(code);
        if (!msg.empty()) {
            opt_status->writeString(msg, 1);
        }
        return (opt_status);
    }

    // Adds Status Code option to the IA.
    void addStatusCode(const uint16_t code, const std::string& msg,
                       Option6IAPtr& opt_ia) {
        opt_ia->addOption(createStatusCode(code, msg));
    }

    // Test processing of the DHCPv6 Client FQDN Option.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    void testFqdn(const uint16_t msg_type,
                  const bool use_oro,
                  const uint8_t in_flags,
                  const std::string& in_domain_name,
                  const Option6ClientFqdn::DomainNameType in_domain_type,
                  const uint8_t exp_flags,
                  const std::string& exp_domain_name) {
        NakedDhcpv6Srv srv(0);
        Pkt6Ptr question = generatePktWithFqdn(msg_type,
                                               in_flags,
                                               in_domain_name,
                                               in_domain_type,
                                               use_oro);
        ASSERT_TRUE(getClientFqdnOption(question));

202 203
        Option6ClientFqdnPtr answ_fqdn;
        ASSERT_NO_THROW(answ_fqdn = srv.processClientFqdn(question));
204 205
        ASSERT_TRUE(answ_fqdn);

206 207 208
        const bool flag_n = (exp_flags & Option6ClientFqdn::FLAG_N) != 0;
        const bool flag_s = (exp_flags & Option6ClientFqdn::FLAG_S) != 0;
        const bool flag_o = (exp_flags & Option6ClientFqdn::FLAG_O) != 0;
209 210 211 212 213 214 215 216

        EXPECT_EQ(flag_n, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_N));
        EXPECT_EQ(flag_s, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_S));
        EXPECT_EQ(flag_o, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_O));

        EXPECT_EQ(exp_domain_name, answ_fqdn->getDomainName());
        EXPECT_EQ(Option6ClientFqdn::FULL, answ_fqdn->getDomainNameType());
    }
217 218 219 220 221 222 223 224 225

    // Tests that the client message holding an FQDN is processed and the
    // lease is acquired.
    void testProcessMessage(const uint8_t msg_type,
                            const std::string& hostname,
                            NakedDhcpv6Srv& srv) {
        // Create a message of a specified type, add server id and
        // FQDN option.
        OptionPtr srvid = srv.getServerID();
226
        Pkt6Ptr req = generatePktWithFqdn(msg_type, Option6ClientFqdn::FLAG_S,
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
                                          hostname,
                                          Option6ClientFqdn::FULL,
                                          true, srvid);

        // For different client's message types we have to invoke different
        // functions to generate response.
        Pkt6Ptr reply;
        if (msg_type == DHCPV6_SOLICIT) {
            ASSERT_NO_THROW(reply = srv.processSolicit(req));

        } else if (msg_type == DHCPV6_REQUEST) {
            ASSERT_NO_THROW(reply = srv.processRequest(req));

        } else if (msg_type == DHCPV6_RENEW) {
            ASSERT_NO_THROW(reply = srv.processRequest(req));

        } else if (msg_type == DHCPV6_RELEASE) {
            // For Release no lease will be acquired so we have to leave
            // function here.
            ASSERT_NO_THROW(reply = srv.processRelease(req));
            return;
        } else {
            // We are not interested in testing other message types.
            return;
        }

        // For Solicit, we will get different message type obviously.
        if (msg_type == DHCPV6_SOLICIT) {
            checkResponse(reply, DHCPV6_ADVERTISE, 1234);

        } else {
            checkResponse(reply, DHCPV6_REPLY, 1234);
        }

        // Check verify that IA_NA is correct.
        Option6IAAddrPtr addr =
            checkIA_NA(reply, 234, subnet_->getT1(), subnet_->getT2());
        ASSERT_TRUE(addr);

        // Check that we have got the address we requested.
        checkIAAddr(addr, IOAddress("2001:db8:1:1::dead:beef"),
                    subnet_->getPreferred(),
                    subnet_->getValid());

        if (msg_type != DHCPV6_SOLICIT) {
            // Check that the lease exists.
            Lease6Ptr lease =
                checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
            ASSERT_TRUE(lease);
        }
    }

    // Verify that NameChangeRequest holds valid values.
    void verifyNameChangeRequest(NakedDhcpv6Srv& srv,
281
                                 const isc::dhcp_ddns::NameChangeType type,
282 283 284 285 286 287 288 289 290 291 292 293 294
                                 const bool reverse, const bool forward,
                                 const std::string& addr,
                                 const std::string& dhcid,
                                 const uint16_t expires,
                                 const uint16_t len) {
        NameChangeRequest ncr = srv.name_change_reqs_.front();
        EXPECT_EQ(type, ncr.getChangeType());
        EXPECT_EQ(forward, ncr.isForwardChange());
        EXPECT_EQ(reverse, ncr.isReverseChange());
        EXPECT_EQ(addr, ncr.getIpAddress());
        EXPECT_EQ(dhcid, ncr.getDhcid().toStr());
        EXPECT_EQ(expires, ncr.getLeaseExpiresOn());
        EXPECT_EQ(len, ncr.getLeaseLength());
295
        EXPECT_EQ(isc::dhcp_ddns::ST_NEW, ncr.getStatus());
296 297 298
        srv.name_change_reqs_.pop();
    }

299
    // Holds a lease used by a test.
300
    Lease6Ptr lease_;
301

302 303
};

304
// This test verifies that incoming SOLICIT can be handled properly when
305
// there are no subnets configured.
306
//
307 308
// This test sends a SOLICIT and the expected response
// is an ADVERTISE with STATUS_NoAddrsAvail and no address provided in the
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
// response
TEST_F(NakedDhcpv6SrvTest, SolicitNoSubnet) {
    NakedDhcpv6Srv srv(0);

    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
    sol->setRemoteAddr(IOAddress("fe80::abcd"));
    sol->addOption(generateIA(234, 1500, 3000));
    OptionPtr clientid = generateClientId();
    sol->addOption(clientid);

    // Pass it to the server and get an advertise
    Pkt6Ptr reply = srv.processSolicit(sol);

    // check that we get the right NAK
    checkNakResponse (reply, DHCPV6_ADVERTISE, 1234, STATUS_NoAddrsAvail);
}

326
// This test verifies that incoming REQUEST can be handled properly when
327
// there are no subnets configured.
328
//
329 330
// This test sends a REQUEST and the expected response
// is an REPLY with STATUS_NoAddrsAvail and no address provided in the
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
// response
TEST_F(NakedDhcpv6SrvTest, RequestNoSubnet) {
    NakedDhcpv6Srv srv(0);

    // Let's create a REQUEST
    Pkt6Ptr req = Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 1234));
    req->setRemoteAddr(IOAddress("fe80::abcd"));
    boost::shared_ptr<Option6IA> ia = generateIA(234, 1500, 3000);

    // with a hint
    IOAddress hint("2001:db8:1:1::dead:beef");
    OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
    ia->addOption(hint_opt);
    req->addOption(ia);
    OptionPtr clientid = generateClientId();
    req->addOption(clientid);

    // server-id is mandatory in REQUEST
    req->addOption(srv.getServerID());

    // Pass it to the server and hope for a REPLY
352
    Pkt6Ptr reply = srv.processRequest(req);
353 354 355 356 357 358 359 360

    // check that we get the right NAK
    checkNakResponse (reply, DHCPV6_REPLY, 1234, STATUS_NoAddrsAvail);
}

// This test verifies that incoming RENEW can be handled properly, even when
// no subnets are configured.
//
361 362
// This test sends a RENEW and the expected response
// is an REPLY with STATUS_NoBinding and no address provided in the
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
// response
TEST_F(NakedDhcpv6SrvTest, RenewNoSubnet) {
    NakedDhcpv6Srv srv(0);

    const IOAddress addr("2001:db8:1:1::cafe:babe");
    const uint32_t iaid = 234;

    // Generate client-id also duid_
    OptionPtr clientid = generateClientId();

    // Let's create a RENEW
    Pkt6Ptr req = Pkt6Ptr(new Pkt6(DHCPV6_RENEW, 1234));
    req->setRemoteAddr(IOAddress("fe80::abcd"));
    boost::shared_ptr<Option6IA> ia = generateIA(iaid, 1500, 3000);

    OptionPtr renewed_addr_opt(new Option6IAAddr(D6O_IAADDR, addr, 300, 500));
    ia->addOption(renewed_addr_opt);
    req->addOption(ia);
    req->addOption(clientid);

    // Server-id is mandatory in RENEW
    req->addOption(srv.getServerID());

    // Pass it to the server and hope for a REPLY
387
    Pkt6Ptr reply = srv.processRenew(req);
388 389 390 391 392 393 394 395

    // check that we get the right NAK
    checkNakResponse (reply, DHCPV6_REPLY, 1234, STATUS_NoBinding);
}

// This test verifies that incoming RELEASE can be handled properly, even when
// no subnets are configured.
//
396 397
// This test sends a RELEASE and the expected response
// is an REPLY with STATUS_NoBinding and no address provided in the
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
// response
TEST_F(NakedDhcpv6SrvTest, ReleaseNoSubnet) {
    NakedDhcpv6Srv srv(0);

    const IOAddress addr("2001:db8:1:1::cafe:babe");
    const uint32_t iaid = 234;

    // Generate client-id also duid_
    OptionPtr clientid = generateClientId();

    // Let's create a RELEASE
    Pkt6Ptr req = Pkt6Ptr(new Pkt6(DHCPV6_RELEASE, 1234));
    req->setRemoteAddr(IOAddress("fe80::abcd"));
    boost::shared_ptr<Option6IA> ia = generateIA(iaid, 1500, 3000);

    OptionPtr released_addr_opt(new Option6IAAddr(D6O_IAADDR, addr, 300, 500));
    ia->addOption(released_addr_opt);
    req->addOption(ia);
    req->addOption(clientid);

    // Server-id is mandatory in RELEASE
    req->addOption(srv.getServerID());

    // Pass it to the server and hope for a REPLY
422
    Pkt6Ptr reply = srv.processRelease(req);
423 424 425 426

    // check that we get the right NAK
    checkNakResponse (reply, DHCPV6_REPLY, 1234, STATUS_NoBinding);
}
427

428

429 430 431
// Test verifies that the Dhcpv6_srv class can be instantiated. It checks a mode
// without open sockets and with sockets opened on a high port (to not require
// root privileges).
432
TEST_F(Dhcpv6SrvTest, basic) {
433 434 435 436
    // srv has stubbed interface detection. It will read
    // interfaces.txt instead. It will pretend to have detected
    // fe80::1234 link-local address on eth0 interface. Obviously
    // an attempt to bind this socket will fail.
437 438
    boost::scoped_ptr<Dhcpv6Srv> srv;

439
    ASSERT_NO_THROW( {
440
        // Skip opening any sockets
441
        srv.reset(new Dhcpv6Srv(0));
442
    });
443
    srv.reset();
444
    ASSERT_NO_THROW({
Tomek Mrugalski's avatar
Tomek Mrugalski committed
445
        // open an unpriviledged port
446
        srv.reset(new Dhcpv6Srv(DHCP6_SERVER_PORT + 10000));
Tomek Mrugalski's avatar
Tomek Mrugalski committed
447
    });
448 449
}

450
// Test checks that DUID is generated properly
Tomek Mrugalski's avatar
Tomek Mrugalski committed
451 452
TEST_F(Dhcpv6SrvTest, DUID) {

453
    boost::scoped_ptr<Dhcpv6Srv> srv;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
454
    ASSERT_NO_THROW( {
455
        srv.reset(new NakedDhcpv6Srv(0));
Tomek Mrugalski's avatar
Tomek Mrugalski committed
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
    });

    OptionPtr srvid = srv->getServerID();
    ASSERT_TRUE(srvid);

    EXPECT_EQ(D6O_SERVERID, srvid->getType());

    OutputBuffer buf(32);
    srvid->pack(buf);

    // length of the actual DUID
    size_t len = buf.getLength() - srvid->getHeaderLen();

    InputBuffer data(buf.getData(), buf.getLength());

    // ignore first four bytes (standard DHCPv6 header)
    data.readUint32();

    uint16_t duid_type = data.readUint16();
    cout << "Duid-type=" << duid_type << endl;
    switch(duid_type) {
477
    case DUID::DUID_LLT: {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
        // DUID must contain at least 6 bytes long MAC
        // + 8 bytes of fixed header
        EXPECT_GE(14, len);

        uint16_t hw_type = data.readUint16();
        // there's no real way to find out "correct"
        // hardware type
        EXPECT_GT(hw_type, 0);

        // check that timer is counted since 1.1.2000,
        // not from 1.1.1970.
        uint32_t seconds = data.readUint32();
        EXPECT_LE(seconds, DUID_TIME_EPOCH);
        // this test will start failing after 2030.
        // Hopefully we will be at BIND12 by then.

        // MAC must not be zeros
        vector<uint8_t> mac(len-8);
        vector<uint8_t> zeros(len-8, 0);
        data.readVector(mac, len-8);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
498
        EXPECT_TRUE(mac != zeros);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
499 500
        break;
    }
501
    case DUID::DUID_EN: {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
502 503 504 505
        // there's not much we can check. Just simple
        // check if it is not all zeros
        vector<uint8_t> content(len-2);
        data.readVector(content, len-2);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
506
        EXPECT_FALSE(isRangeZero(content.begin(), content.end()));
Tomek Mrugalski's avatar
Tomek Mrugalski committed
507 508
        break;
    }
509
    case DUID::DUID_LL: {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
510
        // not supported yet
511 512 513 514 515 516 517
        cout << "Test not implemented for DUID-LL." << endl;

        // No failure here. There's really no way for test LL DUID. It doesn't
        // even make sense to check if that Link Layer is actually present on
        // a physical interface. RFC3315 says a server should write its DUID
        // and keep it despite hardware changes.
        break;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
518
    }
519
    case DUID::DUID_UUID: // not supported yet
Tomek Mrugalski's avatar
Tomek Mrugalski committed
520
    default:
521 522
        ADD_FAILURE() << "Not supported duid type=" << duid_type << endl;
        break;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
523 524 525
    }
}

526 527 528
// This test checks if Option Request Option (ORO) is parsed correctly
// and the requested options are actually assigned.
TEST_F(Dhcpv6SrvTest, advertiseOptions) {
529
    ConstElementPtr x;
530
    string config = "{ \"interfaces\": [ \"all\" ],"
531 532 533 534
        "\"preferred-lifetime\": 3000,"
        "\"rebind-timer\": 2000, "
        "\"renew-timer\": 1000, "
        "\"subnet6\": [ { "
535 536
        "    \"pool\": [ \"2001:db8:1::/64\" ],"
        "    \"subnet\": \"2001:db8:1::/48\", "
537
        "    \"option-data\": [ {"
538 539
        "          \"name\": \"dns-servers\","
        "          \"space\": \"dhcp6\","
540
        "          \"code\": 23,"
541 542
        "          \"data\": \"2001:db8:1234:FFFF::1, 2001:db8:1234:FFFF::2\","
        "          \"csv-format\": True"
543 544
        "        },"
        "        {"
545 546 547
        "          \"name\": \"subscriber-id\","
        "          \"space\": \"dhcp6\","
        "          \"code\": 38,"
548 549
        "          \"data\": \"1234\","
        "          \"csv-format\": False"
550 551 552 553 554 555
        "        } ]"
        " } ],"
        "\"valid-lifetime\": 4000 }";

    ElementPtr json = Element::fromJSON(config);

Tomek Mrugalski's avatar
Tomek Mrugalski committed
556
    NakedDhcpv6Srv srv(0);
557

Tomek Mrugalski's avatar
Tomek Mrugalski committed
558
    EXPECT_NO_THROW(x = configureDhcp6Server(srv, json));
559 560 561 562
    ASSERT_TRUE(x);
    comment_ = parseAnswer(rcode_, x);

    ASSERT_EQ(0, rcode_);
563

Tomek Mrugalski's avatar
Tomek Mrugalski committed
564
    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
565 566 567
    sol->setRemoteAddr(IOAddress("fe80::abcd"));
    sol->addOption(generateIA(234, 1500, 3000));
    OptionPtr clientid = generateClientId();
568 569
    sol->addOption(clientid);

570
    // Pass it to the server and get an advertise
571
    Pkt6Ptr adv = srv.processSolicit(sol);
572 573

    // check if we get response at all
574
    ASSERT_TRUE(adv);
575

576
    // We have not requested any options so they should not
577
    // be included in the response.
578
    ASSERT_FALSE(adv->getOption(D6O_SUBSCRIBER_ID));
579
    ASSERT_FALSE(adv->getOption(D6O_NAME_SERVERS));
580

581 582
    // Let's now request some options. We expect that the server
    // will include them in its response.
583
    boost::shared_ptr<OptionIntArray<uint16_t> >
584
        option_oro(new OptionIntArray<uint16_t>(Option::V6, D6O_ORO));
585 586
    // Create vector with two option codes.
    std::vector<uint16_t> codes(2);
587
    codes[0] = D6O_SUBSCRIBER_ID;
588
    codes[1] = D6O_NAME_SERVERS;
589 590 591 592 593
    // Pass this code to option.
    option_oro->setValues(codes);
    // Append ORO to SOLICIT message.
    sol->addOption(option_oro);

594
    // Need to process SOLICIT again after requesting new option.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
595
    adv = srv.processSolicit(sol);
596
    ASSERT_TRUE(adv);
597

598
    OptionPtr tmp = adv->getOption(D6O_NAME_SERVERS);
599
    ASSERT_TRUE(tmp);
600

601 602 603 604 605 606 607 608 609 610 611
    boost::shared_ptr<Option6AddrLst> reply_nameservers =
        boost::dynamic_pointer_cast<Option6AddrLst>(tmp);
    ASSERT_TRUE(reply_nameservers);

    Option6AddrLst::AddressContainer addrs = reply_nameservers->getAddresses();
    ASSERT_EQ(2, addrs.size());
    EXPECT_TRUE(addrs[0] == IOAddress("2001:db8:1234:FFFF::1"));
    EXPECT_TRUE(addrs[1] == IOAddress("2001:db8:1234:FFFF::2"));

    // There is a dummy option with code 1000 we requested from a server.
    // Expect that this option is in server's response.
612
    tmp = adv->getOption(D6O_SUBSCRIBER_ID);
613 614 615 616 617 618 619 620 621 622
    ASSERT_TRUE(tmp);

    // Check that the option contains valid data (from configuration).
    std::vector<uint8_t> data = tmp->getData();
    ASSERT_EQ(2, data.size());

    const uint8_t foo_expected[] = {
        0x12, 0x34
    };
    EXPECT_EQ(0, memcmp(&data[0], foo_expected, 2));
623 624

    // more checks to be implemented
625
}
626

627

628 629 630
// There are no dedicated tests for Dhcpv6Srv::handleIA_NA and Dhcpv6Srv::assignLeases
// as they are indirectly tested in Solicit and Request tests.

631 632
// This test verifies that incoming SOLICIT can be handled properly, that an
// ADVERTISE is generated, that the response has an address and that address
633 634 635
// really belongs to the configured pool.
//
// This test sends a SOLICIT without any hint in IA_NA.
636 637 638 639 640 641 642 643 644
//
// constructed very simple SOLICIT message with:
// - client-id option (mandatory)
// - IA option (a request for address, without any addresses)
//
// expected returned ADVERTISE message:
// - copy of client-id
// - server-id
// - IA that includes IAADDR
645
TEST_F(Dhcpv6SrvTest, SolicitBasic) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
646
    NakedDhcpv6Srv srv(0);
647

Tomek Mrugalski's avatar
Tomek Mrugalski committed
648
    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
649
    sol->setRemoteAddr(IOAddress("fe80::abcd"));
650 651 652
    sol->addOption(generateIA(234, 1500, 3000));
    OptionPtr clientid = generateClientId();
    sol->addOption(clientid);
653

654
    // Pass it to the server and get an advertise
Tomek Mrugalski's avatar
Tomek Mrugalski committed
655
    Pkt6Ptr reply = srv.processSolicit(sol);
656

657 658
    // check if we get response at all
    checkResponse(reply, DHCPV6_ADVERTISE, 1234);
659

660
    // check that IA_NA was returned and that there's an address included
661
    boost::shared_ptr<Option6IAAddr> addr = checkIA_NA(reply, 234, subnet_->getT1(),
662
                                                subnet_->getT2());
663
    ASSERT_TRUE(addr);
664

665 666 667 668
    // Check that the assigned address is indeed from the configured pool
    checkIAAddr(addr, addr->getAddress(), subnet_->getPreferred(), subnet_->getValid());

    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
669
    checkServerId(reply, srv.getServerID());
670 671 672
    checkClientId(reply, clientid);
}

673 674
// This test verifies that incoming SOLICIT can be handled properly, that an
// ADVERTISE is generated, that the response has an address and that address
675 676 677 678 679 680 681 682 683 684 685 686 687 688
// really belongs to the configured pool.
//
// This test sends a SOLICIT with IA_NA that contains a valid hint.
//
// constructed very simple SOLICIT message with:
// - client-id option (mandatory)
// - IA option (a request for address, with an address that belongs to the
//              configured pool, i.e. is valid as hint)
//
// expected returned ADVERTISE message:
// - copy of client-id
// - server-id
// - IA that includes IAADDR
TEST_F(Dhcpv6SrvTest, SolicitHint) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
689
    NakedDhcpv6Srv srv(0);
690 691 692 693

    // Let's create a SOLICIT
    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
    sol->setRemoteAddr(IOAddress("fe80::abcd"));
694
    boost::shared_ptr<Option6IA> ia = generateIA(234, 1500, 3000);
695 696 697 698 699 700

    // with a valid hint
    IOAddress hint("2001:db8:1:1::dead:beef");
    ASSERT_TRUE(subnet_->inPool(hint));
    OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
    ia->addOption(hint_opt);
701
    sol->addOption(ia);
702
    OptionPtr clientid = generateClientId();
703 704
    sol->addOption(clientid);

705
    // Pass it to the server and get an advertise
Tomek Mrugalski's avatar
Tomek Mrugalski committed
706
    Pkt6Ptr reply = srv.processSolicit(sol);
707 708

    // check if we get response at all
709
    checkResponse(reply, DHCPV6_ADVERTISE, 1234);
710

711
    OptionPtr tmp = reply->getOption(D6O_IA_NA);
712
    ASSERT_TRUE(tmp);
713

714
    // check that IA_NA was returned and that there's an address included
715
    boost::shared_ptr<Option6IAAddr> addr = checkIA_NA(reply, 234, subnet_->getT1(),
716
                                                subnet_->getT2());
717
    ASSERT_TRUE(addr);
718

719 720
    // check that we've got the address we requested
    checkIAAddr(addr, hint, subnet_->getPreferred(), subnet_->getValid());
721

722
    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
723
    checkServerId(reply, srv.getServerID());
724 725
    checkClientId(reply, clientid);
}
726

727 728
// This test verifies that incoming SOLICIT can be handled properly, that an
// ADVERTISE is generated, that the response has an address and that address
729 730 731 732 733 734 735 736 737 738 739 740 741 742
// really belongs to the configured pool.
//
// This test sends a SOLICIT with IA_NA that contains an invalid hint.
//
// constructed very simple SOLICIT message with:
// - client-id option (mandatory)
// - IA option (a request for address, with an address that does not
//              belong to the configured pool, i.e. is valid as hint)
//
// expected returned ADVERTISE message:
// - copy of client-id
// - server-id
// - IA that includes IAADDR
TEST_F(Dhcpv6SrvTest, SolicitInvalidHint) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
743
    NakedDhcpv6Srv srv(0);
744 745 746 747

    // Let's create a SOLICIT
    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
    sol->setRemoteAddr(IOAddress("fe80::abcd"));
748
    boost::shared_ptr<Option6IA> ia = generateIA(234, 1500, 3000);
749 750 751 752 753 754
    IOAddress hint("2001:db8:1::cafe:babe");
    ASSERT_FALSE(subnet_->inPool(hint));
    OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
    ia->addOption(hint_opt);
    sol->addOption(ia);
    OptionPtr clientid = generateClientId();
755 756
    sol->addOption(clientid);

757
    // Pass it to the server and get an advertise
Tomek Mrugalski's avatar
Tomek Mrugalski committed
758
    Pkt6Ptr reply = srv.processSolicit(sol);
759

760 761
    // check if we get response at all
    checkResponse(reply, DHCPV6_ADVERTISE, 1234);
762

763
    // check that IA_NA was returned and that there's an address included
764
    boost::shared_ptr<Option6IAAddr> addr = checkIA_NA(reply, 234, subnet_->getT1(),
765
                                                subnet_->getT2());
766
    ASSERT_TRUE(addr);
767

768 769 770
    // Check that the assigned address is indeed from the configured pool
    checkIAAddr(addr, addr->getAddress(), subnet_->getPreferred(), subnet_->getValid());
    EXPECT_TRUE(subnet_->inPool(addr->getAddress()));
771

772
    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
773
    checkServerId(reply, srv.getServerID());
774
    checkClientId(reply, clientid);
775
}
776

777 778 779
/// @todo: Add a test that client sends hint that is in pool, but currently
/// being used by a different client.

780 781
// This test checks that the server is offering different addresses to different
// clients in ADVERTISEs. Please note that ADVERTISE is not a guarantee that such
Tomek Mrugalski's avatar
Tomek Mrugalski committed
782
// an address will be assigned. Had the pool was very small and contained only
783
// 2 addresses, the third client would get the same advertise as the first one
784
// and this is a correct behavior. It is REQUEST that will fail for the third
785 786 787
// client. ADVERTISE is basically saying "if you send me a request, you will
// probably get an address like this" (there are no guarantees).
TEST_F(Dhcpv6SrvTest, ManySolicits) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
788
    NakedDhcpv6Srv srv(0);
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811

    Pkt6Ptr sol1 = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
    Pkt6Ptr sol2 = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 2345));
    Pkt6Ptr sol3 = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 3456));

    sol1->setRemoteAddr(IOAddress("fe80::abcd"));
    sol2->setRemoteAddr(IOAddress("fe80::1223"));
    sol3->setRemoteAddr(IOAddress("fe80::3467"));

    sol1->addOption(generateIA(1, 1500, 3000));
    sol2->addOption(generateIA(2, 1500, 3000));
    sol3->addOption(generateIA(3, 1500, 3000));

    // different client-id sizes
    OptionPtr clientid1 = generateClientId(12);
    OptionPtr clientid2 = generateClientId(14);
    OptionPtr clientid3 = generateClientId(16);

    sol1->addOption(clientid1);
    sol2->addOption(clientid2);
    sol3->addOption(clientid3);

    // Pass it to the server and get an advertise
Tomek Mrugalski's avatar
Tomek Mrugalski committed
812 813 814
    Pkt6Ptr reply1 = srv.processSolicit(sol1);
    Pkt6Ptr reply2 = srv.processSolicit(sol2);
    Pkt6Ptr reply3 = srv.processSolicit(sol3);
815 816

    // check if we get response at all
817 818 819 820 821
    checkResponse(reply1, DHCPV6_ADVERTISE, 1234);
    checkResponse(reply2, DHCPV6_ADVERTISE, 2345);
    checkResponse(reply3, DHCPV6_ADVERTISE, 3456);

    // check that IA_NA was returned and that there's an address included
822
    boost::shared_ptr<Option6IAAddr> addr1 = checkIA_NA(reply1, 1, subnet_->getT1(),
823
                                                subnet_->getT2());
824
    boost::shared_ptr<Option6IAAddr> addr2 = checkIA_NA(reply2, 2, subnet_->getT1(),
825
                                                subnet_->getT2());
826
    boost::shared_ptr<Option6IAAddr> addr3 = checkIA_NA(reply3, 3, subnet_->getT1(),
827
                                                subnet_->getT2());
828 829 830
    ASSERT_TRUE(addr1);
    ASSERT_TRUE(addr2);
    ASSERT_TRUE(addr3);
831 832 833 834 835 836 837

    // Check that the assigned address is indeed from the configured pool
    checkIAAddr(addr1, addr1->getAddress(), subnet_->getPreferred(), subnet_->getValid());
    checkIAAddr(addr2, addr2->getAddress(), subnet_->getPreferred(), subnet_->getValid());
    checkIAAddr(addr3, addr3->getAddress(), subnet_->getPreferred(), subnet_->getValid());

    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
838 839 840
    checkServerId(reply1, srv.getServerID());
    checkServerId(reply2, srv.getServerID());
    checkServerId(reply3, srv.getServerID());
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
    checkClientId(reply1, clientid1);
    checkClientId(reply2, clientid2);
    checkClientId(reply3, clientid3);

    // Finally check that the addresses offered are different
    EXPECT_NE(addr1->getAddress().toText(), addr2->getAddress().toText());
    EXPECT_NE(addr2->getAddress().toText(), addr3->getAddress().toText());
    EXPECT_NE(addr3->getAddress().toText(), addr1->getAddress().toText());
    cout << "Offered address to client1=" << addr1->getAddress().toText() << endl;
    cout << "Offered address to client2=" << addr2->getAddress().toText() << endl;
    cout << "Offered address to client3=" << addr3->getAddress().toText() << endl;
}

// This test verifies that incoming REQUEST can be handled properly, that a
// REPLY is generated, that the response has an address and that address
856 857
// really belongs to the configured pool.
//
858
// This test sends a REQUEST with IA_NA that contains a valid hint.
859
//
860
// constructed very simple REQUEST message with:
861 862 863 864
// - client-id option (mandatory)
// - IA option (a request for address, with an address that belongs to the
//              configured pool, i.e. is valid as hint)
//
865
// expected returned REPLY message:
866 867 868 869
// - copy of client-id
// - server-id
// - IA that includes IAADDR
TEST_F(Dhcpv6SrvTest, RequestBasic) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
870
    NakedDhcpv6Srv srv(0);
871

872 873 874
    // Let's create a REQUEST
    Pkt6Ptr req = Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 1234));
    req->setRemoteAddr(IOAddress("fe80::abcd"));
875
    boost::shared_ptr<Option6IA> ia = generateIA(234, 1500, 3000);
876 877 878 879 880 881

    // with a valid hint
    IOAddress hint("2001:db8:1:1::dead:beef");
    ASSERT_TRUE(subnet_->inPool(hint));
    OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
    ia->addOption(hint_opt);
882
    req->addOption(ia);
883
    OptionPtr clientid = generateClientId();
884
    req->addOption(clientid);
885

886
    // server-id is mandatory in REQUEST
Tomek Mrugalski's avatar
Tomek Mrugalski committed
887
    req->addOption(srv.getServerID());
888

889
    // Pass it to the server and hope for a REPLY
890
    Pkt6Ptr reply = srv.processRequest(req);
891 892

    // check if we get response at all
893
    checkResponse(reply, DHCPV6_REPLY, 1234);
894

895
    OptionPtr tmp = reply->getOption(D6O_IA_NA);
896
    ASSERT_TRUE(tmp);
897

898
    // check that IA_NA was returned and that there's an address included
899
    boost::shared_ptr<Option6IAAddr> addr = checkIA_NA(reply, 234, subnet_->getT1(),
900
                                                subnet_->getT2());
901
    ASSERT_TRUE(addr);
902

903 904
    // check that we've got the address we requested
    checkIAAddr(addr, hint, subnet_->getPreferred(), subnet_->getValid());
905

906
    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
907
    checkServerId(reply, srv.getServerID());
908
    checkClientId(reply, clientid);
909

910 911 912
    // check that the lease is really in the database
    Lease6Ptr l = checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
    EXPECT_TRUE(l);
913
    LeaseMgrFactory::instance().deleteLease(addr->getAddress());
914
}
915

916 917 918 919
// This test checks that the server is offering different addresses to different
// clients in REQUEST. Please note that ADVERTISE is not a guarantee that such
// and address will be assigned. Had the pool was very small and contained only
// 2 addresses, the third client would get the same advertise as the first one
920
// and this is a correct behavior. It is REQUEST that will fail for the third
921 922 923
// client. ADVERTISE is basically saying "if you send me a request, you will
// probably get an address like this" (there are no guarantees).
TEST_F(Dhcpv6SrvTest, ManyRequests) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
924
    NakedDhcpv6Srv srv(0);
925

926 927
    ASSERT_TRUE(subnet_);

928 929 930
    Pkt6Ptr req1 = Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 1234));
    Pkt6Ptr req2 = Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 2345));
    Pkt6Ptr req3 = Pkt6Ptr(new Pkt6(DHCPV6_REQUEST, 3456));
931

932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
    req1->setRemoteAddr(IOAddress("fe80::abcd"));
    req2->setRemoteAddr(IOAddress("fe80::1223"));
    req3->setRemoteAddr(IOAddress("fe80::3467"));

    req1->addOption(generateIA(1, 1500, 3000));
    req2->addOption(generateIA(2, 1500, 3000));
    req3->addOption(generateIA(3, 1500, 3000));

    // different client-id sizes
    OptionPtr clientid1 = generateClientId(12);
    OptionPtr clientid2 = generateClientId(14);
    OptionPtr clientid3 = generateClientId(16);

    req1->addOption(clientid1);
    req2->addOption(clientid2);
    req3->addOption(clientid3);

949
    // server-id is mandatory in REQUEST
Tomek Mrugalski's avatar
Tomek Mrugalski committed
950 951 952
    req1->addOption(srv.getServerID());
    req2->addOption(srv.getServerID());
    req3->addOption(srv.getServerID());
953

954
    // Pass it to the server and get an advertise
955 956 957
    Pkt6Ptr reply1 = srv.processRequest(req1);
    Pkt6Ptr reply2 = srv.processRequest(req2);
    Pkt6Ptr reply3 = srv.processRequest(req3);
958 959 960 961 962 963 964

    // check if we get response at all
    checkResponse(reply1, DHCPV6_REPLY, 1234);
    checkResponse(reply2, DHCPV6_REPLY, 2345);
    checkResponse(reply3, DHCPV6_REPLY, 3456);

    // check that IA_NA was returned and that there's an address included
965
    boost::shared_ptr<Option6IAAddr> addr1 = checkIA_NA(reply1, 1, subnet_->getT1(),
966
                                                subnet_->getT2());
967
    boost::shared_ptr<Option6IAAddr> addr2 = checkIA_NA(reply2, 2, subnet_->getT1(),
968
                                                subnet_->getT2());
969
    boost::shared_ptr<Option6IAAddr> addr3 = checkIA_NA(reply3, 3, subnet_->getT1(),
970 971
                                                subnet_->getT2());

972 973 974 975
    ASSERT_TRUE(addr1);
    ASSERT_TRUE(addr2);
    ASSERT_TRUE(addr3);

976 977 978 979 980 981
    // Check that the assigned address is indeed from the configured pool
    checkIAAddr(addr1, addr1->getAddress(), subnet_->getPreferred(), subnet_->getValid());
    checkIAAddr(addr2, addr2->getAddress(), subnet_->getPreferred(), subnet_->getValid());
    checkIAAddr(addr3, addr3->getAddress(), subnet_->getPreferred(), subnet_->getValid());

    // check DUIDs
Tomek Mrugalski's avatar
Tomek Mrugalski committed
982 983 984
    checkServerId(reply1, srv.getServerID());
    checkServerId(reply2, srv.getServerID());
    checkServerId(reply3, srv.getServerID());
985 986 987 988 989 990 991 992 993 994 995
    checkClientId(reply1, clientid1);
    checkClientId(reply2, clientid2);
    checkClientId(reply3, clientid3);

    // Finally check that the addresses offered are different
    EXPECT_NE(addr1->getAddress().toText(), addr2->getAddress().toText());
    EXPECT_NE(addr2->getAddress().toText(), addr3->getAddress().toText());
    EXPECT_NE(addr3->getAddress().toText(), addr1->getAddress().toText());
    cout << "Assigned address to client1=" << addr1->getAddress().toText() << endl;
    cout << "Assigned address to client2=" << addr2->getAddress().toText() << endl;
    cout << "Assigned address to client3=" << addr3->getAddress().toText() << endl;
996
}
997

998 999 1000 1001 1002 1003 1004 1005 1006 1007
// This test verifies that incoming (positive) RENEW can be handled properly, that a
// REPLY is generated, that the response has an address and that address
// really belongs to the configured pool and that lease is actually renewed.
//
// expected:
// - returned REPLY message has copy of client-id
// - returned REPLY message has server-id
// - returned REPLY message has IA that includes IAADDR
// - lease is actually renewed in LeaseMgr
TEST_F(Dhcpv6SrvTest, RenewBasic) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1008
    NakedDhcpv6Srv srv(0);
1009

Tomek Mrugalski's avatar
Tomek Mrugalski committed
1010
    const IOAddress addr("2001:db8:1:1::cafe:babe");
1011
    const uint32_t iaid = 234;
1012

Tomek Mrugalski's avatar
Tomek Mrugalski committed
1013
    // Generate client-id also duid_
1014
    OptionPtr clientid = generateClientId();
1015

Tomek Mrugalski's avatar
Tomek Mrugalski committed
1016 1017 1018
    // Check that the address we are about to use is indeed in pool
    ASSERT_TRUE(subnet_->inPool(addr));

1019 1020 1021 1022 1023 1024 1025
    // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
    // value on purpose. They should be updated during RENEW.
    Lease6Ptr lease(new Lease6(Lease6::LEASE_IA_NA, addr, duid_, iaid,
                               501, 502, 503, 504, subnet_->getID(), 0));
    lease->cltt_ = 1234;
    ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));