Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian Schrader
Kea
Commits
e38e8d97
Commit
e38e8d97
authored
Mar 17, 2017
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[102b] rebased
parent
3188ae9a
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
431 additions
and
386 deletions
+431
-386
doc/guide/ctrl-channel.xml
doc/guide/ctrl-channel.xml
+31
-1
doc/guide/dhcp4-srv.xml
doc/guide/dhcp4-srv.xml
+4
-2
doc/guide/dhcp6-srv.xml
doc/guide/dhcp6-srv.xml
+4
-2
src/bin/agent/ca_controller.cc
src/bin/agent/ca_controller.cc
+20
-0
src/bin/agent/ca_controller.h
src/bin/agent/ca_controller.h
+17
-2
src/bin/agent/ca_process.cc
src/bin/agent/ca_process.cc
+19
-8
src/bin/agent/ca_process.h
src/bin/agent/ca_process.h
+0
-20
src/bin/d2/d2_process.cc
src/bin/d2/d2_process.cc
+0
-13
src/bin/d2/d2_process.h
src/bin/d2/d2_process.h
+0
-14
src/bin/d2/tests/d2_controller_unittests.cc
src/bin/d2/tests/d2_controller_unittests.cc
+0
-29
src/bin/d2/tests/d2_process_unittests.cc
src/bin/d2/tests/d2_process_unittests.cc
+0
-14
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
+34
-0
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/ctrl_dhcp4_srv.h
+25
-0
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
+29
-0
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
+34
-1
src/bin/dhcp6/ctrl_dhcp6_srv.h
src/bin/dhcp6/ctrl_dhcp6_srv.h
+25
-0
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
+26
-0
src/bin/shell/tests/shell_process_tests.sh.in
src/bin/shell/tests/shell_process_tests.sh.in
+1
-1
src/lib/cc/command_interpreter.cc
src/lib/cc/command_interpreter.cc
+53
-1
src/lib/cc/command_interpreter.h
src/lib/cc/command_interpreter.h
+17
-0
src/lib/config/base_command_mgr.cc
src/lib/config/base_command_mgr.cc
+0
-52
src/lib/config/base_command_mgr.h
src/lib/config/base_command_mgr.h
+0
-21
src/lib/log/logger_impl.cc
src/lib/log/logger_impl.cc
+1
-1
src/lib/process/d_controller.cc
src/lib/process/d_controller.cc
+47
-59
src/lib/process/d_controller.h
src/lib/process/d_controller.h
+37
-53
src/lib/process/d_process.h
src/lib/process/d_process.h
+6
-20
src/lib/process/tests/d_controller_unittests.cc
src/lib/process/tests/d_controller_unittests.cc
+0
-64
src/lib/process/testutils/d_test_stubs.h
src/lib/process/testutils/d_test_stubs.h
+1
-8
No files found.
doc/guide/ctrl-channel.xml
View file @
e38e8d97
...
...
@@ -113,6 +113,22 @@ will be sent to Kea and the responses received from Kea printed to standard outp
<section
id=
"commands-common"
>
<title>
Commands Supported by Both the DHCPv4 and DHCPv6 Servers
</title>
<section
id=
"command-build-report"
>
<title>
build-report
</title>
<para>
The
<emphasis>
build-report
</emphasis>
command returns
on the control channel what the command line
<command>
-W
</command>
argument displays, i.e. the embedded
content of the
<filename>
config.report
</filename>
file.
This command does not take any parameters.
</para>
<screen>
{
"command": "build-report"
}
</screen>
</section>
<!-- end of command-build-report -->
<section
id=
"command-config-get"
>
<title>
config-get
</title>
...
...
@@ -315,7 +331,21 @@ will be sent to Kea and the responses received from Kea printed to standard outp
</para>
</section>
<!-- end of command-shutdown -->
<section
id=
"command-version-get"
>
<title>
version-get
</title>
<para>
The
<emphasis>
version-get
</emphasis>
command returns on the control
channel what the command line
<command>
-v
</command>
argument
displays with in arguments the extended version, i.e., what
the command line
<command>
-V
</command>
argument displays. This command
does not take any parameters.
</para>
<screen>
{
"command": "version-get"
}
</screen>
</section>
<!-- end of command-version-get -->
</section>
<!-- end of commands supported by both servers -->
...
...
doc/guide/dhcp4-srv.xml
View file @
e38e8d97
...
...
@@ -195,7 +195,7 @@ opening curly bracket (or brace). Each configuration consists of
one or more objects. In this specific example, we have only one
object, called Dhcp4. This is a simplified configuration, as usually
there will be additional objects, like
<command>
Logging
</command>
or
<command>
DhcpDns
</command>
, but we omit them now for clarity. The Dhcp4
<command>
DhcpD
d
ns
</command>
, but we omit them now for clarity. The Dhcp4
configuration starts with the
<command>
"Dhcp4": {
</command>
line
and ends with the corresponding closing brace (in the above example,
the brace after the last comment). Everything defined between those
...
...
@@ -2475,7 +2475,7 @@ It is merely echoed by the server
indicates that the server will use the "client identifier" for lease
lookups and "chaddr" if the first lookup returns no results. The
<command>
false
</command>
means that the server will only
use the "chaddr" to search for client
"
s lease. Whether the DHCID for
use the "chaddr" to search for client
'
s lease. Whether the DHCID for
DNS updates is generated from the "client identifier" or "chaddr" is
controlled through the same parameter accordingly.
</para>
...
...
@@ -3723,12 +3723,14 @@ src/lib/dhcpsrv/cfg_host_operations.cc -->
<para>
The DHCPv4 server supports the following operational commands:
<itemizedlist>
<listitem>
build-report
</listitem>
<listitem>
config-get
</listitem>
<listitem>
config-write
</listitem>
<listitem>
leases-reclaim
</listitem>
<listitem>
list-commands
</listitem>
<listitem>
set-config
</listitem>
<listitem>
shutdown
</listitem>
<listitem>
version-get
</listitem>
</itemizedlist>
as described in
<xref
linkend=
"commands-common"
/>
. In addition,
it supports the following statistics related commands:
...
...
doc/guide/dhcp6-srv.xml
View file @
e38e8d97
...
...
@@ -196,7 +196,7 @@ opening curly bracket (or brace). Each configuration consists of
one or more objects. In this specific example, we have only one
object, called Dhcp6. This is a simplified configuration, as usually
there will be additional objects, like
<command>
Logging
</command>
or
<command>
DhcpDns
</command>
, but we omit them now for clarity. The Dhcp6
<command>
DhcpD
d
ns
</command>
, but we omit them now for clarity. The Dhcp6
configuration starts with the
<command>
"Dhcp6": {
</command>
line
and ends with the corresponding closing brace (in the above example,
the brace after the last comment). Everything defined between those
...
...
@@ -2892,7 +2892,7 @@ should include options from the isc option space:
<userinput>
"option-data": [
{
"name": "vendor-opts",
"data": 4491
"
"data": 4491
},
{
"name": "tftp-servers",
...
...
@@ -4131,12 +4131,14 @@ If not specified, the default value is:
<para>
The DHCPv6 server supports the following operational commands:
<itemizedlist>
<listitem>
build-report
</listitem>
<listitem>
config-get
</listitem>
<listitem>
config-write
</listitem>
<listitem>
leases-reclaim
</listitem>
<listitem>
list-commands
</listitem>
<listitem>
set-config
</listitem>
<listitem>
shutdown
</listitem>
<listitem>
version-get
</listitem>
</itemizedlist>
as described in
<xref
linkend=
"commands-common"
/>
. In addition,
it supports the following statistics related commands:
...
...
src/bin/agent/ca_controller.cc
View file @
e38e8d97
...
...
@@ -8,6 +8,7 @@
#include <agent/ca_controller.h>
#include <agent/ca_process.h>
#include <agent/ca_command_mgr.h>
#include <agent/parser_context.h>
using
namespace
isc
::
process
;
...
...
@@ -47,6 +48,25 @@ CtrlAgentController::parseFile(const std::string& name) {
return
(
parser
.
parseFile
(
name
,
ParserContext
::
PARSER_AGENT
));
}
void
CtrlAgentController
::
registerCommands
()
{
CtrlAgentCommandMgr
::
instance
().
registerCommand
(
VERSION_GET_COMMAND
,
boost
::
bind
(
&
DControllerBase
::
versionGetHandler
,
this
,
_1
,
_2
));
CtrlAgentCommandMgr
::
instance
().
registerCommand
(
BUILD_REPORT_COMMAND
,
boost
::
bind
(
&
DControllerBase
::
buildReportHandler
,
this
,
_1
,
_2
));
CtrlAgentCommandMgr
::
instance
().
registerCommand
(
SHUT_DOWN_COMMAND
,
boost
::
bind
(
&
DControllerBase
::
shutdownHandler
,
this
,
_1
,
_2
));
}
void
CtrlAgentController
::
deregisterCommands
()
{
CtrlAgentCommandMgr
::
instance
().
deregisterCommand
(
VERSION_GET_COMMAND
);
CtrlAgentCommandMgr
::
instance
().
deregisterCommand
(
BUILD_REPORT_COMMAND
);
CtrlAgentCommandMgr
::
instance
().
deregisterCommand
(
SHUT_DOWN_COMMAND
);
}
CtrlAgentController
::
CtrlAgentController
()
:
DControllerBase
(
agent_app_name_
,
agent_bin_name_
)
{
}
...
...
src/bin/agent/ca_controller.h
View file @
e38e8d97
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2016
-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
...
...
@@ -47,6 +47,19 @@ public:
isc
::
data
::
ConstElementPtr
parseFile
(
const
std
::
string
&
name
);
/// @brief Register commands.
///
/// For all commands in the commands_ set at the exception of
/// list-commands register the command with the generic
/// @ref isc::process::DControllerBase::executeCommand() handler.
void
registerCommands
();
/// @brief Deregister commands.
///
/// For all commands in the commands_ set at the exception of
/// list-commands deregister the command.
void
deregisterCommands
();
private:
/// @brief Creates an instance of the Control Agent application
...
...
@@ -64,9 +77,11 @@ private:
/// @brief Constructor is declared private to maintain the integrity of
/// the singleton instance.
CtrlAgentController
();
};
// @Defines a shared pointer to CtrlAgentController
typedef
boost
::
shared_ptr
<
CtrlAgentController
>
CtrlAgentControllerPtr
;
}
// namespace isc::agent
}
// namespace isc
...
...
src/bin/agent/ca_process.cc
View file @
e38e8d97
...
...
@@ -6,6 +6,7 @@
#include <config.h>
#include <agent/ca_process.h>
#include <agent/ca_controller.h>
#include <agent/ca_response_creator_factory.h>
#include <agent/ca_log.h>
#include <asiolink/io_address.h>
...
...
@@ -47,13 +48,20 @@ CtrlAgentProcess::run() {
try
{
// Register commands.
CtrlAgentControllerPtr
controller
=
boost
::
dynamic_pointer_cast
<
CtrlAgentController
>
(
CtrlAgentController
::
instance
());
controller
->
registerCommands
();
// Create response creator factory first. It will be used to generate
// response creators. Each response creator will be used to generate
// answer to specific request.
HttpResponseCreatorFactoryPtr
rcf
(
new
CtrlAgentResponseCreatorFactory
());
DCfgContextBasePtr
base_ctx
=
getCfgMgr
()
->
getContext
();
CtrlAgentCfgContextPtr
ctx
=
boost
::
dynamic_pointer_cast
<
CtrlAgentCfgContext
>
(
base_ctx
);
CtrlAgentCfgContextPtr
ctx
=
boost
::
dynamic_pointer_cast
<
CtrlAgentCfgContext
>
(
base_ctx
);
if
(
!
ctx
)
{
isc_throw
(
Unexpected
,
"Interal logic error: bad context type"
);
}
...
...
@@ -99,6 +107,16 @@ CtrlAgentProcess::run() {
"Process run method failed: "
<<
ex
.
what
());
}
try
{
// Deregister commands.
CtrlAgentControllerPtr
controller
=
boost
::
dynamic_pointer_cast
<
CtrlAgentController
>
(
CtrlAgentController
::
instance
());
controller
->
deregisterCommands
();
}
catch
(
const
std
::
exception
&
)
{
// What to do? Simply ignore...
}
LOG_DEBUG
(
agent_logger
,
DBGLVL_START_SHUT
,
CTRL_AGENT_RUN_EXIT
);
}
...
...
@@ -118,13 +136,6 @@ CtrlAgentProcess::configure(isc::data::ConstElementPtr config_set,
return
(
answer
);
}
isc
::
data
::
ConstElementPtr
CtrlAgentProcess
::
command
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
/*args*/
)
{
return
(
isc
::
config
::
createAnswer
(
COMMAND_INVALID
,
"Unrecognized command: "
+
command
));
}
CtrlAgentCfgMgrPtr
CtrlAgentProcess
::
getCtrlAgentCfgMgr
()
{
...
...
src/bin/agent/ca_process.h
View file @
e38e8d97
...
...
@@ -87,26 +87,6 @@ public:
configure
(
isc
::
data
::
ConstElementPtr
config_set
,
bool
check_only
=
false
);
/// @brief Processes the given command.
///
/// This method is called to execute any custom commands supported by the
/// process. This method must not throw, it should catch any processing
/// errors and return a success or failure answer as described below.
///
/// @param command is a string label representing the command to execute.
/// @param args is a set of arguments (if any) required for the given
/// command.
/// @return an Element that contains the results of command composed
/// of an integer status value:
///
/// - COMMAND_SUCCESS indicates a command was successful.
/// - COMMAND_ERROR indicates a valid command failed execute.
/// - COMMAND_INVALID indicates a command is not valid.
///
/// and a string explanation of the outcome.
virtual
isc
::
data
::
ConstElementPtr
command
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
);
/// @brief Returns a pointer to the configuration manager.
CtrlAgentCfgMgrPtr
getCtrlAgentCfgMgr
();
};
...
...
src/bin/d2/d2_process.cc
View file @
e38e8d97
...
...
@@ -362,19 +362,6 @@ D2Process::reconfigureQueueMgr() {
}
}
isc
::
data
::
ConstElementPtr
D2Process
::
command
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
)
{
// @todo This is the initial implementation. If and when D2 is extended
// to support its own commands, this implementation must change. Otherwise
// it should reject all commands as it does now.
LOG_DEBUG
(
d2_logger
,
DBGLVL_TRACE_BASIC
,
DHCP_DDNS_COMMAND
)
.
arg
(
command
).
arg
(
args
?
args
->
str
()
:
"(no args)"
);
return
(
isc
::
config
::
createAnswer
(
COMMAND_INVALID
,
"Unrecognized command: "
+
command
));
}
D2Process
::~
D2Process
()
{
};
...
...
src/bin/d2/d2_process.h
View file @
e38e8d97
...
...
@@ -161,20 +161,6 @@ public:
configure
(
isc
::
data
::
ConstElementPtr
config_set
,
bool
check_only
=
false
);
/// @brief Processes the given command.
///
/// This method is called to execute any custom commands supported by the
/// process. This method must not throw, it should catch any processing
/// errors and return a success or failure answer as described below.
///
/// @param command is a string label representing the command to execute.
/// @param args is a set of arguments (if any) required for the given
/// command. It can be a NULL pointer if no arguments exist for a command.
/// @return an Element that contains the results of command composed
/// of an integer status value (0 means successful, non-zero means failure),
/// and a string explanation of the outcome.
virtual
isc
::
data
::
ConstElementPtr
command
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
);
/// @brief Destructor
virtual
~
D2Process
();
...
...
src/bin/d2/tests/d2_controller_unittests.cc
View file @
e38e8d97
...
...
@@ -199,35 +199,6 @@ TEST_F(D2ControllerTest, configUpdateTests) {
EXPECT_EQ
(
1
,
rcode
);
}
/// @brief Command execution tests.
/// This really tests just the ability of the handler to invoke the necessary
/// chain of methods and to handle error conditions.
/// This test verifies that:
/// 1. That an unrecognized command is detected and returns a status of
/// d2::COMMAND_INVALID.
/// 2. Shutdown command is recognized and returns a d2::COMMAND_SUCCESS status.
TEST_F
(
D2ControllerTest
,
executeCommandTests
)
{
int
rcode
=
-
1
;
isc
::
data
::
ConstElementPtr
answer
;
isc
::
data
::
ElementPtr
arg_set
;
// Initialize the application process.
ASSERT_NO_THROW
(
initProcess
());
EXPECT_TRUE
(
checkProcess
());
// Verify that an unknown command returns an COMMAND_INVALID response.
std
::
string
bogus_command
(
"bogus"
);
answer
=
executeCommand
(
bogus_command
,
arg_set
);
isc
::
config
::
parseAnswer
(
rcode
,
answer
);
EXPECT_EQ
(
COMMAND_INVALID
,
rcode
);
// Verify that shutdown command returns COMMAND_SUCCESS response.
//answer = executeCommand(SHUT_DOWN_COMMAND, isc::data::ElementPtr());
answer
=
executeCommand
(
SHUT_DOWN_COMMAND
,
arg_set
);
isc
::
config
::
parseAnswer
(
rcode
,
answer
);
EXPECT_EQ
(
COMMAND_SUCCESS
,
rcode
);
}
// Tests that the original configuration is retained after a SIGHUP triggered
// reconfiguration fails due to invalid config content.
TEST_F
(
D2ControllerTest
,
invalidConfigReload
)
{
...
...
src/bin/d2/tests/d2_process_unittests.cc
View file @
e38e8d97
...
...
@@ -394,20 +394,6 @@ TEST_F(D2ProcessTest, badConfigureRecovery) {
EXPECT_FALSE
(
getReconfQueueFlag
());
}
/// @brief Verifies basic command method behavior.
/// @TODO IF the D2Process is extended to support extra commands this testing
/// will need to augmented accordingly.
TEST_F
(
D2ProcessTest
,
command
)
{
// Verify that the process will process unsupported command and
// return a failure response.
int
rcode
=
-
1
;
string
args
=
"{
\"
arg1
\"
: 77 } "
;
isc
::
data
::
ElementPtr
json
=
isc
::
data
::
Element
::
fromJSON
(
args
);
isc
::
data
::
ConstElementPtr
answer
=
command
(
"bogus_command"
,
json
);
parseAnswer
(
rcode
,
answer
);
EXPECT_EQ
(
COMMAND_INVALID
,
rcode
);
}
/// @brief Tests shutdown command argument parsing
/// The shutdown command supports an optional "type" argument. This test
/// checks that for valid values, the shutdown() method: sets the shutdown
...
...
src/bin/dhcp4/ctrl_dhcp4_srv.cc
View file @
e38e8d97
...
...
@@ -15,6 +15,7 @@
#include <dhcpsrv/cfg_db_access.h>
#include <config/command_mgr.h>
#include <stats/stats_mgr.h>
#include <cfgrpt/config_report.h>
using
namespace
isc
::
data
;
using
namespace
isc
::
hooks
;
...
...
@@ -205,6 +206,25 @@ ControlledDhcpv4Srv::commandSetConfigHandler(const string&,
return
(
result
);
}
ConstElementPtr
ControlledDhcpv4Srv
::
commandVersionGetHandler
(
const
string
&
,
ConstElementPtr
)
{
ElementPtr
extended
=
Element
::
create
(
Dhcpv4Srv
::
getVersion
(
true
));
ElementPtr
arguments
=
Element
::
createMap
();
arguments
->
set
(
"extended"
,
extended
);
ConstElementPtr
answer
=
isc
::
config
::
createAnswer
(
0
,
Dhcpv4Srv
::
getVersion
(
false
),
arguments
);
return
(
answer
);
}
ConstElementPtr
ControlledDhcpv4Srv
::
commandBuildReportHandler
(
const
string
&
,
ConstElementPtr
)
{
ConstElementPtr
answer
=
isc
::
config
::
createAnswer
(
0
,
isc
::
detail
::
getConfigReport
());
return
(
answer
);
}
ConstElementPtr
ControlledDhcpv4Srv
::
commandLeasesReclaimHandler
(
const
string
&
,
ConstElementPtr
args
)
{
...
...
@@ -262,6 +282,12 @@ ControlledDhcpv4Srv::processCommand(const string& command,
}
else
if
(
command
==
"config-get"
)
{
return
(
srv
->
commandConfigGetHandler
(
command
,
args
));
}
else
if
(
command
==
"version-get"
)
{
return
(
srv
->
commandVersionGetHandler
(
command
,
args
));
}
else
if
(
command
==
"build-report"
)
{
return
(
srv
->
commandBuildReportHandler
(
command
,
args
));
}
else
if
(
command
==
"leases-reclaim"
)
{
return
(
srv
->
commandLeasesReclaimHandler
(
command
,
args
));
...
...
@@ -398,6 +424,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/)
// These are the commands always supported by the DHCPv4 server.
// Please keep the list in alphabetic order.
CommandMgr
::
instance
().
registerCommand
(
"build-report"
,
boost
::
bind
(
&
ControlledDhcpv4Srv
::
commandBuildReportHandler
,
this
,
_1
,
_2
));
CommandMgr
::
instance
().
registerCommand
(
"config-get"
,
boost
::
bind
(
&
ControlledDhcpv4Srv
::
commandConfigGetHandler
,
this
,
_1
,
_2
));
...
...
@@ -418,6 +447,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/)
CommandMgr
::
instance
().
registerCommand
(
"shutdown"
,
boost
::
bind
(
&
ControlledDhcpv4Srv
::
commandShutdownHandler
,
this
,
_1
,
_2
));
CommandMgr
::
instance
().
registerCommand
(
"version-get"
,
boost
::
bind
(
&
ControlledDhcpv4Srv
::
commandVersionGetHandler
,
this
,
_1
,
_2
));
// Register statistic related commands
CommandMgr
::
instance
().
registerCommand
(
"statistic-get"
,
boost
::
bind
(
&
StatsMgr
::
statisticGetHandler
,
_1
,
_2
));
...
...
@@ -457,6 +489,7 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
CommandMgr
::
instance
().
closeCommandSocket
();
// Deregister any registered commands (please keep in alphabetic order)
CommandMgr
::
instance
().
deregisterCommand
(
"build-report"
);
CommandMgr
::
instance
().
deregisterCommand
(
"config-get"
);
CommandMgr
::
instance
().
deregisterCommand
(
"config-write"
);
CommandMgr
::
instance
().
deregisterCommand
(
"leases-reclaim"
);
...
...
@@ -469,6 +502,7 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
CommandMgr
::
instance
().
deregisterCommand
(
"statistic-remove-all"
);
CommandMgr
::
instance
().
deregisterCommand
(
"statistic-reset"
);
CommandMgr
::
instance
().
deregisterCommand
(
"statistic-reset-all"
);
CommandMgr
::
instance
().
deregisterCommand
(
"version-get"
);
}
catch
(...)
{
// Don't want to throw exceptions from the destructor. The server
...
...
src/bin/dhcp4/ctrl_dhcp4_srv.h
View file @
e38e8d97
...
...
@@ -187,6 +187,31 @@ private:
commandSetConfigHandler
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
);
/// @brief handler for processing 'version-get' command
///
/// This handler processes version-get command, which returns
/// over the control channel the -v and -V command line arguments.
/// @param command (parameter ignored)
/// @param args (parameter ignored)
///
/// @return status of the command with the version in text and
/// the extended version in arguments.
isc
::
data
::
ConstElementPtr
commandVersionGetHandler
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
);
/// @brief handler for processing 'build-report' command
///
/// This handler processes build-report command, which returns
/// over the control channel the -W command line argument.
/// @param command (parameter ignored)
/// @param args (parameter ignored)
///
/// @return status of the command with the config report
isc
::
data
::
ConstElementPtr
commandBuildReportHandler
(
const
std
::
string
&
command
,
isc
::
data
::
ConstElementPtr
args
);
/// @brief Handler for processing 'leases-reclaim' command
///
/// This handler processes leases-reclaim command, which triggers
...
...
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
View file @
e38e8d97
...
...
@@ -381,12 +381,20 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) {
std
::
string
command_list
=
answer
->
get
(
"arguments"
)
->
str
();
EXPECT_TRUE
(
command_list
.
find
(
"
\"
list-commands
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
build-report
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
config-get
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
config-write
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
leases-reclaim
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
libreload
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
set-config
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
shutdown
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-get
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-get-all
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-remove
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-remove-all
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-reset
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
statistic-reset-all
\"
"
)
!=
string
::
npos
);
EXPECT_TRUE
(
command_list
.
find
(
"
\"
version-get
\"
"
)
!=
string
::
npos
);
// Ok, and now delete the server. It should deregister its commands.
server_
.
reset
();
...
...
@@ -482,6 +490,25 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlLeasesReclaim) {
EXPECT_TRUE
(
lease1
->
stateExpiredReclaimed
());
}
// This test verifies that the DHCP server handles version-get commands
TEST_F
(
CtrlChannelDhcpv4SrvTest
,
getversion
)
{
createUnixChannelServer
();
std
::
string
response
;
// Send the version-get command
sendUnixCommand
(
"{
\"
command
\"
:
\"
version-get
\"
}"
,
response
);
EXPECT_TRUE
(
response
.
find
(
"
\"
result
\"
: 0"
)
!=
string
::
npos
);
EXPECT_TRUE
(
response
.
find
(
"log4cplus"
)
!=
string
::
npos
);
EXPECT_FALSE
(
response
.
find
(
"GTEST_VERSION"
)
!=
string
::
npos
);
// Send the build-report command
sendUnixCommand
(
"{
\"
command
\"
:
\"
build-report
\"
}"
,
response
);
EXPECT_TRUE
(
response
.
find
(
"
\"
result
\"
: 0"
)
!=
string
::
npos
);
EXPECT_TRUE
(
response
.
find
(
"GTEST_VERSION"
)
!=
string
::
npos
);
}
// This test verifies that the DHCP server immediately removed expired
// This test verifies that the DHCP server immediately removed expired
// leases on leases-reclaim command with remove = true
TEST_F
(
CtrlChannelDhcpv4SrvTest
,
controlLeasesReclaimRemove
)
{
...
...
@@ -722,6 +749,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) {
EXPECT_NO_THROW
(
rsp
=
Element
::
fromJSON
(
response
));
// We expect the server to report at least the following commands:
checkListCommands
(
rsp
,
"build-report"
);
checkListCommands
(
rsp
,
"config-get"
);
checkListCommands
(
rsp
,
"config-write"
);
checkListCommands
(
rsp
,
"list-commands"
);
...
...
@@ -735,6 +763,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) {
checkListCommands
(
rsp
,
"statistic-remove-all"
);
checkListCommands
(
rsp
,
"statistic-reset"
);
checkListCommands
(
rsp
,
"statistic-reset-all"
);
checkListCommands
(
rsp
,
"version-get"
);
}
// Tests if the server returns its configuration using config-get.
...
...
src/bin/dhcp6/ctrl_dhcp6_srv.cc
View file @
e38e8d97
...
...
@@ -16,6 +16,7 @@
#include <dhcp6/json_config_parser.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <cfgrpt/config_report.h>
using
namespace
isc
::
config
;
using
namespace
isc
::
data
;
...
...
@@ -211,6 +212,24 @@ ControlledDhcpv6Srv::commandSetConfigHandler(const string&,
}
ConstElementPtr
ControlledDhcpv6Srv
::
commandVersionGetHandler
(
const
string
&
,
ConstElementPtr
)
{
ElementPtr
extended
=
Element
::
create
(
Dhcpv6Srv
::
getVersion
(
true
));
ElementPtr
arguments
=
Element
::
createMap
();
arguments
->
set
(
"extended"
,
extended
);
ConstElementPtr
answer
=
isc
::
config
::
createAnswer
(
0
,
Dhcpv6Srv
::
getVersion
(
false
),
arguments
);
return
(
answer
);
}
ConstElementPtr
ControlledDhcpv6Srv
::
commandBuildReportHandler
(
const
string
&
,
ConstElementPtr
)
{
ConstElementPtr
answer
=
isc
::
config
::
createAnswer
(
0
,
isc
::
detail
::
getConfigReport
());
return
(
answer
);
}
ConstElementPtr
ControlledDhcpv6Srv
::
commandLeasesReclaimHandler
(
const
string
&
,
ConstElementPtr
args
)
{
...
...
@@ -268,6 +287,12 @@ ControlledDhcpv6Srv::processCommand(const std::string& command,
}
else
if
(
command
==
"config-get"
)
{
return
(
srv
->
commandConfigGetHandler
(
command
,
args
));
}
else
if
(
command
==
"version-get"
)
{
return
(
srv
->
commandVersionGetHandler
(
command
,
args
));
}
else
if
(
command
==
"build-report"
)
{
return
(
srv
->
commandBuildReportHandler
(
command
,
args
));
}
else
if
(
command
==
"leases-reclaim"
)
{
return
(
srv
->
commandLeasesReclaimHandler
(
command
,
args
));
...
...
@@ -427,6 +452,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port)
// These are the commands always supported by the DHCPv6 server.
// Please keep the list in alphabetic order.
CommandMgr
::
instance
().
registerCommand
(
"build-report"
,
boost
::
bind
(
&
ControlledDhcpv6Srv
::
commandBuildReportHandler
,
this
,
_1
,
_2
));
CommandMgr
::
instance
().
registerCommand
(
"config-get"
,
boost
::
bind
(
&
ControlledDhcpv6Srv
::
commandConfigGetHandler
,
this
,
_1
,
_2
));
...
...
@@ -447,6 +475,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port)
CommandMgr
::
instance
().
registerCommand
(
"shutdown"
,
boost
::
bind
(
&
ControlledDhcpv6Srv
::
commandShutdownHandler
,
this
,
_1
,
_2
));
CommandMgr
::
instance
().
registerCommand
(
"version-get"
,
boost
::
bind
(
&
ControlledDhcpv6Srv
::
commandVersionGetHandler
,
this
,
_1
,
_2
));
// Register statistic related commands
CommandMgr
::
instance
().
registerCommand
(
"statistic-get"
,
boost
::
bind
(
&
StatsMgr
::
statisticGetHandler
,
_1
,
_2
));
...
...
@@ -485,10 +516,11 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {