Commit 1f31a082 authored by Thomas Markwalder's avatar Thomas Markwalder

[#260,!120] Replaced hard-coded default queue type names

parent 0b493bb1
......@@ -12,22 +12,21 @@
namespace isc {
namespace dhcp {
PacketQueueMgr4::PacketQueueMgr4() {
// @todo Please forgive magic strings and constants. The default values,
// mechanisms will soon be reworked.
const std::string PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 = "kea-ring4";
PacketQueueMgr4::PacketQueueMgr4() {
// Register default queue factory
registerPacketQueueFactory("kea-ring4", [](data::ConstElementPtr parameters)
registerPacketQueueFactory(DEFAULT_QUEUE_TYPE4, [](data::ConstElementPtr parameters)
-> PacketQueue4Ptr {
size_t capacity;
try {
capacity = data::SimpleParser::getInteger(parameters, "capacity");
} catch (const std::exception& ex) {
isc_throw(InvalidQueueParameter, "kea-ring4 factory:"
isc_throw(InvalidQueueParameter, DEFAULT_QUEUE_TYPE4 << " factory:"
" 'capacity' parameter is missing/invalid: " << ex.what());
}
PacketQueue4Ptr queue(new PacketQueueRing4("kea-ring4", capacity));
PacketQueue4Ptr queue(new PacketQueueRing4(DEFAULT_QUEUE_TYPE4, capacity));
return (queue);
});
}
......
......@@ -27,6 +27,9 @@ namespace dhcp {
class PacketQueueMgr4 : public PacketQueueMgr<PacketQueue4Ptr>,
public boost::noncopyable {
public:
/// @brief Logical name of the pre-registered, default queue implementation
static const std::string DEFAULT_QUEUE_TYPE4;
/// @brief virtual Destructor
virtual ~PacketQueueMgr4(){}
......
......@@ -12,22 +12,21 @@
namespace isc {
namespace dhcp {
PacketQueueMgr6::PacketQueueMgr6() {
// @todo Please forgive magic strings and constants. The default values,
// mechanisms will soon be reworked.
const std::string PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 = "kea-ring6";
PacketQueueMgr6::PacketQueueMgr6() {
// Register default queue factory
registerPacketQueueFactory("kea-ring6", [](data::ConstElementPtr parameters)
registerPacketQueueFactory(DEFAULT_QUEUE_TYPE6, [](data::ConstElementPtr parameters)
-> PacketQueue6Ptr {
size_t capacity;
try {
capacity = data::SimpleParser::getInteger(parameters, "capacity");
} catch (const std::exception& ex) {
isc_throw(InvalidQueueParameter, "kea-ring6 factory:"
isc_throw(InvalidQueueParameter, DEFAULT_QUEUE_TYPE6 << " factory:"
" 'capacity' parameter is missing/invalid: " << ex.what());
}
PacketQueue6Ptr queue(new PacketQueueRing6("kea-ring6", capacity));
PacketQueue6Ptr queue(new PacketQueueRing6(DEFAULT_QUEUE_TYPE6, capacity));
return (queue);
});
}
......
......@@ -27,6 +27,8 @@ namespace dhcp {
class PacketQueueMgr6 : public PacketQueueMgr<PacketQueue6Ptr>,
public boost::noncopyable {
public:
/// @brief Logical name of the pre-registered, default queue implementation
static const std::string DEFAULT_QUEUE_TYPE6;
/// @brief virtual Destructor
virtual ~PacketQueueMgr6(){}
......
......@@ -865,10 +865,10 @@ TEST_F(IfaceMgrTest, packetQueue4) {
ASSERT_FALSE(ifacemgr.getPacketQueue4());
// Verify that we can create a queue with default factory.
data::ConstElementPtr config = makeQueueConfig("kea-ring4", 2000);
data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 2000);
ASSERT_NO_THROW(PacketQueueMgr4::instance().createPacketQueue(config));
checkInfo(ifacemgr.getPacketQueue4(),
"{ \"capacity\": 2000, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
CHECK_QUEUE_INFO(ifacemgr.getPacketQueue4(), "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }");
// Verify that fetching the queue via IfaceMgr and PacketQueueMgr
// returns the same queue.
......@@ -883,10 +883,10 @@ TEST_F(IfaceMgrTest, packetQueue6) {
ASSERT_FALSE(ifacemgr.getPacketQueue6());
// Verify that we can create a queue with default factory.
data::ConstElementPtr config = makeQueueConfig("kea-ring6", 2000);
data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 2000);
ASSERT_NO_THROW(PacketQueueMgr6::instance().createPacketQueue(config));
checkInfo(ifacemgr.getPacketQueue6(),
"{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
CHECK_QUEUE_INFO(ifacemgr.getPacketQueue6(), "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }");
// Verify that fetching the queue via IfaceMgr and PacketQueueMgr
// returns the same queue.
......@@ -1286,12 +1286,12 @@ TEST_F(IfaceMgrTest, sendReceive6) {
sendReceive6Test(queue_control, false);
// Now let's populate queue control.
queue_control = makeQueueConfig("kea-ring6", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
// With queueing disabled, we should use direct reception.
sendReceive6Test(queue_control, false);
// Queuing enabled, indirection reception should work.
queue_control = makeQueueConfig("kea-ring6", 500, true);
queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, true);
sendReceive6Test(queue_control, true);
}
......@@ -1305,12 +1305,12 @@ TEST_F(IfaceMgrTest, sendReceive4) {
sendReceive4Test(queue_control, false);
// Now let's populate queue control.
queue_control = makeQueueConfig("kea-ring4", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
// With queueing disabled, we should use direct reception.
sendReceive4Test(queue_control, false);
// Queuing enabled, indirection reception should work.
queue_control = makeQueueConfig("kea-ring4", 500, true);
queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, true);
sendReceive4Test(queue_control, true);
}
......@@ -3071,7 +3071,7 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest4) {
ASSERT_FALSE(ifacemgr->isReceiverRunning());
// Now let's try with a populated queue control, but with enable-queue = false.
queue_control = makeQueueConfig("kea-ring4", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control));
EXPECT_FALSE(queue_enabled);
EXPECT_FALSE(ifacemgr->getPacketQueue4());
......@@ -3079,12 +3079,12 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest4) {
ASSERT_FALSE(ifacemgr->isReceiverRunning());
// Now let's enable the queue.
queue_control = makeQueueConfig("kea-ring4", 500, true);
queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, true);
ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control));
ASSERT_TRUE(queue_enabled);
// Verify we have correctly created the queue.
checkInfo(ifacemgr->getPacketQueue4(),
"{ \"capacity\": 500, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
CHECK_QUEUE_INFO(ifacemgr->getPacketQueue4(), "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }");
// configureDHCPPacketQueue() should never start the thread.
ASSERT_FALSE(ifacemgr->isReceiverRunning());
......@@ -3096,7 +3096,7 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest4) {
ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET), InvalidOperation);
// Create a disabled config.
queue_control = makeQueueConfig("kea-ring4", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
// Trying to reconfigure with a running thread should throw.
ASSERT_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control),
......@@ -3140,7 +3140,7 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest6) {
ASSERT_FALSE(ifacemgr->isReceiverRunning());
// Now let's try with a populated queue control, but with enable-queue = false.
queue_control = makeQueueConfig("kea-ring6", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control));
EXPECT_FALSE(queue_enabled);
EXPECT_FALSE(ifacemgr->getPacketQueue6());
......@@ -3148,12 +3148,12 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest6) {
ASSERT_FALSE(ifacemgr->isReceiverRunning());
// Now let's enable the queue.
queue_control = makeQueueConfig("kea-ring6", 500, true);
queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, true);
ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control));
ASSERT_TRUE(queue_enabled);
// Verify we have correctly created the queue.
checkInfo(ifacemgr->getPacketQueue6(),
"{ \"capacity\": 500, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
CHECK_QUEUE_INFO(ifacemgr->getPacketQueue6(), "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }");
// configureDHCPPacketQueue() should never start the thread.
ASSERT_FALSE(ifacemgr->isReceiverRunning());
......@@ -3165,7 +3165,7 @@ TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest6) {
ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET6), InvalidOperation);
// Create a disabled config.
queue_control = makeQueueConfig("kea-ring6", 500, false);
queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
// Trying to reconfigure with a running thread should throw.
ASSERT_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control),
......
......@@ -39,7 +39,8 @@ public:
/// @brief Constructor
///
/// Note that it instantiates the PQM singleton.
PacketQueueMgr4Test(){
PacketQueueMgr4Test()
: default_queue_type_(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4) {
PacketQueueMgr4::create();
}
......@@ -95,17 +96,19 @@ public:
checkInfo((mgr().getPacketQueue()), exp_json);
}
std::string default_queue_type_;
};
// Verifies that DHCPv4 PQM provides a default queue factory
TEST_F(PacketQueueMgr4Test, defaultQueue) {
// Should not be a queue at start-up
// Should not be a queue at start-up
ASSERT_FALSE(mgr().getPacketQueue());
// Verify that we can create a queue with default factory.
data::ConstElementPtr config = makeQueueConfig("kea-ring4", 2000);
data::ConstElementPtr config = makeQueueConfig(default_queue_type_, 2000);
ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
CHECK_QUEUE_INFO (mgr().getPacketQueue(), "{ \"capacity\": 2000, \"queue-type\": \""
<< default_queue_type_ << "\", \"size\": 0 }");
// We should be able to recreate the manager.
ASSERT_NO_THROW(PacketQueueMgr4::create());
......@@ -138,9 +141,10 @@ TEST_F(PacketQueueMgr4Test, customQueueType) {
ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
// Verify we can create a default type queue with non-default capacity.
config = makeQueueConfig("kea-ring4", 2000);
config = makeQueueConfig(default_queue_type_, 2000);
ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring4\", \"size\": 0 }");
CHECK_QUEUE_INFO (mgr().getPacketQueue(), "{ \"capacity\": 2000, \"queue-type\": \""
<< default_queue_type_ << "\", \"size\": 0 }");
}
} // end of anonymous namespace
......@@ -25,7 +25,8 @@ public:
/// @brief Constructor
///
/// Note that it instantiates the PQM singleton.
PacketQueueMgr6Test(){
PacketQueueMgr6Test()
: default_queue_type_(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6) {
PacketQueueMgr6::create();
}
......@@ -81,17 +82,19 @@ public:
checkInfo((mgr().getPacketQueue()), exp_json);
}
std::string default_queue_type_;
};
// Verifies that DHCPv6 PQM provides a default queue factory
TEST_F(PacketQueueMgr6Test, defaultQueue) {
// Should not be a queue at start-up
// Should not be a queue at start-up
ASSERT_FALSE(mgr().getPacketQueue());
// Verify that we can create a queue with default factory.
data::ConstElementPtr config = makeQueueConfig("kea-ring6", 2000);
data::ConstElementPtr config = makeQueueConfig(default_queue_type_, 2000);
ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
CHECK_QUEUE_INFO (mgr().getPacketQueue(), "{ \"capacity\": 2000, \"queue-type\": \""
<< default_queue_type_ << "\", \"size\": 0 }");
// We should be able to recreate the manager.
ASSERT_NO_THROW(PacketQueueMgr6::create());
......@@ -124,9 +127,10 @@ TEST_F(PacketQueueMgr6Test, customQueueType) {
ASSERT_THROW(mgr().createPacketQueue(config), InvalidQueueType);
// Verify we can create a default type queue with non-default capacity.
config = makeQueueConfig("kea-ring6", 2000);
config = makeQueueConfig(default_queue_type_, 2000);
ASSERT_NO_THROW(mgr().createPacketQueue(config));
checkMyInfo("{ \"capacity\": 2000, \"queue-type\": \"kea-ring6\", \"size\": 0 }");
CHECK_QUEUE_INFO (mgr().getPacketQueue(), "{ \"capacity\": 2000, \"queue-type\": \""
<< default_queue_type_ << "\", \"size\": 0 }");
}
} // end of anonymous namespace
......@@ -30,6 +30,14 @@ template<typename PacketQueuePtrType> void checkInfo(PacketQueuePtrType queue, c
EXPECT_TRUE(exp_elems->equals(*info));
}
#define CHECK_QUEUE_INFO(queue, stream) \
{ \
std::ostringstream oss__; \
oss__ << stream; \
checkInfo(queue, oss__.str().c_str());\
}
template<typename PacketQueuePtrType> void checkIntStat(PacketQueuePtrType queue,
const std::string& name, size_t exp_value) {
ASSERT_TRUE(queue) << "packet queue ptr is null";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment