-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 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
#include <dhcpsrv/d2_client_cfg.h>
#include <dhcpsrv/dhcpsrv_log.h>
+#include <boost/algorithm/string/predicate.hpp>
+
#include <string>
using namespace std;
namespace isc {
namespace dhcp {
-const char *D2ClientConfig::DFT_SERVER_IP = "127.0.0.1";
+const char* D2ClientConfig::DFT_SERVER_IP = "127.0.0.1";
const size_t D2ClientConfig::DFT_SERVER_PORT = 53001;
-const char *D2ClientConfig::DFT_V4_SENDER_IP = "0.0.0.0";
-const char *D2ClientConfig::DFT_V6_SENDER_IP = "::";
+const char* D2ClientConfig::DFT_V4_SENDER_IP = "0.0.0.0";
+const char* D2ClientConfig::DFT_V6_SENDER_IP = "::";
const size_t D2ClientConfig::DFT_SENDER_PORT = 0;
const size_t D2ClientConfig::DFT_MAX_QUEUE_SIZE = 1024;
-const char *D2ClientConfig::DFT_NCR_PROTOCOL = "UDP";
-const char *D2ClientConfig::DFT_NCR_FORMAT = "JSON";
+const char* D2ClientConfig::DFT_NCR_PROTOCOL = "UDP";
+const char* D2ClientConfig::DFT_NCR_FORMAT = "JSON";
const bool D2ClientConfig::DFT_ALWAYS_INCLUDE_FQDN = false;
const bool D2ClientConfig::DFT_OVERRIDE_NO_UPDATE = false;
const bool D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE = false;
-const bool D2ClientConfig::DFT_REPLACE_CLIENT_NAME = false;
-const char *D2ClientConfig::DFT_GENERATED_PREFIX = "myhost";
+const char* D2ClientConfig::DFT_REPLACE_CLIENT_NAME_MODE = "NEVER";
+const char* D2ClientConfig::DFT_GENERATED_PREFIX = "myhost";
+
+
+D2ClientConfig::ReplaceClientNameMode stringToReplaceClientNameMode(const std::string& mode_str) {
+ if (boost::iequals(mode_str, "NEVER")) {
+ return (D2ClientConfig::RCM_NEVER);
+ }
+
+ if (boost::iequals(mode_str, "ALWAYS")) {
+ return (D2ClientConfig::RCM_ALWAYS);
+ }
+
+ if (boost::iequals(mode_str, "WHEN_PRESENT")) {
+ return (D2ClientConfig::RCM_WHEN_PRESENT);
+ }
+
+ if (boost::iequals(mode_str, "WHEN_NOT_PRESENT")) {
+ return (D2ClientConfig::RCM_WHEN_NOT_PRESENT);
+ }
+
+ isc_throw(BadValue,
+ "Invalid ReplaceClientNameMode: " << mode_str);
+}
+
+std::string replaceClientNameModeToString(D2ClientConfig::ReplaceClientNameMode mode) {
+ switch (mode) {
+ case D2ClientConfig::RCM_NEVER:
+ return ("NEVER");
+ case D2ClientConfig::RCM_ALWAYS:
+ return ("ALWAYS");
+ case D2ClientConfig::RCM_WHEN_PRESENT:
+ return ("WHEN_PRESENT");
+ case D2ClientConfig::RCM_WHEN_NOT_PRESENT:
+ return ("WHEN_NOT_PRESENT");
+ default:
+ break;
+ }
+
+ std::ostringstream stream;
+ stream << "UNKNOWN(" << mode << ")";
+ return (stream.str());
+}
D2ClientConfig::D2ClientConfig(const bool enable_updates,
const isc::asiolink::IOAddress& server_ip,
const bool always_include_fqdn,
const bool override_no_update,
const bool override_client_update,
- const bool replace_client_name,
+ const ReplaceClientNameMode replace_client_name_mode,
const std::string& generated_prefix,
const std::string& qualifying_suffix)
: enable_updates_(enable_updates),
always_include_fqdn_(always_include_fqdn),
override_no_update_(override_no_update),
override_client_update_(override_client_update),
- replace_client_name_(replace_client_name),
+ replace_client_name_mode_(replace_client_name_mode),
generated_prefix_(generated_prefix),
qualifying_suffix_(qualifying_suffix) {
validateContents();
always_include_fqdn_(DFT_ALWAYS_INCLUDE_FQDN),
override_no_update_(DFT_OVERRIDE_NO_UPDATE),
override_client_update_(DFT_OVERRIDE_CLIENT_UPDATE),
- replace_client_name_(DFT_REPLACE_CLIENT_NAME),
+ replace_client_name_mode_(stringToReplaceClientNameMode(DFT_REPLACE_CLIENT_NAME_MODE)),
generated_prefix_(DFT_GENERATED_PREFIX),
qualifying_suffix_("") {
validateContents();
(always_include_fqdn_ == other.always_include_fqdn_) &&
(override_no_update_ == other.override_no_update_) &&
(override_client_update_ == other.override_client_update_) &&
- (replace_client_name_ == other.replace_client_name_) &&
+ (replace_client_name_mode_ == other.replace_client_name_mode_) &&
(generated_prefix_ == other.generated_prefix_) &&
(qualifying_suffix_ == other.qualifying_suffix_));
}
<< ", sender_ip: " << sender_ip_.toText()
<< ", sender_port: " << sender_port_
<< ", max_queue_size: " << max_queue_size_
- << ", ncr_protocol: " << ncr_protocol_
- << ", ncr_format: " << ncr_format_
+ << ", ncr_protocol: " << ncrProtocolToString(ncr_protocol_)
+ << ", ncr_format: " << ncrFormatToString(ncr_format_)
<< ", always_include_fqdn: " << (always_include_fqdn_ ?
"yes" : "no")
<< ", override_no_update: " << (override_no_update_ ?
"yes" : "no")
<< ", override_client_update: " << (override_client_update_ ?
"yes" : "no")
- << ", replace_client_name: " << (replace_client_name_ ?
- "yes" : "no")
+ << ", replace_client_name: "
+ << replaceClientNameModeToString(replace_client_name_mode_)
<< ", generated_prefix: [" << generated_prefix_ << "]"
<< ", qualifying_suffix: [" << qualifying_suffix_ << "]";
}
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2016 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
namespace {
+/// @brief Tests conversion of NameChangeFormat between enum and strings.
+TEST(ReplaceClientNameModeTest, formatEnumConversion){
+ ASSERT_EQ(stringToReplaceClientNameMode("NEVER"), D2ClientConfig::RCM_NEVER);
+ ASSERT_EQ(stringToReplaceClientNameMode("ALWAYS"), D2ClientConfig::RCM_ALWAYS);
+ ASSERT_EQ(stringToReplaceClientNameMode("WHEN_PRESENT"), D2ClientConfig::RCM_WHEN_PRESENT);
+ ASSERT_EQ(stringToReplaceClientNameMode("WHEN_NOT_PRESENT"),
+ D2ClientConfig::RCM_WHEN_NOT_PRESENT);
+ ASSERT_THROW(stringToReplaceClientNameMode("BOGUS"), isc::BadValue);
+
+ ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_NEVER), "NEVER");
+ ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_ALWAYS), "ALWAYS");
+ ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_WHEN_PRESENT), "WHEN_PRESENT");
+ ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_WHEN_NOT_PRESENT),
+ "WHEN_NOT_PRESENT");
+}
+
/// @brief Checks constructors and accessors of D2ClientConfig.
TEST(D2ClientConfigTest, constructorsAndAccessors) {
D2ClientConfigPtr d2_client_config;
bool always_include_fqdn = true;
bool override_no_update = true;
bool override_client_update = true;
- bool replace_client_name = true;
+ D2ClientConfig::ReplaceClientNameMode replace_client_name_mode = D2ClientConfig::
+ RCM_WHEN_PRESENT;
std::string generated_prefix = "the_prefix";
std::string qualifying_suffix = "the.suffix.";
ncr_format,
always_include_fqdn,
override_no_update,
- override_client_update,
- replace_client_name,
+ override_client_update,
+ replace_client_name_mode,
generated_prefix,
qualifying_suffix)));
EXPECT_EQ(d2_client_config->getOverrideNoUpdate(), override_no_update);
EXPECT_EQ(d2_client_config->getOverrideClientUpdate(),
override_client_update);
- EXPECT_EQ(d2_client_config->getReplaceClientName(), replace_client_name);
+ EXPECT_EQ(d2_client_config->getReplaceClientNameMode(), replace_client_name_mode);
EXPECT_EQ(d2_client_config->getGeneratedPrefix(), generated_prefix);
EXPECT_EQ(d2_client_config->getQualifyingSuffix(), qualifying_suffix);
always_include_fqdn,
override_no_update,
override_client_update,
- replace_client_name,
+ replace_client_name_mode,
generated_prefix,
qualifying_suffix)),
D2ClientError);
ASSERT_NO_THROW(ref_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(ref_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_TRUE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(false,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
test_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 333, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, test_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 333, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 2048,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, true, true, true,
+ false, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, false, true, true,
+ true, false, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, false, true,
+ true, true, false, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, false,
+ true, true, true, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"bogus", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "bogus")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, true, true,
+ true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
// Verify that we can assign a new, non-empty configuration.
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, false,
+ false, false, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, false,
+ false, false, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, true, false, false,
+ false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, true, false, false,
+ false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", ""))); //empty suffix
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "hasdot.com.")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, true, false,
+ false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, false,
+ false, false, false, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
- ASSERT_FALSE(cfg->getReplaceClientName());
+ ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode());
// replace-client-name is false, client passes in empty fqdn
// reponse domain should be empty/partial.
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, true,
+ false, false, false, D2ClientConfig::RCM_WHEN_PRESENT,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
- ASSERT_TRUE(cfg->getReplaceClientName());
+ ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode());
// replace-client-name is true, client passes in empty fqdn
// reponse domain should be empty/partial.
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, false,
+ false, false, false, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
- ASSERT_FALSE(cfg->getReplaceClientName());
+ ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode());
// replace-client-name is false, client passes in empty fqdn
// reponse domain should be empty/partial.
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, false, false, true,
+ false, false, false, D2ClientConfig::RCM_WHEN_PRESENT,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
- ASSERT_TRUE(cfg->getReplaceClientName());
+ ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode());
// replace-client-name is true, client passes in empty fqdn
// reponse domain should be empty/partial.
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, true, false, false,
+ false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());