return (map);
}
+ElementPtr
+Network4::toElement() const {
+ ElementPtr map = Network::toElement();
+
+ // Set match-client-id
+ map->set("match-client-id", Element::create(getMatchClientId()));
+
+ return (map);
+}
+
+ElementPtr
+Network6::toElement() const {
+ ElementPtr map = Network::toElement();
+
+ // Set preferred-lifetime
+ map->set("preferred-lifetime",
+ Element::create(static_cast<long long>
+ (getPreferred().get())));
+
+ // Set interface-id
+ const OptionPtr& ifaceid = getInterfaceId();
+ if (ifaceid) {
+ std::vector<uint8_t> bin = ifaceid->getData();
+ std::string ifid;
+ ifid.resize(bin.size());
+ if (!bin.empty()) {
+ std::memcpy(&ifid[0], &bin[0], bin.size());
+ }
+ map->set("interface-id", Element::create(ifid));
+ }
+
+ // Set rapid-commit
+ bool rapid_commit = getRapidCommit();
+ map->set("rapid-commit", Element::create(rapid_commit));
+
+ return (map);
+}
+
} // end of namespace isc::dhcp
} // end of namespace isc
#include <cc/cfg_to_element.h>
#include <cc/data.h>
#include <dhcp/classify.h>
+#include <dhcp/option.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfg_4o6.h>
#include <dhcpsrv/triplet.h>
/// @brief Weak pointer to the @ref Network object.
typedef boost::weak_ptr<Network> WeakNetworkPtr;
+/// @brief Specialization of the @ref Network object for DHCPv4 case.
class Network4 : public Network {
public:
+
+ /// @brief Constructor.
+ Network4()
+ : Network(), match_client_id_(true) {
+ }
+
+ /// @brief Returns the flag indicating if the client identifiers should
+ /// be used to identify the client's lease.
+ ///
+ /// @return true if client identifiers should be used, false otherwise.
+ bool getMatchClientId() const {
+ return (match_client_id_);
+ }
+
+ /// @brief Sets the flag indicating if the client identifier should be
+ /// used to identify the client's lease.
+ ///
+ /// @param match If this value is true, the client identifiers are not
+ /// used for lease lookup.
+ void setMatchClientId(const bool match) {
+ match_client_id_ = match;
+ }
+
+ /// @brief Unparses network object.
+ ///
+ /// @return A pointer to unparsed network configuration.
+ virtual data::ElementPtr toElement() const;
+
+private:
+
+ /// @brief Should server use client identifiers for client lease
+ /// lookup.
+ bool match_client_id_;
};
+/// @brief Specialization of the @ref Network object for DHCPv6 case.
class Network6 : public Network {
public:
+
+ /// @brief Constructor.
+ Network6()
+ : Network(), preferred_(0), interface_id_(), rapid_commit_(false) {
+ setRelayInfo(asiolink::IOAddress::IPV6_ZERO_ADDRESS());
+ }
+
+ /// @brief Returns preferred lifetime (in seconds)
+ ///
+ /// @return a triplet with preferred lifetime
+ Triplet<uint32_t> getPreferred() const {
+ return (preferred_);
+ }
+
+ /// @brief Sets new preferred lifetime for a network.
+ ///
+ /// @param valid New preferred lifetime in seconds.
+ void setPreferred(const Triplet<uint32_t>& preferred) {
+ preferred_ = preferred;
+ }
+
+ /// @brief Returns interface-id value (if specified)
+ ///
+ /// @return interface-id option (if defined)
+ OptionPtr getInterfaceId() const {
+ return (interface_id_);
+ }
+
+ /// @brief sets interface-id option (if defined)
+ ///
+ /// @param ifaceid pointer to interface-id option
+ void setInterfaceId(const OptionPtr& ifaceid) {
+ interface_id_ = ifaceid;
+ }
+
+ /// @brief Returns boolean value indicating that the Rapid Commit option
+ /// is supported or unsupported for the subnet.
+ ///
+ /// @return true if the Rapid Commit option is supported, false otherwise.
+ bool getRapidCommit() const {
+ return (rapid_commit_);
+ }
+
+ /// @brief Enables or disables Rapid Commit option support for the subnet.
+ ///
+ /// @param rapid_commit A boolean value indicating that the Rapid Commit
+ /// option support is enabled (if true), or disabled (if false).
+ void setRapidCommit(const bool rapid_commit) {
+ rapid_commit_ = rapid_commit;
+ };
+
+ /// @brief Unparses network object.
+ ///
+ /// @return A pointer to unparsed network configuration.
+ virtual data::ElementPtr toElement() const;
+
+private:
+
+ /// @brief a triplet with preferred lifetime (in seconds)
+ Triplet<uint32_t> preferred_;
+
+ /// @brief specifies optional interface-id
+ OptionPtr interface_id_;
+
+ /// @brief A flag indicating if Rapid Commit option is supported
+ /// for this network.
+ ///
+ /// It's default value is false, which indicates that the Rapid
+ /// Commit is disabled for the subnet.
+ bool rapid_commit_;
};
} // end of namespace isc::dhcp
ElementPtr
SharedNetwork4::toElement() const {
- ElementPtr map = Network::toElement();
+ ElementPtr map = Network4::toElement();
// Set shared network name.
if (!name_.empty()) {
ElementPtr
SharedNetwork6::toElement() const {
- ElementPtr map = Network::toElement();
+ ElementPtr map = Network6::toElement();
// Set shared network name.
if (!name_.empty()) {
const Triplet<uint32_t>& t2,
const Triplet<uint32_t>& valid_lifetime,
const SubnetID id)
- : Subnet(prefix, length, id), Network(),
- siaddr_(IOAddress("0.0.0.0")), match_client_id_(true) {
+ : Subnet(prefix, length, id), Network4(),
+ siaddr_(IOAddress("0.0.0.0")) {
if (!prefix.isV4()) {
isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText()
<< " specified in subnet4");
const Triplet<uint32_t>& preferred_lifetime,
const Triplet<uint32_t>& valid_lifetime,
const SubnetID id)
- :Subnet(prefix, length, id), Network(),
- preferred_(preferred_lifetime), rapid_commit_(false) {
+ : Subnet(prefix, length, id), Network6() {
if (!prefix.isV6()) {
isc_throw(BadValue, "Non IPv6 prefix " << prefix
<< " specified in subnet6");
// Timers.
setT1(t1);
setT2(t2);
+ setPreferred(preferred_lifetime);
setValid(valid_lifetime);
}
Subnet4::toElement() const {
// Prepare the map
ElementPtr map = Subnet::toElement();
- ElementPtr network_map = Network::toElement();
+ ElementPtr network_map = Network4::toElement();
merge(map, network_map);
- // Set match-client-id
- map->set("match-client-id", Element::create(getMatchClientId()));
-
// Set DHCP4o6
const Cfg4o6& d4o6 = get4o6();
isc::data::merge(map, d4o6.toElement());
Subnet6::toElement() const {
// Prepare the map
ElementPtr map = Subnet::toElement();
- ElementPtr network_map = Network::toElement();
+ ElementPtr network_map = Network6::toElement();
merge(map, network_map);
- // Set interface-id
- const OptionPtr& ifaceid = getInterfaceId();
- if (ifaceid) {
- std::vector<uint8_t> bin = ifaceid->getData();
- std::string ifid;
- ifid.resize(bin.size());
- if (!bin.empty()) {
- std::memcpy(&ifid[0], &bin[0], bin.size());
- }
- map->set("interface-id", Element::create(ifid));
- }
-
- // Set preferred-lifetime
- map->set("preferred-lifetime",
- Element::create(static_cast<long long>
- (getPreferred().get())));
- // Set rapid-commit
- bool rapid_commit = getRapidCommit();
- map->set("rapid-commit", Element::create(rapid_commit));
-
// Set pools
const PoolCollection& pools = getPools(Lease::TYPE_NA);
ElementPtr pool_list = Element::createList();
#include <asiolink/io_address.h>
#include <cc/data.h>
-#include <dhcp/option.h>
#include <dhcp/option_space_container.h>
#include <dhcpsrv/assignable_network.h>
#include <dhcpsrv/lease.h>
/// @brief A configuration holder for IPv4 subnet.
///
/// This class represents an IPv4 subnet.
-class Subnet4 : public Subnet, public Network {
+class Subnet4 : public Subnet, public Network4 {
public:
/// @brief Constructor with all parameters
/// @return siaddr value
isc::asiolink::IOAddress getSiaddr() const;
- /// @brief Sets the flag indicating if the client identifier should be
- /// used to identify the client's lease.
- ///
- /// @param match If this value is true, the client identifiers are not
- /// used for lease lookup.
- void setMatchClientId(const bool match) {
- match_client_id_ = match;
- }
-
- /// @brief Returns the flag indicating if the client identifiers should
- /// be used to identify the client's lease.
- ///
- /// @return true if client identifiers should be used, false otherwise.
- bool getMatchClientId() const {
- return (match_client_id_);
- }
-
/// @brief Returns DHCP4o6 configuration parameters.
///
/// This structure is always available. If the 4o6 is not enabled, its
/// @brief siaddr value for this subnet
isc::asiolink::IOAddress siaddr_;
- /// @brief Should server use client identifiers for client lease
- /// lookup.
- bool match_client_id_;
-
/// @brief All the information related to DHCP4o6
Cfg4o6 dhcp4o6_;
};
/// @brief A configuration holder for IPv6 subnet.
///
/// This class represents an IPv6 subnet.
-class Subnet6 : public Subnet, public Network {
+class Subnet6 : public Subnet, public Network6 {
public:
/// @brief Constructor with all parameters
const Triplet<uint32_t>& valid_lifetime,
const SubnetID id = 0);
- /// @brief Returns preferred lifetime (in seconds)
- ///
- /// @return a triplet with preferred lifetime
- Triplet<uint32_t> getPreferred() const {
- return (preferred_);
- }
-
- /// @brief sets interface-id option (if defined)
- ///
- /// @param ifaceid pointer to interface-id option
- void setInterfaceId(const OptionPtr& ifaceid) {
- interface_id_ = ifaceid;
- }
-
- /// @brief returns interface-id value (if specified)
- /// @return interface-id option (if defined)
- OptionPtr getInterfaceId() const {
- return interface_id_;
- }
-
- /// @brief Enables or disables Rapid Commit option support for the subnet.
- ///
- /// @param rapid_commit A boolean value indicating that the Rapid Commit
- /// option support is enabled (if true), or disabled (if false).
- void setRapidCommit(const bool rapid_commit) {
- rapid_commit_ = rapid_commit;
- };
-
- /// @brief Returns boolean value indicating that the Rapid Commit option
- /// is supported or unsupported for the subnet.
- ///
- /// @return true if the Rapid Commit option is supported, false otherwise.
- bool getRapidCommit() const {
- return (rapid_commit_);
- }
-
/// @brief Unparse a subnet object.
///
/// @return A pointer to unparsed subnet configuration.
/// @throw BadValue if invalid value is used
virtual void checkType(Lease::Type type) const;
- /// @brief specifies optional interface-id
- OptionPtr interface_id_;
-
- /// @brief a triplet with preferred lifetime (in seconds)
- Triplet<uint32_t> preferred_;
-
- /// @brief A flag indicating if Rapid Commit option is supported
- /// for this subnet.
- ///
- /// It's default value is false, which indicates that the Rapid
- /// Commit is disabled for the subnet.
- bool rapid_commit_;
-
};
/// @brief A const pointer to a @c Subnet6 object.
"[\n"
" {\n"
" \"interface\": \"eth1\",\n"
+ " \"match-client-id\": true,\n"
" \"name\": \"dog\",\n"
" \"option-data\": [ ],\n"
- " \"subnet4\": [ ]\n"
+ " \"rebind-timer\": 0,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"0.0.0.0\"\n"
+ " },\n"
+ " \"renew-timer\": 0,\n"
+ " \"reservation-mode\": \"all\","
+ " \"subnet4\": [ ],\n"
+ " \"valid-lifetime\": 0\n"
" },\n"
" {\n"
" \"interface\": \"eth0\",\n"
+ " \"match-client-id\": true,\n"
" \"name\": \"frog\",\n"
" \"option-data\": [ ],\n"
- " \"subnet4\": [ ]\n"
+ " \"rebind-timer\": 0,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"0.0.0.0\"\n"
+ " },\n"
+ " \"renew-timer\": 0,\n"
+ " \"reservation-mode\": \"all\","
+ " \"subnet4\": [ ],\n"
+ " \"valid-lifetime\": 0\n"
" }\n"
"]\n";
" \"interface\": \"eth1\",\n"
" \"name\": \"dog\",\n"
" \"option-data\": [ ],\n"
- " \"subnet6\": [ ]\n"
+ " \"preferred-lifetime\": 0,\n"
+ " \"rapid-commit\": false,\n"
+ " \"rebind-timer\": 0,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"::\"\n"
+ " },\n"
+ " \"renew-timer\": 0,\n"
+ " \"reservation-mode\": \"all\","
+ " \"subnet6\": [ ],\n"
+ " \"valid-lifetime\": 0\n"
" },\n"
" {\n"
" \"interface\": \"eth0\",\n"
" \"name\": \"frog\",\n"
" \"option-data\": [ ],\n"
- " \"subnet6\": [ ]\n"
+ " \"preferred-lifetime\": 0,\n"
+ " \"rapid-commit\": false,\n"
+ " \"rebind-timer\": 0,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"::\"\n"
+ " },\n"
+ " \"renew-timer\": 0,\n"
+ " \"reservation-mode\": \"all\","
+ " \"subnet6\": [ ],\n"
+ " \"valid-lifetime\": 0\n"
" }\n"
"]\n";
// Set interface name.
network->setIface("eth1");
+ network->setT1(100);
+ network->setT2(150);
+ network->setValid(200);
+ network->setMatchClientId(false);
+
// Add several subnets.
Subnet4Ptr subnet1(new Subnet4(IOAddress("10.0.0.0"), 8, 10, 20, 30,
SubnetID(1)));
std::string expected = "{\n"
" \"interface\": \"eth1\",\n"
+ " \"match-client-id\": false,\n"
" \"name\": \"frog\",\n"
" \"option-data\": [ ],\n"
+ " \"rebind-timer\": 150,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"0.0.0.0\"\n"
+ " },\n"
+ " \"renew-timer\": 100,\n"
+ " \"reservation-mode\": \"all\","
" \"subnet4\": [\n"
" {\n"
" \"4o6-interface\": \"\",\n"
" \"subnet\": \"192.0.2.0/24\",\n"
" \"valid-lifetime\": 30\n"
" }\n"
- " ]\n"
+ " ],\n"
+ " \"valid-lifetime\": 200\n"
"}\n";
test::runToElementTest<SharedNetwork4>(expected, *network);
TEST(SharedNetwork6Test, unparse) {
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
network->setIface("eth1");
+ network->setT1(100);
+ network->setT2(150);
+ network->setPreferred(200);
+ network->setValid(300);
+ network->setRapidCommit(true);
// Add several subnets.
Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 64, 10, 20, 30,
" \"interface\": \"eth1\",\n"
" \"name\": \"frog\",\n"
" \"option-data\": [ ],\n"
+ " \"preferred-lifetime\": 200,\n"
+ " \"rapid-commit\": true,\n"
+ " \"rebind-timer\": 150,\n"
+ " \"relay\": {\n"
+ " \"ip-address\": \"::\"\n"
+ " },\n"
+ " \"renew-timer\": 100,\n"
+ " \"reservation-mode\": \"all\","
" \"subnet6\": [\n"
" {\n"
" \"id\": 1,\n"
" \"subnet\": \"3000::/16\",\n"
" \"valid-lifetime\": 40\n"
" }\n"
- " ]\n"
+ " ],\n"
+ " \"valid-lifetime\": 300\n"
"}\n";
test::runToElementTest<SharedNetwork6>(expected, *network);