shared_network.cc 2.69 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright (C) 2017 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 <dhcpsrv/shared_network.h>

9
using namespace isc::data;
10 11 12 13 14
using namespace isc::dhcp;

namespace isc {
namespace dhcp {

15 16 17 18 19 20 21 22 23 24 25 26
ElementPtr
SharedNetwork::toElement() const {
    ElementPtr map = Network::toElement();

    // Set shared network name.
    if (!name_.empty()) {
        map->set("name", Element::create(name_));
    }

    return (map);
}

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
NetworkPtr
SharedNetwork4::sharedFromThis() {
    return (shared_from_this());
}

void
SharedNetwork4::add(const Subnet4Ptr& subnet) {
    SharedNetwork::add(subnets_, subnet);
}

void
SharedNetwork4::del(const SubnetID& subnet_id) {
    SharedNetwork::del(subnets_, subnet_id);
}

Subnet4Ptr
SharedNetwork4::getSubnet(const SubnetID& subnet_id) const {
    return (SharedNetwork::getSubnet<Subnet4Ptr>(subnets_, subnet_id));
}

Subnet4Ptr
SharedNetwork4::getNextSubnet(const Subnet4Ptr& first_subnet,
                              const Subnet4Ptr& current_subnet) const {
    return (SharedNetwork::getNextSubnet(subnets_, first_subnet,
                                         current_subnet));
}

54 55 56 57 58 59 60 61 62 63 64 65 66 67
ElementPtr
SharedNetwork4::toElement() const {
    ElementPtr map = SharedNetwork::toElement();

    ElementPtr subnet4 = Element::createList();
    for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
        subnet4->add((*subnet)->toElement());
    }

    map->set("subnet4", subnet4);

    return (map);
}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
NetworkPtr
SharedNetwork6::sharedFromThis() {
    return (shared_from_this());
}

void
SharedNetwork6::add(const Subnet6Ptr& subnet) {
    SharedNetwork::add(subnets_, subnet);
}

void
SharedNetwork6::del(const SubnetID& subnet_id) {
    SharedNetwork::del(subnets_, subnet_id);
}

Subnet6Ptr
SharedNetwork6::getSubnet(const SubnetID& subnet_id) const {
    return (SharedNetwork::getSubnet<Subnet6Ptr>(subnets_, subnet_id));
}

Subnet6Ptr
SharedNetwork6::getNextSubnet(const Subnet6Ptr& first_subnet,
                              const Subnet6Ptr& current_subnet) const {
    return (SharedNetwork::getNextSubnet(subnets_, first_subnet,
                                         current_subnet));
}

95 96 97 98 99 100 101 102 103 104 105 106 107 108
ElementPtr
SharedNetwork6::toElement() const {
    ElementPtr map = SharedNetwork::toElement();

    ElementPtr subnet6 = Element::createList();
    for (auto subnet = subnets_.cbegin(); subnet != subnets_.cend(); ++subnet) {
        subnet6->add((*subnet)->toElement());
    }

    map->set("subnet6", subnet6);

    return (map);
}

109 110
} // end of namespace isc::dhcp
} // end of namespace isc