dhcp4_srv_unittest.cc 56.7 KB
Newer Older
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1
// Copyright (C) 2011-2013  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 <dhcp/dhcp4.h>
20
#include <dhcp/iface_mgr.h>
21
#include <dhcp/option.h>
22
#include <dhcp/option4_addrlst.h>
23
#include <dhcp/option_custom.h>
24
#include <dhcp/option_int_array.h>
25 26
#include <dhcp/pkt_filter.h>
#include <dhcp/pkt_filter_inet.h>
27
#include <dhcp4/dhcp4_srv.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
28
#include <dhcp4/dhcp4_log.h>
29
#include <hooks/server_hooks.h>
30 31 32 33
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/utils.h>
34 35
#include <gtest/gtest.h>

36 37
#include <boost/scoped_ptr.hpp>

38 39 40 41
#include <fstream>
#include <iostream>

#include <arpa/inet.h>
42 43 44 45

using namespace std;
using namespace isc;
using namespace isc::dhcp;
46
using namespace isc::asiolink;
47 48 49 50

namespace {

class NakedDhcpv4Srv: public Dhcpv4Srv {
51
    // "Naked" DHCPv4 server, exposes internal fields
52
public:
53 54 55

    /// @brief Constructor.
    ///
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    /// This constructor disables default modes of operation used by the
    /// Dhcpv4Srv class:
    /// - Send/receive broadcast messages through sockets on interfaces
    /// which support broadcast traffic.
    /// - Direct DHCPv4 traffic - communication with clients which do not
    /// have IP address assigned yet.
    ///
    /// Enabling these modes requires root privilges so they must be
    /// disabled for unit testing.
    ///
    /// Note, that disabling broadcast options on sockets does not impact
    /// the operation of these tests because they use local loopback
    /// interface which doesn't have broadcast capability anyway. It rather
    /// prevents setting broadcast options on other (broadcast capable)
    /// sockets which are opened on other interfaces in Dhcpv4Srv constructor.
    ///
    /// The Direct DHCPv4 Traffic capability can be disabled here because
    /// it is tested with PktFilterLPFTest unittest. The tests which belong
    /// to PktFilterLPFTest can be enabled on demand when root privileges can
    /// be guaranteed.
76 77 78
    ///
    /// @param port port number to listen on; the default value 0 indicates
    /// that sockets should not be opened.
79
    NakedDhcpv4Srv(uint16_t port = 0)
80
        : Dhcpv4Srv(port, "type=memfile", false, false) {
81
    }
82

83
    using Dhcpv4Srv::adjustRemoteAddr;
84 85 86 87 88 89
    using Dhcpv4Srv::processDiscover;
    using Dhcpv4Srv::processRequest;
    using Dhcpv4Srv::processRelease;
    using Dhcpv4Srv::processDecline;
    using Dhcpv4Srv::processInform;
    using Dhcpv4Srv::getServerID;
90 91 92
    using Dhcpv4Srv::loadServerID;
    using Dhcpv4Srv::generateServerID;
    using Dhcpv4Srv::writeServerID;
93
    using Dhcpv4Srv::sanityCheck;
94
    using Dhcpv4Srv::srvidToString;
95 96
};

97 98
static const char* SRVID_FILE = "server-id-test.txt";

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
/// @brief Dummy Packet Filtering class.
///
/// This class reports capability to respond directly to the
/// client which doesn't have address configured yet.
///
/// All packet and socket handling functions do nothing because
/// they are not used in unit tests.
class PktFilterTest : public PktFilter {
public:

    /// @brief Reports 'direct response' capability.
    ///
    /// @return always true.
    virtual bool isDirectResponseSupported() const {
        return (true);
    }

    /// Does nothing.
    virtual int openSocket(const Iface&, const IOAddress&, const uint16_t,
                           const bool, const bool) {
        return (0);
    }

    /// Does nothing.
    virtual Pkt4Ptr receive(const Iface&, const SocketInfo&) {
        return Pkt4Ptr();
    }

    /// Does nothing.
    virtual int send(const Iface&, uint16_t, const Pkt4Ptr&) {
        return (0);
    }

};

134 135
class Dhcpv4SrvTest : public ::testing::Test {
public:
136 137 138 139 140

    /// @brief Constructor
    ///
    /// Initializes common objects used in many tests.
    /// Also sets up initial configuration in CfgMgr.
141
    Dhcpv4SrvTest() {
142 143 144 145 146 147 148
        subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1000,
                                         2000, 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_);
149

150 151 152 153
        // Add Router option.
        Option4AddrLstPtr opt_routers(new Option4AddrLst(DHO_ROUTERS));
        opt_routers->setAddress(IOAddress("192.0.2.2"));
        subnet_->addOption(opt_routers, false, "dhcp4");
154

155 156
        // it's ok if that fails. There should not be such a file anyway
        unlink(SRVID_FILE);
157
    }
158

159 160 161
    virtual ~Dhcpv4SrvTest() {
    }

162
    /// @brief Add 'Parameter Request List' option to the packet.
163
    ///
164
    /// This function PRL option comprising the following option codes:
165 166 167 168 169 170 171 172 173 174 175 176 177 178
    /// - 5 - Name Server
    /// - 15 - Domain Name
    /// - 7 - Log Server
    /// - 8 - Quotes Server
    /// - 9 - LPR Server
    ///
    /// @param pkt packet to add PRL option to.
    void addPrlOption(Pkt4Ptr& pkt) {

        OptionUint8ArrayPtr option_prl =
            OptionUint8ArrayPtr(new OptionUint8Array(Option::V4,
                                                     DHO_DHCP_PARAMETER_REQUEST_LIST));

        // Let's request options that have been configured for the subnet.
179 180 181 182
        option_prl->addValue(DHO_DOMAIN_NAME_SERVERS);
        option_prl->addValue(DHO_DOMAIN_NAME);
        option_prl->addValue(DHO_LOG_SERVERS);
        option_prl->addValue(DHO_COOKIE_SERVERS);
183 184
        // Let's also request the option that hasn't been configured. In such
        // case server should ignore request for this particular option.
185
        option_prl->addValue(DHO_LPR_SERVERS);
186 187 188 189 190 191
        // And add 'Parameter Request List' option into the DISCOVER packet.
        pkt->addOption(option_prl);
    }

    /// @brief Configures options being requested in the PRL option.
    ///
192
    /// The lpr-servers option is NOT configured here although it is
193 194
    /// added to the 'Parameter Request List' option in the
    /// \ref addPrlOption. When requested option is not configured
195
    /// the server should not return it in its response. The goal
196 197 198 199 200 201 202 203 204 205 206 207
    /// of not configuring the requested option is to verify that
    /// the server will not return it.
    void configureRequestedOptions() {
        // dns-servers
        Option4AddrLstPtr
            option_dns_servers(new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS));
        option_dns_servers->addAddress(IOAddress("192.0.2.1"));
        option_dns_servers->addAddress(IOAddress("192.0.2.100"));
        ASSERT_NO_THROW(subnet_->addOption(option_dns_servers, false, "dhcp4"));

        // domain-name
        OptionDefinition def("domain-name", DHO_DOMAIN_NAME, OPT_FQDN_TYPE);
208
        OptionCustomPtr option_domain_name(new OptionCustom(def, Option::V4));
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        option_domain_name->writeFqdn("example.com");
        subnet_->addOption(option_domain_name, false, "dhcp4");

        // log-servers
        Option4AddrLstPtr option_log_servers(new Option4AddrLst(DHO_LOG_SERVERS));
        option_log_servers->addAddress(IOAddress("192.0.2.2"));
        option_log_servers->addAddress(IOAddress("192.0.2.10"));
        ASSERT_NO_THROW(subnet_->addOption(option_log_servers, false, "dhcp4"));

        // cookie-servers
        Option4AddrLstPtr option_cookie_servers(new Option4AddrLst(DHO_COOKIE_SERVERS));
        option_cookie_servers->addAddress(IOAddress("192.0.2.1"));
        ASSERT_NO_THROW(subnet_->addOption(option_cookie_servers, false, "dhcp4"));
    }

224 225 226
    /// @brief checks that the response matches request
    /// @param q query (client's message)
    /// @param a answer (server's message)
227
    void messageCheck(const Pkt4Ptr& q, const Pkt4Ptr& a) {
228 229 230 231 232 233 234
        ASSERT_TRUE(q);
        ASSERT_TRUE(a);

        EXPECT_EQ(q->getHops(),   a->getHops());
        EXPECT_EQ(q->getIface(),  a->getIface());
        EXPECT_EQ(q->getIndex(),  a->getIndex());
        EXPECT_EQ(q->getGiaddr(), a->getGiaddr());
235 236 237
        // When processing an incoming packet the remote address
        // is copied as a src address, and the source address is
        // copied as a remote address to the response.
238 239
        EXPECT_TRUE(q->getLocalHWAddr() == a->getLocalHWAddr());
        EXPECT_TRUE(q->getRemoteHWAddr() == a->getRemoteHWAddr());
240

241 242 243
        // Check that bare minimum of required options are there.
        // We don't check options requested by a client. Those
        // are checked elsewhere.
244 245 246 247 248
        EXPECT_TRUE(a->getOption(DHO_SUBNET_MASK));
        EXPECT_TRUE(a->getOption(DHO_ROUTERS));
        EXPECT_TRUE(a->getOption(DHO_DHCP_SERVER_IDENTIFIER));
        EXPECT_TRUE(a->getOption(DHO_DHCP_LEASE_TIME));
        EXPECT_TRUE(a->getOption(DHO_SUBNET_MASK));
249 250
        EXPECT_TRUE(a->getOption(DHO_DOMAIN_NAME));
        EXPECT_TRUE(a->getOption(DHO_DOMAIN_NAME_SERVERS));
251

252
        // Check that something is offered
253 254 255
        EXPECT_TRUE(a->getYiaddr().toText() != "0.0.0.0");
    }

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    /// @brief Check that requested options are present.
    ///
    /// @param pkt packet to be checked.
    void optionsCheck(const Pkt4Ptr& pkt) {
        // Check that the requested and configured options are returned
        // in the ACK message.
        EXPECT_TRUE(pkt->getOption(DHO_DOMAIN_NAME))
            << "domain-name not present in the response";
        EXPECT_TRUE(pkt->getOption(DHO_DOMAIN_NAME_SERVERS))
            << "dns-servers not present in the response";
        EXPECT_TRUE(pkt->getOption(DHO_LOG_SERVERS))
            << "log-servers not present in the response";
        EXPECT_TRUE(pkt->getOption(DHO_COOKIE_SERVERS))
            << "cookie-servers not present in the response";
        // Check that the requested but not configured options are not
        // returned in the ACK message.
        EXPECT_FALSE(pkt->getOption(DHO_LPR_SERVERS))
            << "domain-name present in the response but it is"
            << " expected not to be present";
    }

277 278 279 280 281 282 283 284
    /// @brief generates client-id option
    ///
    /// Generate client-id option of specified length
    /// Ids with different lengths are sufficent to generate
    /// unique ids. If more fine grained control is required,
    /// tests generate client-ids on their own.
    /// Sets client_id_ field.
    /// @param size size of the client-id to be generated
285 286 287 288 289 290 291 292 293 294 295 296 297 298
    OptionPtr generateClientId(size_t size = 4) {

        OptionBuffer clnt_id(size);
        for (int i = 0; i < size; i++) {
            clnt_id[i] = 100 + i;
        }

        client_id_ = ClientIdPtr(new ClientId(clnt_id));

        return (OptionPtr(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER,
                                     clnt_id.begin(),
                                     clnt_id.begin() + size)));
    }

299 300 301 302
    /// @brief generate hardware address
    ///
    /// @param size size of the generated MAC address
    /// @param pointer to Hardware Address object
Tomek Mrugalski's avatar
Tomek Mrugalski committed
303
    HWAddrPtr generateHWAddr(size_t size = 6) {
304
        const uint8_t hw_type = 123; // Just a fake number (typically 6=HTYPE_ETHER, see dhcp4.h)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
305 306 307 308 309 310 311
        OptionBuffer mac(size);
        for (int i = 0; i < size; ++i) {
            mac[i] = 50 + i;
        }
        return (HWAddrPtr(new HWAddr(mac, hw_type)));
    }

312 313 314
    /// Check that address was returned from proper range, that its lease
    /// lifetime is correct, that T1 and T2 are returned properly
    /// @param rsp response to be checked
315 316
    /// @param subnet subnet that should be used to verify assigned address
    ///        and options
317 318
    /// @param t1_mandatory is T1 mandatory?
    /// @param t2_mandatory is T2 mandatory?
319
    void checkAddressParams(const Pkt4Ptr& rsp, const SubnetPtr subnet,
320 321
                            bool t1_mandatory = false,
                            bool t2_mandatory = false) {
322 323 324 325 326 327 328

        // Technically inPool implies inRange, but let's be on the safe
        // side and check both.
        EXPECT_TRUE(subnet->inRange(rsp->getYiaddr()));
        EXPECT_TRUE(subnet->inPool(rsp->getYiaddr()));

        // Check lease time
329 330
        OptionPtr opt = rsp->getOption(DHO_DHCP_LEASE_TIME);
        if (!opt) {
331 332
            ADD_FAILURE() << "Lease time option missing in response";
        } else {
333
            EXPECT_EQ(opt->getUint32(), subnet->getValid());
334 335 336
        }

        // Check T1 timer
337 338 339
        opt = rsp->getOption(DHO_DHCP_RENEWAL_TIME);
        if (opt) {
            EXPECT_EQ(opt->getUint32(), subnet->getT1());
340 341 342 343 344 345 346
        } else {
            if (t1_mandatory) {
                ADD_FAILURE() << "Required T1 option missing";
            }
        }

        // Check T2 timer
347 348 349
        opt = rsp->getOption(DHO_DHCP_REBINDING_TIME);
        if (opt) {
            EXPECT_EQ(opt->getUint32(), subnet->getT2());
350
        } else {
351
            if (t2_mandatory) {
352 353 354 355 356
                ADD_FAILURE() << "Required T2 option missing";
            }
        }
    }

357 358 359 360 361
    /// @brief Basic checks for generated response (message type and trans-id).
    ///
    /// @param rsp response packet to be validated
    /// @param expected_message_type expected message type
    /// @param expected_transid expected transaction-id
362 363 364 365 366 367 368
    void checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
                       uint32_t expected_transid) {
        ASSERT_TRUE(rsp);
        EXPECT_EQ(expected_message_type, rsp->getType());
        EXPECT_EQ(expected_transid, rsp->getTransid());
    }

369 370 371 372 373 374
    /// @brief Checks if the lease sent to client is present in the database
    ///
    /// @param rsp response packet to be validated
    /// @param client_id expected client-identifier (or NULL)
    /// @param HWAddr expected hardware address (not used now)
    /// @param expected_addr expected address
375
    Lease4Ptr checkLease(const Pkt4Ptr& rsp, const OptionPtr& client_id,
376
                         const HWAddrPtr&, const IOAddress& expected_addr) {
377 378 379 380 381 382 383 384 385 386 387 388 389 390

        ClientIdPtr id;
        if (client_id) {
            OptionBuffer data = client_id->getData();
            id.reset(new ClientId(data));
        }

        Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(expected_addr);
        if (!lease) {
            cout << "Lease for " << expected_addr.toText()
                 << " not found in the database backend.";
            return (Lease4Ptr());
        }

391 392
        EXPECT_EQ(rsp->getYiaddr().toText(), expected_addr.toText());

393 394 395 396 397 398 399 400 401
        EXPECT_EQ(expected_addr.toText(), lease->addr_.toText());
        if (client_id) {
            EXPECT_TRUE(*lease->client_id_ == *id);
        }
        EXPECT_EQ(subnet_->getID(), lease->subnet_id_);

        return (lease);
    }

402 403 404
    /// @brief Checks if server response (OFFER, ACK, NAK) includes proper server-id
    /// @param rsp response packet to be validated
    /// @param expected_srvid expected value of server-id
405
    void checkServerId(const Pkt4Ptr& rsp, const OptionPtr& expected_srvid) {
406 407 408 409 410 411
        // Check that server included its server-id
        OptionPtr opt = rsp->getOption(DHO_DHCP_SERVER_IDENTIFIER);
        ASSERT_TRUE(opt);
        EXPECT_EQ(opt->getType(), expected_srvid->getType() );
        EXPECT_EQ(opt->len(), expected_srvid->len() );
        EXPECT_TRUE(opt->getData() == expected_srvid->getData());
412 413
    }

414 415 416
    /// @brief Checks if server response (OFFER, ACK, NAK) includes proper client-id
    /// @param rsp response packet to be validated
    /// @param expected_clientid expected value of client-id
417 418
    void checkClientId(const Pkt4Ptr& rsp, const OptionPtr& expected_clientid) {
        // check that server included our own client-id
419 420 421 422 423
        OptionPtr opt = rsp->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
        ASSERT_TRUE(opt);
        EXPECT_EQ(expected_clientid->getType(), opt->getType());
        EXPECT_EQ(expected_clientid->len(), opt->len());
        EXPECT_TRUE(expected_clientid->getData() == opt->getData());
424 425
    }

426 427 428
    /// @brief Tests if Discover or Request message is processed correctly
    ///
    /// @param msg_type DHCPDISCOVER or DHCPREQUEST
429
    void testDiscoverRequest(const uint8_t msg_type) {
430
        // Create an instance of the tested class.
431
        boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
432 433

        // Initialize the source HW address.
434
        vector<uint8_t> mac(6);
435
        for (int i = 0; i < 6; ++i) {
436
            mac[i] = i * 10;
437
        }
438
        // Initialized the destination HW address.
439
        vector<uint8_t> dst_mac(6);
440
        for (int i = 0; i < 6; ++i) {
441 442
            dst_mac[i] = i * 20;
        }
443 444
        // Create a DHCP message. It will be used to simulate the
        // incoming message.
445
        boost::shared_ptr<Pkt4> req(new Pkt4(msg_type, 1234));
446 447
        // Create a response message. It will hold a reponse packet.
        // Initially, set it to NULL.
448
        boost::shared_ptr<Pkt4> rsp;
449
        // Set the name of the interface on which packet is received.
450
        req->setIface("eth0");
451
        // Set the interface index. It is just a dummy value and will
452
        // not be interpreted.
453
        req->setIndex(17);
454 455
        // Set the target HW address. This value is normally used to
        // construct the data link layer header.
456
        req->setRemoteHWAddr(1, 6, dst_mac);
457
        // Set the HW address. This value is set on DHCP level (in chaddr).
458
        req->setHWAddr(1, 6, mac);
459 460
        // Set local HW address. It is used to construct the data link layer
        // header.
461
        req->setLocalHWAddr(1, 6, mac);
462
        // Set target IP address.
463
        req->setRemoteAddr(IOAddress("192.0.2.55"));
464
        // Set relay address.
465
        req->setGiaddr(IOAddress("192.0.2.10"));
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 495 496 497 498 499 500

        // We are going to test that certain options are returned
        // in the response message when requested using 'Parameter
        // Request List' option. Let's configure those options that
        // are returned when requested.
        configureRequestedOptions();

        if (msg_type == DHCPDISCOVER) {
            ASSERT_NO_THROW(
                rsp = srv->processDiscover(req);
            );

            // Should return OFFER
            ASSERT_TRUE(rsp);
            EXPECT_EQ(DHCPOFFER, rsp->getType());

        } else {
            ASSERT_NO_THROW(
                rsp = srv->processRequest(req);
            );

            // Should return ACK
            ASSERT_TRUE(rsp);
            EXPECT_EQ(DHCPACK, rsp->getType());

        }

        messageCheck(req, rsp);

        // We did not request any options so these should not be present
        // in the RSP.
        EXPECT_FALSE(rsp->getOption(DHO_LOG_SERVERS));
        EXPECT_FALSE(rsp->getOption(DHO_COOKIE_SERVERS));
        EXPECT_FALSE(rsp->getOption(DHO_LPR_SERVERS));

501
        // Repeat the test but request some options.
502 503 504
        // Add 'Parameter Request List' option.
        addPrlOption(req);

505 506 507 508
        if (msg_type == DHCPDISCOVER) {
            ASSERT_NO_THROW(
                rsp = srv->processDiscover(req);
            );
509

510 511 512
            // Should return non-NULL packet.
            ASSERT_TRUE(rsp);
            EXPECT_EQ(DHCPOFFER, rsp->getType());
513

514 515 516 517 518 519 520 521 522 523
        } else {
            ASSERT_NO_THROW(
                rsp = srv->processRequest(req);
            );

            // Should return non-NULL packet.
            ASSERT_TRUE(rsp);
            EXPECT_EQ(DHCPACK, rsp->getType());

        }
524 525 526

        // Check that the requested options are returned.
        optionsCheck(rsp);
527

528 529
    }

530 531 532
    /// @brief This function cleans up after the test.
    virtual void TearDown() {

533
        CfgMgr::instance().deleteSubnets4();
534 535 536

        // Let's clean up if there is such a file.
        unlink(SRVID_FILE);
537

538 539 540
        // Close all open sockets.
        IfaceMgr::instance().closeSockets();

541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
        // Some unit tests override the default packet filtering class, used
        // by the IfaceMgr. The dummy class, called PktFilterTest, reports the
        // capability to directly respond to the clients without IP address
        // assigned. This capability is not supported by the default packet
        // filtering class: PktFilterInet. Therefore setting the dummy class
        // allows to test scenarios, when server responds to the broadcast address
        // on client's request, despite having support for direct response.
        // The following call restores the use of original packet filtering class
        // after the test.
        try {
            IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterInet()));

        } catch (const Exception& ex) {
            FAIL() << "Failed to restore the default (PktFilterInet) packet filtering"
                   << " class after the test. Exception has been caught: "
                   << ex.what();
        }
    }
559

560
    /// @brief A subnet used in most tests
561 562
    Subnet4Ptr subnet_;

563
    /// @brief A pool used in most tests
564 565
    Pool4Ptr pool_;

566
    /// @brief A client-id used in most tests
567
    ClientIdPtr client_id_;
568 569
};

Tomek Mrugalski's avatar
Tomek Mrugalski committed
570 571
// Sanity check. Verifies that both Dhcpv4Srv and its derived
// class NakedDhcpv4Srv can be instantiated and destroyed.
572 573
TEST_F(Dhcpv4SrvTest, basic) {

574
    // Check that the base class can be instantiated
575
    boost::scoped_ptr<Dhcpv4Srv> srv;
576 577
    ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000, "type=memfile",
                                            false, false)));
578
    srv.reset();
579 580 581 582 583
    // 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();
584

585
    // Check that the derived class can be instantiated
586 587
    boost::scoped_ptr<NakedDhcpv4Srv> naked_srv;
    ASSERT_NO_THROW(
588
        naked_srv.reset(new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
589
    EXPECT_TRUE(naked_srv->getServerID());
590 591
    // Close sockets again for the next test.
    IfaceMgr::instance().closeSockets();
592

593
    ASSERT_NO_THROW(naked_srv.reset(new NakedDhcpv4Srv(0)));
594
    EXPECT_TRUE(naked_srv->getServerID());
595 596
}

597 598 599
// 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.
600 601 602
TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRelay) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));

603
    // Create the instance of the incoming packet.
604
    boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
605
    // Set the giaddr to non-zero address as if it was relayed.
606
    req->setGiaddr(IOAddress("192.0.2.1"));
607 608
    // Set ciaddr to zero. This simulates the client which applies
    // for the new lease.
609
    req->setCiaddr(IOAddress("0.0.0.0"));
610 611 612 613 614 615 616
    // Clear broadcast flag.
    req->setFlags(0x0000);

    // 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));
617
    resp->setYiaddr(IOAddress("192.0.2.100"));
618 619
    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));
620

621
    // This function never throws.
622 623
    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

624
    // Now the destination address should be relay's address.
625
    EXPECT_EQ("192.0.2.1", resp->getRemoteAddr().toText());
626 627 628 629 630 631

    // 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.
    req->setGiaddr(IOAddress("192.0.2.50"));
    req->setCiaddr(IOAddress("192.0.2.11"));
632
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
633 634 635 636 637 638 639 640 641 642 643

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

    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

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

644 645 646 647
// 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.
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRenewRebind) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));

    // 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).
    req->setCiaddr(IOAddress("192.0.2.15"));
    // 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.
666
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683

    // 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.
    resp->setYiaddr(IOAddress("192.0.2.13"));
    // Clear the remote address.
    resp->setRemoteAddr(IOAddress("0.0.0.0"));

    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

    // Check that server responds to ciaddr
    EXPECT_EQ("192.0.2.15", resp->getRemoteAddr().toText());
}

684 685 686 687 688 689 690
// 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.
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
TEST_F(Dhcpv4SrvTest, adjustRemoteAddressSelect) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));

    // 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);

    // 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"));

    // 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.
    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

    // 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());

    // 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
    // response based on the capability reported by IfaceMgr. In order
    // to set this capability we have to provide a dummy Packet Filter
    // class which would report the support for direct responses.
    // This class is called PktFilterTest.
    IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterTest()));

    // Now we expect that the server will send its response to the
    // address assigned for the client.
    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

    EXPECT_EQ("192.0.2.13", resp->getRemoteAddr().toText());
}

741 742 743 744 745
// 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.
746 747 748 749 750 751 752 753 754 755 756 757
TEST_F(Dhcpv4SrvTest, adjustRemoteAddressBroadcast) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));

    // 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 set the broadcast flag.
758
    req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786

    // 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"));

    // When running unit tests, the IfaceMgr is using the default Packet
    // Filtering class, PktFilterInet. This class does not support direct
    // responses to the clients without address assigned. If giaddr and
    // ciaddr are zero and client has just got the new lease, the assigned
    // address is carried in yiaddr. In order to send this address to the
    // client, server must send the response to the broadcast address when
    // direct response is not supported. This conflicts with the purpose
    // of this test which is supposed to verify that responses are sent
    // to broadcast address only, when broadcast flag is set. Therefore,
    // in order to simulate that direct responses are supported we have
    // to replace the default packet filtering class with a dummy class
    // which reports direct response capability.
    IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterTest()));

    ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));

    // 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());
787 788
}

789
// Verifies that DISCOVER message can be processed correctly,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
790 791 792 793 794 795 796
// 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.
797 798
TEST_F(Dhcpv4SrvTest, processDiscover) {
    testDiscoverRequest(DHCPDISCOVER);
799
}
800

801
// Verifies that REQUEST message can be processed correctly,
802
// that the OFFER message generated in response is valid and
Tomek Mrugalski's avatar
Tomek Mrugalski committed
803 804 805 806
// contains necessary options.
//
// Note: this test focuses on the packet correctness. There
// are other tests that verify correctness of the allocation
807 808
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
// and DiscoverInvalidHint.
809 810
TEST_F(Dhcpv4SrvTest, processRequest) {
    testDiscoverRequest(DHCPREQUEST);
811 812 813
}

TEST_F(Dhcpv4SrvTest, processRelease) {
814
    NakedDhcpv4Srv srv;
815
    Pkt4Ptr pkt(new Pkt4(DHCPRELEASE, 1234));
816

817
    // Should not throw
818
    EXPECT_NO_THROW(srv.processRelease(pkt));
819 820 821
}

TEST_F(Dhcpv4SrvTest, processDecline) {
822
    NakedDhcpv4Srv srv;
823
    Pkt4Ptr pkt(new Pkt4(DHCPDECLINE, 1234));
824

825
    // Should not throw
826
    EXPECT_NO_THROW(srv.processDecline(pkt));
827 828 829
}

TEST_F(Dhcpv4SrvTest, processInform) {
830
    NakedDhcpv4Srv srv;
831
    Pkt4Ptr pkt(new Pkt4(DHCPINFORM, 1234));
832

833
    // Should not throw
834
    EXPECT_NO_THROW(srv.processInform(pkt));
835

836
    // Should return something
837
    EXPECT_TRUE(srv.processInform(pkt));
838

839
    // @todo Implement more reasonable tests before starting
840
    // work on processSomething() method.
841 842
}

843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
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));
        }
    }
}

875 876 877 878 879 880 881 882 883 884 885 886 887
// 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
TEST_F(Dhcpv4SrvTest, DiscoverBasic) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
888
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
889 890 891 892 893 894

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

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

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

901
    // Check that address was returned from proper range, that its lease
902 903 904
    // lifetime is correct, that T1 and T2 are returned properly
    checkAddressParams(offer, subnet_);

905
    // Check identifiers
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
    checkServerId(offer, srv->getServerID());
    checkClientId(offer, clientid);
}


// 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
//
// expected returned OFFER message:
// - copy of client-id
// - server-id
// - offered address
TEST_F(Dhcpv4SrvTest, DiscoverHint) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
925
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
926 927 928 929 930 931 932 933
    IOAddress hint("192.0.2.107");

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

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

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

940
    // Check that address was returned from proper range, that its lease
941 942 943 944 945
    // lifetime is correct, that T1 and T2 are returned properly
    checkAddressParams(offer, subnet_);

    EXPECT_EQ(offer->getYiaddr().toText(), hint.toText());

946
    // Check identifiers
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
    checkServerId(offer, srv->getServerID());
    checkClientId(offer, clientid);
}


// 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:
// - address set to specific value as hint
//
// expected returned OFFER message:
// - copy of client-id
// - server-id
// - offered address
TEST_F(Dhcpv4SrvTest, DiscoverNoClientId) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
965
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
966 967 968 969 970 971
    IOAddress hint("192.0.2.107");

    Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
    dis->setRemoteAddr(IOAddress("192.0.2.1"));
    dis->setYiaddr(hint);

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

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

978
    // Check that address was returned from proper range, that its lease
979 980 981 982 983
    // lifetime is correct, that T1 and T2 are returned properly
    checkAddressParams(offer, subnet_);

    EXPECT_EQ(offer->getYiaddr().toText(), hint.toText());

984
    // Check identifiers
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
    checkServerId(offer, srv->getServerID());
}

// 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)
TEST_F(Dhcpv4SrvTest, DiscoverInvalidHint) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
1002
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
1003 1004 1005 1006 1007 1008 1009 1010
    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);

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

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

1017
    // Check that address was returned from proper range, that its lease
1018 1019 1020 1021 1022
    // lifetime is correct, that T1 and T2 are returned properly
    checkAddressParams(offer, subnet_);

    EXPECT_NE(offer->getYiaddr().toText(), hint.toText());

1023
    // Check identifiers
1024 1025 1026 1027 1028 1029 1030 1031
    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
1032 1033
// 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
1034
// 2 addresses, the third client would get the same offer as the first one
1035
// and this is a correct behavior. It is REQUEST that will fail for the third
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1036
// client. OFFER is basically saying "if you send me a request, you will
1037 1038 1039
// probably get an address like this" (there are no guarantees).
TEST_F(Dhcpv4SrvTest, ManyDiscovers) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
1040
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
1041 1042 1043 1044 1045 1046 1047 1048 1049

    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"));

1050
    // Different client-id sizes
1051 1052 1053 1054 1055 1056 1057 1058
    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);

1059 1060 1061 1062
    // Pass it to the server and get an offer
    Pkt4Ptr offer1 = srv->processDiscover(dis1);
    Pkt4Ptr offer2 = srv->processDiscover(dis2);
    Pkt4Ptr offer3 = srv->processDiscover(dis3);
1063

1064 1065 1066 1067
    // Check if we get response at all
    checkResponse(offer1, DHCPOFFER, 1234);
    checkResponse(offer2, DHCPOFFER, 2345);
    checkResponse(offer3, DHCPOFFER, 3456);
1068

1069 1070 1071
    IOAddress addr1 = offer1->getYiaddr();
    IOAddress addr2 = offer2->getYiaddr();
    IOAddress addr3 = offer3->getYiaddr();
1072 1073

    // Check that the assigned address is indeed from the configured pool
1074 1075 1076 1077
    checkAddressParams(offer1, subnet_);
    checkAddressParams(offer2, subnet_);
    checkAddressParams(offer3, subnet_);

1078
    // Check server-ids
1079 1080 1081 1082 1083 1084
    checkServerId(offer1, srv->getServerID());
    checkServerId(offer2, srv->getServerID());
    checkServerId(offer3, srv->getServerID());
    checkClientId(offer1, clientid1);
    checkClientId(offer2, clientid2);
    checkClientId(offer3, clientid3);
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094

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

Tomek Mrugalski's avatar
Tomek Mrugalski committed
1095 1096
// This test verifies that incoming REQUEST can be handled properly, that an
// ACK is generated, that the response has an address and that address
1097 1098
// really belongs to the configured pool.
//
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1099
// constructed a single REQUEST message with:
1100
// - client-id option
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1101 1102
// - hwaddr information
// - requested address (that the client received in DISCOVER/OFFER exchange)
1103
//
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1104
// expected returned ACK message:
1105 1106
// - copy of client-id
// - server-id
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1107 1108 1109
// - assigned address
//
// Test verifies that the lease is actually in the database.
1110 1111
TEST_F(Dhcpv4SrvTest, RequestBasic) {
    boost::scoped_ptr<NakedDhcpv4Srv> srv;
1112
    ASSERT_NO_THROW(srv.reset(new NakedDhcpv4Srv(0)));
1113 1114