Commit 90fd7ebf authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[#42] Implemented PacketQueueMgr class

New files:
    src/lib/dhcp/packet_queue_mgr.h
    src/lib/dhcp/packet_queue_mgr4.cc
    src/lib/dhcp/packet_queue_mgr4.h
    src/lib/dhcp/packet_queue_mgr6.cc
    src/lib/dhcp/packet_queue_mgr6.h
    src/lib/dhcp/tests/packet_queue_mgr4_unittest.cc
    src/lib/dhcp/tests/packet_queue_mgr6_unittest.cc
    src/lib/dhcp/tests/packet_queue_testutils.h

src/bin/dhcp4/ctrl_dhcp4_srv.cc
    Cleaned up packet queue config block

src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp4/tests/config_parser_unittest.cc
    added queue-type

src/bin/dhcp4/dhcp4_messages.mes
    added DHCP4_CONFIG_PACKET_QUEUE message

src/lib/dhcp/Makefile.am
    packet_queue_mgr.h
    packet_queue_mgr4.cc packet_queue_mgr4.h
    packet_queue_mgr6.cc packet_queue_mgr6.h

src/lib/dhcp/iface_mgr.*
    Replaced packet queue members with PQM members
    Added PQM instantion to IfaceMgr ctor

src/lib/dhcp/packet_queue.h
    added getInfo,getInfoStr

src/lib/dhcp/tests/Makefile.am
    packet_queue_mgr4_unittest.cc
    packet_queue_mgr6_unittest.cc

src/lib/dhcpsrv/parsers/queue_control_parser.cc
    added queue-type
parent 036d249f
...@@ -634,20 +634,24 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { ...@@ -634,20 +634,24 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
return (isc::config::createAnswer(1, err.str())); return (isc::config::createAnswer(1, err.str()));
} }
// Configure packet queue
try { try {
// @todo Consider making this a function and consider whether
// it should check for old gc != null and new gc null before
// calling setPacketQueueControl(). Or if we should even
// call it when it's null?
// Still grappling with what to if there is a custom queue
// loaded. Could have a flag in the control that means
// using custom impl, in which case we don't make the call
// at all. ... I dunno
ConstQueueControlPtr qc; ConstQueueControlPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getQueueControlInfo(); qc = CfgMgr::instance().getStagingCfg()->getQueueControlInfo();
IfaceMgr::instance().setPacketQueueControl4(qc); if (!qc) {
qc = IfaceMgr::instance().getPacketQueueControl4(); // For right now, we are maually constructing the default
std::cout << "TKM using capacity: " << qc->getCapacity() << std::endl; // This probably needs to be built into the PQM?
QueueControl default_qc;
default_qc.setQueueType("kea-ring4");
default_qc.setCapacity(500);
PacketQueueMgr4::instance().createPacketQueue(default_qc);
} else {
PacketQueueMgr4::instance().createPacketQueue(*qc);
}
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CONFIG_PACKET_QUEUE)
.arg(PacketQueueMgr4::instance().getPacketQueue()->getInfoStr());
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
err << "Error setting packet queue controls after server reconfiguration: " err << "Error setting packet queue controls after server reconfiguration: "
<< ex.what(); << ex.what();
......
This diff is collapsed.
...@@ -1250,6 +1250,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} ...@@ -1250,6 +1250,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
} }
} }
\"queue-type\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::QUEUE_CONTROL:
return isc::dhcp::Dhcp4Parser::make_QUEUE_TYPE(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("queue-type", driver.loc_);
}
}
\"capacity\" { \"capacity\" {
switch(driver.ctx_) { switch(driver.ctx_) {
case isc::dhcp::Parser4Context::QUEUE_CONTROL: case isc::dhcp::Parser4Context::QUEUE_CONTROL:
......
...@@ -120,6 +120,11 @@ new configuration. It is output during server startup, and when an updated ...@@ -120,6 +120,11 @@ new configuration. It is output during server startup, and when an updated
configuration is committed by the administrator. Additional information configuration is committed by the administrator. Additional information
may be provided. may be provided.
% DHCP4_CONFIG_PACKET_QUEUE DHCPv4 packet queue info after configuration: %1
This debug message is emitted during DHCPv4 server configuration, immediately
after configuring the DHCPv4 packet queue. The information shown depends
upon the packet queue type selected.
% DHCP4_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2 % DHCP4_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
This error message indicates that the DHCPv4 configuration has failed. This error message indicates that the DHCPv4 configuration has failed.
If this is an initial configuration (during server's startup) the server If this is an initial configuration (during server's startup) the server
......
This diff is collapsed.
...@@ -461,60 +461,61 @@ namespace isc { namespace dhcp { ...@@ -461,60 +461,61 @@ namespace isc { namespace dhcp {
TOKEN_SOCKET_TYPE = 368, TOKEN_SOCKET_TYPE = 368,
TOKEN_SOCKET_NAME = 369, TOKEN_SOCKET_NAME = 369,
TOKEN_QUEUE_CONTROL = 370, TOKEN_QUEUE_CONTROL = 370,
TOKEN_CAPACITY = 371, TOKEN_QUEUE_TYPE = 371,
TOKEN_DHCP_DDNS = 372, TOKEN_CAPACITY = 372,
TOKEN_ENABLE_UPDATES = 373, TOKEN_DHCP_DDNS = 373,
TOKEN_QUALIFYING_SUFFIX = 374, TOKEN_ENABLE_UPDATES = 374,
TOKEN_SERVER_IP = 375, TOKEN_QUALIFYING_SUFFIX = 375,
TOKEN_SERVER_PORT = 376, TOKEN_SERVER_IP = 376,
TOKEN_SENDER_IP = 377, TOKEN_SERVER_PORT = 377,
TOKEN_SENDER_PORT = 378, TOKEN_SENDER_IP = 378,
TOKEN_MAX_QUEUE_SIZE = 379, TOKEN_SENDER_PORT = 379,
TOKEN_NCR_PROTOCOL = 380, TOKEN_MAX_QUEUE_SIZE = 380,
TOKEN_NCR_FORMAT = 381, TOKEN_NCR_PROTOCOL = 381,
TOKEN_ALWAYS_INCLUDE_FQDN = 382, TOKEN_NCR_FORMAT = 382,
TOKEN_OVERRIDE_NO_UPDATE = 383, TOKEN_ALWAYS_INCLUDE_FQDN = 383,
TOKEN_OVERRIDE_CLIENT_UPDATE = 384, TOKEN_OVERRIDE_NO_UPDATE = 384,
TOKEN_REPLACE_CLIENT_NAME = 385, TOKEN_OVERRIDE_CLIENT_UPDATE = 385,
TOKEN_GENERATED_PREFIX = 386, TOKEN_REPLACE_CLIENT_NAME = 386,
TOKEN_TCP = 387, TOKEN_GENERATED_PREFIX = 387,
TOKEN_JSON = 388, TOKEN_TCP = 388,
TOKEN_WHEN_PRESENT = 389, TOKEN_JSON = 389,
TOKEN_NEVER = 390, TOKEN_WHEN_PRESENT = 390,
TOKEN_ALWAYS = 391, TOKEN_NEVER = 391,
TOKEN_WHEN_NOT_PRESENT = 392, TOKEN_ALWAYS = 392,
TOKEN_HOSTNAME_CHAR_SET = 393, TOKEN_WHEN_NOT_PRESENT = 393,
TOKEN_HOSTNAME_CHAR_REPLACEMENT = 394, TOKEN_HOSTNAME_CHAR_SET = 394,
TOKEN_LOGGING = 395, TOKEN_HOSTNAME_CHAR_REPLACEMENT = 395,
TOKEN_LOGGERS = 396, TOKEN_LOGGING = 396,
TOKEN_OUTPUT_OPTIONS = 397, TOKEN_LOGGERS = 397,
TOKEN_OUTPUT = 398, TOKEN_OUTPUT_OPTIONS = 398,
TOKEN_DEBUGLEVEL = 399, TOKEN_OUTPUT = 399,
TOKEN_SEVERITY = 400, TOKEN_DEBUGLEVEL = 400,
TOKEN_FLUSH = 401, TOKEN_SEVERITY = 401,
TOKEN_MAXSIZE = 402, TOKEN_FLUSH = 402,
TOKEN_MAXVER = 403, TOKEN_MAXSIZE = 403,
TOKEN_DHCP6 = 404, TOKEN_MAXVER = 404,
TOKEN_DHCPDDNS = 405, TOKEN_DHCP6 = 405,
TOKEN_CONTROL_AGENT = 406, TOKEN_DHCPDDNS = 406,
TOKEN_TOPLEVEL_JSON = 407, TOKEN_CONTROL_AGENT = 407,
TOKEN_TOPLEVEL_DHCP4 = 408, TOKEN_TOPLEVEL_JSON = 408,
TOKEN_SUB_DHCP4 = 409, TOKEN_TOPLEVEL_DHCP4 = 409,
TOKEN_SUB_INTERFACES4 = 410, TOKEN_SUB_DHCP4 = 410,
TOKEN_SUB_SUBNET4 = 411, TOKEN_SUB_INTERFACES4 = 411,
TOKEN_SUB_POOL4 = 412, TOKEN_SUB_SUBNET4 = 412,
TOKEN_SUB_RESERVATION = 413, TOKEN_SUB_POOL4 = 413,
TOKEN_SUB_OPTION_DEFS = 414, TOKEN_SUB_RESERVATION = 414,
TOKEN_SUB_OPTION_DEF = 415, TOKEN_SUB_OPTION_DEFS = 415,
TOKEN_SUB_OPTION_DATA = 416, TOKEN_SUB_OPTION_DEF = 416,
TOKEN_SUB_HOOKS_LIBRARY = 417, TOKEN_SUB_OPTION_DATA = 417,
TOKEN_SUB_DHCP_DDNS = 418, TOKEN_SUB_HOOKS_LIBRARY = 418,
TOKEN_SUB_LOGGING = 419, TOKEN_SUB_DHCP_DDNS = 419,
TOKEN_SUB_CONFIG_CONTROL = 420, TOKEN_SUB_LOGGING = 420,
TOKEN_STRING = 421, TOKEN_SUB_CONFIG_CONTROL = 421,
TOKEN_INTEGER = 422, TOKEN_STRING = 422,
TOKEN_FLOAT = 423, TOKEN_INTEGER = 423,
TOKEN_BOOLEAN = 424 TOKEN_FLOAT = 424,
TOKEN_BOOLEAN = 425
}; };
}; };
...@@ -1085,6 +1086,10 @@ namespace isc { namespace dhcp { ...@@ -1085,6 +1086,10 @@ namespace isc { namespace dhcp {
symbol_type symbol_type
make_QUEUE_CONTROL (const location_type& l); make_QUEUE_CONTROL (const location_type& l);
static inline
symbol_type
make_QUEUE_TYPE (const location_type& l);
static inline static inline
symbol_type symbol_type
make_CAPACITY (const location_type& l); make_CAPACITY (const location_type& l);
...@@ -1506,12 +1511,12 @@ namespace isc { namespace dhcp { ...@@ -1506,12 +1511,12 @@ namespace isc { namespace dhcp {
enum enum
{ {
yyeof_ = 0, yyeof_ = 0,
yylast_ = 1005, ///< Last index in yytable_. yylast_ = 1029, ///< Last index in yytable_.
yynnts_ = 377, ///< Number of nonterminal symbols. yynnts_ = 379, ///< Number of nonterminal symbols.
yyfinal_ = 30, ///< Termination state number. yyfinal_ = 30, ///< Termination state number.
yyterror_ = 1, yyterror_ = 1,
yyerrcode_ = 256, yyerrcode_ = 256,
yyntokens_ = 170 ///< Number of tokens. yyntokens_ = 171 ///< Number of tokens.
}; };
...@@ -1570,9 +1575,9 @@ namespace isc { namespace dhcp { ...@@ -1570,9 +1575,9 @@ namespace isc { namespace dhcp {
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 166, 167, 168, 169 165, 166, 167, 168, 169, 170
}; };
const unsigned int user_token_number_max_ = 424; const unsigned int user_token_number_max_ = 425;
const token_number_type undef_token_ = 2; const token_number_type undef_token_ = 2;
if (static_cast<int>(t) <= yyeof_) if (static_cast<int>(t) <= yyeof_)
...@@ -1605,30 +1610,30 @@ namespace isc { namespace dhcp { ...@@ -1605,30 +1610,30 @@ namespace isc { namespace dhcp {
{ {
switch (other.type_get ()) switch (other.type_get ())
{ {
case 186: // value case 187: // value
case 190: // map_value case 191: // map_value
case 230: // socket_type case 231: // socket_type
case 233: // outbound_interface_value case 234: // outbound_interface_value
case 255: // db_type case 256: // db_type
case 337: // hr_mode case 338: // hr_mode
case 489: // ncr_protocol_value case 492: // ncr_protocol_value
case 497: // replace_client_name_value case 500: // replace_client_name_value
value.copy< ElementPtr > (other.value); value.copy< ElementPtr > (other.value);
break; break;
case 169: // "boolean" case 170: // "boolean"
value.copy< bool > (other.value); value.copy< bool > (other.value);
break; break;
case 168: // "floating point" case 169: // "floating point"
value.copy< double > (other.value); value.copy< double > (other.value);
break; break;
case 167: // "integer" case 168: // "integer"
value.copy< int64_t > (other.value); value.copy< int64_t > (other.value);
break; break;
case 166: // "constant string" case 167: // "constant string"
value.copy< std::string > (other.value); value.copy< std::string > (other.value);
break; break;
...@@ -1649,30 +1654,30 @@ namespace isc { namespace dhcp { ...@@ -1649,30 +1654,30 @@ namespace isc { namespace dhcp {
(void) v; (void) v;
switch (this->type_get ()) switch (this->type_get ())
{ {
case 186: // value case 187: // value
case 190: // map_value case 191: // map_value
case 230: // socket_type case 231: // socket_type
case 233: // outbound_interface_value case 234: // outbound_interface_value
case 255: // db_type case 256: // db_type
case 337: // hr_mode case 338: // hr_mode
case 489: // ncr_protocol_value case 492: // ncr_protocol_value
case 497: // replace_client_name_value case 500: // replace_client_name_value
value.copy< ElementPtr > (v); value.copy< ElementPtr > (v);
break; break;
case 169: // "boolean" case 170: // "boolean"
value.copy< bool > (v); value.copy< bool > (v);
break; break;
case 168: // "floating point" case 169: // "floating point"
value.copy< double > (v); value.copy< double > (v);
break; break;
case 167: // "integer" case 168: // "integer"
value.copy< int64_t > (v); value.copy< int64_t > (v);
break; break;
case 166: // "constant string" case 167: // "constant string"
value.copy< std::string > (v); value.copy< std::string > (v);
break; break;
...@@ -1752,30 +1757,30 @@ namespace isc { namespace dhcp { ...@@ -1752,30 +1757,30 @@ namespace isc { namespace dhcp {
// Type destructor. // Type destructor.
switch (yytype) switch (yytype)
{ {
case 186: // value case 187: // value
case 190: // map_value case 191: // map_value
case 230: // socket_type case 231: // socket_type
case 233: // outbound_interface_value case 234: // outbound_interface_value
case 255: // db_type case 256: // db_type
case 337: // hr_mode case 338: // hr_mode
case 489: // ncr_protocol_value case 492: // ncr_protocol_value
case 497: // replace_client_name_value case 500: // replace_client_name_value
value.template destroy< ElementPtr > (); value.template destroy< ElementPtr > ();
break; break;
case 169: // "boolean" case 170: // "boolean"
value.template destroy< bool > (); value.template destroy< bool > ();
break; break;
case 168: // "floating point" case 169: // "floating point"
value.template destroy< double > (); value.template destroy< double > ();
break; break;
case 167: // "integer" case 168: // "integer"
value.template destroy< int64_t > (); value.template destroy< int64_t > ();
break; break;
case 166: // "constant string" case 167: // "constant string"
value.template destroy< std::string > (); value.template destroy< std::string > ();
break; break;
...@@ -1802,30 +1807,30 @@ namespace isc { namespace dhcp { ...@@ -1802,30 +1807,30 @@ namespace isc { namespace dhcp {
super_type::move(s); super_type::move(s);
switch (this->type_get ()) switch (this->type_get ())
{ {
case 186: // value case 187: // value
case 190: // map_value case 191: // map_value
case 230: // socket_type case 231: // socket_type
case 233: // outbound_interface_value case 234: // outbound_interface_value
case 255: // db_type case 256: // db_type
case 337: // hr_mode case 338: // hr_mode
case 489: // ncr_protocol_value case 492: // ncr_protocol_value
case 497: // replace_client_name_value case 500: // replace_client_name_value
value.move< ElementPtr > (s.value); value.move< ElementPtr > (s.value);
break; break;
case 169: // "boolean" case 170: // "boolean"
value.move< bool > (s.value); value.move< bool > (s.value);
break; break;
case 168: // "floating point" case 169: // "floating point"
value.move< double > (s.value); value.move< double > (s.value);
break; break;
case 167: // "integer" case 168: // "integer"
value.move< int64_t > (s.value); value.move< int64_t > (s.value);
break; break;
case 166: // "constant string" case 167: // "constant string"
value.move< std::string > (s.value); value.move< std::string > (s.value);
break; break;
...@@ -1900,7 +1905,8 @@ namespace isc { namespace dhcp { ...@@ -1900,7 +1905,8 @@ namespace isc { namespace dhcp {
385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
415, 416, 417, 418, 419, 420, 421, 422, 423, 424 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
425
}; };
return static_cast<token_type> (yytoken_number_[type]); return static_cast<token_type> (yytoken_number_[type]);
} }
...@@ -2589,6 +2595,12 @@ namespace isc { namespace dhcp { ...@@ -2589,6 +2595,12 @@ namespace isc { namespace dhcp {
return symbol_type (token::TOKEN_QUEUE_CONTROL, l); return symbol_type (token::TOKEN_QUEUE_CONTROL, l);
} }
Dhcp4Parser::symbol_type
Dhcp4Parser::make_QUEUE_TYPE (const location_type& l)
{
return symbol_type (token::TOKEN_QUEUE_TYPE, l);
}
Dhcp4Parser::symbol_type Dhcp4Parser::symbol_type
Dhcp4Parser::make_CAPACITY (const location_type& l) Dhcp4Parser::make_CAPACITY (const location_type& l)
{ {
...@@ -2916,7 +2928,7 @@ namespace isc { namespace dhcp { ...@@ -2916,7 +2928,7 @@ namespace isc { namespace dhcp {
#line 14 "dhcp4_parser.yy" // lalr1.cc:377 #line 14 "dhcp4_parser.yy" // lalr1.cc:377
} } // isc::dhcp } } // isc::dhcp
#line 2920 "dhcp4_parser.h" // lalr1.cc:377 #line 2932 "dhcp4_parser.h" // lalr1.cc:377
......
...@@ -171,6 +171,7 @@ using namespace std; ...@@ -171,6 +171,7 @@ using namespace std;
SOCKET_NAME "socket-name" SOCKET_NAME "socket-name"
QUEUE_CONTROL "queue-control" QUEUE_CONTROL "queue-control"
QUEUE_TYPE "queue-type"
CAPACITY "capacity" CAPACITY "capacity"
DHCP_DDNS "dhcp-ddns" DHCP_DDNS "dhcp-ddns"
...@@ -1836,6 +1837,7 @@ queue_control: QUEUE_CONTROL { ...@@ -1836,6 +1837,7 @@ queue_control: QUEUE_CONTROL {
ctx.stack_.push_back(m); ctx.stack_.push_back(m);
ctx.enter(ctx.QUEUE_CONTROL); ctx.enter(ctx.QUEUE_CONTROL);
} COLON LCURLY_BRACKET queue_control_params RCURLY_BRACKET { } COLON LCURLY_BRACKET queue_control_params RCURLY_BRACKET {
ctx.require("queue-type", ctx.loc2pos(@4), ctx.loc2pos(@6));
ctx.require("capacity", ctx.loc2pos(@4), ctx.loc2pos(@6)); ctx.require("capacity", ctx.loc2pos(@4), ctx.loc2pos(@6));
ctx.stack_.pop_back(); ctx.stack_.pop_back();
ctx.leave(); ctx.leave();
...@@ -1845,12 +1847,21 @@ queue_control_params: queue_control_param ...@@ -1845,12 +1847,21 @@ queue_control_params: queue_control_param
| queue_control_params COMMA queue_control_param | queue_control_params COMMA queue_control_param
; ;
queue_control_param: capacity queue_control_param: queue_type
| capacity
| user_context | user_context
| comment | comment
| unknown_map_entry | unknown_map_entry
; ;
queue_type : QUEUE_TYPE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr qtype(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("queue-type", qtype);
ctx.leave();
};
capacity: CAPACITY COLON INTEGER { capacity: CAPACITY COLON INTEGER {
ElementPtr i(new IntElement($3, ctx.loc2pos(@3))); ElementPtr i(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("capacity", i); ctx.stack_.back()->set("capacity", i);
......
...@@ -6348,6 +6348,7 @@ TEST_F(Dhcp4ParserTest, queueControl) { ...@@ -6348,6 +6348,7 @@ TEST_F(Dhcp4ParserTest, queueControl) {
"{ " + genIfaceConfig() + ", \n" + "{ " + genIfaceConfig() + ", \n" +
" \"subnet4\": [ ], \n" " \"subnet4\": [ ], \n"
" \"queue-control\": { \n" " \"queue-control\": { \n"
" \"queue-type\": \"some-type\", \n"
" \"capacity\": 75 \n" " \"capacity\": 75 \n"
" } \n" " } \n"
"} \n"; "} \n";
...@@ -6356,6 +6357,7 @@ TEST_F(Dhcp4ParserTest, queueControl) { ...@@ -6356,6 +6357,7 @@ TEST_F(Dhcp4ParserTest, queueControl) {
"{ " + genIfaceConfig() + ", \n" + "{ " + genIfaceConfig() + ", \n" +
" \"subnet4\": [ ], \n" " \"subnet4\": [ ], \n"
" \"queue-control\": { \n" " \"queue-control\": { \n"
" \"queue-type\": \"some-type\", \n"
" \"capacity\": 90, \n" " \"capacity\": 90, \n"
" \"user-context\": { \"comment\": \"some text\" } \n" " \"user-context\": { \"comment\": \"some text\" } \n"
" } \n" " } \n"
...@@ -6406,6 +6408,15 @@ TEST_F(Dhcp4ParserTest, queueControlInvalid) { ...@@ -6406,6 +6408,15 @@ TEST_F(Dhcp4ParserTest, queueControlInvalid) {
" \"queue-control\": 75 \n"