11 #include <boost/make_shared.hpp> 
   45     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
   46     static void add(SubnetCollectionType& subnets, 
const SubnetPtrType& subnet) {
 
   50                       " to a shared network");
 
   54         if (getSubnet<SubnetPtrType>(subnets, subnet->getID())) {
 
   56                       " duplicated subnet identifier " << subnet->getID());
 
   57         } 
else if (getSubnet<SubnetPtrType>(subnets, subnet->toText())) {
 
   59                       " duplicated subnet prefix " << subnet->toText());
 
   64         subnet->getSharedNetwork(network);
 
   67                       << 
" being added to a shared network" 
   68                       " already belongs to a shared network");
 
   72         static_cast<void>(subnets.insert(subnet));
 
   95     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
   96     static bool replace(SubnetCollectionType& subnets,
 
   97                         const SubnetPtrType& subnet) {
 
  101         subnet->getSharedNetwork(network);
 
  104                       << 
" being replaced in a shared network" 
  105                       " already belongs to a shared network");
 
  109         const SubnetID& subnet_id = subnet->getID();
 
  110         auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
 
  111         auto subnet_it = index.find(subnet_id);
 
  112         if (subnet_it == index.end()) {
 
  119         return (index.replace(subnet_it, subnet));
 
  132     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
  133     static SubnetPtrType del(SubnetCollectionType& subnets,
 
  135         auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
 
  136         auto subnet_it = index.find(subnet_id);
 
  137         if (subnet_it == index.end()) {
 
  139                       << 
" from shared network. Subnet doesn't belong" 
  140                       " to this shared network");
 
  142         auto subnet = *subnet_it;
 
  143         index.erase(subnet_it);
 
  158     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
  159     static SubnetPtrType getSubnet(
const SubnetCollectionType& subnets,
 
  161         const auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
 
  162         auto subnet_it = index.find(subnet_id);
 
  163         if (subnet_it != index.cend()) {
 
  168         return (SubnetPtrType());
 
  183     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
  184     static SubnetPtrType getSubnet(
const SubnetCollectionType& subnets,
 
  185                                    const std::string& subnet_prefix) {
 
  186         const auto& index = subnets.template get<SubnetPrefixIndexTag>();
 
  187         auto subnet_it = index.find(subnet_prefix);
 
  188         if (subnet_it != index.cend()) {
 
  193         return (SubnetPtrType());
 
  235     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
  236     static SubnetPtrType getNextSubnet(
const SubnetCollectionType& subnets,
 
  237                                        const SubnetPtrType& first_subnet,
 
  241         if (subnets.empty()) {
 
  242             return (SubnetPtrType());
 
  248         const auto& index = subnets.template get<SubnetSubnetIdIndexTag>();
 
  249         auto subnet_it = index.find(current_subnet);
 
  250         if (subnet_it == index.cend()) {
 
  252                       << 
" within shared network");
 
  256         if (++subnet_it == subnets.cend()) {
 
  259             subnet_it = subnets.cbegin();
 
  264         if ((*subnet_it)->getID() == first_subnet->getID()) {
 
  265             return (SubnetPtrType());
 
  296     template<
typename SubnetPtrType, 
typename SubnetCollectionType>
 
  297     static SubnetPtrType getPreferredSubnet(
const SubnetCollectionType& subnets,
 
  298                                             const SubnetPtrType& selected_subnet,
 
  301         auto preferred_subnet = selected_subnet;
 
  302         for (
auto s = subnets.begin(); s != subnets.end(); ++s) {
 
  303             if (((*s)->getClientClass() == selected_subnet->getClientClass()) &&
 
  304                 ((*s)->getLastAllocatedTime(lease_type) >
 
  305                  selected_subnet->getLastAllocatedTime(lease_type))) {
 
  306                 preferred_subnet = (*s);
 
  310         return (preferred_subnet);
 
  320 SharedNetwork4::create(
const std::string& name) {
 
  321     return (boost::make_shared<SharedNetwork4>(name));
 
  326     Impl::add(subnets_, subnet);
 
  328     subnet->setSharedNetwork(shared_from_this());
 
  329     subnet->setSharedNetworkName(
name_);
 
  337                   " to a shared network");
 
  339     const Subnet4Ptr& old = getSubnet(subnet->getID());
 
  340     bool ret = Impl::replace(subnets_, subnet);
 
  343         subnet->setSharedNetwork(shared_from_this());
 
  344         subnet->setSharedNetworkName(
name_);
 
  347         old->setSharedNetworkName(
"");
 
  354     Subnet4Ptr subnet = Impl::del<Subnet4Ptr>(subnets_, subnet_id);
 
  356     subnet->setSharedNetworkName(
"");
 
  360 SharedNetwork4::delAll() {
 
  361     for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
 
  363         (*subnet)->setSharedNetworkName(
"");
 
  369 SharedNetwork4::getSubnet(
const SubnetID& subnet_id)
 const {
 
  370     return (Impl::getSubnet<Subnet4Ptr>(subnets_, subnet_id));
 
  374 SharedNetwork4::getSubnet(
const std::string& subnet_prefix)
 const {
 
  375     return (Impl::getSubnet<Subnet4Ptr>(subnets_, subnet_prefix));
 
  379 SharedNetwork4::getNextSubnet(
const Subnet4Ptr& first_subnet,
 
  380                               const SubnetID& current_subnet)
 const {
 
  381     return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
 
  385 SharedNetwork4::getPreferredSubnet(
const Subnet4Ptr& selected_subnet)
 const {
 
  386     return (Impl::getPreferredSubnet<Subnet4Ptr>(subnets_, selected_subnet,
 
  391 SharedNetwork4::subnetsIncludeMatchClientId(
const Subnet4Ptr& first_subnet,
 
  393     for (
Subnet4Ptr subnet = first_subnet; subnet;
 
  394          subnet = subnet->getNextSubnet(first_subnet, client_classes)) {
 
  395         if (subnet->getMatchClientId()) {
 
  403 SharedNetwork4::toElement()
 const {
 
  407     if (!
name_.empty()) {
 
  412     for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
 
  413         subnet4->add((*subnet)->toElement());
 
  416     map->set(
"subnet4", subnet4);
 
  422 SharedNetwork6::create(
const std::string& name) {
 
  423     return (boost::make_shared<SharedNetwork6>(name));
 
  428     Impl::add(subnets_, subnet);
 
  430     subnet->setSharedNetwork(shared_from_this());
 
  431     subnet->setSharedNetworkName(
name_);
 
  439                   " to a shared network");
 
  441     const Subnet6Ptr& old = getSubnet(subnet->getID());
 
  442     bool ret = Impl::replace(subnets_, subnet);
 
  445         subnet->setSharedNetwork(shared_from_this());
 
  446         subnet->setSharedNetworkName(
name_);
 
  449         old->setSharedNetworkName(
"");
 
  456     Subnet6Ptr subnet = Impl::del<Subnet6Ptr>(subnets_, subnet_id);
 
  458     subnet->setSharedNetworkName(
"");
 
  462 SharedNetwork6::delAll() {
 
  463     for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
 
  470 SharedNetwork6::getSubnet(
const SubnetID& subnet_id)
 const {
 
  471     return (Impl::getSubnet<Subnet6Ptr>(subnets_, subnet_id));
 
  475 SharedNetwork6::getSubnet(
const std::string& subnet_prefix)
 const {
 
  476     return (Impl::getSubnet<Subnet6Ptr>(subnets_, subnet_prefix));
 
  480 SharedNetwork6::getNextSubnet(
const Subnet6Ptr& first_subnet,
 
  481                               const SubnetID& current_subnet)
 const {
 
  482     return (Impl::getNextSubnet(subnets_, first_subnet, current_subnet));
 
  486 SharedNetwork6::getPreferredSubnet(
const Subnet6Ptr& selected_subnet,
 
  488     return (Impl::getPreferredSubnet(subnets_, selected_subnet, lease_type));
 
  492 SharedNetwork6::toElement()
 const {
 
  496     if (!
name_.empty()) {
 
  501     for (
auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
 
  502         subnet6->add((*subnet)->toElement());
 
  505     map->set(
"subnet6", subnet6);
 
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object. 
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object. 
boost::shared_ptr< Element > ElementPtr
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr. 
#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< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object. 
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object. 
Defines the logger used by the top-level component of kea-dhcp-ddns. 
static ElementPtr create(const Position &pos=ZERO_POSITION())
Type
Type of lease or pool. 
A generic exception that is thrown if a function is called in a prohibited way. 
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object. 
Container for storing client class names. 
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)