const std::string& name) {
StampedValueCollection parameters;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(name)
};
const SubnetID& subnet_id) {
Subnet4Collection subnets;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createInteger<uint32_t>(subnet_id)
};
const std::string& subnet_prefix) {
Subnet4Collection subnets;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(subnet_prefix)
};
/// subnets should be inserted.
void getAllSubnets4(const ServerSelector& server_selector,
Subnet4Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getSubnets4(GET_ALL_SUBNETS4, in_bindings, subnets);
void getModifiedSubnets4(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
Subnet4Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_ts)
};
void getSharedNetworkSubnets4(const ServerSelector& server_selector,
const std::string& shared_network_name,
Subnet4Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(shared_network_name)
};
/// structure where shared networks should be inserted.
void getAllSharedNetworks4(const ServerSelector& server_selector,
SharedNetwork4Collection& shared_networks) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getSharedNetworks4(GET_ALL_SHARED_NETWORKS4, in_bindings, shared_networks);
void getModifiedSharedNetworks4(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
SharedNetwork4Collection& shared_networks) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_ts)
};
// a server into the dhcp4_options_server table.
MySqlBindingCollection in_server_bindings = {
MySqlBinding::createInteger<uint64_t>(id), // option_id
- MySqlBinding::createString(*getServerTags(server_selector).begin()), // server_tag
+ MySqlBinding::createString(server_selector.getTags().begin()->get()), // server_tag
in_bindings[11] // copy modification timestamp from option
};
MySqlConfigBackendDHCPv4::getAllGlobalParameters4(const ServerSelector& server_selector) const {
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_ALL_GLOBAL_PARAMETERS4);
StampedValueCollection parameters;
- auto tags = impl_->getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
- MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag) };
+ MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag.get()) };
impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4,
in_bindings, parameters);
}
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_MODIFIED_GLOBAL_PARAMETERS4)
.arg(util::ptimeToText(modification_time));
StampedValueCollection parameters;
- auto tags = impl_->getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
};
impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_GLOBAL_PARAMETERS4,
const std::string& name) {
StampedValueCollection parameters;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(name)
};
const SubnetID& subnet_id) {
Subnet6Collection subnets;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createInteger<uint32_t>(subnet_id)
};
const std::string& subnet_prefix) {
Subnet6Collection subnets;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(subnet_prefix)
};
/// subnets should be inserted.
void getAllSubnets6(const ServerSelector& server_selector,
Subnet6Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getSubnets6(GET_ALL_SUBNETS6, in_bindings, subnets);
void getModifiedSubnets6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
Subnet6Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_ts)
};
void getSharedNetworkSubnets6(const ServerSelector& server_selector,
const std::string& shared_network_name,
Subnet6Collection& subnets) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createString(shared_network_name)
};
/// structure where shared networks should be inserted.
void getAllSharedNetworks6(const ServerSelector& server_selector,
SharedNetwork6Collection& shared_networks) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getSharedNetworks6(GET_ALL_SHARED_NETWORKS6, in_bindings, shared_networks);
void getModifiedSharedNetworks6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
SharedNetwork6Collection& shared_networks) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_ts)
};
// a server into the dhcp6_options_server table.
MySqlBindingCollection in_server_bindings = {
MySqlBinding::createInteger<uint64_t>(id), // option_id
- MySqlBinding::createString(*getServerTags(server_selector).begin()), // server_tag
+ MySqlBinding::createString(server_selector.getTags().begin()->get()), // server_tag
in_bindings[11] // copy modification timestamp from option
};
MySqlConfigBackendDHCPv6::getAllGlobalParameters6(const ServerSelector& server_selector) const {
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_ALL_GLOBAL_PARAMETERS6);
StampedValueCollection parameters;
- auto tags = impl_->getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
- MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag) };
+ MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag.get()) };
impl_->getGlobalParameters(MySqlConfigBackendDHCPv6Impl::GET_ALL_GLOBAL_PARAMETERS6,
in_bindings, parameters);
}
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_MODIFIED_GLOBAL_PARAMETERS6)
.arg(util::ptimeToText(modification_time));
StampedValueCollection parameters;
- auto tags = impl_->getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
};
impl_->getGlobalParameters(MySqlConfigBackendDHCPv6Impl::GET_MODIFIED_GLOBAL_PARAMETERS6,
MySqlBinding::createString(AUDIT_ENTRY_LOG_MESSAGE_BUF_LENGTH) // log_message
};
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
// There is only one input binding, modification time.
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
};
MySqlConfigBackendImpl::getAllOptionDefs(const int index,
const ServerSelector& server_selector,
OptionDefContainer& option_defs) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getOptionDefs(index, in_bindings, option_defs);
}
const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time,
OptionDefContainer& option_defs) {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
};
getOptionDefs(index, in_bindings, option_defs);
const ServerSelector& server_selector) {
OptionContainer options;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag)
+ MySqlBinding::createString(tag.get())
};
getOptions(index, in_bindings, universe, options);
}
const boost::posix_time::ptime& modification_time) {
OptionContainer options;
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag),
+ MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
};
getOptions(index, in_bindings, universe, options);
const db::MySqlBindingPtr& min_binding,
const db::MySqlBindingPtr& max_binding);
- /// @brief Returns server tags associated with the particular selector.
- ///
- /// @param server_selector Server selector.
- /// @return Set of server tags.
- std::set<std::string> getServerTags(const db::ServerSelector& server_selector) const {
- std::set<std::string> tags;
- switch (server_selector.getType()) {
- case db::ServerSelector::Type::ALL:
- tags.insert("all");
- return (tags);
-
- default:
- return (server_selector.getTags());
- }
-
- // Unassigned server case.
- return (tags);
- }
-
/// @brief Returns server tag associated with the particular selector.
///
/// This method expects that there is exactly one server tag associated with
/// is more than one server tag associated with the selector.
std::string getServerTag(const db::ServerSelector& server_selector,
const std::string& operation) const {
- auto tags = getServerTags(server_selector);
+ auto tags = server_selector.getTags();
if (tags.size() != 1) {
isc_throw(InvalidOperation, "expected exactly one server tag to be specified"
" while " << operation << ". Got: "
<< getServerTagsAsText(server_selector));
}
- return (*tags.begin());
+ return (tags.begin()->get());
}
/// @brief Returns server tags associated with the particular selector
/// This method is useful for logging purposes.
std::string getServerTagsAsText(const db::ServerSelector& server_selector) const {
std::ostringstream s;
- auto server_tags = getServerTags(server_selector);
+ auto server_tags = server_selector.getTags();
for (auto tag : server_tags) {
if (s.tellp() != 0) {
s << ", ";
}
- s << tag;
+ s << tag.get();
}
return (s.str());
} else if (tags.size() == 1) {
// Get the server tag for which we run the current test.
- tag = *tags.begin();
+ tag = tags.begin()->get();
}
}
} else if (tags.size() == 1) {
// Get the server tag for which we run the current test.
- tag = *tags.begin();
+ tag = tags.begin()->get();
}
}
return (tag_ == ALL);
}
+std::ostream&
+operator<<(std::ostream& os, const ServerTag& server_tag) {
+ os << server_tag.get();
+ return (os);
+}
+
} // end of namespace isc::data
} // end of namespace isc
return (tag_);
}
+ /// @brief Overload of the less operator for using @c ServerTag in sets.
+ ///
+ /// @param other other server tag to compare to.
+ /// @return true if this server tag is less than the other server tag.
+ bool operator<(const ServerTag& other) const {
+ return (tag_ < other.tag_);
+ }
+
private:
/// @brief Holds server tag as string.
std::string tag_;
};
+/// @brief Insert the @c ServerTag as a string into stream.
+///
+/// @param os stream to insert server tag into.
+/// @param server_tag server tag to be converted to text and
+/// inserted into a stream.
+/// @return Reference to the stream object with inserted server
+/// tag.
+std::ostream&
+operator<<(std::ostream& os, const ServerTag& server_tag);
+
} // end of namespace isc::data
} // end of namespace isc
libkea_database_la_SOURCES += db_messages.cc db_messages.h
libkea_database_la_SOURCES += server.cc server.h
libkea_database_la_SOURCES += server_collection.cc server_collection.h
-libkea_database_la_SOURCES += server_selector.h
+libkea_database_la_SOURCES += server_selector.cc server_selector.h
libkea_database_la_LIBADD = $(top_builddir)/src/lib/cc/libkea-cc.la
libkea_database_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
--- /dev/null
+// Copyright (C) 2019 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 <database/server_selector.h>
+#include <exceptions/exceptions.h>
+
+using namespace isc::data;
+
+namespace isc {
+namespace db {
+
+ServerSelector
+ServerSelector::MULTIPLE(const std::set<std::string>& server_tags) {
+ if (server_tags.empty()) {
+ isc_throw(InvalidOperation, "ServerSelector: expecting at least one"
+ " server tag");
+ }
+
+ std::set<ServerTag> tags;
+
+ // Create a set of tags from strings.
+ for (auto tag : server_tags) {
+ tags.insert(ServerTag(tag));
+ }
+
+ ServerSelector selector(tags);
+ return (selector);
+}
+
+ServerSelector::ServerSelector(const Type& type)
+ : type_(type), tags_() {
+ if (type_ == Type::ALL) {
+ tags_.insert(ServerTag());
+ }
+}
+
+ServerSelector::ServerSelector(const ServerTag& server_tag)
+ : type_(server_tag.amAll() ? Type::ALL : Type::SUBSET), tags_({server_tag}) {
+}
+
+ServerSelector::ServerSelector(const std::set<ServerTag>& server_tags)
+ : type_(Type::SUBSET), tags_(server_tags) {
+}
+
+} // end of namespace isc::db
+} // end of namespace isc
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
#ifndef SERVER_SELECTOR_H
#define SERVER_SELECTOR_H
+#include <cc/server_tag.h>
#include <set>
#include <string>
///
/// @param server_tag tag of the single server to be selected.
static ServerSelector ONE(const std::string& server_tag) {
- ServerSelector selector(server_tag);
+ ServerSelector selector((data::ServerTag(server_tag)));
return (selector);
}
/// @brief Factory returning "multiple servers" selector.
///
/// @param server_tags set of server tags to be selected.
- static ServerSelector MULTIPLE(const std::set<std::string>& server_tags) {
- ServerSelector selector(server_tags);
- return (selector);
- }
+ /// @throw InvalidOperation if no server tags provided.
+ static ServerSelector MULTIPLE(const std::set<std::string>& server_tags);
/// @brief Returns type of the selector.
Type getType() const {
///
/// @return server tags for mutliple selections and for one server,
/// empty set for all servers and and unassigned.
- std::set<std::string> getTags() const {
+ std::set<data::ServerTag> getTags() const {
return (tags_);
}
return (getType() == Type::UNASSIGNED);
}
+ /// @brief Convenience method checking if the server selector has multiple tags.
+ ///
+ /// @return true if it has multiple tags, false otherwise.
+ bool hasMultipleTags() const {
+ return (tags_.size() > 1);
+ }
+
private:
/// @brief Constructor used for "unassigned" and "all" slection types.
///
/// @param type selector type.
- explicit ServerSelector(const Type& type)
- : type_(type), tags_() {
- }
+ explicit ServerSelector(const Type& type);
/// @brief Constructor used for selecting a single server.
///
/// @param server_tag tag of the server to be selected.
- explicit ServerSelector(const std::string& server_tag)
- : type_(Type::SUBSET), tags_() {
- tags_.insert(server_tag);
- }
+ explicit ServerSelector(const data::ServerTag& server_tag);
/// @brief Constructor used for selecting multiple servers.
///
/// @param server_tags set of server tags.
- explicit ServerSelector(const std::set<std::string>& server_tags)
- : type_(Type::SUBSET), tags_(server_tags) {
- }
+ explicit ServerSelector(const std::set<data::ServerTag>& server_tags);
/// @brief Selection type used.
Type type_;
/// @brief Holds tags of explicitly selected servers.
- std::set<std::string> tags_;
+ std::set<data::ServerTag> tags_;
};
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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 <cc/server_tag.h>
#include <database/server_selector.h>
#include <gtest/gtest.h>
+using namespace isc::data;
using namespace isc::db;
namespace {
EXPECT_EQ(ServerSelector::Type::UNASSIGNED, selector.getType());
EXPECT_TRUE(selector.amUnassigned());
EXPECT_TRUE(selector.getTags().empty());
+ EXPECT_FALSE(selector.hasMultipleTags());
}
// Check that server selector can be set to ALL.
ServerSelector selector = ServerSelector::ALL();
EXPECT_EQ(ServerSelector::Type::ALL, selector.getType());
EXPECT_FALSE(selector.amUnassigned());
- EXPECT_TRUE(selector.getTags().empty());
+
+ auto tags = selector.getTags();
+ EXPECT_EQ(1, tags.size());
+ EXPECT_EQ(1, tags.count(ServerTag("all")));
+ EXPECT_FALSE(selector.hasMultipleTags());
}
// Check that a single server can be selected.
EXPECT_EQ(ServerSelector::Type::SUBSET, selector.getType());
EXPECT_FALSE(selector.amUnassigned());
- std::set<std::string> tags = selector.getTags();
+ auto tags = selector.getTags();
ASSERT_EQ(1, tags.size());
- EXPECT_EQ(1, tags.count("some-tag"));
+ EXPECT_EQ(1, tags.count(ServerTag("some-tag")));
+ EXPECT_FALSE(selector.hasMultipleTags());
}
// Check that multiple servers can be selected.
EXPECT_EQ(ServerSelector::Type::SUBSET, selector.getType());
EXPECT_FALSE(selector.amUnassigned());
- std::set<std::string> tags = selector.getTags();
+ auto tags = selector.getTags();
ASSERT_EQ(3, tags.size());
- EXPECT_EQ(1, tags.count("tag1"));
- EXPECT_EQ(1, tags.count("tag2"));
- EXPECT_EQ(1, tags.count("tag3"));
+ EXPECT_EQ(1, tags.count(ServerTag("tag1")));
+ EXPECT_EQ(1, tags.count(ServerTag("tag2")));
+ EXPECT_EQ(1, tags.count(ServerTag("tag3")));
+ EXPECT_TRUE(selector.hasMultipleTags());
}
}
return ("all");
}
// Return first tag found.
- std::set<std::string> tags = server_selector.getTags();
+ auto tags = server_selector.getTags();
if (!tags.empty()) {
- return (*tags.begin());
+ return (tags.begin()->get());
}
return ("");
}
}
StampedValuePtr
-TestConfigBackendDHCPv4::getGlobalParameter4(const db::ServerSelector& /* server_selector */,
+TestConfigBackendDHCPv4::getGlobalParameter4(const db::ServerSelector& server_selector,
const std::string& name) const {
const auto& index = globals_.get<StampedValueNameIndexTag>();
- auto global_it = index.find(name);
- return ((global_it != index.cend()) ? (*global_it) : StampedValuePtr());
+ auto global_range = index.equal_range(name);
+ for (auto global_it = global_range.first; global_it != global_range.second;
+ ++global_it) {
+ auto tags = server_selector.getTags();
+ for (auto tag : tags) {
+ if ((*global_it)->hasServerTag(ServerTag(tag))) {
+ return (*global_it);
+ }
+ }
+ }
+
+ auto global_all_it = index.find(name);
+ if ((global_all_it != index.end()) && ((*global_all_it)->hasAllServerTag())) {
+ return (*global_all_it);
+ }
+
+ return (StampedValuePtr());
}
value->setServerTag(getServerTag(server_selector));
auto& index = globals_.get<StampedValueNameIndexTag>();
- auto global_it = index.find(value->getName());
-
- if (global_it != index.end()) {
- index.replace(global_it, value);
+ auto global_it_pair = index.equal_range(value->getName());
- } else {
- index.insert(value);
+ for (auto global_it = global_it_pair.first; global_it != global_it_pair.second;
+ ++global_it) {
+ auto existing_value = *global_it;
+ if (existing_value->hasServerTag(ServerTag(getServerTag(server_selector)))) {
+ index.replace(global_it, value);
+ return;
+ }
}
+
+ index.insert(value);
}
void
}
uint64_t
-TestConfigBackendDHCPv4::deleteGlobalParameter4(const db::ServerSelector& /* server_selector */,
+TestConfigBackendDHCPv4::deleteGlobalParameter4(const db::ServerSelector& server_selector,
const std::string& name) {
auto& index = globals_.get<StampedValueNameIndexTag>();
- return (index.erase(name));
+ auto global_it_pair = index.equal_range(name);
+
+ for (auto global_it = global_it_pair.first; global_it != global_it_pair.second;
+ ++global_it) {
+ auto value = *global_it;
+ if (value->hasServerTag(ServerTag(getServerTag(server_selector)))) {
+ index.erase(global_it);
+ return (1);
+ }
+ }
+ return (0);
}
uint64_t
}
StampedValuePtr
-TestConfigBackendDHCPv6::getGlobalParameter6(const db::ServerSelector& /* server_selector */,
+TestConfigBackendDHCPv6::getGlobalParameter6(const db::ServerSelector& server_selector,
const std::string& name) const {
const auto& index = globals_.get<StampedValueNameIndexTag>();
- auto global_it = index.find(name);
- return ((global_it != index.cend()) ? (*global_it) : StampedValuePtr());
+ auto global_range = index.equal_range(name);
+ for (auto global_it = global_range.first; global_it != global_range.second;
+ ++global_it) {
+ auto tags = server_selector.getTags();
+ for (auto tag : tags) {
+ if ((*global_it)->hasServerTag(ServerTag(tag))) {
+ return (*global_it);
+ }
+ }
+ }
+
+ auto global_all_it = index.find(name);
+ if ((global_all_it != index.end()) && ((*global_all_it)->hasAllServerTag())) {
+ return (*global_all_it);
+ }
+
+ return (StampedValuePtr());
}
value->setServerTag(getServerTag(server_selector));
auto& index = globals_.get<StampedValueNameIndexTag>();
- auto global_it = index.find(value->getName());
-
- if (global_it != index.end()) {
- index.replace(global_it, value);
+ auto global_it_pair = index.equal_range(value->getName());
- } else {
- index.insert(value);
+ for (auto global_it = global_it_pair.first; global_it != global_it_pair.second;
+ ++global_it) {
+ auto existing_value = *global_it;
+ if (existing_value->hasServerTag(ServerTag(getServerTag(server_selector)))) {
+ index.replace(global_it, value);
+ return;
+ }
}
+
+ index.insert(value);
}
void
}
uint64_t
-TestConfigBackendDHCPv6::deleteGlobalParameter6(const db::ServerSelector& /* server_selector */,
+TestConfigBackendDHCPv6::deleteGlobalParameter6(const db::ServerSelector& server_selector,
const std::string& name) {
auto& index = globals_.get<StampedValueNameIndexTag>();
- return (index.erase(name));
+ auto global_it_pair = index.equal_range(name);
+
+ for (auto global_it = global_it_pair.first; global_it != global_it_pair.second;
+ ++global_it) {
+ auto value = *global_it;
+ if (value->hasServerTag(ServerTag(getServerTag(server_selector)))) {
+ index.erase(global_it);
+ return (1);
+ }
+ }
+ return (0);
}
uint64_t
// correct.
auto tags = cb_ctl_.getServerSelector().getTags();
ASSERT_EQ(1, tags.size());
- EXPECT_EQ("a-tag", *tags.begin());
+ EXPECT_EQ("a-tag", tags.begin()->get());
}
// This test verifies that incremental configuration changes can be