dhcp4_srv_unittest.cc 126 KB
Newer Older
1
// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
// 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.

#include <config.h>
#include <sstream>

18
#include <asiolink/io_address.h>
19
#include <config/ccsession.h>
20
#include <dhcp4/tests/dhcp4_test_utils.h>
21
#include <dhcp/dhcp4.h>
22
#include <dhcp/iface_mgr.h>
23
#include <dhcp/option.h>
24
#include <dhcp/option_int.h>
25
#include <dhcp/option4_addrlst.h>
26
#include <dhcp/option_custom.h>
27
#include <dhcp/option_int_array.h>
28
#include <dhcp/option_vendor.h>
29 30
#include <dhcp/pkt_filter.h>
#include <dhcp/pkt_filter_inet.h>
31
#include <dhcp/docsis3_option_defs.h>
32
#include <dhcp/tests/iface_mgr_test_config.h>
33
#include <dhcp4/dhcp4_srv.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
34
#include <dhcp4/dhcp4_log.h>
35
#include <dhcp4/json_config_parser.h>
36
#include <hooks/server_hooks.h>
37 38 39 40
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/utils.h>
41
#include <gtest/gtest.h>
42 43
#include <hooks/server_hooks.h>
#include <hooks/hooks_manager.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
44
#include <config/ccsession.h>
45

46 47
#include <boost/scoped_ptr.hpp>

48 49 50
#include <iostream>

#include <arpa/inet.h>
51 52 53 54

using namespace std;
using namespace isc;
using namespace isc::dhcp;
55
using namespace isc::data;
56
using namespace isc::asiolink;
57
using namespace isc::hooks;
58
using namespace isc::dhcp::test;
59 60 61

namespace {

62 63 64
// This test verifies that the destination address of the response
// message is set to giaddr, when giaddr is set to non-zero address
// in the received message.
65 66 67 68
TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelay) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

69
    // Create the instance of the incoming packet.
70
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
71 72
    // Set the giaddr to non-zero address and hops to non-zero value
    // as if it was relayed.
73
    req->setGiaddr(IOAddress("192.0.1.1"));
74
    req->setHops(2);
75 76
    // Set ciaddr to zero. This simulates the client which applies
    // for the new lease.
77
    req->setCiaddr(IOAddress("0.0.0.0"));
78 79 80
    // Clear broadcast flag.
    req->setFlags(0x0000);

81
    // Set local address, port and interface.
82
    req->setLocalAddr(IOAddress("192.0.2.1"));
83
    req->setLocalPort(1001);
84
    req->setIface("eth1");
85 86
    req->setIndex(1);

87 88 89 90
    // Create a response packet. Assume that the new lease have
    // been created and new address allocated. This address is
    // stored in yiaddr field.
    boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
91
    resp->setYiaddr(IOAddress("192.0.1.100"));
92 93
    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));
94 95
    // Set hops value for the response.
    resp->setHops(req->getHops());
96

97
    // This function never throws.
98
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
99

100
    // Now the destination address should be relay's address.
101
    EXPECT_EQ("192.0.1.1", resp->getRemoteAddr().toText());
102 103
    // The query has been relayed, so the response must be sent to the port 67.
    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
104 105
    // Local address should be the address assigned to interface eth1.
    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
106 107 108 109
    // The local port is always DHCPv4 server port 67.
    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
    // We will send response over the same interface which was used to receive
    // query.
110
    EXPECT_EQ("eth1", resp->getIface());
111
    EXPECT_EQ(1, resp->getIndex());
112 113 114 115

    // Let's do another test and set other fields: ciaddr and
    // flags. By doing it, we want to make sure that the relay
    // address will take precedence.
116 117
    req->setGiaddr(IOAddress("192.0.1.50"));
    req->setCiaddr(IOAddress("192.0.1.11"));
118
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
119

120
    resp->setYiaddr(IOAddress("192.0.1.100"));
121 122 123
    // Clear remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));

124
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
125 126

    // Response should be sent back to the relay address.
127
    EXPECT_EQ("192.0.1.50", resp->getRemoteAddr().toText());
128 129
}

130 131 132 133
// This test verifies that the destination address of the response message
// is set to ciaddr when giaddr is set to zero and the ciaddr is set to
// non-zero address in the received message. This is the case when the
// client is in Renew or Rebind state.
134 135 136 137
TEST_F(Dhcpv4SrvTest, adjustIfaceDataRenew) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

138 139 140 141 142 143 144 145
    // Create instance of the incoming packet.
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));

    // Clear giaddr to simulate direct packet.
    req->setGiaddr(IOAddress("0.0.0.0"));
    // Set ciaddr to non-zero address. The response should be sent to this
    // address as the client is in renewing or rebinding state (it is fully
    // configured).
146
    req->setCiaddr(IOAddress("192.0.1.15"));
147 148 149 150 151 152
    // Let's configure broadcast flag. It should be ignored because
    // we are responding directly to the client having an address
    // and trying to extend his lease. Broadcast flag is only used
    // when new lease is acquired and server must make a decision
    // whether to unicast the response to the acquired address or
    // broadcast it.
153
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
154 155 156
    // This is a direct message, so the hops should be cleared.
    req->setHops(0);
    // Set local unicast address as if we are renewing a lease.
157
    req->setLocalAddr(IOAddress("192.0.2.1"));
158 159 160
    // Request is received on the DHCPv4 server port.
    req->setLocalPort(DHCP4_SERVER_PORT);
    // Set the interface. The response should be sent over the same interface.
161
    req->setIface("eth1");
162
    req->setIndex(1);
163 164 165 166 167 168 169

    // Create a response.
    boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
    // Let's extend the lease for the client in such a way that
    // it will actually get different address. The response
    // should not be sent to this address but rather to ciaddr
    // as client still have ciaddr configured.
170
    resp->setYiaddr(IOAddress("192.0.1.13"));
171 172
    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));
173 174
    // Copy hops value from the query.
    resp->setHops(req->getHops());
175

176
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
177 178

    // Check that server responds to ciaddr
179
    EXPECT_EQ("192.0.1.15", resp->getRemoteAddr().toText());
180 181 182 183 184
    // The query was non-relayed, so the response should be sent to a DHCPv4
    // client port 68.
    EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getRemotePort());
    // The response should be sent from the unicast address on which the
    // query has been received.
185
    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
186 187 188
    // The response should be sent from the DHCPv4 server port.
    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
    // The interface data should match the data in the query.
189
    EXPECT_EQ("eth1", resp->getIface());
190 191
    EXPECT_EQ(1, resp->getIndex());

192 193
}

194 195 196 197 198 199 200
// This test verifies that the destination address of the response message
// is set correctly when giaddr and ciaddr is zeroed in the received message
// and the new lease is acquired. The lease address is carried in the
// response message in the yiaddr field. In this case destination address
// of the response should be set to yiaddr if server supports direct responses
// to the client which doesn't have an address yet or broadcast if the server
// doesn't support direct responses.
201 202 203 204
TEST_F(Dhcpv4SrvTest, adjustIfaceDataSelect) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

205 206 207 208 209 210 211 212 213 214 215
    // Create instance of the incoming packet.
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));

    // Clear giaddr to simulate direct packet.
    req->setGiaddr(IOAddress("0.0.0.0"));
    // Clear client address as it hasn't got any address configured yet.
    req->setCiaddr(IOAddress("0.0.0.0"));

    // Let's clear the broadcast flag.
    req->setFlags(0);

216 217 218 219 220 221 222
    // This is a non-relayed message, so let's clear hops count.
    req->setHops(0);
    // The query is sent to the broadcast address in the Select state.
    req->setLocalAddr(IOAddress("255.255.255.255"));
    // The query has been received on the DHCPv4 server port 67.
    req->setLocalPort(DHCP4_SERVER_PORT);
    // Set the interface. The response should be sent via the same interface.
223
    req->setIface("eth1");
224 225
    req->setIndex(1);

226 227 228
    // Create a response.
    boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
    // Assign some new address for this client.
229
    resp->setYiaddr(IOAddress("192.0.1.13"));
230 231
    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));
232 233 234 235 236 237 238 239
    // Copy hops count.
    resp->setHops(req->getHops());

    // We want to test the case, when the server (packet filter) doesn't support
    // ddirect responses to the client which doesn't have an address yet. In
    // case, the server should send its response to the broadcast address.
    // We can control whether the current packet filter returns that its support
    // direct responses or not.
240
    test_config.setDirectResponse(false);
241 242 243 244 245 246 247

    // When running unit tests, the IfaceMgr is using the default Packet
    // Filtering class, PktFilterInet. This class does not support direct
    // responses to clients without address assigned. When giaddr and ciaddr
    // are zero and client has just got new lease, the assigned address is
    // carried in yiaddr. In order to send this address to the client,
    // server must broadcast its response.
248
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
249 250 251 252 253

    // Check that the response is sent to broadcast address as the
    // server doesn't have capability to respond directly.
    EXPECT_EQ("255.255.255.255", resp->getRemoteAddr().toText());

254 255 256
    // Although the query has been sent to the broadcast address, the
    // server should select a unicast address on the particular interface
    // as a source address for the response.
257
    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
258 259 260 261 262 263

    // The response should be sent from the DHCPv4 server port.
    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());

    // The response should be sent via the same interface through which
    // query has been received.
264
    EXPECT_EQ("eth1", resp->getIface());
265 266
    EXPECT_EQ(1, resp->getIndex());

267 268 269
    // We also want to test the case when the server has capability to
    // respond directly to the client which is not configured. Server
    // makes decision whether it responds directly or broadcast its
270 271 272
    // response based on the capability reported by IfaceMgr. We can
    // control whether the current packet filter returns that it supports
    // direct responses or not.
273
    test_config.setDirectResponse(true);
274 275 276

    // Now we expect that the server will send its response to the
    // address assigned for the client.
277
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
278

279
    EXPECT_EQ("192.0.1.13", resp->getRemoteAddr().toText());
280 281
}

282 283 284 285 286
// This test verifies that the destination address of the response message
// is set to broadcast address when client set broadcast flag in its
// query. Client sets this flag to indicate that it can't receive direct
// responses from the server when it doesn't have its interface configured.
// Server must respect broadcast flag.
287 288 289 290
TEST_F(Dhcpv4SrvTest, adjustIfaceDataBroadcast) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

291 292 293 294 295 296 297
    // Create instance of the incoming packet.
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));

    // Clear giaddr to simulate direct packet.
    req->setGiaddr(IOAddress("0.0.0.0"));
    // Clear client address as it hasn't got any address configured yet.
    req->setCiaddr(IOAddress("0.0.0.0"));
298 299 300 301 302
    // The query is sent to the broadcast address in the Select state.
    req->setLocalAddr(IOAddress("255.255.255.255"));
    // The query has been received on the DHCPv4 server port 67.
    req->setLocalPort(DHCP4_SERVER_PORT);
    // Set the interface. The response should be sent via the same interface.
303
    req->setIface("eth1");
304
    req->setIndex(1);
305 306

    // Let's set the broadcast flag.
307
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
308 309 310 311

    // Create a response.
    boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
    // Assign some new address for this client.
312
    resp->setYiaddr(IOAddress("192.0.1.13"));
313 314 315 316

    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));

317
    ASSERT_NO_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp));
318 319 320 321

    // Server must repond to broadcast address when client desired that
    // by setting the broadcast flag in its request.
    EXPECT_EQ("255.255.255.255", resp->getRemoteAddr().toText());
322 323 324 325

    // Although the query has been sent to the broadcast address, the
    // server should select a unicast address on the particular interface
    // as a source address for the response.
326
    EXPECT_EQ("192.0.2.3", resp->getLocalAddr().toText());
327 328 329 330 331 332

    // The response should be sent from the DHCPv4 server port.
    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());

    // The response should be sent via the same interface through which
    // query has been received.
333
    EXPECT_EQ("eth1", resp->getIface());
334 335 336 337
    EXPECT_EQ(1, resp->getIndex());

}

338 339
// This test verifies that exception is thrown of the invalid combination
// of giaddr and hops is specified in a client's message.
340
TEST_F(Dhcpv4SrvTest, adjustIfaceDataInvalid) {
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));

    // The hops and giaddr values are used to determine if the client's
    // message has been relayed or sent directly. The allowed combinations
    // are (giaddr = 0 and hops = 0) or (giaddr != 0 and hops != 0). Any
    // other combination is invalid and the adjustIfaceData should throw
    // an exception. We will test that exception is indeed thrown.
    req->setGiaddr(IOAddress("0.0.0.0"));
    req->setHops(1);

    // Clear client address as it hasn't got any address configured yet.
    req->setCiaddr(IOAddress("0.0.0.0"));
    // The query is sent to the broadcast address in the Select state.
    req->setLocalAddr(IOAddress("255.255.255.255"));
    // The query has been received on the DHCPv4 server port 67.
    req->setLocalPort(DHCP4_SERVER_PORT);
    // Set the interface. The response should be sent via the same interface.
    req->setIface("eth0");
    req->setIndex(1);

    // Create a response.
    boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
    // Assign some new address for this client.
    resp->setYiaddr(IOAddress("192.0.2.13"));

    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));

    EXPECT_THROW(NakedDhcpv4Srv::adjustIfaceData(req, resp), isc::BadValue);
}

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
// This test verifies that the server identifier option is appended to
// a specified DHCPv4 message and the server identifier is correct.
TEST_F(Dhcpv4SrvTest, appendServerID) {
    Pkt4Ptr response(new Pkt4(DHCPDISCOVER, 1234));
    // Set a local address. It is required by the function under test
    // to create the Server Identifier option.
    response->setLocalAddr(IOAddress("192.0.3.1"));

    // Append the Server Identifier.
    ASSERT_NO_THROW(NakedDhcpv4Srv::appendServerID(response));

    // Make sure that the option has been added.
    OptionPtr opt = response->getOption(DHO_DHCP_SERVER_IDENTIFIER);
    ASSERT_TRUE(opt);
    Option4AddrLstPtr opt_server_id =
        boost::dynamic_pointer_cast<Option4AddrLst>(opt);
    ASSERT_TRUE(opt_server_id);

    // The option is represented as a list of IPv4 addresses but with
    // only one address added.
    Option4AddrLst::AddressContainer addrs = opt_server_id->getAddresses();
    ASSERT_EQ(1, addrs.size());
    // This address should match the local address of the packet.
    EXPECT_EQ("192.0.3.1", addrs[0].toText());
396 397
}

398 399 400 401 402 403
// Sanity check. Verifies that both Dhcpv4Srv and its derived
// class NakedDhcpv4Srv can be instantiated and destroyed.
TEST_F(Dhcpv4SrvTest, basic) {

    // Check that the base class can be instantiated
    boost::scoped_ptr<Dhcpv4Srv> srv;
404 405
    ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000, false,
                                            false)));
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
    srv.reset();
    // We have to close open sockets because further in this test we will
    // call the Dhcpv4Srv constructor again. This constructor will try to
    // set the appropriate packet filter class for IfaceMgr. This requires
    // that all sockets are closed.
    IfaceMgr::instance().closeSockets();

    // Check that the derived class can be instantiated
    boost::scoped_ptr<NakedDhcpv4Srv> naked_srv;
    ASSERT_NO_THROW(
        naked_srv.reset(new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
    // Close sockets again for the next test.
    IfaceMgr::instance().closeSockets();

    ASSERT_NO_THROW(naked_srv.reset(new NakedDhcpv4Srv(0)));
}

423
// Verifies that DISCOVER message can be processed correctly,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
424 425 426 427 428 429 430
// that the OFFER message generated in response is valid and
// contains necessary options.
//
// Note: this test focuses on the packet correctness. There
// are other tests that verify correctness of the allocation
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
// and DiscoverInvalidHint.
431
TEST_F(Dhcpv4SrvTest, processDiscover) {
432
    testDiscoverRequest(DHCPDISCOVER);
433
}
434

435
// Verifies that REQUEST message can be processed correctly,
436
// that the OFFER message generated in response is valid and
Tomek Mrugalski's avatar
Tomek Mrugalski committed
437 438 439 440
// contains necessary options.
//
// Note: this test focuses on the packet correctness. There
// are other tests that verify correctness of the allocation
441 442
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
// and DiscoverInvalidHint.
443
TEST_F(Dhcpv4SrvTest, processRequest) {
444
    testDiscoverRequest(DHCPREQUEST);
445 446
}

447
TEST_F(Dhcpv4SrvTest, processRelease) {
448
    NakedDhcpv4Srv srv;
449
    Pkt4Ptr pkt(new Pkt4(DHCPRELEASE, 1234));
450

451
    // Should not throw
452
    EXPECT_NO_THROW(srv.processRelease(pkt));
453 454
}

455
TEST_F(Dhcpv4SrvTest, processDecline) {
456
    NakedDhcpv4Srv srv;
457
    Pkt4Ptr pkt(new Pkt4(DHCPDECLINE, 1234));
458

459
    // Should not throw
460
    EXPECT_NO_THROW(srv.processDecline(pkt));
461 462
}

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
TEST_F(Dhcpv4SrvTest, serverReceivedPacketName) {
    // Check all possible packet types
    for (int itype = 0; itype < 256; ++itype) {
        uint8_t type = itype;

        switch (type) {
        case DHCPDECLINE:
            EXPECT_STREQ("DECLINE", Dhcpv4Srv::serverReceivedPacketName(type));
            break;

        case DHCPDISCOVER:
            EXPECT_STREQ("DISCOVER", Dhcpv4Srv::serverReceivedPacketName(type));
            break;

        case DHCPINFORM:
            EXPECT_STREQ("INFORM", Dhcpv4Srv::serverReceivedPacketName(type));
            break;

        case DHCPRELEASE:
            EXPECT_STREQ("RELEASE", Dhcpv4Srv::serverReceivedPacketName(type));
            break;

        case DHCPREQUEST:
            EXPECT_STREQ("REQUEST", Dhcpv4Srv::serverReceivedPacketName(type));
            break;

        default:
            EXPECT_STREQ("UNKNOWN", Dhcpv4Srv::serverReceivedPacketName(type));
        }
    }
}

495 496 497 498 499 500 501 502 503 504 505
// This test verifies that incoming DISCOVER can be handled properly, that an
// OFFER is generated, that the response has an address and that address
// really belongs to the configured pool.
//
// constructed very simple DISCOVER message with:
// - client-id option
//
// expected returned OFFER message:
// - copy of client-id
// - server-id
// - offered address
506 507 508 509
TEST_F(Dhcpv4SrvTest, DiscoverBasic) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

510
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
511
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
512 513 514 515 516

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.1"));
    OptionPtr clientid = generateClientId();
    dis->addOption(clientid);
517
    dis->setIface("eth1");
518

519
    // Pass it to the server and get an offer
520 521
    Pkt4Ptr offer = srv->processDiscover(dis);

522
    // Check if we get response at all
523 524
    checkResponse(offer, DHCPOFFER, 1234);

525
    // Check that address was returned from proper range, that its lease
526
    // lifetime is correct, that T1 and T2 are returned properly
527
    checkAddressParams(offer, subnet_, true, true);
528

529
    // Check identifiers
530 531 532 533
    checkServerId(offer, srv->getServerID());
    checkClientId(offer, clientid);
}

534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
// Check that option 58 and 59 are not included if they are not specified.
TEST_F(Dhcpv4SrvTest, DiscoverNoTimers) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

    boost::scoped_ptr<NakedDhcpv4Srv> srv;
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.1"));
    OptionPtr clientid = generateClientId();
    dis->addOption(clientid);
    dis->setIface("eth1");

    // Recreate a subnet but set T1 and T2 to "unspecified".
    subnet_.reset(new Subnet4(IOAddress("192.0.2.0"), 24,
                              Triplet<uint32_t>(),
                              Triplet<uint32_t>(),
                              3000));
    pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.100"),
                               IOAddress("192.0.2.110")));
    subnet_->addPool(pool_);
    CfgMgr::instance().deleteSubnets4();
    CfgMgr::instance().addSubnet4(subnet_);

    // Pass it to the server and get an offer
    Pkt4Ptr offer = srv->processDiscover(dis);

    // Check if we get response at all
    checkResponse(offer, DHCPOFFER, 1234);

    // T1 and T2 timers must not be present.
    checkAddressParams(offer, subnet_, false, false);

    // Check identifiers
    checkServerId(offer, srv->getServerID());
    checkClientId(offer, clientid);
}
572 573 574 575 576 577 578 579 580 581 582 583 584

// This test verifies that incoming DISCOVER can be handled properly, that an
// OFFER is generated, that the response has an address and that address
// really belongs to the configured pool.
//
// constructed very simple DISCOVER message with:
// - client-id option
// - address set to specific value as hint, but that hint is invalid
//
// expected returned OFFER message:
// - copy of client-id
// - server-id
// - offered address (!= hint)
585 586 587 588
TEST_F(Dhcpv4SrvTest, DiscoverInvalidHint) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

589
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
590
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
591 592 593 594 595 596 597
    IOAddress hint("10.1.2.3");

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.107"));
    OptionPtr clientid = generateClientId();
    dis->addOption(clientid);
    dis->setYiaddr(hint);
598
    dis->setIface("eth1");
599

600
    // Pass it to the server and get an offer
601 602
    Pkt4Ptr offer = srv->processDiscover(dis);

603
    // Check if we get response at all
604 605
    checkResponse(offer, DHCPOFFER, 1234);

606
    // Check that address was returned from proper range, that its lease
607
    // lifetime is correct, that T1 and T2 are returned properly
608
    checkAddressParams(offer, subnet_, true, true);
609

610
    EXPECT_NE(offer->getYiaddr(), hint);
611

612
    // Check identifiers
613 614 615 616 617 618 619 620
    checkServerId(offer, srv->getServerID());
    checkClientId(offer, clientid);
}

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

// This test checks that the server is offering different addresses to different
Tomek Mrugalski's avatar
Tomek Mrugalski committed
621 622
// clients in OFFERs. Please note that OFFER is not a guarantee that such
// an address will be assigned. Had the pool was very small and contained only
623
// 2 addresses, the third client would get the same offer as the first one
624
// and this is a correct behavior. It is REQUEST that will fail for the third
Tomek Mrugalski's avatar
Tomek Mrugalski committed
625
// client. OFFER is basically saying "if you send me a request, you will
626
// probably get an address like this" (there are no guarantees).
627 628 629 630
TEST_F(Dhcpv4SrvTest, ManyDiscovers) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

631
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
632
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
633 634 635 636 637 638 639 640 641

    Pkt4Ptr dis1 = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    Pkt4Ptr dis2 = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 2345));
    Pkt4Ptr dis3 = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 3456));

    dis1->setRemoteAddr(IOAddress("192.0.2.1"));
    dis2->setRemoteAddr(IOAddress("192.0.2.2"));
    dis3->setRemoteAddr(IOAddress("192.0.2.3"));

642
    // Assign interfaces
643 644 645
    dis1->setIface("eth1");
    dis2->setIface("eth1");
    dis3->setIface("eth1");
646

647
    // Different client-id sizes
648 649 650 651 652 653 654 655
    OptionPtr clientid1 = generateClientId(4); // length 4
    OptionPtr clientid2 = generateClientId(5); // length 5
    OptionPtr clientid3 = generateClientId(6); // length 6

    dis1->addOption(clientid1);
    dis2->addOption(clientid2);
    dis3->addOption(clientid3);

656 657 658 659
    // Pass it to the server and get an offer
    Pkt4Ptr offer1 = srv->processDiscover(dis1);
    Pkt4Ptr offer2 = srv->processDiscover(dis2);
    Pkt4Ptr offer3 = srv->processDiscover(dis3);
660

661 662 663 664
    // Check if we get response at all
    checkResponse(offer1, DHCPOFFER, 1234);
    checkResponse(offer2, DHCPOFFER, 2345);
    checkResponse(offer3, DHCPOFFER, 3456);
665

666 667 668
    IOAddress addr1 = offer1->getYiaddr();
    IOAddress addr2 = offer2->getYiaddr();
    IOAddress addr3 = offer3->getYiaddr();
669 670

    // Check that the assigned address is indeed from the configured pool
671 672 673
    checkAddressParams(offer1, subnet_, true, true);
    checkAddressParams(offer2, subnet_, true, true);
    checkAddressParams(offer3, subnet_, true, true);
674

675
    // Check server-ids
676 677 678 679 680 681
    checkServerId(offer1, srv->getServerID());
    checkServerId(offer2, srv->getServerID());
    checkServerId(offer3, srv->getServerID());
    checkClientId(offer1, clientid1);
    checkClientId(offer2, clientid2);
    checkClientId(offer3, clientid3);
682 683

    // Finally check that the addresses offered are different
684 685 686 687 688 689
    EXPECT_NE(addr1, addr2);
    EXPECT_NE(addr2, addr3);
    EXPECT_NE(addr3, addr1);
    cout << "Offered address to client1=" << addr1 << endl;
    cout << "Offered address to client2=" << addr2 << endl;
    cout << "Offered address to client3=" << addr3 << endl;
690 691
}

Tomek Mrugalski's avatar
Tomek Mrugalski committed
692 693 694
// Checks whether echoing back client-id is controllable, i.e.
// whether the server obeys echo-client-id and sends (or not)
// client-id
695 696 697 698
TEST_F(Dhcpv4SrvTest, discoverEchoClientId) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

699 700 701 702 703 704
    NakedDhcpv4Srv srv(0);

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.1"));
    OptionPtr clientid = generateClientId();
    dis->addOption(clientid);
705
    dis->setIface("eth1");
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721

    // Pass it to the server and get an offer
    Pkt4Ptr offer = srv.processDiscover(dis);

    // Check if we get response at all
    checkResponse(offer, DHCPOFFER, 1234);
    checkClientId(offer, clientid);

    CfgMgr::instance().echoClientId(false);
    offer = srv.processDiscover(dis);

    // Check if we get response at all
    checkResponse(offer, DHCPOFFER, 1234);
    checkClientId(offer, clientid);
}

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
// Check that option 58 and 59 are not included if they are not specified.
TEST_F(Dhcpv4SrvTest, RequestNoTimers) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

    boost::scoped_ptr<NakedDhcpv4Srv> srv;
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));

    Pkt4Ptr req = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
    req->setRemoteAddr(IOAddress("192.0.2.1"));
    OptionPtr clientid = generateClientId();
    req->addOption(clientid);
    req->setIface("eth1");

    // Recreate a subnet but set T1 and T2 to "unspecified".
    subnet_.reset(new Subnet4(IOAddress("192.0.2.0"), 24,
                              Triplet<uint32_t>(),
                              Triplet<uint32_t>(),
                              3000));
    pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.100"),
                               IOAddress("192.0.2.110")));
    subnet_->addPool(pool_);
    CfgMgr::instance().deleteSubnets4();
    CfgMgr::instance().addSubnet4(subnet_);

    // Pass it to the server and get an ACK.
    Pkt4Ptr ack = srv->processRequest(req);

    // Check if we get response at all
    checkResponse(ack, DHCPACK, 1234);

    // T1 and T2 timers must not be present.
    checkAddressParams(ack, subnet_, false, false);

    // Check identifiers
    checkServerId(ack, srv->getServerID());
    checkClientId(ack, clientid);
}

761
// Checks whether echoing back client-id is controllable
762 763 764 765
TEST_F(Dhcpv4SrvTest, requestEchoClientId) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

766 767 768 769 770 771
    NakedDhcpv4Srv srv(0);

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.1"));
    OptionPtr clientid = generateClientId();
    dis->addOption(clientid);
772
    dis->setIface("eth1");
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788

    // Pass it to the server and get ACK
    Pkt4Ptr ack = srv.processRequest(dis);

    // Check if we get response at all
    checkResponse(ack, DHCPACK, 1234);
    checkClientId(ack, clientid);

    CfgMgr::instance().echoClientId(false);
    ack = srv.processDiscover(dis);

    // Check if we get response at all
    checkResponse(ack, DHCPOFFER, 1234);
    checkClientId(ack, clientid);
}

Tomek Mrugalski's avatar
Tomek Mrugalski committed
789 790

// This test verifies that incoming (positive) REQUEST/Renewing can be handled properly, that a
791 792 793 794 795 796 797 798
// 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
799 800 801 802
TEST_F(Dhcpv4SrvTest, RenewBasic) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

803
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
804
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
805 806

    const IOAddress addr("192.0.2.106");
807 808 809 810
    const uint32_t temp_t1 = 50;
    const uint32_t temp_t2 = 75;
    const uint32_t temp_valid = 100;
    const time_t temp_timestamp = time(NULL) - 10;
811

812
    // Generate client-id also sets client_id_ member
813 814 815
    OptionPtr clientid = generateClientId();

    // Check that the address we are about to use is indeed in pool
816
    ASSERT_TRUE(subnet_->inPool(Lease::TYPE_V4, addr));
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840

    // let's create a lease and put it in the LeaseMgr
    uint8_t hwaddr2[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
    Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, sizeof(hwaddr2),
                              &client_id_->getDuid()[0], client_id_->getDuid().size(),
                              temp_valid, temp_t1, temp_t2, temp_timestamp,
                              subnet_->getID()));
    ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));

    // Check that the lease is really in the database
    Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
    ASSERT_TRUE(l);

    // Check that T1, T2, preferred, valid and cltt really set.
    // Constructed lease looks as if it was assigned 10 seconds ago
    // EXPECT_EQ(l->t1_, temp_t1);
    // EXPECT_EQ(l->t2_, temp_t2);
    EXPECT_EQ(l->valid_lft_, temp_valid);
    EXPECT_EQ(l->cltt_, temp_timestamp);

    // Let's create a RENEW
    Pkt4Ptr req = Pkt4Ptr(new Pkt4(DHCPREQUEST, 1234));
    req->setRemoteAddr(IOAddress(addr));
    req->setYiaddr(addr);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
841
    req->setCiaddr(addr); // client's address
842
    req->setIface("eth0");
843 844 845 846 847 848 849 850 851

    req->addOption(clientid);
    req->addOption(srv->getServerID());

    // Pass it to the server and hope for a REPLY
    Pkt4Ptr ack = srv->processRequest(req);

    // Check if we get response at all
    checkResponse(ack, DHCPACK, 1234);
852
    EXPECT_EQ(addr, ack->getYiaddr());
853

854
    // Check that address was returned from proper range, that its lease
855
    // lifetime is correct, that T1 and T2 are returned properly
856
    checkAddressParams(ack, subnet_, true, true);
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873

    // Check identifiers
    checkServerId(ack, srv->getServerID());
    checkClientId(ack, clientid);

    // Check that the lease is really in the database
    l = checkLease(ack, clientid, req->getHWAddr(), addr);
    ASSERT_TRUE(l);

    // Check that T1, T2, preferred, valid and cltt were really updated
    EXPECT_EQ(l->t1_, subnet_->getT1());
    EXPECT_EQ(l->t2_, subnet_->getT2());
    EXPECT_EQ(l->valid_lft_, subnet_->getValid());

    // Checking for CLTT is a bit tricky if we want to avoid off by 1 errors
    int32_t cltt = static_cast<int32_t>(l->cltt_);
    int32_t expected = static_cast<int32_t>(time(NULL));
874
    // Equality or difference by 1 between cltt and expected is ok.
875 876 877 878 879
    EXPECT_GE(1, abs(cltt - expected));

    EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
}

880 881 882 883 884 885 886
// This test verifies that the logic which matches server identifier in the
// received message with server identifiers used by a server works correctly:
// - a message with no server identifier is accepted,
// - a message with a server identifier which matches one of the server
// identifiers used by a server is accepted,
// - a message with a server identifier which doesn't match any server
// identifier used by a server, is not accepted.
887 888 889 890
TEST_F(Dhcpv4SrvTest, acceptServerId) {
    IfaceMgrTestConfig test_config(true);
    IfaceMgr::instance().openSockets4();

891 892 893 894 895 896 897
    NakedDhcpv4Srv srv(0);

    Pkt4Ptr pkt(new Pkt4(DHCPREQUEST, 1234));
    // If no server identifier option is present, the message is always
    // accepted.
    EXPECT_TRUE(srv.acceptServerId(pkt));

898 899 900 901
    // Create definition of the server identifier option.
    OptionDefinition def("server-identifier", DHO_DHCP_SERVER_IDENTIFIER,
                         "ipv4-address", false);

902 903 904
    // Add a server identifier option which doesn't match server ids being
    // used by the server. The accepted server ids are the IPv4 addresses
    // configured on the interfaces. The 10.1.2.3 is not configured on
905 906 907
    // any interfaces.
    OptionCustomPtr other_serverid(new OptionCustom(def, Option::V6));
    other_serverid->writeAddress(IOAddress("10.1.2.3"));
908 909 910 911 912 913 914 915
    pkt->addOption(other_serverid);
    EXPECT_FALSE(srv.acceptServerId(pkt));

    // Remove the server identifier.
    ASSERT_NO_THROW(pkt->delOption(DHO_DHCP_SERVER_IDENTIFIER));

    // Add a server id being an IPv4 address configured on eth0 interface.
    // A DHCPv4 message holding this server identifier should be accepted.
916
    OptionCustomPtr eth0_serverid(new OptionCustom(def, Option::V6));
917
    eth0_serverid->writeAddress(IOAddress("192.0.2.3"));
918 919 920 921 922 923 924 925
    ASSERT_NO_THROW(pkt->addOption(eth0_serverid));
    EXPECT_TRUE(srv.acceptServerId(pkt));

    // Remove the server identifier.
    ASSERT_NO_THROW(pkt->delOption(DHO_DHCP_SERVER_IDENTIFIER));

    // Add a server id being an IPv4 address configured on eth1 interface.
    // A DHCPv4 message holding this server identifier should be accepted.
926 927
    OptionCustomPtr eth1_serverid(new OptionCustom(def, Option::V6));
    eth1_serverid->writeAddress(IOAddress("10.0.0.1"));
928 929 930 931 932
    ASSERT_NO_THROW(pkt->addOption(eth1_serverid));
    EXPECT_TRUE(srv.acceptServerId(pkt));

}

933 934 935 936 937
// @todo: Implement tests for rejecting renewals

// This test verifies if the sanityCheck() really checks options presence.
TEST_F(Dhcpv4SrvTest, sanityCheck) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
938
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
939 940

    Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
941
    pkt->setHWAddr(generateHWAddr(6));
942

943
    // Server-id is optional for information-request, so
944
    EXPECT_NO_THROW(NakedDhcpv4Srv::sanityCheck(pkt, Dhcpv4Srv::OPTIONAL));
945

946
    // Empty packet, no server-id
947 948
    EXPECT_THROW(NakedDhcpv4Srv::sanityCheck(pkt, Dhcpv4Srv::MANDATORY),
                 RFCViolation);
949 950 951

    pkt->addOption(srv->getServerID());

952
    // Server-id is mandatory and present = no exception
953
    EXPECT_NO_THROW(NakedDhcpv4Srv::sanityCheck(pkt, Dhcpv4Srv::MANDATORY));
954

955
    // Server-id is forbidden, but present => exception
956
    EXPECT_THROW(NakedDhcpv4Srv::sanityCheck(pkt, Dhcpv4Srv::FORBIDDEN),
957
                 RFCViolation);
958 959 960 961

    // There's no client-id and no HWADDR. Server needs something to
    // identify the client
    pkt->setHWAddr(generateHWAddr(0));
962 963
    EXPECT_THROW(NakedDhcpv4Srv::sanityCheck(pkt, Dhcpv4Srv::MANDATORY),
                 RFCViolation);
964 965
}

Tomek Mrugalski's avatar
Tomek Mrugalski committed
966 967 968
// This test verifies that incoming (positive) RELEASE can be handled properly.
// As there is no REPLY in DHCPv4, the only thing to verify here is that
// the lease is indeed removed from the database.
969
TEST_F(Dhcpv4SrvTest, ReleaseBasic) {
970
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
971
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
972 973 974 975 976 977 978 979 980 981 982

    const IOAddress addr("192.0.2.106");
    const uint32_t temp_t1 = 50;
    const uint32_t temp_t2 = 75;
    const uint32_t temp_valid = 100;
    const time_t temp_timestamp = time(NULL) - 10;

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

    // Check that the address we are about to use is indeed in pool
983
    ASSERT_TRUE(subnet_->inPool(Lease::TYPE_V4, addr));
984

985
    // Let's create a lease and put it in the LeaseMgr
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
    uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
    HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
    Lease4Ptr used(new Lease4(addr, mac_addr, sizeof(mac_addr),
                              &client_id_->getDuid()[0], client_id_->getDuid().size(),
                              temp_valid, temp_t1, temp_t2, temp_timestamp,
                              subnet_->getID()));
    ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));

    // Check that the lease is really in the database
    Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
    ASSERT_TRUE(l);

    // Let's create a RELEASE
    // Generate client-id also duid_
    Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
    rel->setRemoteAddr(addr);
1002
    rel->setCiaddr(addr);
1003 1004 1005
    rel->addOption(clientid);
    rel->addOption(srv->getServerID());
    rel->setHWAddr(hw);
1006
    rel->setIface("eth0");
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

    // Pass it to the server and hope for a REPLY
    // Note: this is no response to RELEASE in DHCPv4
    EXPECT_NO_THROW(srv->processRelease(rel));

    // The lease should be gone from LeaseMgr
    l = LeaseMgrFactory::instance().getLease4(addr);
    EXPECT_FALSE(l);

    // Try to get the lease by hardware address
1017 1018
    Lease4Collection leases = LeaseMgrFactory::instance().getLease4(hw->hwaddr_);
    EXPECT_EQ(leases.size(), 0);
1019

1020
    // Try to get it by hw/subnet_id combination
1021 1022 1023 1024
    l = LeaseMgrFactory::instance().getLease4(hw->hwaddr_, subnet_->getID());
    EXPECT_FALSE(l);

    // Try by client-id
1025 1026
    leases = LeaseMgrFactory::instance().getLease4(*client_id_);
    EXPECT_EQ(leases.size(), 0);
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040

    // Try by client-id/subnet-id
    l = LeaseMgrFactory::instance().getLease4(*client_id_, subnet_->getID());
    EXPECT_FALSE(l);

    // Ok, the lease is *really* not there.
}

// This test verifies that incoming (invalid) RELEASE can be handled properly.
//
// This test checks 3 scenarios:
// 1. there is no such lease at all
// 2. there is such a lease, but it is assigned to a different IAID
// 3. there is such a lease, but it belongs to a different client
1041
TEST_F(Dhcpv4SrvTest, ReleaseReject) {
1042
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
1043
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
1044 1045 1046 1047 1048 1049 1050

    const IOAddress addr("192.0.2.106");
    const uint32_t t1 = 50;
    const uint32_t t2 = 75;
    const uint32_t valid = 100;
    const time_t timestamp = time(NULL) - 10;

1051
    // Let's create a lease and put it in the LeaseMgr