// Configure packet queue
try {
- ConstQueueControlPtr qc;
+ data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getQueueControlInfo();
if (!qc) {
- // For right now, we are maually constructing the default
+ // @todo For now we're manually constructing default queue config
// This probably needs to be built into the PQM?
- QueueControl default_qc;
- default_qc.setQueueType("kea-ring4");
- default_qc.setCapacity(500);
+ data::ElementPtr default_qc = data::Element::createMap();
+ default_qc->set("queue-type", data::Element::create("kea-ring4"));
+ default_qc->set("capacity", data::Element::create(static_cast<long int>(500)));
PacketQueueMgr4::instance().createPacketQueue(default_qc);
} else {
- PacketQueueMgr4::instance().createPacketQueue(*qc);
+ PacketQueueMgr4::instance().createPacketQueue(qc);
}
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CONFIG_PACKET_QUEUE)
if (config_pair.first == "queue-control") {
QueueControlParser parser(AF_INET);
- QueueControlPtr queue_control = parser.parse(config_pair.second);
- srv_cfg->setQueueControlInfo(queue_control);
+ srv_cfg->setQueueControlInfo(parser.parse(config_pair.second));
continue;
}
"} \n";
// Let's check the default. It should be empty.
- ConstQueueControlPtr control;
+ data::ConstElementPtr control;
control = CfgMgr::instance().getStagingCfg()->getQueueControlInfo();
ASSERT_FALSE(control);
configure(config_with_queue, CONTROL_RESULT_SUCCESS, "");
control = CfgMgr::instance().getStagingCfg()->getQueueControlInfo();
ASSERT_TRUE(control);
- EXPECT_EQ(75, control->getCapacity());
- EXPECT_FALSE(control->getContext());
+ // Clear the config
CfgMgr::instance().clear();
// Configuration with queue with context should be valid.
configure(config_with_context, CONTROL_RESULT_SUCCESS, "");
control = CfgMgr::instance().getStagingCfg()->getQueueControlInfo();
ASSERT_TRUE(control);
- EXPECT_EQ(90, control->getCapacity());
- EXPECT_TRUE(control->getContext());
}
// Check whether it is possible to configure server-tag
libkea_dhcp___la_SOURCES += pkt_filter6.h pkt_filter6.cc
libkea_dhcp___la_SOURCES += pkt_filter_inet.cc pkt_filter_inet.h
libkea_dhcp___la_SOURCES += pkt_filter_inet6.cc pkt_filter_inet6.h
-libkea_dhcp___la_SOURCES += queue_control.cc queue_control.h
libkea_dhcp___la_SOURCES += socket_info.h
# Utilize Linux Packet Filtering on Linux.
pkt_filter6.h \
pkt_filter_inet.h \
pkt_filter_inet6.h \
- queue_control.h \
protocol_util.h \
socket_info.h \
std_option_defs.h
#define PACKET_QUEUE_H
#include <cc/data.h>
-#include <dhcp/queue_control.h>
#include <dhcp/socket_info.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
#ifndef PACKET_QUEUE_MGR_H
#define PACKET_QUEUE_MGR_H
+#include <cc/data.h>
+#include <cc/simple_parser.h>
#include <dhcp/packet_queue.h>
#include <exceptions/exceptions.h>
#include <boost/shared_ptr.hpp>
///
/// Factory function returns a pointer to the instance of the configuration
/// backend created.
- typedef std::function<PacketQueueTypePtr(const QueueControl&)> Factory;
+ typedef std::function<PacketQueueTypePtr(data::ConstElementPtr)> Factory;
/// @brief Constructor.
PacketQueueMgr()
/// in a hooks library. In such a case, this function should be called from
/// the @c load function in this library. When the queue impl is registered,
/// the server will use it when required by the configuration, i.e. a
- /// user specifies it by name in "queue-control".
+ /// user specifies it in "queue-control:queue-type"
///
/// If the given queue type has already been registered, perhaps
/// by another hooks library, the PQM will refuse to register another
/// @brief Create an instance of a packet queue.
///
- /// This method uses provided @c dbaccess string representing database
- /// connection information to create an instance of the database
- /// backend. If the specified backend type is not supported, i.e. there
- /// is no relevant factory function registered, an exception is thrown.
+ /// Replace the current packet queue with a new one based on the
+ /// given configuration parameters. The set of parameters must
+ /// contain at least "queue-type". This value is used to locate
+ /// the registered queue factory to invoke to create the new queue.
///
- /// @param dbaccess Database access string being a collection of
- /// key=value pairs.
+ /// The factory is passed the parameters verbatim for its use in
+ /// creating the new queue. Factories are expected to throw exceptions
+ /// on creation failure. Note the existing queue is not altered or
+ /// replaced unless the new queue is successfully created.
///
- /// @throw InvalidQueueType if the queue type requested is not supported
+ /// @throw InvalidQueueParameter if parameters is not map that contains
+ /// "queue-type", InvalidQueueType if the queue type requested is not
+ /// supported.
/// @throw Unexpected if the backend factory function returned NULL.
- void createPacketQueue(const QueueControl& queue_control) {
+ void createPacketQueue(data::ConstElementPtr parameters) {
+ if (!parameters) {
+ isc_throw(Unexpected, "createPacketQueue - queue parameters is null");
+ }
+
// Get the database type to locate a factory function.
- // easier if these are elements no?
- std::string queue_type = queue_control.getQueueType();
+ std::string queue_type ;
+ try {
+ queue_type = data::SimpleParser::getString(parameters, "queue-type");
+ } catch (std::exception& ex) {
+ isc_throw(InvalidQueueParameter, "queue-type missing or invalid: " << ex.what());
+ }
+
+ // Look up the factory.
auto index = factories_.find(queue_type);
- // No match?
+ // Punt if there is no matching factory.
if (index == factories_.end()) {
isc_throw(InvalidQueueType, "The type of the packet queue: '" <<
- queue_type << "' is not supported");
- }
+ queue_type << "' is not supported"); }
// Call the factory to create the new queue.
// Factories should throw InvalidQueueParameter if given
// bad values in the control.
- auto new_queue = index->second(queue_control);
+ auto new_queue = index->second(parameters);
if (!new_queue) {
isc_throw(Unexpected, "Packet queue " << queue_type <<
" factory returned NULL");
PacketQueueMgr4::PacketQueueMgr4() {
// Register default queue factory
- registerPacketQueueFactory("kea-ring4", [](const QueueControl& control)
+ registerPacketQueueFactory("kea-ring4", [](data::ConstElementPtr parameters)
-> PacketQueue4Ptr {
- PacketQueue4Ptr queue(new PacketQueueRing4("kea-ring4", control.getCapacity()));
+ size_t capacity;
+ try {
+ capacity = data::SimpleParser::getInteger(parameters, "capacity");
+ } catch (const std::exception& ex) {
+ isc_throw(InvalidQueueParameter, "kea-ring4 factory:"
+ " 'capacity' parameter is missing/invalid: " << ex.what());
+ }
+
+ PacketQueue4Ptr queue(new PacketQueueRing4("kea-ring4", capacity));
return (queue);
});
- QueueControl control;
- control.setQueueType("kea-ring4");
// @todo default comes from ?
- control.setCapacity(500);
- createPacketQueue(control);
+ data::ElementPtr parameters = data::Element::createMap();
+ parameters->set("queue-type", data::Element::create("kea-ring4"));
+ parameters->set("capacity", data::Element::create(static_cast<long int>(500)));
+ createPacketQueue(parameters);
}
boost::scoped_ptr<PacketQueueMgr4>&
class PacketQueueMgr4 : public PacketQueueMgr<PacketQueue4Ptr>,
public boost::noncopyable {
public:
-
/// @brief virtual Destructor
virtual ~PacketQueueMgr4(){}
PacketQueueMgr6::PacketQueueMgr6() {
// Register default queue factory
- registerPacketQueueFactory("kea-ring6", [](const QueueControl& control)
+ registerPacketQueueFactory("kea-ring6", [](data::ConstElementPtr parameters)
-> PacketQueue6Ptr {
- PacketQueue6Ptr queue(new PacketQueueRing6("kea-ring6", control.getCapacity()));
+ size_t capacity;
+ try {
+ capacity = data::SimpleParser::getInteger(parameters, "capacity");
+ } catch (const std::exception& ex) {
+ isc_throw(InvalidQueueParameter, "kea-ring6 factory:"
+ " 'capacity' parameter is missing/invalid: " << ex.what());
+ }
+
+ PacketQueue6Ptr queue(new PacketQueueRing6("kea-ring6", capacity));
return (queue);
});
- QueueControl control;
- control.setQueueType("kea-ring6");
// @todo default comes from ?
- control.setCapacity(500);
- createPacketQueue(control);
+ data::ElementPtr parameters = data::Element::createMap();
+ parameters->set("queue-type", data::Element::create("kea-ring6"));
+ parameters->set("capacity", data::Element::create(static_cast<long int>(500)));
+ createPacketQueue(parameters);
}
boost::scoped_ptr<PacketQueueMgr6>&
+++ /dev/null
-// Copyright (C) 2018 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 <config.h>
-#include <dhcp/queue_control.h>
-
-using namespace isc::data;
-
-namespace isc {
-namespace dhcp {
-
-QueueControl::QueueControl()
- : queue_type_(""), capacity_(0) {
-}
-
-bool
-QueueControl::equals(const QueueControl& other) const {
- return (queue_type_ == other.queue_type_ &&
- capacity_ == other.capacity_);
-}
-
-ElementPtr
-QueueControl::toElement() const {
- ElementPtr result = Element::createMap();
-
- // Add "capacity"
- result->set("queue-type", Element::create(queue_type_));
-
- // Add "capacity"
- result->set("capacity", Element::create(static_cast<long int>(capacity_)));
-
- // Set user context
- contextToElement(result);
-
-
- return (result);
-}
-
-} // end of isc::dhcp namespace
-} // end of isc namespace
+++ /dev/null
-// Copyright (C) 2018 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/.
-
-#ifndef QUEUE_CONTROL_H
-#define QUEUE_CONTROL_H
-
-#include <cc/cfg_to_element.h>
-#include <cc/user_context.h>
-#include <boost/shared_ptr.hpp>
-
-namespace isc {
-namespace dhcp {
-
-/// @brief Represents DHCP packet queue controls
-///
-/// This class manages the configurable parameters used to tailor the
-/// behavior of DHCP packet queueing.
-class QueueControl : public isc::data::UserContext, public isc::data::CfgToElement {
-public:
-
- /// @brief Constructor.
- QueueControl();
-
- /// @brief Destructor
- ~QueueControl(){};
-
- /// @return true if objects are equal, false otherwise.
- bool equals(const QueueControl& other) const;
-
- /// @brief Fetches the queue type
- ///
- /// @return string containg the queue type
- std::string getQueueType() const {
- return (queue_type_);
- }
-
- /// @brief Sets the queue type
- ///
- /// @param queue_type new value for the queue type
- void setQueueType(const std::string& queue_type) {
- queue_type_ = queue_type;
- }
-
- /// @brief Fetches the maximum number of packets that the queue may hold.
- ///
- /// @return the current capacity of the packet queue.
- size_t getCapacity() const {
- return (capacity_);
- }
-
- /// @brief Set the capacity of the DHCPv4 packet queue buffer.
- ///
- /// Sets the maximum number of packets that the queue may hold.
- ///
- /// @param capacity new value for the queue capacity
- void setCapacity(const size_t capacity) {
- capacity_ = capacity;
- }
-
- /// @brief Equality operator.
- ///
- /// @param other Object to be compared with this object.
- ///
- /// @return true if objects are equal, false otherwise.
- bool operator==(const QueueControl& other) const {
- return (equals(other));
- }
-
- /// @brief Inequality operator.
- ///
- /// @param other Object to be compared with this object.
- ///
- /// @return true if objects are not equal, false otherwise.
- bool operator!=(const QueueControl& other) const {
- return (!equals(other));
- }
-
- /// @brief Unparse a configuration object
- ///
- /// @return a pointer to unparsed configuration
- virtual isc::data::ElementPtr toElement() const;
-
-private:
- /// @brief Name of the queue type
- /// This is the value used to uniquely identify/register
- /// packet queue implementations
- std::string queue_type_;
-
- /// @brief A set of interface names specified by the user.
- size_t capacity_;
-};
-
-/// @brief A pointer to the @c QueueControl .
-typedef boost::shared_ptr<QueueControl> QueueControlPtr;
-
-/// @brief A pointer to the const @c QueueControl.
-typedef boost::shared_ptr<const QueueControl> ConstQueueControlPtr;
-
-}
-}
-
-#endif // QUEUE_CONTROL_H
libdhcp___unittests_SOURCES += pkt_filter6_test_stub.cc pkt_filter_test_stub.h
libdhcp___unittests_SOURCES += pkt_filter_test_utils.h pkt_filter_test_utils.cc
libdhcp___unittests_SOURCES += pkt_filter6_test_utils.h pkt_filter6_test_utils.cc
-libdhcp___unittests_SOURCES += queue_control_unittest.cc
# Utilize Linux Packet Filtering on Linux.
if OS_LINUX
using namespace std;
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::dhcp::test;
namespace {
using namespace std;
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::dhcp::test;
namespace {
using namespace std;
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::dhcp::test;
+
+data::ElementPtr
+isc::dhcp::test::makeQueueConfig(const std::string& queue_type, size_t capacity) {
+ data::ElementPtr config = data::Element::createMap();
+ config->set("queue-type", data::Element::create(queue_type));
+ config->set("capacity", data::Element::create(static_cast<long int>(capacity)));
+ return (config);
+}
namespace {
bool addCustomQueueType(const std::string& queue_type) {
bool did_it =
mgr().registerPacketQueueFactory(queue_type,
- [](const QueueControl& control)
+ [](data::ConstElementPtr parameters)
-> PacketQueue4Ptr {
- return (PacketQueue4Ptr(new PacketQueueRing4(control.getQueueType(),
- control.getCapacity())));
+ std::string queue_type ;
+ try {
+ queue_type = data::SimpleParser::getString(parameters, "queue-type");
+ } catch (std::exception& ex) {
+ isc_throw(InvalidQueueParameter,
+ "queue-type missing or invalid: " << ex.what());
+ }
+
+ size_t capacity;
+ try {
+ capacity = data::SimpleParser::getInteger(parameters, "capacity");
+ } catch (const std::exception& ex) {
+ isc_throw(InvalidQueueParameter,
+ "'capacity' missing or invalid: " << ex.what());
+ }
+
+ return (PacketQueue4Ptr(new PacketQueueRing4(queue_type, capacity)));
});
return did_it;
// Verify that we have a default queue and its info is correct.
checkMyInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
- QueueControl control;
- control.setQueueType("kea-ring4");
- control.setCapacity(2000);
+ data::ConstElementPtr config = makeQueueConfig("kea-ring4", 2000);
// Verify that we can replace the default queue with different capacity queue
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
// We should be able to recreate the manager.
}
TEST_F(PacketQueueMgr4Test, customQueueType) {
- QueueControl control;
- control.setQueueType("custom-queue");
- control.setCapacity(2000);
// Verify that we cannot create a queue for a non-existant type
- ASSERT_THROW(mgr().createPacketQueue(control), InvalidQueueType);
+ data::ConstElementPtr config = makeQueueConfig("custom-queue", 2000);
+ ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
// Register our adjustable-type factory
ASSERT_TRUE(addCustomQueueType("custom-queue"));
checkMyInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
// Verify that we can replace the default queue with a "custom-queue" queue
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
// Now unregister the factory.
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
// Try and recreate the custom queue, type should be invalid.
- ASSERT_THROW(mgr().createPacketQueue(control), InvalidQueueType);
+ ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
- // Verify we can create a default type queue.
- control.setQueueType("kea-ring4");
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
+ // Verify we can create a default type queue with non-default capacity.
+ config = makeQueueConfig("kea-ring4", 2000);
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
}
#include <config.h>
#include <dhcp/packet_queue_mgr6.h>
+#include <packet_queue_testutils.h>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
using namespace std;
using namespace isc;
using namespace isc::dhcp;
+using namespace isc::dhcp::test;
namespace {
bool addCustomQueueType(const std::string& queue_type) {
bool did_it =
mgr().registerPacketQueueFactory(queue_type,
- [](const QueueControl& control)
+ [](data::ConstElementPtr parameters)
-> PacketQueue6Ptr {
- return (PacketQueue6Ptr(new PacketQueueRing6(control.getQueueType(),
- control.getCapacity())));
+ std::string queue_type ;
+ try {
+ queue_type = data::SimpleParser::getString(parameters, "queue-type");
+ } catch (std::exception& ex) {
+ isc_throw(InvalidQueueParameter,
+ "queue-type missing or invalid: " << ex.what());
+ }
+
+ size_t capacity;
+ try {
+ capacity = data::SimpleParser::getInteger(parameters, "capacity");
+ } catch (const std::exception& ex) {
+ isc_throw(InvalidQueueParameter,
+ "'capacity' missing or invalid: " << ex.what());
+ }
+
+ return (PacketQueue6Ptr(new PacketQueueRing6(queue_type, capacity)));
});
return did_it;
return (PacketQueueMgr6::instance());
};
- void checkInfo(const std::string& exp_json) {
- // Fetch the queue info and verify it has all the expected values.
- ASSERT_TRUE(mgr().getPacketQueue()) << " no packet queue!";
- data::ElementPtr info;
- ASSERT_NO_THROW(info = mgr().getPacketQueue()->getInfo());
- ASSERT_TRUE(info);
- data::ElementPtr exp_elems;
- ASSERT_NO_THROW(exp_elems = data::Element::fromJSON(exp_json))
- << " exp_elems is invalid JSON : " << exp_json
- << " test is broken";
- EXPECT_TRUE(exp_elems->equals(*info));
+ void checkMyInfo(const std::string& exp_json) {
+ checkInfo((mgr().getPacketQueue()), exp_json);
}
};
TEST_F(PacketQueueMgr6Test, defaultQueue) {
// Verify that we have a default queue and its info is correct.
- checkInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
+ checkMyInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
- QueueControl control;
- control.setQueueType("kea-ring6");
- control.setCapacity(2000);
+ data::ConstElementPtr config = makeQueueConfig("kea-ring6", 2000);
// Verify that we can replace the default queue with different capacity queue
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
- checkInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
+ checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
// We should be able to recreate the manager.
ASSERT_NO_THROW(PacketQueueMgr6::create());
// And be back to having the default queue.
- checkInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
+ checkMyInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
}
TEST_F(PacketQueueMgr6Test, customQueueType) {
- QueueControl control;
- control.setQueueType("custom-queue");
- control.setCapacity(2000);
// Verify that we cannot create a queue for a non-existant type
- ASSERT_THROW(mgr().createPacketQueue(control), InvalidQueueType);
+ data::ConstElementPtr config = makeQueueConfig("custom-queue", 2000);
+ ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
// Register our adjustable-type factory
ASSERT_TRUE(addCustomQueueType("custom-queue"));
// We still have our default queue.
- checkInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
+ checkMyInfo("{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
// Verify that we can replace the default queue with a "custom-queue" queue
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
- checkInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
+ checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
// Now unregister the factory.
ASSERT_NO_THROW(mgr().unregisterPacketQueueFactory("custom-queue"));
// Verify we did not lose the queue.
- checkInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
+ checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"custom-queue\", \"size\": 0 }");
// Try and recreate the custom queue, type should be invalid.
- ASSERT_THROW(mgr().createPacketQueue(control), InvalidQueueType);
+ ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
- // Verify we can create a default type queue.
- control.setQueueType("kea-ring6");
- ASSERT_NO_THROW(mgr().createPacketQueue(control));
- checkInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
+ // Verify we can create a default type queue with non-default capacity.
+ config = makeQueueConfig("kea-ring6", 2000);
+ ASSERT_NO_THROW(mgr().createPacketQueue(config));
+ checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
}
} // end of anonymous namespace
// 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/.
+#ifndef PACKET_QUEUE_TESTUTILS_H
+#define PACKET_QUEUE_TESTUTILS_H
+
#include <config.h>
#include <dhcp/packet_queue.h>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
-using namespace std;
-using namespace isc;
-using namespace isc::dhcp;
+namespace isc {
+namespace dhcp {
+namespace test {
template<typename PacketQueuePtrType> void checkInfo(PacketQueuePtrType queue, const std::string& exp_json) {
ASSERT_TRUE(queue) << "packet queue ptr is null";
ASSERT_NO_THROW(value = elem->intValue());
EXPECT_EQ(exp_value, value) << "stat: " << name << " is wrong" << std::endl;;
}
+
+extern data::ElementPtr makeQueueConfig(const std::string& queue_type, size_t capacity);
+
+}; // end of namespace isc::dhcp::test
+}; // end of namespace isc::dhcp
+}; // end of namespace isc
+
+#endif // PACKET_QUEUE_TESTUTILS_H
+++ /dev/null
-// Copyright (C) 2018 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 <config.h>
-
-#include <cc/data.h>
-#include <dhcp/queue_control.h>
-
-#include <boost/shared_ptr.hpp>
-#include <gtest/gtest.h>
-
-using namespace std;
-using namespace isc;
-using namespace isc::dhcp;
-
-namespace {
-
-// Verifies QueueControl essentials
-TEST(QueueControl, basics) {
- QueueControlPtr control1;
- QueueControlPtr control2;
-
- ASSERT_NO_THROW(control1.reset(new QueueControl()));
- EXPECT_EQ(0, control1->getCapacity());
-
- control1->setCapacity(100);
- EXPECT_EQ(100, control1->getCapacity());
-
- ASSERT_NO_THROW(control2.reset(new QueueControl()));
- control2->setCapacity(200);
- EXPECT_EQ(200, control2->getCapacity());
-
- EXPECT_FALSE(*control1 == *control2);
- EXPECT_TRUE(*control1 != *control2);
-
- control2->setCapacity(100);
- EXPECT_TRUE(*control1 == *control2);
- EXPECT_FALSE(*control1 != *control2);
-}
-
-// Verifies QueueControl::toElement
-TEST(QueueControl, toElement) {
- QueueControlPtr control;
- ASSERT_NO_THROW(control.reset(new QueueControl()));
- control->setQueueType("qtype");
- control->setCapacity(100);
-
- data::ElementPtr exp_elements;
- std::string json = "{ \"capacity\": 100, \"queue-type\": \"qtype\" }";
-
- ASSERT_NO_THROW(exp_elements = data::Element::fromJSON(json))
- << "invalid JSON, test is broken";
-
- data::ElementPtr elements;
- ASSERT_NO_THROW(elements = control->toElement());
-
- ASSERT_TRUE(elements);
- EXPECT_TRUE(elements->equals(*exp_elements));
-}
-
-}
}
}
-QueueControlPtr
+data::ElementPtr
QueueControlParser::parse(const isc::data::ConstElementPtr& queue_elem) {
QueueControlPtr queue_control(new QueueControl());
+ // All we really do here is verify that it is a map that
+ // contains at least queue-type. All other content depends
+ // on the packet queue implementation of that type.
if (queue_elem->getType() != Element::map) {
isc_throw(DhcpConfigError, "queue-control must be a map");
}
queue_control->setQueueType(elem->stringValue());
}
- try {
- size_t capacity = getInteger(queue_elem, "capacity");
- queue_control->setCapacity(capacity);
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError, ex.what()
- << " (" << getPosition("capacity", queue_elem) << ")");
- }
-
- ConstElementPtr user_context = queue_elem->get("user-context");
- if (user_context) {
- queue_control->setContext(user_context);
- }
-
- return (queue_control);
+ // Return a copy of it.
+ return (data::copy(queue_elem));
}
} // end of namespace isc::dhcp
/// with the parsed values
///
/// @throw DhcpConfigError if any of the values are invalid.
- QueueControlPtr parse(const isc::data::ConstElementPtr& values);
+ data::ElementPtr parse(const isc::data::ConstElementPtr& values);
private:
/// @brief AF_INET for DHCPv4 and AF_INET6 for DHCPv6.
}
// Set queue-control (if it exists)
- ConstQueueControlPtr queue_control = getQueueControlInfo();
+ data::ConstElementPtr queue_control = getQueueControlInfo();
if (queue_control) {
- dhcp->set("queue-control", queue_control->toElement());
+ dhcp->set("queue-control", queue_control);
}
return (result);
#define DHCPSRV_CONFIG_H
#include <cc/cfg_to_element.h>
-#include <dhcp/queue_control.h>
#include <dhcpsrv/cfg_db_access.h>
#include <dhcpsrv/cfg_duid.h>
#include <dhcpsrv/cfg_expiration.h>
/// @brief Returns queue control information
/// @return pointer to a queue control information
- const isc::dhcp::ConstQueueControlPtr getQueueControlInfo() const {
+ const isc::data::ConstElementPtr getQueueControlInfo() const {
return (queue_control_);
}
/// @brief Sets information about the queue control
/// @param new queue control information
- void setQueueControlInfo(const isc::dhcp::ConstQueueControlPtr& queue_control) {
+ void setQueueControlInfo(const isc::data::ConstElementPtr queue_control) {
queue_control_ = queue_control;
}
isc::data::ConstElementPtr control_socket_;
/// @brief Pointer to the queue-control information
- isc::dhcp::ConstQueueControlPtr queue_control_;
+ isc::data::ConstElementPtr queue_control_;
/// @brief Pointer to the dictionary of global client class definitions
ClientClassDictionaryPtr class_dictionary_;