Commit 194f7617 authored by Marcin Siodelski's avatar Marcin Siodelski

[#99,!176] Implemented test config backend for DHCPv4.

parent 7fbbfde2
......@@ -8,6 +8,10 @@
#define STAMPED_VALUE_H
#include <cc/stamped_element.h>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/shared_ptr.hpp>
#include <cstdint>
#include <string>
......@@ -20,9 +24,6 @@ class StampedValue;
/// @brief Pointer to the stamped value.
typedef boost::shared_ptr<StampedValue> StampedValuePtr;
/// @brief Collection of pointers to values.
typedef std::vector<StampedValuePtr> StampedValueCollection;
/// @brief This class represents string or signed integer configuration
/// element associated with the modification timestamp.
///
......@@ -91,8 +92,43 @@ private:
std::string value_;
};
/// @brief Pointer to the stamped value.
typedef boost::shared_ptr<StampedValue> StampedValuePtr;
/// @name Definition of the multi index container for @c StampedValue.
///
//@{
/// @brief Tag for the index for access by value name.
struct StampedValueNameIndexTag { };
/// @brief Tag for the index for access by modification time.
struct StampedValueModificationTimeIndexTag { };
/// @brief Multi index container for @c StampedValue.
typedef boost::multi_index_container<
StampedValuePtr,
boost::multi_index::indexed_by<
// Index used to access value by name.
boost::multi_index::hashed_non_unique<
boost::multi_index::tag<StampedValueNameIndexTag>,
boost::multi_index::const_mem_fun<
StampedValue,
std::string,
&StampedValue::getName
>
>,
// Index used to access value by modification time.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<StampedValueModificationTimeIndexTag>,
boost::multi_index::const_mem_fun<
StampedElement,
boost::posix_time::ptime,
&StampedElement::getModificationTime
>
>
>
> StampedValueCollection;
//@}
} // end of namespace isc::data
} // end of namespace isc
......
......@@ -15,6 +15,7 @@
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/shared_ptr.hpp>
......@@ -811,6 +812,16 @@ typedef boost::multi_index_container<
std::string,
&OptionDefinition::getName
>
>,
// Start definition of index #3
boost::multi_index::ordered_non_unique<
// Use option definition modification time as the index key.
// This value is returned by the StampedElement::getModificationTime
boost::multi_index::const_mem_fun<
data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime
>
>
>
> OptionDefContainer;
......
......@@ -15,6 +15,7 @@
#include <dhcpsrv/key_from_key.h>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/member.hpp>
......@@ -198,6 +199,15 @@ typedef boost::multi_index_container<
bool,
&OptionDescriptor::persistent_
>
>,
// Start definition of index #3.
// Use StampedElement::getModificationTime as a key.
boost::multi_index::ordered_non_unique<
boost::multi_index::const_mem_fun<
data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime
>
>
>
> OptionContainer;
......@@ -404,6 +414,31 @@ public:
return (*od_itr);
}
/// @brief Deletes option for the specified key and option code.
///
/// The key should be a string, in which case it specifies an option space
/// name, or an uint32_t value, in which case it specifies a vendor
/// identifier.
///
/// @param key Option space name or vendor identifier.
/// @param option_code Code of the option to be returned.
/// @tparam Selector one of: @c std::string or @c uint32_t
///
/// @return Number of deleted options.
template<typename Selector>
size_t del(const Selector& key, const uint16_t option_code) {
// Check for presence of options.
OptionContainerPtr options = getAll(key);
if (!options || options->empty()) {
// There are no options, so there is nothing to do.
return (0);
}
// Some options present, locate the one we are interested in.
auto& idx = options->get<1>();
return (idx.erase(option_code));
}
/// @brief Returns a list of configured option space names.
///
/// The returned option space names exclude vendor option spaces,
......
......@@ -34,6 +34,10 @@ struct SharedNetworkNameIndexTag { };
/// @brief A tag for accessing index by server identifier.
struct SharedNetworkServerIdIndexTag { };
/// @brief Tag for the index for searching by shared network modification
/// time.
struct SharedNetworkModificationTimeIndexTag { };
/// @brief Shared network holding IPv4 subnets.
///
/// Specialization of the @ref Network4 class for IPv4 shared networks.
......@@ -188,8 +192,14 @@ typedef boost::multi_index_container<
boost::multi_index::tag<SharedNetworkServerIdIndexTag>,
boost::multi_index::const_mem_fun<Network4, asiolink::IOAddress,
&Network4::getServerId>
>,
// Fourth index allows for searching using subnet modification time.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SharedNetworkModificationTimeIndexTag>,
boost::multi_index::const_mem_fun<data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime>
>
>
> SharedNetwork4Collection;
......@@ -340,6 +350,13 @@ typedef boost::multi_index_container<
boost::multi_index::tag<SharedNetworkNameIndexTag>,
boost::multi_index::const_mem_fun<SharedNetwork6, std::string,
&SharedNetwork6::getName>
>,
// Third index allows for searching using subnet modification time.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SharedNetworkModificationTimeIndexTag>,
boost::multi_index::const_mem_fun<data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime>
>
>
> SharedNetwork6Collection;
......
......@@ -744,6 +744,9 @@ struct SubnetPrefixIndexTag { };
/// @brief Tag for the index for searching by server identifier.
struct SubnetServerIdIndexTag { };
/// @brief Tag for the index for searching by subnet modification time.
struct SubnetModificationTimeIndexTag { };
/// @brief A collection of @c Subnet4 objects
///
/// This container provides a set of indexes which can be used to retrieve
......@@ -788,11 +791,19 @@ typedef boost::multi_index_container<
boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
>,
// Fourth index allows for searching using an output from getServerId
// Fourth index allows for searching using an output from getServerId.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SubnetServerIdIndexTag>,
boost::multi_index::const_mem_fun<Network4, asiolink::IOAddress,
&Network4::getServerId>
>,
// Fifth index allows for searching using subnet modification time.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SubnetModificationTimeIndexTag>,
boost::multi_index::const_mem_fun<data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime>
>
>
> Subnet4Collection;
......@@ -838,6 +849,13 @@ typedef boost::multi_index_container<
boost::multi_index::ordered_unique<
boost::multi_index::tag<SubnetPrefixIndexTag>,
boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
>,
// Fourth index allows for searching using subnet modification time.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SubnetModificationTimeIndexTag>,
boost::multi_index::const_mem_fun<data::StampedElement,
boost::posix_time::ptime,
&data::StampedElement::getModificationTime>
>
>
> Subnet6Collection;
......
......@@ -16,6 +16,9 @@
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <map>
#include <string>
namespace isc {
namespace dhcp {
namespace test {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment