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
448015b0
Commit
448015b0
authored
Oct 17, 2015
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3978] Cleaned up code
parent
c5ac0457
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
40 deletions
+54
-40
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
+2
-0
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/ctrl_dhcp4_srv.h
+1
-0
src/bin/dhcp4/kea_controller.cc
src/bin/dhcp4/kea_controller.cc
+4
-4
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
+4
-0
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
+3
-0
src/bin/dhcp6/ctrl_dhcp6_srv.h
src/bin/dhcp6/ctrl_dhcp6_srv.h
+1
-0
src/bin/dhcp6/kea_controller.cc
src/bin/dhcp6/kea_controller.cc
+4
-4
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
+35
-32
No files found.
src/bin/dhcp4/ctrl_dhcp4_srv.cc
View file @
448015b0
...
...
@@ -106,6 +106,8 @@ ControlledDhcpv4Srv::processCommand(const string& command,
}
else
if
(
command
==
"config-reload"
)
{
return
(
srv
->
commandConfigReloadHandler
(
command
,
args
));
}
else
if
(
command
==
"leases-reclaim"
)
{
return
(
srv
->
commandLeasesReclaimHandler
(
command
,
args
));
}
ConstElementPtr
answer
=
isc
::
config
::
createAnswer
(
1
,
"Unrecognized command:"
+
command
);
...
...
src/bin/dhcp4/ctrl_dhcp4_srv.h
View file @
448015b0
...
...
@@ -70,6 +70,7 @@ public:
/// - shutdown
/// - libreload
/// - config-reload
/// - leases-reclaim
///
/// @note It never throws.
///
...
...
src/bin/dhcp4/kea_controller.cc
View file @
448015b0
...
...
@@ -69,11 +69,11 @@ void configure(const std::string& file_name) {
// works only for map.
if
(
json
->
getType
()
!=
isc
::
data
::
Element
::
map
)
{
isc_throw
(
isc
::
BadValue
,
"Configuration file is expected to be "
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp4' that itself is a map. "
<<
file_name
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp4' that itself is a map. "
<<
file_name
<<
" is a valid JSON, but its top element is not a map."
" Did you forget to add { } around your configuration?"
);
" Did you forget to add { } around your configuration?"
);
}
// If there's no logging element, we'll just pass NULL pointer,
...
...
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
View file @
448015b0
...
...
@@ -22,6 +22,7 @@
#include <dhcpsrv/lease.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <testutils/unix_control_client.h>
#include "marker_file.h"
...
...
@@ -45,6 +46,7 @@ using namespace isc::data;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
using
namespace
isc
::
hooks
;
using
namespace
isc
::
stats
;
namespace
{
...
...
@@ -82,6 +84,8 @@ public:
/// @brief Destructor
~
CtrlChannelDhcpv4SrvTest
()
{
LeaseMgrFactory
::
destroy
();
StatsMgr
::
instance
().
removeAll
();
server_
.
reset
();
reset
();
};
...
...
src/bin/dhcp6/ctrl_dhcp6_srv.cc
View file @
448015b0
...
...
@@ -103,6 +103,9 @@ ControlledDhcpv6Srv::processCommand(const std::string& command,
}
else
if
(
command
==
"config-reload"
)
{
return
(
srv
->
commandConfigReloadHandler
(
command
,
args
));
}
else
if
(
command
==
"leases-reclaim"
)
{
return
(
srv
->
commandLeasesReclaimHandler
(
command
,
args
));
}
return
(
isc
::
config
::
createAnswer
(
1
,
"Unrecognized command:"
...
...
src/bin/dhcp6/ctrl_dhcp6_srv.h
View file @
448015b0
...
...
@@ -70,6 +70,7 @@ public:
/// - shutdown
/// - libreload
/// - config-reload
/// - leases-reclaim
///
/// @note It never throws.
///
...
...
src/bin/dhcp6/kea_controller.cc
View file @
448015b0
...
...
@@ -73,11 +73,11 @@ void configure(const std::string& file_name) {
// works only for map.
if
(
json
->
getType
()
!=
isc
::
data
::
Element
::
map
)
{
isc_throw
(
isc
::
BadValue
,
"Configuration file is expected to be "
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp6' that itself is a map. "
<<
file_name
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp6' that itself is a map. "
<<
file_name
<<
" is a valid JSON, but its top element is not a map."
" Did you forget to add { } around your configuration?"
);
" Did you forget to add { } around your configuration?"
);
}
// Let's configure logging before applying the configuration,
...
...
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
View file @
448015b0
...
...
@@ -22,6 +22,7 @@
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <testutils/unix_control_client.h>
#include "marker_file.h"
...
...
@@ -41,6 +42,7 @@ using namespace isc::data;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
using
namespace
isc
::
hooks
;
using
namespace
isc
::
stats
;
namespace
{
...
...
@@ -63,6 +65,8 @@ public:
}
virtual
~
CtrlDhcpv6SrvTest
()
{
LeaseMgrFactory
::
destroy
();
StatsMgr
::
instance
().
removeAll
();
reset
();
};
...
...
@@ -415,6 +419,37 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelShutdown) {
EXPECT_EQ
(
"{
\"
result
\"
: 0,
\"
text
\"
:
\"
Shutting down.
\"
}"
,
response
);
}
// Thist test verifies that the DHCP server immediately reclaims expired
// leases on leases-reclaim command
TEST_F
(
CtrlChannelDhcpv6SrvTest
,
controlLeasesReclaim
)
{
createUnixChannelServer
();
// Create an expired lease. The lease is expired by 40 seconds ago
// (valid lifetime = 60, cltt = now - 100).
DuidPtr
duid_expired
(
new
DUID
(
DUID
::
fromText
(
"00:01:02:03:04:05:06"
).
getDuid
()));
Lease6Ptr
lease_expired
(
new
Lease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
),
duid_expired
,
1
,
50
,
60
,
10
,
20
,
SubnetID
(
1
)));
lease_expired
->
cltt_
=
time
(
NULL
)
-
100
;
// Add lease to the database.
LeaseMgr
&
lease_mgr
=
LeaseMgrFactory
().
instance
();
ASSERT_NO_THROW
(
lease_mgr
.
addLease
(
lease_expired
));
// Make sure it has been added.
ASSERT_TRUE
(
lease_mgr
.
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
)));
// Send the command.
std
::
string
response
;
sendUnixCommand
(
"{
\"
command
\"
:
\"
leases-reclaim
\"
}"
,
response
);
EXPECT_EQ
(
"{
\"
result
\"
: 0,
\"
text
\"
:
\"
Leases successfully reclaimed.
\"
}"
,
response
);
// Verify that the lease in the database has been processed as expected.
ASSERT_NO_THROW
(
lease_expired
=
lease_mgr
.
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
))
);
EXPECT_FALSE
(
lease_expired
);
}
// Tests that the server properly responds to statistics commands. Note this
// is really only intended to verify that the appropriate Statistics handler
// is called based on the command. It is not intended to be an exhaustive
...
...
@@ -461,36 +496,4 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
response
);
}
// Thist test verifies that the DHCP server immediately reclaims expired
// leases on leases-reclaim command
// @todo currently must be last as it changes statistics.
TEST_F
(
CtrlChannelDhcpv6SrvTest
,
controlLeasesReclaim
)
{
createUnixChannelServer
();
// Create an expired lease. The lease is expired by 40 seconds ago
// (valid lifetime = 60, cltt = now - 100).
DuidPtr
duid_expired
(
new
DUID
(
DUID
::
fromText
(
"00:01:02:03:04:05:06"
).
getDuid
()));
Lease6Ptr
lease_expired
(
new
Lease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
),
duid_expired
,
1
,
50
,
60
,
10
,
20
,
SubnetID
(
1
)));
lease_expired
->
cltt_
=
time
(
NULL
)
-
100
;
// Add lease to the database.
LeaseMgr
&
lease_mgr
=
LeaseMgrFactory
().
instance
();
ASSERT_NO_THROW
(
lease_mgr
.
addLease
(
lease_expired
));
// Make sure it has been added.
ASSERT_TRUE
(
lease_mgr
.
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
)));
// Send the command.
std
::
string
response
;
sendUnixCommand
(
"{
\"
command
\"
:
\"
leases-reclaim
\"
}"
,
response
);
EXPECT_EQ
(
"{
\"
result
\"
: 0,
\"
text
\"
:
\"
Leases successfully reclaimed.
\"
}"
,
response
);
// Verify that the lease in the database has been processed as expected.
ASSERT_NO_THROW
(
lease_expired
=
lease_mgr
.
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"3000::1"
))
);
EXPECT_FALSE
(
lease_expired
);
}
}
// 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