Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
00eee13b
Commit
00eee13b
authored
Nov 29, 2012
by
Tomek Mrugalski
🛰
Browse files
[2325] Pkt6::getOptions() implemented.
parent
7793f98f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcp/pkt6.cc
View file @
00eee13b
...
...
@@ -81,13 +81,6 @@ Pkt6::pack() {
bool
Pkt6
::
packUDP
()
{
// TODO: Once OutputBuffer is used here, some thing like this
// will be used. Yikes! That's ugly.
// bufferOut_.writeData(ciaddr_.getAddress().to_v6().to_bytes().data(), 16);
// It is better to implement a method in IOAddress that extracts
// vector<uint8_t>
try
{
// DHCPv6 header: message-type (1 octect) + transaction id (3 octets)
bufferOut_
.
writeUint8
(
msg_type_
);
...
...
@@ -172,17 +165,30 @@ Pkt6::toText() {
return
tmp
.
str
();
}
boost
::
shared_ptr
<
isc
::
dhcp
::
Option
>
Option
Ptr
Pkt6
::
getOption
(
uint16_t
opt_type
)
{
isc
::
dhcp
::
Option
::
OptionCollection
::
const_iterator
x
=
options_
.
find
(
opt_type
);
if
(
x
!=
options_
.
end
())
{
return
(
*
x
).
second
;
}
return
boost
::
shared_ptr
<
isc
::
dhcp
::
Option
>
();
// NULL
return
OptionPtr
();
// NULL
}
isc
::
dhcp
::
Option
::
OptionCollection
Pkt6
::
getOptions
(
uint16_t
opt_type
)
{
isc
::
dhcp
::
Option
::
OptionCollection
found
;
for
(
Option
::
OptionCollection
::
const_iterator
x
=
options_
.
begin
();
x
!=
options_
.
end
();
++
x
)
{
if
(
x
->
first
==
opt_type
)
{
found
.
insert
(
make_pair
(
opt_type
,
x
->
second
));
}
}
return
(
found
);
}
void
Pkt6
::
addOption
(
boost
::
shared_ptr
<
Option
>
opt
)
{
Pkt6
::
addOption
(
const
Option
Ptr
&
opt
)
{
options_
.
insert
(
pair
<
int
,
boost
::
shared_ptr
<
Option
>
>
(
opt
->
getType
(),
opt
));
}
...
...
src/lib/dhcp/pkt6.h
View file @
00eee13b
...
...
@@ -147,19 +147,28 @@ public:
/// Adds an option to this packet.
///
/// @param opt option to be added.
void
addOption
(
OptionPtr
opt
);
void
addOption
(
const
OptionPtr
&
opt
);
/// @brief Returns the first option of specified type.
///
/// Returns the first option of specified type. Note that in DHCPv6 several
/// instances of the same option are allowed (and frequently used).
///
See
getOptions().
///
Also see \ref
getOptions().
///
/// @param type option type we are looking for
///
/// @return pointer to found option (or NULL)
OptionPtr
getOption
(
uint16_t
type
);
/// @brief Returns all instances of specified type.
///
/// Returns all instances of options of the specified type. DHCPv6 protocol
/// allows (and uses frequently) multiple instances.
///
/// @param type option type we are looking for
/// @return instance of option collection with requested options
isc
::
dhcp
::
Option
::
OptionCollection
getOptions
(
uint16_t
type
);
/// Attempts to delete first suboption of requested type
///
/// @param type Type of option to be deleted.
...
...
@@ -246,8 +255,6 @@ public:
/// @return interface name
void
setIface
(
const
std
::
string
&
iface
)
{
iface_
=
iface
;
};
/// TODO Need to implement getOptions() as well
/// collection of options present in this message
///
/// @warning This protected member is accessed by derived
...
...
src/lib/dhcp/tests/pkt6_unittest.cc
View file @
00eee13b
...
...
@@ -170,6 +170,8 @@ TEST_F(Pkt6Test, packUnpack) {
delete
clone
;
}
// This test verifies that options can be added (addOption()), retrieved
// (getOption(), getOptions()) and deleted (delOption()).
TEST_F
(
Pkt6Test
,
addGetDelOptions
)
{
Pkt6
*
parent
=
new
Pkt6
(
DHCPV6_SOLICIT
,
random
()
);
...
...
@@ -190,6 +192,25 @@ TEST_F(Pkt6Test, addGetDelOptions) {
// now there are 2 options of type 2
parent
->
addOption
(
opt3
);
Option
::
OptionCollection
options
=
parent
->
getOptions
(
2
);
EXPECT_EQ
(
2
,
options
.
size
());
// there should be 2 instances
// both options must be of type 2 and there must not be
// any other type returned
for
(
Option
::
OptionCollection
::
const_iterator
x
=
options
.
begin
();
x
!=
options
.
end
();
++
x
)
{
EXPECT_EQ
(
2
,
x
->
second
->
getType
());
}
// Try to get a single option. Normally for singular options
// it is better to use getOption(), but getOptions() must work
// as well
options
=
parent
->
getOptions
(
1
);
ASSERT_EQ
(
1
,
options
.
size
());
EXPECT_EQ
(
1
,
(
*
options
.
begin
()).
second
->
getType
());
EXPECT_EQ
(
opt1
,
options
.
begin
()
->
second
);
// let's delete one of them
EXPECT_EQ
(
true
,
parent
->
delOption
(
2
));
...
...
@@ -205,6 +226,10 @@ TEST_F(Pkt6Test, addGetDelOptions) {
// let's try to delete - should fail
EXPECT_TRUE
(
false
==
parent
->
delOption
(
2
));
// Finally try to get a non-existent option
options
=
parent
->
getOptions
(
1234
);
EXPECT_EQ
(
0
,
options
.
size
());
delete
parent
;
}
...
...
Write
Preview
Supports
Markdown
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