Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
b34f147f
Commit
b34f147f
authored
Sep 22, 2014
by
Marcin Siodelski
Browse files
[3589] Added function to copy the options configuration.
parent
ed84b5a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/cfg_option.cc
View file @
b34f147f
...
...
@@ -100,8 +100,16 @@ void
CfgOption
::
merge
(
CfgOption
&
other
)
const
{
// Merge non-vendor options.
mergeInternal
(
options_
,
other
.
options_
);
// Merge vendor options.
mergeInternal
(
vendor_options_
,
other
.
vendor_options_
);
// Merge verndor options.
}
void
CfgOption
::
copy
(
CfgOption
&
other
)
const
{
// Create empty object and "merge" data to it.
CfgOption
new_cfg
;
merge
(
new_cfg
);
other
=
new_cfg
;
}
template
<
typename
Selector
>
...
...
src/lib/dhcpsrv/cfg_option.h
View file @
b34f147f
...
...
@@ -261,6 +261,13 @@ public:
/// @param [out] other Configuration object to merge to.
void
merge
(
CfgOption
&
other
)
const
;
/// @brief Copies this configuration to another configuration.
///
/// This method copies options configuration to another object.
///
/// @param [out] other An object to copy the configuration to.
void
copy
(
CfgOption
&
other
)
const
;
/// @brief Returns all options for the specified option space.
///
/// This method will not return vendor options, i.e. having option space
...
...
src/lib/dhcpsrv/tests/cfg_option_unittest.cc
View file @
b34f147f
...
...
@@ -199,6 +199,46 @@ TEST(CfgOption, merge) {
}
}
// This test verifies that the options configuration can be copied between
// objects.
TEST
(
CfgOptionTest
,
copy
)
{
CfgOption
cfg_src
;
// Add 10 options to the custom option space in the source configuration.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
OptionPtr
option
(
new
Option
(
Option
::
V6
,
code
,
OptionBuffer
(
1
,
0x01
)));
ASSERT_NO_THROW
(
cfg_src
.
add
(
option
,
false
,
"foo"
));
}
CfgOption
cfg_dst
;
// Add 20 options to the custom option space in destination configuration.
for
(
uint16_t
code
=
100
;
code
<
120
;
++
code
)
{
OptionPtr
option
(
new
Option
(
Option
::
V6
,
code
,
OptionBuffer
(
1
,
0xFF
)));
ASSERT_NO_THROW
(
cfg_dst
.
add
(
option
,
false
,
"isc"
));
}
// Copy entire configuration to the destination. This should override any
// existing data.
ASSERT_NO_THROW
(
cfg_src
.
copy
(
cfg_dst
));
// Validate options in the destination configuration.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
OptionDescriptor
desc
=
cfg_dst
.
get
(
"foo"
,
code
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_EQ
(
1
,
desc
.
option
->
getData
().
size
());
EXPECT_EQ
(
0x01
,
desc
.
option
->
getData
()[
0
]);
}
// Any existing options should be removed.
OptionContainerPtr
container
=
cfg_dst
.
getAll
(
"isc"
);
ASSERT_TRUE
(
container
);
EXPECT_TRUE
(
container
->
empty
());
// The option space "foo" should contain exactly 10 options.
container
=
cfg_dst
.
getAll
(
"foo"
);
ASSERT_TRUE
(
container
);
EXPECT_EQ
(
10
,
container
->
size
());
}
// This test verifies that single option can be retrieved from the configuration
// using option code and option space.
TEST
(
CfgOption
,
get
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment