7 #ifndef CFG_SHARED_NETWORKS_H
8 #define CFG_SHARED_NETWORKS_H
15 #include <boost/shared_ptr.hpp>
33 template<
typename SharedNetworkPtrType,
typename SharedNetworkCollection>
37 const SharedNetworkCollection*
getAll()
const {
47 void add(
const SharedNetworkPtrType& network) {
50 "' found in the configuration");
53 static_cast<void>(
networks_.push_back(network));
61 void del(
const std::string& name) {
62 auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
63 auto shared_network = index.find(name);
64 if (shared_network != index.end()) {
66 (*shared_network)->delAll();
69 index.erase(shared_network);
72 << name <<
"' from shared networks configuration");
88 uint64_t
del(
const uint64_t
id) {
89 auto& index =
networks_.template get<SharedNetworkIdIndexTag>();
90 auto sn_range = index.equal_range(
id);
94 for (
auto it = sn_range.first; it != sn_range.second; ++it) {
99 return (static_cast<uint64_t>(index.erase(
id)));
108 SharedNetworkPtrType
getByName(
const std::string& name)
const {
109 const auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
110 auto shared_network = index.find(name);
111 if (shared_network != index.cend()) {
112 return (*shared_network);
114 return (SharedNetworkPtrType());
125 const auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
126 for (
auto shared_network = index.begin(); shared_network != index.end();
128 list->add((*shared_network)->toElement());
163 auto& index =
networks_.template get<SharedNetworkNameIndexTag>();
168 auto other_networks = other.
getAll();
169 for (
auto other_network = other_networks->begin();
170 other_network != other_networks->end(); ++other_network) {
175 (*other_network)->delAll();
178 auto existing_network = index.find((*other_network)->getName());
179 if (existing_network != index.end()) {
182 if (*existing_network == *other_network) {
189 const auto subnets = (*existing_network)->getAllSubnets();
191 auto copy_subnets(*subnets);
192 for (
auto subnet = copy_subnets.cbegin(); subnet != copy_subnets.cend(); ++subnet) {
193 (*existing_network)->del((*subnet)->getID());
194 (*other_network)->add(*subnet);
198 index.erase(existing_network);
202 (*other_network)->getCfgOption()->createOptions(cfg_def);
205 static_cast<void>(
networks_.push_back(*other_network));
217 SharedNetwork4Collection> {
233 SharedNetwork6Collection> {
243 #endif // CFG_SHARED_NETWORKS_H
SharedNetworkCollection networks_
Multi index container holding shared networks.
void add(const SharedNetworkPtrType &network)
Adds new shared network to the configuration.
boost::shared_ptr< CfgSharedNetworks6 > CfgSharedNetworks6Ptr
Pointer to the configuration of IPv6 shared networks.
const SharedNetworkCollection * getAll() const
Returns pointer to all configured shared networks.
void del(const std::string &name)
Deletes shared network from the configuration.
SharedNetworkPtrType getByName(const std::string &name) const
Retrieves shared network by name.
Represents configuration of IPv4 shared networks.
uint64_t del(const uint64_t id)
Deletes shared networks from the configuration by id.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
bool hasNetworkWithServerId(const asiolink::IOAddress &server_id) const
Checks if specified server identifier has been specified for any network.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
virtual data::ElementPtr toElement() const
Unparses shared networks configuration.
Abstract class for configuration Cfg_* classes.
This class holds configuration of shared networks.
Represents configuration of IPv6 shared networks.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks &other)
Merges specified shared network configuration into this configuration.
The IOAddress class represents an IP addresses (version agnostic)