Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Adam Osuchowski
Kea
Commits
c924b233
Commit
c924b233
authored
Jan 09, 2013
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2317] Test configuration of option definition comprising a record.
parent
f000b6b5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
22 deletions
+55
-22
src/bin/dhcp4/config_parser.cc
src/bin/dhcp4/config_parser.cc
+4
-20
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
+51
-2
No files found.
src/bin/dhcp4/config_parser.cc
View file @
c924b233
...
...
@@ -1145,32 +1145,16 @@ public:
CfgMgr
&
cfg_mgr
=
CfgMgr
::
instance
();
cfg_mgr
.
deleteOptionDefs
();
// We need to move option definitions from the temporary
// storage to the global storage. However for new definition
// we need to check whether such a definition already exists
// or we are adding it for the fitsy time.
// storage to the global storage.
BOOST_FOREACH
(
std
::
string
space_name
,
option_defs_local_
.
getOptionSpaceNames
())
{
// For the particular option space we have to get all
// items in the temporary storage and store it in the
// global storage.
BOOST_FOREACH
(
OptionDefinitionPtr
def
,
*
option_defs_local_
.
getItems
(
space_name
))
{
assert
(
def
);
// For the particular option space get all definitions
// existing in the global storage.
OptionDefContainerPtr
global_defs
=
cfg_mgr
.
getOptionDefs
(
space_name
);
assert
(
global_defs
);
// Find the option definition for the particular
// option code.
OptionDefContainerTypeIndex
&
idx
=
global_defs
->
get
<
1
>
();
const
OptionDefContainerTypeRange
&
range
=
idx
.
equal_range
(
def
->
getCode
());
// If there is one in the global storage, erase it.
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
>
0
)
{
idx
.
erase
(
range
.
first
,
range
.
second
);
}
// Add the newly created option definition.
cfg_mgr
.
addOptionDef
(
def
,
space_name
);
}
}
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
c924b233
...
...
@@ -234,6 +234,7 @@ public:
"
\"
renew-timer
\"
: 1000, "
"
\"
valid-lifetime
\"
: 4000, "
"
\"
subnet4
\"
: [ ], "
"
\"
option-def
\"
: [ ], "
"
\"
option-data
\"
: [ ] }"
;
try
{
...
...
@@ -437,8 +438,8 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) {
}
// The goal of this test is to check whether an option definition
//
can be added to the dhcp4 option space
.
TEST_F
(
Dhcp4ParserTest
,
optionDef
Add
)
{
//
that defines an option carrying an IPv4 address can be created
.
TEST_F
(
Dhcp4ParserTest
,
optionDef
Ipv4Address
)
{
// Configuration string.
std
::
string
config
=
...
...
@@ -473,6 +474,54 @@ TEST_F(Dhcp4ParserTest, optionDefAdd) {
EXPECT_EQ
(
OPT_IPV4_ADDRESS_TYPE
,
def
->
getType
());
}
// The goal of this test is to check whether an option definiiton
// that defines an option carrying a record of data fields can
// be created.
TEST_F
(
Dhcp4ParserTest
,
optionDefRecord
)
{
// Configuration string.
std
::
string
config
=
"{
\"
option-def
\"
: [ {"
"
\"
name
\"
:
\"
foo
\"
,"
"
\"
code
\"
: 100,"
"
\"
type
\"
:
\"
record
\"
,"
"
\"
array
\"
: False,"
"
\"
record-types
\"
:
\"
uint16, ipv4-address, ipv6-address, string
\"
,"
"
\"
space
\"
:
\"
isc
\"
"
" } ]"
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
ASSERT_FALSE
(
def
);
// Use the configuration string to create new option definition.
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
ASSERT_TRUE
(
status
);
// The option definition should now be available in the CfgMgr.
def
=
CfgMgr
::
instance
().
getOptionDef
(
"isc"
,
100
);
ASSERT_TRUE
(
def
);
// Check the option data.
EXPECT_EQ
(
"foo"
,
def
->
getName
());
EXPECT_EQ
(
100
,
def
->
getCode
());
EXPECT_EQ
(
OPT_RECORD_TYPE
,
def
->
getType
());
EXPECT_FALSE
(
def
->
getArrayType
());
// The option comprises the record of data fields. Verify that all
// fields are present and they are of the expected types.
const
OptionDefinition
::
RecordFieldsCollection
&
record_fields
=
def
->
getRecordFields
();
ASSERT_EQ
(
4
,
record_fields
.
size
());
EXPECT_EQ
(
OPT_UINT16_TYPE
,
record_fields
[
0
]);
EXPECT_EQ
(
OPT_IPV4_ADDRESS_TYPE
,
record_fields
[
1
]);
EXPECT_EQ
(
OPT_IPV6_ADDRESS_TYPE
,
record_fields
[
2
]);
EXPECT_EQ
(
OPT_STRING_TYPE
,
record_fields
[
3
]);
}
// Goal of this test is to verify that global option
// data is configured for the subnet if the subnet
// configuration does not include options configuration.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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