Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
0fe0d44a
Commit
0fe0d44a
authored
Jan 03, 2013
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2315] Added routine to get the single option for the space and code.
parent
5530bff2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
1 deletion
+51
-1
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/subnet.cc
+16
-0
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/subnet.h
+10
-1
src/lib/dhcpsrv/tests/subnet_unittest.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc
+25
-0
No files found.
src/lib/dhcpsrv/subnet.cc
View file @
0fe0d44a
...
...
@@ -85,6 +85,22 @@ Subnet::getOptions(const std::string& option_space) const {
return
(
options
->
second
);
}
Subnet
::
OptionDescriptor
Subnet
::
getOptionSingle
(
const
std
::
string
&
option_space
,
const
uint16_t
option_code
)
{
const
OptionContainer
&
options
=
getOptions
(
option_space
);
if
(
options
.
empty
())
{
return
(
OptionDescriptor
(
false
));
}
const
OptionContainerTypeIndex
&
idx
=
options
.
get
<
1
>
();
const
OptionContainerTypeRange
&
range
=
idx
.
equal_range
(
option_code
);
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
==
0
)
{
return
(
OptionDescriptor
(
false
));
}
return
(
*
range
.
first
);
}
std
::
string
Subnet
::
toText
()
const
{
std
::
stringstream
tmp
;
tmp
<<
prefix_
.
toText
()
<<
"/"
<<
static_cast
<
unsigned
int
>
(
prefix_len_
);
...
...
src/lib/dhcpsrv/subnet.h
View file @
0fe0d44a
...
...
@@ -264,7 +264,7 @@ public:
return
(
t2_
);
}
/// @brief Return a collection of options.
/// @brief Return a collection of option
descriptor
s.
///
/// @param option_space name of the option space
///
...
...
@@ -273,6 +273,15 @@ public:
/// returned it still exists.
const
OptionContainer
&
getOptions
(
const
std
::
string
&
option_space
)
const
;
/// @brief Return single option descriptor.
///
/// @param option_space name of the option space.
///
/// @return option descriptor found for the specified option space
/// and option code.
OptionDescriptor
getOptionSingle
(
const
std
::
string
&
option_space
,
const
uint16_t
option_code
);
/// @brief returns the last address that was tried from this pool
///
/// This method returns the last address that was attempted to be allocated
...
...
src/lib/dhcpsrv/tests/subnet_unittest.cc
View file @
0fe0d44a
...
...
@@ -427,6 +427,31 @@ TEST(Subnet6Test, addPersistentOption) {
EXPECT_EQ
(
0
,
options
.
size
());
}
TEST
(
Subnet6Test
,
getOptionSingle
)
{
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8::"
),
56
,
1
,
2
,
3
,
4
));
// Add 10 options to a "dhcp6" option space in the subnet.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
OptionPtr
option
(
new
Option
(
Option
::
V6
,
code
,
OptionBuffer
(
10
,
0xFF
)));
ASSERT_NO_THROW
(
subnet
->
addOption
(
option
,
false
,
"dhcp6"
));
}
// Check that we can get each added option descriptor using
// individually.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
std
::
ostringstream
stream
;
// First, try the invalid option space name.
Subnet
::
OptionDescriptor
desc
=
subnet
->
getOptionSingle
(
"isc"
,
code
);
// Returned descriptor should contain NULL option ptr.
EXPECT_FALSE
(
desc
.
option
);
// Now, try the valid option space.
desc
=
subnet
->
getOptionSingle
(
"dhcp6"
,
code
);
// Test that the option code matches the expected code.
ASSERT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
code
,
desc
.
option
->
getType
());
}
}
// This test verifies that inRange() and inPool() methods work properly.
TEST
(
Subnet6Test
,
inRangeinPool
)
{
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8::"
),
32
,
1
,
2
,
3
,
4
));
...
...
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