Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
415
Issues
415
List
Boards
Labels
Service Desk
Milestones
Merge Requests
67
Merge Requests
67
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
338d7d58
Commit
338d7d58
authored
Nov 15, 2013
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2940] Implemented Lease6::getDuidVector function and remove key extractors
parent
3328fb38
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
24 deletions
+62
-24
src/lib/dhcp/duid.cc
src/lib/dhcp/duid.cc
+1
-1
src/lib/dhcp/duid.h
src/lib/dhcp/duid.h
+9
-6
src/lib/dhcpsrv/lease.cc
src/lib/dhcpsrv/lease.cc
+10
-0
src/lib/dhcpsrv/lease.h
src/lib/dhcpsrv/lease.h
+10
-0
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.h
+8
-15
src/lib/dhcpsrv/tests/lease_unittest.cc
src/lib/dhcpsrv/tests/lease_unittest.cc
+24
-2
No files found.
src/lib/dhcp/duid.cc
View file @
338d7d58
...
...
@@ -46,7 +46,7 @@ DUID::DUID(const uint8_t* data, size_t len) {
duid_
=
std
::
vector
<
uint8_t
>
(
data
,
data
+
len
);
}
std
::
vector
<
uint8_t
>
DUID
::
getDuid
()
const
{
const
std
::
vector
<
uint8_t
>&
DUID
::
getDuid
()
const
{
return
(
duid_
);
}
...
...
src/lib/dhcp/duid.h
View file @
338d7d58
...
...
@@ -58,12 +58,13 @@ class DUID {
/// @brief Returns a const reference to the actual DUID value
///
/// Note: For safety reasons, this method returns a copy of data as
/// otherwise the reference would be only valid as long as the object that
/// returned it. In any case, this method should be used only sporadically.
/// If there are frequent uses, we must implement some other method
/// (e.g. storeSelf()) that will avoid data copying.
std
::
vector
<
uint8_t
>
getDuid
()
const
;
/// @warning Since this function returns a reference to the vector (not a
/// copy) the returned object must be used with caution because it remains
/// valid only for the time period when the object which returned it is
/// valid.
///
/// @return A reference to a vector holding a DUID.
const
std
::
vector
<
uint8_t
>&
getDuid
()
const
;
/// @brief Returns the DUID type
DUIDType
getType
()
const
;
...
...
@@ -122,6 +123,8 @@ public:
/// copy) the returned object must be used with caution because it remains
/// valid only for the time period when the object which returned it is
/// valid.
///
/// @return A reference to a vector holding a client identifier.
const
std
::
vector
<
uint8_t
>&
getClientId
()
const
;
/// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
...
...
src/lib/dhcpsrv/lease.cc
View file @
338d7d58
...
...
@@ -139,6 +139,16 @@ Lease6::Lease6(Type type, const isc::asiolink::IOAddress& addr,
cltt_
=
time
(
NULL
);
}
const
std
::
vector
<
uint8_t
>&
Lease6
::
getDuidVector
()
const
{
if
(
!
duid_
)
{
static
std
::
vector
<
uint8_t
>
empty_vec
;
return
(
empty_vec
);
}
return
(
duid_
->
getDuid
());
}
std
::
string
Lease6
::
toText
()
const
{
ostringstream
stream
;
...
...
src/lib/dhcpsrv/lease.h
View file @
338d7d58
...
...
@@ -331,6 +331,16 @@ struct Lease6 : public Lease {
type_
(
TYPE_NA
)
{
}
/// @brief Returns a reference to a vector representing a DUID.
///
/// @warning Since the function returns the reference to a vector (not a
/// copy), the returned object should be used with caution because it will
/// remain valid only for the period of time when an object which returned
/// it exists.
///
/// @return A reference to a vector holding a DUID.
const
std
::
vector
<
uint8_t
>&
getDuidVector
()
const
;
/// @brief Compare two leases for equality
///
/// @param other lease6 object with which to compare
...
...
src/lib/dhcpsrv/memfile_lease_mgr.h
View file @
338d7d58
...
...
@@ -16,7 +16,6 @@
#define MEMFILE_LEASE_MGR_H
#include <dhcp/hwaddr.h>
#include <dhcpsrv/key_from_key.h>
#include <dhcpsrv/lease_mgr.h>
#include <boost/multi_index/indexed_by.hpp>
...
...
@@ -267,20 +266,10 @@ protected:
// the lease using three attributes: DUID, IAID, Subnet Id.
boost
::
multi_index
::
composite_key
<
Lease6
,
// The DUID value can't be directly accessed from the Lease6
// object because it is wrapped with the DUID object (actually
// pointer to this object). Therefore we need to use
// KeyFromKeyExtractor class to extract the DUID value from
// this cascaded structure.
KeyFromKeyExtractor
<
// The value of the DUID is accessed by the getDuid() method
// from the DUID object.
boost
::
multi_index
::
const_mem_fun
<
DUID
,
std
::
vector
<
uint8_t
>
,
&
DUID
::
getDuid
>
,
// The DUID object is stored in the duid_ member of the
// Lease6 object.
boost
::
multi_index
::
member
<
Lease6
,
DuidPtr
,
&
Lease6
::
duid_
>
>
,
// The DUID can be retrieved from the Lease6 object using
// a getDuidVector const function.
boost
::
multi_index
::
const_mem_fun
<
Lease6
,
const
std
::
vector
<
uint8_t
>&
,
&
Lease6
::
getDuidVector
>
,
// The two other ingredients of this index are IAID and
// subnet id.
boost
::
multi_index
::
member
<
Lease6
,
uint32_t
,
&
Lease6
::
iaid_
>
,
...
...
@@ -330,6 +319,8 @@ protected:
// lease: client id and subnet id.
boost
::
multi_index
::
composite_key
<
Lease4
,
// The client id can be retrieved from the Lease4 object by
// calling getClientIdVector const function.
boost
::
multi_index
::
const_mem_fun
<
Lease4
,
const
std
::
vector
<
uint8_t
>&
,
&
Lease4
::
getClientIdVector
>
,
// The subnet id is accessed through the subnet_id_ member.
...
...
@@ -343,6 +334,8 @@ protected:
// lease: client id and subnet id.
boost
::
multi_index
::
composite_key
<
Lease4
,
// The client id can be retrieved from the Lease4 object by
// calling getClientIdVector const function.
boost
::
multi_index
::
const_mem_fun
<
Lease4
,
const
std
::
vector
<
uint8_t
>&
,
&
Lease4
::
getClientIdVector
>
,
// The hardware address is held in the hwaddr_ member of the
...
...
src/lib/dhcpsrv/tests/lease_unittest.cc
View file @
338d7d58
...
...
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <dhcp/duid.h>
#include <dhcpsrv/lease.h>
#include <gtest/gtest.h>
#include <vector>
...
...
@@ -22,8 +23,9 @@ using namespace isc::dhcp;
namespace
{
// @todo Currently this file contains a single test. Other tests for Lease
// objects must be implemented. See http://bind10.isc.org/ticket/3240.
// @todo Currently this file contains tests for new functions which return DUID
// or client identifier. Other tests for Lease objects must be implemented.
// See http://bind10.isc.org/ticket/3240.
// Verify that the client id can be returned as a vector object and if client
// id is NULL the empty vector is returned.
...
...
@@ -45,5 +47,25 @@ TEST(Lease4Test, getClientIdVector) {
EXPECT_TRUE
(
returned_vec
==
client_id_vec
);
}
// Verify that the DUID can be returned as a vector object and if DUID is NULL
// the empty vector is returned.
TEST
(
Lease6Test
,
getDuidVector
)
{
// Create a lease.
Lease6
lease
;
// By default, the lease should have client id set to NULL. If it doesn't,
// continuing the test makes no sense.
ASSERT_FALSE
(
lease
.
duid_
);
// When client id is NULL the vector returned should be empty.
EXPECT_TRUE
(
lease
.
getDuidVector
().
empty
());
// Now, let's set the non NULL DUID. Fill it with the 8 bytes, each
// holding a value of 0x42.
std
::
vector
<
uint8_t
>
duid_vec
(
8
,
0x42
);
lease
.
duid_
=
DuidPtr
(
new
DUID
(
duid_vec
));
// Check that the returned vector, encapsulating DUID is equal to
// the one that has been used to set the DUID for the lease.
std
::
vector
<
uint8_t
>
returned_vec
=
lease
.
getDuidVector
();
EXPECT_TRUE
(
returned_vec
==
duid_vec
);
}
};
// end of anonymous namespace
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