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
446
Issues
446
List
Boards
Labels
Service Desk
Milestones
Merge Requests
72
Merge Requests
72
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
ISC Open Source Projects
Kea
Commits
efcbf029
Commit
efcbf029
authored
Sep 30, 2014
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Plain Diff
[master] Merge branch 'trac3588'
parents
eb70c1d3
2f666cd1
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
854 additions
and
521 deletions
+854
-521
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
+2
-2
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
+40
-18
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
+6
-4
src/bin/dhcp4/tests/kea_controller_unittest.cc
src/bin/dhcp4/tests/kea_controller_unittest.cc
+2
-0
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
+2
-1
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
+41
-16
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
+6
-4
src/bin/dhcp6/tests/kea_controller_unittest.cc
src/bin/dhcp6/tests/kea_controller_unittest.cc
+2
-0
src/lib/dhcp/option_definition.cc
src/lib/dhcp/option_definition.cc
+10
-0
src/lib/dhcp/option_definition.h
src/lib/dhcp/option_definition.h
+32
-1
src/lib/dhcp/option_space.h
src/lib/dhcp/option_space.h
+3
-0
src/lib/dhcp/tests/option_definition_unittest.cc
src/lib/dhcp/tests/option_definition_unittest.cc
+94
-0
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/Makefile.am
+1
-0
src/lib/dhcpsrv/cfg_option_def.cc
src/lib/dhcpsrv/cfg_option_def.cc
+142
-0
src/lib/dhcpsrv/cfg_option_def.h
src/lib/dhcpsrv/cfg_option_def.h
+142
-0
src/lib/dhcpsrv/cfgmgr.cc
src/lib/dhcpsrv/cfgmgr.cc
+0
-70
src/lib/dhcpsrv/cfgmgr.h
src/lib/dhcpsrv/cfgmgr.h
+0
-49
src/lib/dhcpsrv/dhcp_parsers.cc
src/lib/dhcpsrv/dhcp_parsers.cc
+13
-70
src/lib/dhcpsrv/dhcp_parsers.h
src/lib/dhcpsrv/dhcp_parsers.h
+1
-16
src/lib/dhcpsrv/logging.h
src/lib/dhcpsrv/logging.h
+1
-1
src/lib/dhcpsrv/option_space_container.h
src/lib/dhcpsrv/option_space_container.h
+1
-1
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.cc
+6
-3
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/srv_config.h
+38
-0
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/Makefile.am
+2
-1
src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc
src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc
+247
-0
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
+0
-191
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+4
-73
src/lib/dhcpsrv/tests/srv_config_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc
+16
-0
No files found.
src/bin/dhcp4/dhcp4_srv.cc
View file @
efcbf029
...
...
@@ -1806,8 +1806,8 @@ Dhcpv4Srv::unpackOptions(const OptionBuffer& buf,
// Get the list of stdandard option definitions.
option_defs
=
LibDHCP
::
getOptionDefs
(
Option
::
V4
);
}
else
if
(
!
option_space
.
empty
())
{
OptionDefContainerPtr
option_defs_ptr
=
CfgMgr
::
instance
().
getOptionDefs
(
option_space
);
OptionDefContainerPtr
option_defs_ptr
=
CfgMgr
::
instance
()
.
getCurrentCfg
()
->
getCfgOptionDef
()
->
getAll
(
option_space
);
if
(
option_defs_ptr
!=
NULL
)
{
option_defs
=
*
option_defs_ptr
;
}
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
efcbf029
...
...
@@ -80,6 +80,7 @@ public:
srv_
.
reset
(
new
Dhcpv4Srv
(
0
));
// Create fresh context.
globalContext
()
->
copyContext
(
ParserContext
(
Option
::
V4
));
resetConfiguration
();
}
// Check that no hooks libraries are loaded. This is a pre-condition for
...
...
@@ -444,8 +445,6 @@ public:
void
resetConfiguration
()
{
string
config
=
"{
\"
interfaces
\"
: [
\"
*
\"
],"
"
\"
hooks-libraries
\"
: [ ], "
"
\"
rebind-timer
\"
: 2000, "
"
\"
renew-timer
\"
: 1000, "
"
\"
valid-lifetime
\"
: 4000, "
"
\"
subnet4
\"
: [ ], "
"
\"
dhcp-ddns
\"
: {
\"
enable-updates
\"
: false }, "
...
...
@@ -453,6 +452,7 @@ public:
"
\"
option-data
\"
: [ ] }"
;
static_cast
<
void
>
(
executeConfiguration
(
config
,
"reset configuration database"
));
CfgMgr
::
instance
().
clear
();
}
...
...
@@ -1231,7 +1231,8 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1241,7 +1242,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Verify that the option definition data is valid.
...
...
@@ -1272,7 +1273,8 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1282,7 +1284,7 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1330,8 +1332,10 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the option definitions do not exist yet.
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
101
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
101
));
// Use the configuration string to create new option definitions.
ConstElementPtr
status
;
...
...
@@ -1340,7 +1344,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
checkResult
(
status
,
0
);
// Check the first definition we have created.
OptionDefinitionPtr
def1
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def1
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def1
);
// Check the option data.
...
...
@@ -1351,7 +1356,8 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
EXPECT_TRUE
(
def1
->
getEncapsulatedSpace
().
empty
());
// Check the second option definition we have created.
OptionDefinitionPtr
def2
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
101
);
OptionDefinitionPtr
def2
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
101
);
ASSERT_TRUE
(
def2
);
// Check the option data.
...
...
@@ -1392,7 +1398,8 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the option definition does not exist yet.
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
));
// Use the configuration string to create new option definitions.
ConstElementPtr
status
;
...
...
@@ -1422,7 +1429,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1432,7 +1440,8 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1463,7 +1472,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1473,7 +1483,8 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1670,7 +1681,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp4"
,
109
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp4"
,
109
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1680,7 +1692,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp4"
,
109
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp4"
,
109
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1736,7 +1749,8 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
// Expecting success.
checkResult
(
status
,
0
);
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp4"
,
65
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp4"
,
65
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1950,6 +1964,8 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
ASSERT_TRUE
(
status
);
checkResult
(
status
,
0
);
CfgMgr
::
instance
().
clear
();
// Stage 2. Configure base option and a subnet. Please note that
// the configuration from the stage 2 is repeated because BIND
// configuration manager sends whole configuration for the lists
...
...
@@ -2524,6 +2540,8 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
ASSERT_TRUE
(
status
);
checkResult
(
status
,
0
);
CfgMgr
::
instance
().
clear
();
// Once the definitions have been added we can configure the
// standard option #17. This option comprises an enterprise
// number and sub options. By convention (introduced in
...
...
@@ -2879,6 +2897,10 @@ TEST_F(Dhcp4ParserTest, LibrariesSpecified) {
EXPECT_TRUE
(
checkMarkerFile
(
LOAD_MARKER_FILE
,
"12"
));
EXPECT_FALSE
(
checkMarkerFileExists
(
UNLOAD_MARKER_FILE
));
// Commit the changes so as we get the fresh configuration for the
// second part of this test.
CfgMgr
::
instance
().
commit
();
// Unload the libraries. The load file should not have changed, but
// the unload one should indicate the unload() functions have been run.
config
=
buildHooksLibrariesConfig
();
...
...
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
View file @
efcbf029
...
...
@@ -1315,10 +1315,12 @@ TEST_F(Dhcpv4SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under
// different option space.
CfgMgr
&
cfgmgr
=
CfgMgr
::
instance
();
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def
,
"space-foobar"
));
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def2
,
"space-foo"
));
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def3
,
"space-bar"
));
CfgOptionDefPtr
cfg_option_def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
();
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def
,
"space-foobar"
));
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def2
,
"space-foo"
));
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def3
,
"space-bar"
));
CfgMgr
::
instance
().
commit
();
// Create the buffer holding the structure of options.
const
char
raw_data
[]
=
{
...
...
src/bin/dhcp4/tests/kea_controller_unittest.cc
View file @
efcbf029
...
...
@@ -18,6 +18,7 @@
#include <dhcp/dhcp4.h>
#include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcpsrv/cfgmgr.h>
#include <log/logger_support.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
...
...
@@ -57,6 +58,7 @@ public:
}
~
JSONFileBackendTest
()
{
isc
::
log
::
setDefaultLoggingOutput
();
static_cast
<
void
>
(
unlink
(
TEST_FILE
));
};
...
...
src/bin/dhcp6/dhcp6_srv.cc
View file @
efcbf029
...
...
@@ -2444,7 +2444,8 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
option_defs
=
LibDHCP
::
getOptionDefs
(
Option
::
V6
);
}
else
if
(
!
option_space
.
empty
())
{
OptionDefContainerPtr
option_defs_ptr
=
CfgMgr
::
instance
().
getOptionDefs
(
option_space
);
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgOptionDef
()
->
getAll
(
option_space
);
if
(
option_defs_ptr
!=
NULL
)
{
option_defs
=
*
option_defs_ptr
;
}
...
...
src/bin/dhcp6/tests/config_parser_unittest.cc
View file @
efcbf029
...
...
@@ -302,6 +302,7 @@ public:
try
{
ElementPtr
json
=
Element
::
fromJSON
(
config
);
status
=
configureDhcp6Server
(
srv_
,
json
);
}
catch
(
const
std
::
exception
&
ex
)
{
ADD_FAILURE
()
<<
"Unable to "
<<
operation
<<
". "
<<
"The following configuration was used: "
<<
std
::
endl
...
...
@@ -382,6 +383,7 @@ public:
EXPECT_NO_THROW
(
x
=
configureDhcp6Server
(
srv_
,
json
));
checkResult
(
x
,
1
);
EXPECT_TRUE
(
errorContainsPosition
(
x
,
"<string>"
));
CfgMgr
::
instance
().
clear
();
}
/// @brief Test invalid option paramater value.
...
...
@@ -399,6 +401,7 @@ public:
EXPECT_NO_THROW
(
x
=
configureDhcp6Server
(
srv_
,
json
));
checkResult
(
x
,
1
);
EXPECT_TRUE
(
errorContainsPosition
(
x
,
"<string>"
));
CfgMgr
::
instance
().
clear
();
}
/// @brief Test option against given code and data.
...
...
@@ -468,11 +471,13 @@ public:
const
size_t
expected_data_len
)
{
std
::
string
config
=
createConfigWithOption
(
params
);
ASSERT_TRUE
(
executeConfiguration
(
config
,
"parse option configuration"
));
// The subnet should now hold one option with the specified code.
Subnet
::
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
option_code
);
ASSERT_TRUE
(
desc
.
option
);
testOption
(
desc
,
option_code
,
expected_data
,
expected_data_len
);
CfgMgr
::
instance
().
clear
();
}
int
rcode_
;
///< Return code (see @ref isc::config::parseAnswer)
...
...
@@ -1466,7 +1471,8 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1475,7 +1481,7 @@ TEST_F(Dhcp6ParserTest, optionDefIpv6Address) {
ASSERT_TRUE
(
status
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Verify that the option definition data is valid.
...
...
@@ -1505,7 +1511,8 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1515,7 +1522,7 @@ TEST_F(Dhcp6ParserTest, optionDefRecord) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1562,8 +1569,10 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the option definitions do not exist yet.
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
101
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
101
));
// Use the configuration string to create new option definitions.
ConstElementPtr
status
;
...
...
@@ -1572,7 +1581,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
checkResult
(
status
,
0
);
// Check the first definition we have created.
OptionDefinitionPtr
def1
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def1
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def1
);
// Check the option data.
...
...
@@ -1582,7 +1592,8 @@ TEST_F(Dhcp6ParserTest, optionDefMultiple) {
EXPECT_FALSE
(
def1
->
getArrayType
());
// Check the second option definition we have created.
OptionDefinitionPtr
def2
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
101
);
OptionDefinitionPtr
def2
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
101
);
ASSERT_TRUE
(
def2
);
// Check the option data.
...
...
@@ -1622,7 +1633,8 @@ TEST_F(Dhcp6ParserTest, optionDefDuplicate) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the option definition does not exist yet.
ASSERT_FALSE
(
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
));
// Use the configuration string to create new option definitions.
ConstElementPtr
status
;
...
...
@@ -1652,7 +1664,8 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1662,7 +1675,7 @@ TEST_F(Dhcp6ParserTest, optionDefArray) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1692,7 +1705,8 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1702,7 +1716,7 @@ TEST_F(Dhcp6ParserTest, optionDefEncapsulate) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
get
OptionDef
(
"isc"
,
100
);
def
=
CfgMgr
::
instance
().
get
StagingCfg
()
->
getCfgOptionDef
()
->
get
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1900,7 +1914,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp6"
,
100
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp6"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
...
...
@@ -1910,7 +1925,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
checkResult
(
status
,
0
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp6"
,
100
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp6"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -1966,7 +1982,8 @@ TEST_F(Dhcp6ParserTest, optionStandardDefOverride) {
// Expecting success.
checkResult
(
status
,
0
);
def
=
CfgMgr
::
instance
().
getOptionDef
(
"dhcp6"
,
59
);
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
"dhcp6"
,
59
);
ASSERT_TRUE
(
def
);
// Check the option data.
...
...
@@ -2190,6 +2207,8 @@ TEST_F(Dhcp6ParserTest, optionDataEncapsulate) {
ASSERT_TRUE
(
status
);
checkResult
(
status
,
0
);
CfgMgr
::
instance
().
clear
();
// Stage 2. Configure base option and a subnet. Please note that
// the configuration from the stage 2 is repeated because BIND
// configuration manager sends whole configuration for the lists
...
...
@@ -2383,6 +2402,8 @@ TEST_F(Dhcp6ParserTest, optionDataBoolean) {
ASSERT_TRUE
(
executeConfiguration
(
config
,
"parse configuration with a"
" boolean value"
));
CfgMgr
::
instance
().
commit
();
// The subnet should now hold one option with the code 1000.
Subnet
::
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
1000
);
...
...
@@ -2773,6 +2794,8 @@ TEST_F(Dhcp6ParserTest, stdOptionDataEncapsulate) {
ASSERT_TRUE
(
status
);
checkResult
(
status
,
0
);
CfgMgr
::
instance
().
clear
();
// Once the definitions have been added we can configure the
// standard option #17. This option comprises an enterprise
// number and sub options. By convention (introduced in
...
...
@@ -3015,6 +3038,8 @@ TEST_F(Dhcp6ParserTest, LibrariesSpecified) {
EXPECT_TRUE
(
checkMarkerFile
(
LOAD_MARKER_FILE
,
"12"
));
EXPECT_FALSE
(
checkMarkerFileExists
(
UNLOAD_MARKER_FILE
));
CfgMgr
::
instance
().
commit
();
// Unload the libraries. The load file should not have changed, but
// the unload one should indicate the unload() functions have been run.
config
=
buildHooksLibrariesConfig
();
...
...
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
View file @
efcbf029
...
...
@@ -1713,10 +1713,12 @@ TEST_F(Dhcpv6SrvTest, unpackOptions) {
// Add option definitions to the Configuration Manager. Each goes under
// different option space.
CfgMgr
&
cfgmgr
=
CfgMgr
::
instance
();
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def
,
"space-foobar"
));
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def2
,
"space-foo"
));
ASSERT_NO_THROW
(
cfgmgr
.
addOptionDef
(
opt_def3
,
"space-bar"
));
CfgOptionDefPtr
cfg_option_def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
();
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def
,
"space-foobar"
));
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def2
,
"space-foo"
));
ASSERT_NO_THROW
(
cfg_option_def
->
add
(
opt_def3
,
"space-bar"
));
CfgMgr
::
instance
().
commit
();
// Create the buffer holding the structure of options.
const
char
raw_data
[]
=
{
...
...
src/bin/dhcp6/tests/kea_controller_unittest.cc
View file @
efcbf029
...
...
@@ -18,6 +18,7 @@
#include <dhcp/dhcp6.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcpsrv/cfgmgr.h>
#include <log/logger_support.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
...
...
@@ -52,6 +53,7 @@ public:
}
~
JSONFileBackendTest
()
{
isc
::
log
::
setDefaultLoggingOutput
();
static_cast
<
void
>
(
unlink
(
TEST_FILE
));
};
...
...
src/lib/dhcp/option_definition.cc
View file @
efcbf029
...
...
@@ -92,6 +92,16 @@ OptionDefinition::OptionDefinition(const std::string& name,
encapsulated_space_
(
encapsulated_space
)
{
}
bool
OptionDefinition
::
equals
(
const
OptionDefinition
&
other
)
const
{
return
(
name_
==
other
.
name_
&&
code_
==
other
.
code_
&&
type_
==
other
.
type_
&&
array_type_
==
other
.
array_type_
&&
encapsulated_space_
==
other
.
encapsulated_space_
&&
record_fields_
==
other
.
record_fields_
);
}
void
OptionDefinition
::
addRecordField
(
const
std
::
string
&
data_type_name
)
{
OptionDataType
data_type
=
OptionDataTypeUtil
::
getDataType
(
data_type_name
);
...
...
src/lib/dhcp/option_definition.h
View file @
efcbf029
...
...
@@ -203,6 +203,35 @@ public:
const
char
*
encapsulated_space
);
/// @name Comparison functions and operators.
///
//@{
/// @brief Check if option definition is equal to other.
///
/// @param other Option definition to compare to.
///
/// @return true if two option definitions are equal, false otherwise.
bool
equals
(
const
OptionDefinition
&
other
)
const
;
/// @brief Equality operator.
///
/// @param other Option definition to compare to.
///
/// @return true if two option definitions are equal, false otherwise.
bool
operator
==
(
const
OptionDefinition
&
other
)
const
{
return
(
equals
(
other
));
}
/// @brief Inequality operator.
///
/// @param other Option definition to compare to.
///
/// @return true if option definitions are not equal, false otherwise.
bool
operator
!=
(
const
OptionDefinition
&
other
)
const
{
return
(
!
equals
(
other
));
}
//@}
/// @brief Adds data field to the record.
///
/// @param data_type_name name of the data type for the field.
...
...
@@ -247,7 +276,9 @@ public:
/// @brief Return list of record fields.
///
/// @return list of record fields.
const
RecordFieldsCollection
&
getRecordFields
()
const
{
return
(
record_fields_
);
}
const
RecordFieldsCollection
&
getRecordFields
()
const
{
return
(
record_fields_
);
}
/// @brief Return option data type.
///
...
...
src/lib/dhcp/option_space.h
View file @
efcbf029
...
...
@@ -21,6 +21,9 @@
#include <stdint.h>
#include <string>
#define DHCP4_OPTION_SPACE "dhcp4"
#define DHCP6_OPTION_SPACE "dhcp6"
namespace
isc
{
namespace
dhcp
{
...
...
src/lib/dhcp/tests/option_definition_unittest.cc
View file @
efcbf029
...
...
@@ -47,6 +47,7 @@ class OptionDefinitionTest : public ::testing::Test {
public:
// @brief Constructor.
OptionDefinitionTest
()
{
}
};
// The purpose of this test is to verify that OptionDefinition
...
...
@@ -115,6 +116,99 @@ TEST_F(OptionDefinitionTest, constructor) {
);
}
// This test checks that the copy constructor works properly.
TEST_F
(
OptionDefinitionTest
,
copyConstructor
)
{
OptionDefinition
opt_def
(
"option-foo"
,
27
,
"record"
,
true
);
ASSERT_NO_THROW
(
opt_def
.
addRecordField
(
"uint16"
));
ASSERT_NO_THROW
(
opt_def
.
addRecordField
(
"string"
));
OptionDefinition
opt_def_copy
(
opt_def
);
EXPECT_EQ
(
"option-foo"
,
opt_def_copy
.
getName
());
EXPECT_EQ
(
27
,
opt_def_copy
.
getCode
());
EXPECT_TRUE
(
opt_def_copy
.
getArrayType
());
EXPECT_TRUE
(
opt_def_copy
.
getEncapsulatedSpace
().
empty
());
ASSERT_EQ
(
OPT_RECORD_TYPE
,
opt_def_copy
.
getType
());
const
OptionDefinition
::
RecordFieldsCollection
fields
=
opt_def_copy
.
getRecordFields
();
ASSERT_EQ
(
2
,
fields
.
size
());
EXPECT_EQ
(
OPT_UINT16_TYPE
,
fields
[
0
]);
EXPECT_EQ
(
OPT_STRING_TYPE
,
fields
[
1
]);
// Let's make anothe