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
159af7d5
Commit
159af7d5
authored
Nov 29, 2012
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2325] Option::equal() method implemented.
parent
00eee13b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
3 deletions
+43
-3
src/lib/dhcp/option.cc
src/lib/dhcp/option.cc
+4
-0
src/lib/dhcp/option.h
src/lib/dhcp/option.h
+15
-2
src/lib/dhcp/tests/option_unittest.cc
src/lib/dhcp/tests/option_unittest.cc
+23
-0
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/subnet.h
+1
-1
No files found.
src/lib/dhcp/option.cc
View file @
159af7d5
...
...
@@ -314,6 +314,10 @@ void Option::setData(const OptionBufferConstIter first,
std
::
copy
(
first
,
last
,
data_
.
begin
());
}
bool
Option
::
equal
(
const
OptionPtr
&
other
)
const
{
return
(
(
getType
()
==
other
->
getType
())
&&
(
getData
()
==
other
->
getData
())
);
}
Option
::~
Option
()
{
...
...
src/lib/dhcp/option.h
View file @
159af7d5
...
...
@@ -197,7 +197,7 @@ public:
/// Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
///
/// @return option type
uint16_t
getType
()
{
return
(
type_
);
}
uint16_t
getType
()
const
{
return
(
type_
);
}
/// Returns length of the complete option (data length + DHCPv4/DHCPv6
/// option header)
...
...
@@ -219,7 +219,7 @@ public:
///
/// @return pointer to actual data (or reference to an empty vector
/// if there is no data)
virtual
const
OptionBuffer
&
getData
()
{
return
(
data_
);
}
virtual
const
OptionBuffer
&
getData
()
const
{
return
(
data_
);
}
/// Adds a sub-option.
///
...
...
@@ -303,6 +303,19 @@ public:
/// just to force that every option has virtual dtor
virtual
~
Option
();
/// @brief Checks if two options are equal
///
/// Equality verifies option type and option content. Care should
/// be taken when using this method. Implementation for derived
/// classes should be provided when this method is expected to be
/// used. It is safe in general, as the first check (different types)
/// will detect differences between base Option and derived
/// objects.
///
/// @param other the other option
/// @return true if both options are equal
virtual
bool
equal
(
const
OptionPtr
&
other
)
const
;
protected:
/// Builds raw (over-wire) buffer of this option, including all
/// defined suboptions. Version for building DHCPv4 options.
...
...
src/lib/dhcp/tests/option_unittest.cc
View file @
159af7d5
...
...
@@ -524,4 +524,27 @@ TEST_F(OptionTest, setData) {
EXPECT_TRUE
(
0
==
memcmp
(
&
buf_
[
0
],
test_data
+
opt1
->
getHeaderLen
(),
buf_
.
size
()));
}
// This test verifies that options can be compared using equal() method.
TEST_F
(
OptionTest
,
equal
)
{
// five options with varying lengths
OptionPtr
opt1
(
new
Option
(
Option
::
V6
,
258
,
buf_
.
begin
(),
buf_
.
begin
()
+
1
));
OptionPtr
opt2
(
new
Option
(
Option
::
V6
,
258
,
buf_
.
begin
(),
buf_
.
begin
()
+
2
));
OptionPtr
opt3
(
new
Option
(
Option
::
V6
,
258
,
buf_
.
begin
(),
buf_
.
begin
()
+
3
));
// the same content as opt2, but different type
OptionPtr
opt4
(
new
Option
(
Option
::
V6
,
1
,
buf_
.
begin
(),
buf_
.
begin
()
+
2
));
// another instance with the same type and content as opt2
OptionPtr
opt5
(
new
Option
(
Option
::
V6
,
258
,
buf_
.
begin
(),
buf_
.
begin
()
+
2
));
EXPECT_TRUE
(
opt1
->
equal
(
opt1
));
EXPECT_FALSE
(
opt1
->
equal
(
opt2
));
EXPECT_FALSE
(
opt1
->
equal
(
opt3
));
EXPECT_FALSE
(
opt1
->
equal
(
opt4
));
EXPECT_TRUE
(
opt2
->
equal
(
opt5
));
}
}
src/lib/dhcpsrv/subnet.h
View file @
159af7d5
...
...
@@ -172,7 +172,7 @@ public:
// Use option type as the index key. The type is held
// in OptionPtr object so we have to call Option::getType
// to retrieve this key for each element.
boost
::
multi_index
::
mem_fun
<
boost
::
multi_index
::
const_
mem_fun
<
Option
,
uint16_t
,
&
Option
::
getType
...
...
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