7#ifndef CFG_SHARED_NETWORKS_H
8#define CFG_SHARED_NETWORKS_H
15#include <boost/foreach.hpp>
16#include <boost/shared_ptr.hpp>
34template<
typename SharedNetworkPtrType,
typename SharedNetworkCollection>
38 const SharedNetworkCollection*
getAll()
const {
48 void add(
const SharedNetworkPtrType& network) {
51 "' found in the configuration");
54 static_cast<void>(
networks_.push_back(network));
62 void del(
const std::string& name) {
63 auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
64 auto shared_network = index.find(name);
65 if (shared_network != index.end()) {
67 (*shared_network)->delAll();
70 index.erase(shared_network);
73 << name <<
"' from shared networks configuration");
89 uint64_t
del(
const uint64_t
id) {
90 auto& index =
networks_.template get<SharedNetworkIdIndexTag>();
91 auto sn_range = index.equal_range(
id);
95 BOOST_FOREACH(
auto const& it, sn_range) {
100 return (
static_cast<uint64_t
>(index.erase(
id)));
109 SharedNetworkPtrType
getByName(
const std::string& name)
const {
110 auto const& index =
networks_.template get<SharedNetworkNameIndexTag>();
111 auto shared_network = index.find(name);
112 if (shared_network != index.cend()) {
113 return (*shared_network);
115 return (SharedNetworkPtrType());
126 auto const& index =
networks_.template get<SharedNetworkNameIndexTag>();
127 for (
auto const& shared_network : index) {
128 list->add(shared_network->toElement());
163 auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
168 auto const& other_networks = other.getAll();
169 for (
auto const& other_network : *other_networks) {
174 other_network->delAll();
177 auto existing_network = index.find(other_network->getName());
178 if (existing_network != index.end()) {
181 if (*existing_network == other_network) {
188 auto const subnets = (*existing_network)->getAllSubnets();
190 auto copy_subnets(*subnets);
191 for (
auto const& subnet : copy_subnets) {
192 (*existing_network)->del(subnet->getID());
193 other_network->add(subnet);
197 index.erase(existing_network);
201 other_network->getCfgOption()->createOptions(cfg_def);
205 other_network->getCfgOption()->encapsulate();
208 static_cast<void>(
networks_.push_back(other_network));
220 SharedNetwork4Collection> {
236 SharedNetwork6Collection> {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Represents configuration of IPv4 shared networks.
bool hasNetworkWithServerId(const asiolink::IOAddress &server_id) const
Checks if specified server identifier has been specified for any network.
Represents configuration of IPv6 shared networks.
This class holds configuration of shared networks.
virtual data::ElementPtr toElement() const
Unparses shared networks configuration.
const SharedNetworkCollection * getAll() const
Returns pointer to all configured shared networks.
void merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks &other)
Merges specified shared network configuration into this configuration.
void add(const SharedNetworkPtrType &network)
Adds new shared network to the configuration.
uint64_t del(const uint64_t id)
Deletes shared networks from the configuration by id.
SharedNetworkPtrType getByName(const std::string &name) const
Retrieves shared network by name.
SharedNetworkCollection networks_
Multi index container holding shared networks.
void del(const std::string &name)
Deletes shared network from the configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< CfgSharedNetworks6 > CfgSharedNetworks6Ptr
Pointer to the configuration of IPv6 shared networks.
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.