1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>
#include <asiolink/io_address.h>
#include <cc/data.h>
#include <dhcp/dhcp4.h>
#include <dhcp_ddns/ncr_msg.h>
#include <dhcp/testutils/iface_mgr_test_config.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/subnet_id.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/dhcp4_client.h>

using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::dhcp::test;

namespace {

/// @brief Set of JSON configurations used throughout the out of range
///  tests.
///
/// - Configuration 0 - Reference configuration, all tests start with the
///   server configured with this configuration:
///   - 1 subnet: 10.0.0.0/24
///   - with one pool  10.0.0.10 - 10.0.0.100
///   - 1 address reservation (fixed host) for HW address:
///     ff:ff:ff:ff:ff:01
///   - 1 hostname reservation (dynamic host) for HW address:
///     dd:dd:dd:dd:dd:01,
///   - DDNS enabled
/// - Configuration 1 - same subnet, different pool
/// - Configuration 2 - same subnet, different pool, no reservations
/// - Configuration 3 - different subnet with reservations
/// - Configuration 4 - different subnet with no reservations
/// - Configuration 5 - same as reference, no reservations
///
const char* OOR_CONFIGS[] = {
// Configuration 0 - reference configuration
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"10.0.0.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
        "    \"reservations\": [ "
        "       {"
        "         \"hw-address\": \"ff:ff:ff:ff:ff:01\","
        "         \"ip-address\": \"10.0.0.7\""
        "       },"
        "       {"
        "         \"hw-address\": \"dd:dd:dd:dd:dd:01\","
        "         \"hostname\": \"test.example.com\""
        "       }"
        "    ]"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

// Configuration 1 - same subnet as reference, different pool
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"10.0.0.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"10.0.0.101-10.0.0.200\" } ],"
        "    \"reservations\": [ "
        "       {"
        "         \"hw-address\": \"ff:ff:ff:ff:ff:01\","
        "         \"ip-address\": \"10.0.0.7\""
        "       },"
        "       {"
        "         \"hw-address\": \"dd:dd:dd:dd:dd:01\","
        "         \"hostname\": \"reserved.example.com\""
        "       }"
        "    ]"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

// Configuration 2 - same subnet as reference, different pool, no reservations
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"10.0.0.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"10.0.0.101-10.0.0.200\" } ],"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

// Configuration 3 - different subnet with reservations
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"192.0.2.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"192.0.2.101-192.0.2.200\" } ],"
        "    \"reservations\": [ "
        "       {"
        "         \"hw-address\": \"ff:ff:ff:ff:ff:01\","
        "         \"ip-address\": \"192.0.2.7\""
        "       },"
        "       {"
        "         \"hw-address\": \"dd:dd:dd:dd:dd:01\","
        "         \"hostname\": \"reserved.example.com\""
        "       }"
        "    ]"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

// Configuration 4 - different subnet with no reservations
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"192.0.2.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"192.0.2.101-192.0.2.200\" } ]"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

// Configuration 5 - same as reference, no reservations
    "{ \"interfaces-config\": {"
        "      \"interfaces\": [ \"*\" ]"
        "},"
        "\"valid-lifetime\": 600,"
        "\"subnet4\": [ { "
        "    \"subnet\": \"10.0.0.0/24\", "
        "    \"id\": 1, "
        "    \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]"
        "} ],"
        "\"dhcp-ddns\": {"
        "     \"enable-updates\": true,"
        "     \"qualifying-suffix\": \"\""
        "}"
    "}",

};

/// @brief Test fixture class for testing various exchanges when the client's
/// leased address is out of range due to configuration changes.
class OutOfRangeTest : public Dhcpv4SrvTest {
public:

    /// @brief Enum for indexing into the array of configurations.
    /// These were created to make the test cases easier to follow.
    enum CfgIndex {
        REF_CFG = 0,
        DIFF_POOL,
        DIFF_POOL_NO_HR,
        DIFF_SUBNET,
        DIFF_SUBNET_NO_HR,
        NO_HR
    };

    /// @brief Enum for specifying expected response to client renewal attempt.
    enum RenewOutcome {
        DOES_RENEW,
        DOES_NOT_RENEW,
        DOES_NOT_NAK
    };

    /// @brief Enum for specifying expected response to client release attempt.
    enum ReleaseOutcome {
        DOES_RELEASE_EXPIRE,
        DOES_RELEASE_DELETE,
        DOES_NOT_RELEASE
    };

    /// @brief Constructor.
    ///
    /// Sets up fake interfaces.
    OutOfRangeTest()
        : Dhcpv4SrvTest(),
          d2_mgr_(CfgMgr::instance().getD2ClientMgr()),
          iface_mgr_test_config_(true) {
    }

    /// @brief Destructor.
    ///
    /// Cleans up statistics after the test.
    ~OutOfRangeTest() {
    }

    /// @brief Configure specified DHCP server using JSON string.
    ///
    /// @param config String holding server configuration in JSON format.
    /// @param client Instance of the client.
    /// @param lease_affinity A flag which indicates if lease affinity should
    /// be enabled or disabled.
    void configure(const std::string& config, Dhcp4Client& client,
                   const LeaseAffinity lease_affinity) {
        NakedDhcpv4Srv& server = *client.getServer();
        ASSERT_NO_FATAL_FAILURE(Dhcpv4SrvTest::configure(config, server, true,
                                                         true, true, false,
                                                         lease_affinity));
        if (d2_mgr_.ddnsEnabled()) {
            ASSERT_NO_THROW(server.startD2());
        }
    }

    /// @briefVerify that a NameChangeRequest has been queued
    ///
    /// Checks that a NCR of a given type (ADD or REMOVE) for a given
    /// ip address has been queued.  If the NCR exits, it is processed
    /// off the queue.  Note the function expects there to be 1 and only
    /// 1 NCR queued.
    ///
    /// @param type - NCR type expected, either CHG_ADD or CHG_REMOVE
    /// @param addr - string containing the ip address expected in the NCR
    void verifyNameChangeRequest(const isc::dhcp_ddns::NameChangeType type,
                                 const std::string& addr) {
        ASSERT_TRUE(d2_mgr_.getQueueSize() > 0);

        isc::dhcp_ddns::NameChangeRequestPtr ncr;
        ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
        ASSERT_TRUE(ncr);

        EXPECT_EQ(type, ncr->getChangeType());
        EXPECT_EQ(addr, ncr->getIpAddress());

        // Process the message off the queue
        ASSERT_NO_THROW(d2_mgr_.runReadyIO());
    }

    /// @brief Conducts a single out-of-range test scenario
    ///
    /// Each test cycles consists of the following two stages, the first is
    /// a set-up stage during which the server is configured with an initial,
    /// reference, configuration and a client then verifies that it can acquire
    /// and renew a lease.  The second stage verifies that the server, having
    /// been reconfigured such that the original lease is now "out-of-range",
    /// responds correctly to the same client first attempting to renew the
    /// lease and then attempting to release the lease.
    ///
    /// The test also expects the configuration to enable DDNS, and verifies
    /// that a DNS add is done during stage one, and a DNS remove is done
    /// in stage two as part of the release request processing.
    ///
    /// @param cfg_idx - index of the "replacement" configuration used to
    /// reconfigure the server during stage two
    /// @param hwaddress - text value, if not empty, to use as the hardware
    /// address.  This is used for host reservation tests.
    /// in client queries
    /// @param expected_address - text value of the expected address.  If not
    /// empty the test will fail if the server responds with a different lease
    /// address
    /// @param renew_outcome - expected server reaction in response to the
    /// client's stage two renewal attempt.
    /// @param release_outcome - expected server reaction in response to the
    /// client's stage two release attempt. Currently defaults to
    /// DOES_RELEASE_DELETE as no cases have been identified which do otherwise.
    /// @param lease_affinity A flag which indicates if lease affinity should
    /// be enabled or disabled. In the case lease affinity is enabled, the lease
    /// is not removed, but instead it is expired, and no DNS update is
    /// performed.
    void oorRenewReleaseTest(CfgIndex cfg_idx,
                             const std::string& hwaddress,
                             const std::string& expected_address,
                             RenewOutcome renew_outcome,
                             ReleaseOutcome release_outcome,
                             const LeaseAffinity lease_affinity);

    /// @brief D2 client manager.
    D2ClientMgr& d2_mgr_;

    /// @brief Interface Manager's fake configuration control.
    IfaceMgrTestConfig iface_mgr_test_config_;
};

void
OutOfRangeTest::oorRenewReleaseTest(CfgIndex cfg_idx,
                                    const std::string& hwaddress,
                                    const std::string& expected_address,
                                    RenewOutcome renew_outcome,
                                    ReleaseOutcome release_outcome,
                                    const LeaseAffinity lease_affinity) {
    // STAGE ONE:

    // Step 1 is to acquire the lease
    Dhcp4Client client(Dhcp4Client::SELECTING);

    // Configure DHCP server.
    configure(OOR_CONFIGS[REF_CFG], client, lease_affinity);

    // Set the host name so DNS updates will be performed
    client.includeHostname("test.example.com");

    // Set the hw address if given one
    if (!hwaddress.empty()) {
        client.setHWAddress(hwaddress);
    }

    // Acquire the lease via DORA
    ASSERT_NO_THROW(client.doDORA());

    // Make sure that the server responded.
    ASSERT_TRUE(client.getContext().response_);
    Pkt4Ptr resp = client.getContext().response_;

    // Make sure that the server has responded with DHCPACK.
    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));

    // Verify a lease was created
    IOAddress leased_address = client.config_.lease_.addr_;
    Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(leased_address);
    ASSERT_TRUE(lease);

    // Check the expected address if given
    if (!expected_address.empty()) {
        ASSERT_EQ(leased_address, expected_address);
    }

    // Verify that a DNS add was requested
    verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, leased_address.toText());

    // The address is still valid, let's verify the lease can be renewed
    // Set the unicast destination address to indicate that it is a renewal.
    client.setState(Dhcp4Client::RENEWING);
    client.setDestAddress(IOAddress("10.0.0.1"));
    ASSERT_NO_THROW(client.doRequest());

    // Verify that we received an ACK to our renewal
    resp = client.getContext().response_;
    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
    EXPECT_EQ(0, d2_mgr_.getQueueSize());

    // STAGE TWO:

    // Now reconfigure which should render our leased address out-of-range
    configure(OOR_CONFIGS[cfg_idx], client, lease_affinity);

    // Try to renew after the configuration change..
    ASSERT_NO_THROW(client.doRequest());
    resp = client.getContext().response_;

    switch(renew_outcome) {
    case DOES_RENEW:
        ASSERT_TRUE(resp);
        ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
        break;
    case DOES_NOT_RENEW:
        ASSERT_TRUE(resp);
        ASSERT_EQ(DHCPNAK, static_cast<int>(resp->getType()));
        break;
    case DOES_NOT_NAK:
        ASSERT_FALSE(resp);
        break;
    }

    // Verify that the lease still exists in the database as it has not
    // been explicitly released.
    lease = LeaseMgrFactory::instance().getLease4(leased_address);
    ASSERT_TRUE(lease);

    // Recreate the client lease info, a preceding NAK will have wiped it out
    client.createLease(leased_address, lease->valid_lft_);

    // Send the release. The server should remove it from the DB and
    // request DNS remove.
    ASSERT_NO_THROW(client.doRelease());

    lease = LeaseMgrFactory::instance().getLease4(leased_address);

    if (release_outcome == DOES_RELEASE_DELETE) {
        EXPECT_FALSE(lease);
        // Verify the DNS remove was queued.
        verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE,
                                leased_address.toText());
    } else {
        // Lease should still exist, and no NCR should be queued.
        ASSERT_TRUE(lease);
        EXPECT_EQ(0, d2_mgr_.getQueueSize());
        if (release_outcome == DOES_RELEASE_EXPIRE) {
            EXPECT_EQ(lease->valid_lft_, 0);
        } else {
            EXPECT_FALSE(lease->expired());
            EXPECT_TRUE(lease->valid_lft_ > 0);
        }
    }
}

// Verifies that once-valid lease, whose address is no longer
// within the subnet's pool:
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicOutOfPool) {<--- syntax error

    std::string hwaddress = "";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Verifies that once-valid lease, whose address is no longer
// within the subnet's pool:
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicOutOfPoolNoDelete) {

    std::string hwaddress = "";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Verifies that once-valid lease whose address is no longer
// within any configured subnet:
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicOutOfSubnet) {

    std::string hwaddress = "";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Verifies that once-valid lease whose address is no longer
// within any configured subnet:
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicOutOfSubnetNoDelete) {

    std::string hwaddress = "";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within the subnet's pool:
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfPool) {
    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within the subnet's pool:
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfPoolNoDelete) {
    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within any configured subnet:
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfSubnet) {
    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within any configured subnet:
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfSubnetNoDelete) {
    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is within the configured subnet and pool, but whose
// reservation has been removed:
//
// a: Is allowed to renew
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostReservationRemoved) {
    Dhcp4Client client(Dhcp4Client::SELECTING);

    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(NO_HR, hwaddress, expected_address, DOES_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is within the configured subnet and pool, but whose
// reservation has been removed:
//
// a: Is allowed to renew
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostReservationRemovedNoDelete) {
    Dhcp4Client client(Dhcp4Client::SELECTING);

    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(NO_HR, hwaddress, expected_address, DOES_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within any configured subnet, and which
// no longer has reservation defined:
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfSubnetReservationRemoved) {
    Dhcp4Client client(Dhcp4Client::SELECTING);

    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET_NO_HR, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid dynamic address host reservation,
// whose address is no longer within any configured subnet, and which
// no longer has reservation defined:
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, dynamicHostOutOfSubnetReservationRemovedNoDelete) {
    Dhcp4Client client(Dhcp4Client::SELECTING);

    std::string hwaddress = "dd:dd:dd:dd:dd:01";
    std::string expected_address = "";

    oorRenewReleaseTest(DIFF_SUBNET_NO_HR, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid in-subnet fixed-address host reservation,
// after the subnet pool changes:
//
// a: Is NAK'd upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, fixedHostOutOfSubnet) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid in-subnet fixed-address host reservation,
// after the subnet pool changes:
//
// a: Is NAK'd upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, fixedHostOutOfSubnetNoDelete) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_SUBNET, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid in-subnet fixed-address host reservation,
// after the subnet pool is changed:
//
// a: Is ACK'd upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, fixedHostDifferentPool) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid in-subnet fixed-address host reservation,
// after the subnet pool is changed:
//
// a: Is ACK'd upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, fixedHostDifferentPoolNoDelete) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_POOL, hwaddress, expected_address, DOES_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid in-subnet fixed-address host reservation,
// whose reservation has been removed from the configuration
//
// a: Is NAK'd upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, fixedHostReservationRemoved) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(NO_HR, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}


// Test verifies that once-valid in-subnet fixed-address host reservation,
// whose reservation has been removed from the configuration
//
// a: Is NAK'd upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, fixedHostReservationRemovedNoDelete) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(NO_HR, hwaddress, expected_address, DOES_NOT_NAK,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

// Test verifies that once-valid fixed address host reservation,
// whose address is no longer within any configured subnet
//
// a: Is NAKed upon a renewal attempt
// b: Is deleted properly upon release, including DNS removal
//
TEST_F(OutOfRangeTest, fixedHostOutOfSubnetReservationRemoved) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_SUBNET_NO_HR, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_DELETE, LEASE_AFFINITY_DISABLED);
}

// Test verifies that once-valid fixed address host reservation,
// whose address is no longer within any configured subnet
//
// a: Is NAKed upon a renewal attempt
// b: Is expired properly upon release, including no DNS removal
//
TEST_F(OutOfRangeTest, fixedHostOutOfSubnetReservationRemovedNoDelete) {
    std::string hwaddress = "ff:ff:ff:ff:ff:01";
    std::string expected_address = "10.0.0.7";

    oorRenewReleaseTest(DIFF_SUBNET_NO_HR, hwaddress, expected_address, DOES_NOT_RENEW,
                        DOES_RELEASE_EXPIRE, LEASE_AFFINITY_ENABLED);
}

} // end of anonymous namespace