Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
feb21c04
Commit
feb21c04
authored
Oct 21, 2014
by
Marcin Siodelski
Browse files
[3587] Use CfgSubnets4 object to obtain information about subnets.
parent
3e0307cc
Changes
18
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/dhcp4_srv.cc
View file @
feb21c04
...
...
@@ -29,6 +29,7 @@
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/callout_handle_store.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/subnet.h>
...
...
@@ -1539,47 +1540,17 @@ Subnet4Ptr
Dhcpv4Srv
::
selectSubnet
(
const
Pkt4Ptr
&
question
)
const
{
Subnet4Ptr
subnet
;
static
const
IOAddress
notset
(
"0.0.0.0"
);
static
const
IOAddress
bcast
(
"255.255.255.255"
);
// If a message is relayed, use the relay (giaddr) address to select subnet
// for the client. Note that this may result in exception if the value
// of hops does not correspond with the Giaddr. Such message is considered
// to be malformed anyway and the message will be dropped by the higher
// level functions.
if
(
question
->
isRelayed
())
{
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
question
->
getGiaddr
(),
question
->
classes_
,
true
);
// The message is not relayed so it is sent directly by a client. But
// the client may be renewing its lease and in such case it unicasts
// its message to the server. Note that the unicast Request bypasses
// relays and the client may be in a different network, so we can't
// use IP address on the local interface to get the subnet. Instead,
// we rely on the client's address to get the subnet.
}
else
if
((
question
->
getLocalAddr
()
!=
bcast
)
&&
(
question
->
getCiaddr
()
!=
notset
))
{
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
question
->
getCiaddr
(),
question
->
classes_
);
// Either renewing client or the client that sends DHCPINFORM
// must set the ciaddr. But apparently some clients don't do it,
// so if the client didn't include ciaddr we will use the source
// address.
}
else
if
((
question
->
getLocalAddr
()
!=
bcast
)
&&
(
question
->
getRemoteAddr
()
!=
notset
))
{
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
question
->
getRemoteAddr
(),
question
->
classes_
);
// The message has been received from a directly connected client
// and this client appears to have no address. The IPv4 address
// assigned to the interface on which this message has been received,
// will be used to determine the subnet suitable for the client.
}
else
{
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
question
->
getIface
(),
question
->
classes_
);
}
CfgSubnets4
::
Selector
selector
;
selector
.
ciaddr_
=
question
->
getCiaddr
();
selector
.
giaddr_
=
question
->
getGiaddr
();
selector
.
local_address_
=
question
->
getLocalAddr
();
selector
.
remote_address_
=
question
->
getRemoteAddr
();
selector
.
client_classes_
=
question
->
classes_
;
selector
.
iface_name_
=
question
->
getIface
();
CfgMgr
&
cfgmgr
=
CfgMgr
::
instance
();
subnet
=
cfgmgr
.
getCurrentCfg
()
->
getCfgSubnets4
()
->
get
(
selector
);
// Let's execute all callouts registered for subnet4_select
if
(
HooksManager
::
calloutsPresent
(
hook_index_subnet4_select_
))
{
...
...
@@ -1592,7 +1563,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) const {
callout_handle
->
setArgument
(
"query4"
,
question
);
callout_handle
->
setArgument
(
"subnet4"
,
subnet
);
callout_handle
->
setArgument
(
"subnet4collection"
,
CfgMgr
::
instance
().
getSubnets4
());
cfgmgr
.
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
());
// Call user (and server-side) callouts
HooksManager
::
callCallouts
(
hook_index_subnet4_select_
,
...
...
src/bin/dhcp4/json_config_parser.cc
View file @
feb21c04
...
...
@@ -138,7 +138,7 @@ public:
// subnet id is invalid (duplicate). Thus, we catch exceptions
// here to append a position in the configuration string.
try
{
isc
::
dhcp
::
CfgMgr
::
instance
().
addSubnet4
(
sub4ptr
);
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
add
(
sub4ptr
);
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
ex
.
what
()
<<
" ("
<<
subnet
->
getPosition
()
<<
")"
);
...
...
@@ -317,28 +317,16 @@ public:
///
/// @param subnets_list pointer to a list of IPv4 subnets
void
build
(
ConstElementPtr
subnets_list
)
{
// @todo: Implement more subtle reconfiguration than toss
// the old one and replace with the new one.
// remove old subnets
CfgMgr
::
instance
().
deleteSubnets4
();
BOOST_FOREACH
(
ConstElementPtr
subnet
,
subnets_list
->
listValue
())
{
ParserPtr
parser
(
new
Subnet4ConfigParser
(
"subnet"
));
parser
->
build
(
subnet
);
subnets_
.
push_back
(
parser
);
}
}
/// @brief commits subnets definitions.
///
/// Iterates over all Subnet4 parsers. Each parser contains definitions of
/// a single subnet and its parameters and commits each subnet separately.
/// Does nothing.
void
commit
()
{
BOOST_FOREACH
(
ParserPtr
subnet
,
subnets_
)
{
subnet
->
commit
();
}
}
/// @brief Returns Subnet4ListConfigParser object
...
...
@@ -347,10 +335,6 @@ public:
static
DhcpConfigParser
*
factory
(
const
std
::
string
&
param_name
)
{
return
(
new
Subnets4ListConfigParser
(
param_name
));
}
/// @brief collection of subnet parsers.
ParserCollection
subnets_
;
};
}
// anonymous namespace
...
...
@@ -545,10 +529,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// This operation should be exception safe but let's make sure.
if
(
!
rollback
)
{
try
{
if
(
subnet_parser
)
{
subnet_parser
->
commit
();
}
// No need to commit interface names as this is handled by the
// CfgMgr::commit() function.
...
...
@@ -582,7 +562,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
}
LOG_INFO
(
dhcp4_logger
,
DHCP4_CONFIG_COMPLETE
)
.
arg
(
CfgMgr
::
instance
().
get
Current
Cfg
()
->
.
arg
(
CfgMgr
::
instance
().
get
Staging
Cfg
()
->
getConfigSummary
(
SrvConfig
::
CFGSEL_ALL4
));
// Everything was fine. Configuration is successful.
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
feb21c04
...
...
@@ -28,6 +28,7 @@
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <hooks/hooks_manager.h>
...
...
@@ -235,8 +236,8 @@ public:
getOptionFromSubnet
(
const
IOAddress
&
subnet_address
,
const
uint16_t
option_code
,
const
uint16_t
expected_options_count
=
1
)
{
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
subnet_address
,
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
subnet_address
);
if
(
!
subnet
)
{
/// @todo replace toText() with the use of operator <<.
ADD_FAILURE
()
<<
"A subnet for the specified address "
...
...
@@ -397,6 +398,7 @@ public:
/// latter case, a failure will have been added to the current test.
bool
executeConfiguration
(
const
std
::
string
&
config
,
const
char
*
operation
)
{
CfgMgr
::
instance
().
clear
();
ConstElementPtr
status
;
try
{
ElementPtr
json
=
Element
::
fromJSON
(
config
);
...
...
@@ -532,8 +534,8 @@ TEST_F(Dhcp4ParserTest, unspecifiedRenewTimer) {
checkGlobalUint32
(
"rebind-timer"
,
2000
);
checkGlobalUint32
(
"valid-lifetime"
,
4000
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_TRUE
(
subnet
->
getT1
().
unspecified
());
EXPECT_FALSE
(
subnet
->
getT2
().
unspecified
());
...
...
@@ -566,8 +568,8 @@ TEST_F(Dhcp4ParserTest, unspecifiedRebindTimer) {
checkGlobalUint32
(
"renew-timer"
,
1000
);
checkGlobalUint32
(
"valid-lifetime"
,
4000
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_FALSE
(
subnet
->
getT1
().
unspecified
());
EXPECT_EQ
(
1000
,
subnet
->
getT1
());
...
...
@@ -601,8 +603,8 @@ TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
1000
,
subnet
->
getT1
());
EXPECT_EQ
(
2000
,
subnet
->
getT2
());
...
...
@@ -649,7 +651,10 @@ TEST_F(Dhcp4ParserTest, multipleSubnets) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
CfgMgr
::
instance
().
commit
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
4
,
subnets
->
size
());
// We expect 4 subnets
...
...
@@ -702,7 +707,10 @@ TEST_F(Dhcp4ParserTest, multipleSubnetsExplicitIDs) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
CfgMgr
::
instance
().
commit
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
4
,
subnets
->
size
());
// We expect 4 subnets
...
...
@@ -833,16 +841,19 @@ TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
4
,
subnets
->
size
());
// We expect 4 subnets
CfgMgr
::
instance
().
clear
();
// Do the reconfiguration (the last subnet is removed)
json
=
Element
::
fromJSON
(
config_first3
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
subnets
=
CfgMgr
::
instance
().
getS
ubnets4
();
subnets
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
3
,
subnets
->
size
());
// We expect 3 subnets now (4th is removed)
...
...
@@ -851,6 +862,8 @@ TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
EXPECT_EQ
(
2
,
subnets
->
at
(
1
)
->
getID
());
EXPECT_EQ
(
3
,
subnets
->
at
(
2
)
->
getID
());
CfgMgr
::
instance
().
clear
();
/// CASE 2: Configure 4 subnets, then reconfigure and remove one
/// from in between (not first, not last)
...
...
@@ -859,12 +872,14 @@ TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
CfgMgr
::
instance
().
clear
();
// Do reconfiguration
json
=
Element
::
fromJSON
(
config_second_removed
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
subnets
=
CfgMgr
::
instance
().
getS
ubnets4
();
subnets
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
3
,
subnets
->
size
());
// We expect 4 subnets
...
...
@@ -901,8 +916,8 @@ TEST_F(Dhcp4ParserTest, nextServerGlobal) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
"1.2.3.4"
,
subnet
->
getSiaddr
().
toText
());
}
...
...
@@ -931,8 +946,8 @@ TEST_F(Dhcp4ParserTest, nextServerSubnet) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
"1.2.3.4"
,
subnet
->
getSiaddr
().
toText
());
}
...
...
@@ -1022,8 +1037,8 @@ TEST_F(Dhcp4ParserTest, nextServerOverride) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
"1.2.3.4"
,
subnet
->
getSiaddr
().
toText
());
}
...
...
@@ -1061,6 +1076,8 @@ TEST_F(Dhcp4ParserTest, echoClientId) {
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json_false
));
ASSERT_FALSE
(
CfgMgr
::
instance
().
echoClientId
());
CfgMgr
::
instance
().
clear
();
// Now check that "true" configuration is really applied.
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json_true
));
ASSERT_TRUE
(
CfgMgr
::
instance
().
echoClientId
());
...
...
@@ -1093,8 +1110,8 @@ TEST_F(Dhcp4ParserTest, subnetLocal) {
// returned value should be 0 (configuration success)
checkResult
(
status
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
1
,
subnet
->
getT1
());
EXPECT_EQ
(
2
,
subnet
->
getT2
());
...
...
@@ -1131,7 +1148,8 @@ TEST_F(Dhcp4ParserTest, multiplePools) {
ASSERT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
status
,
0
);
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
2
,
subnets
->
size
());
// We expect 2 subnets
...
...
@@ -1204,8 +1222,8 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) {
// returned value must be 0 (configuration accepted)
checkResult
(
status
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
1000
,
subnet
->
getT1
());
EXPECT_EQ
(
2000
,
subnet
->
getT2
());
...
...
@@ -1794,8 +1812,8 @@ TEST_F(Dhcp4ParserTest, optionDataDefaults) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
OptionContainerPtr
options
=
subnet
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
ASSERT_EQ
(
2
,
options
->
size
());
...
...
@@ -1880,8 +1898,8 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
checkResult
(
status
,
0
);
// Options should be now available for the subnet.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
// Try to get the option from the space dhcp4.
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
56
);
...
...
@@ -2034,8 +2052,8 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
checkResult
(
status
,
0
);
// Get the subnet.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
// We should have one option available.
...
...
@@ -2101,8 +2119,8 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.24"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.24"
)
);
ASSERT_TRUE
(
subnet
);
OptionContainerPtr
options
=
subnet
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
ASSERT_EQ
(
2
,
options
->
size
());
...
...
@@ -2252,8 +2270,8 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
Subnet4Ptr
subnet1
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.100"
),
classify_
);
Subnet4Ptr
subnet1
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.100"
)
);
ASSERT_TRUE
(
subnet1
);
OptionContainerPtr
options1
=
subnet1
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options1
->
size
());
...
...
@@ -2277,8 +2295,8 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
testOption
(
*
range1
.
first
,
56
,
foo_expected
,
sizeof
(
foo_expected
));
// Test another subnet in the same way.
Subnet4Ptr
subnet2
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.3.102"
),
classify_
);
Subnet4Ptr
subnet2
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.3.102"
)
);
ASSERT_TRUE
(
subnet2
);
OptionContainerPtr
options2
=
subnet2
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options2
->
size
());
...
...
@@ -2355,8 +2373,8 @@ TEST_F(Dhcp4ParserTest, optionDataLowerCase) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
OptionContainerPtr
options
=
subnet
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options
->
size
());
...
...
@@ -2398,8 +2416,8 @@ TEST_F(Dhcp4ParserTest, stdOptionData) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
OptionContainerPtr
options
=
subnet
->
getCfgOption
()
->
getAll
(
"dhcp4"
);
...
...
@@ -2606,8 +2624,8 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
checkResult
(
status
,
0
);
// Get the subnet.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
// We should have one option available.
...
...
@@ -2690,8 +2708,8 @@ TEST_F(Dhcp4ParserTest, vendorOptionsHex) {
checkResult
(
status
,
0
);
// Options should be now available for the subnet.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
...
...
@@ -2751,8 +2769,8 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
checkResult
(
status
,
0
);
// Options should be now available for the subnet.
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.5"
)
);
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
...
...
@@ -3127,8 +3145,8 @@ TEST_F(Dhcp4ParserTest, subnetRelayInfo) {
// returned value should be 0 (configuration success)
checkResult
(
status
,
0
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
ubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getS
tagingCfg
()
->
getCfgSubnets4
()
->
get
(
IOAddress
(
"192.0.2.200"
)
);
ASSERT_TRUE
(
subnet
);
EXPECT_EQ
(
"192.0.2.123"
,
subnet
->
getRelayInfo
().
addr_
.
toText
());
}
...
...
@@ -3166,7 +3184,8 @@ TEST_F(Dhcp4ParserTest, classifySubnets) {
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_TRUE
(
subnets
);
ASSERT_EQ
(
4
,
subnets
->
size
());
// We expect 4 subnets
...
...
src/bin/dhcp4/tests/d2_unittest.cc
View file @
feb21c04
...
...
@@ -127,6 +127,8 @@ Dhcp4SrvD2Test::configure(const std::string& config, bool exp_result) {
ElementPtr
json
=
Element
::
fromJSON
(
config
);
ConstElementPtr
status
;
CfgMgr
::
instance
().
clear
();
// Configure the server and make sure the config is accepted
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
srv_
,
json
));
ASSERT_TRUE
(
status
);
...
...
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
View file @
feb21c04
...
...
@@ -553,8 +553,9 @@ TEST_F(Dhcpv4SrvTest, DiscoverNoTimers) {
pool_
=
Pool4Ptr
(
new
Pool4
(
IOAddress
(
"192.0.2.100"
),
IOAddress
(
"192.0.2.110"
)));
subnet_
->
addPool
(
pool_
);
CfgMgr
::
instance
().
deleteSubnets4
();
CfgMgr
::
instance
().
addSubnet4
(
subnet_
);
CfgMgr
::
instance
().
clear
();
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
add
(
subnet_
);
CfgMgr
::
instance
().
commit
();
// Pass it to the server and get an offer
Pkt4Ptr
offer
=
srv
->
processDiscover
(
dis
);
...
...
@@ -741,8 +742,9 @@ TEST_F(Dhcpv4SrvTest, RequestNoTimers) {
pool_
=
Pool4Ptr
(
new
Pool4
(
IOAddress
(
"192.0.2.100"
),
IOAddress
(
"192.0.2.110"
)));
subnet_
->
addPool
(
pool_
);
CfgMgr
::
instance
().
deleteSubnets4
();
CfgMgr
::
instance
().
addSubnet4
(
subnet_
);
CfgMgr
::
instance
().
clear
();
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
add
(
subnet_
);
CfgMgr
::
instance
().
commit
();
// Pass it to the server and get an ACK.
Pkt4Ptr
ack
=
srv
->
processRequest
(
req
);
...
...
@@ -1207,6 +1209,8 @@ TEST_F(Dhcpv4SrvTest, vendorOptionsDocsis) {
comment_
=
config
::
parseAnswer
(
rcode_
,
status
);
ASSERT_EQ
(
0
,
rcode_
);
CfgMgr
::
instance
().
commit
();
// Let's create a relayed DISCOVER. This particular relayed DISCOVER has
// added option 82 (relay agent info) with 3 suboptions. The server
// is supposed to echo it back in its response.
...
...
@@ -1448,6 +1452,8 @@ TEST_F(Dhcpv4SrvTest, nextServerOverride) {
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
srv
,
json
));
CfgMgr
::
instance
().
commit
();
// check if returned status is OK
ASSERT_TRUE
(
status
);
comment_
=
config
::
parseAnswer
(
rcode_
,
status
);
...
...
@@ -1492,6 +1498,8 @@ TEST_F(Dhcpv4SrvTest, nextServerGlobal) {
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
srv
,
json
));
CfgMgr
::
instance
().
commit
();
// check if returned status is OK
ASSERT_TRUE
(
status
);
comment_
=
config
::
parseAnswer
(
rcode_
,
status
);
...
...
@@ -2513,7 +2521,8 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
// Check that pkt4 argument passing was successful and returned proper value
EXPECT_TRUE
(
callback_pkt4_
.
get
()
==
sol
.
get
());
const
Subnet4Collection
*
exp_subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
exp_subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
// The server is supposed to pick the first subnet, because of matching
// interface. Check that the value is reported properly.
...
...
@@ -2562,6 +2571,8 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
comment_
=
config
::
parseAnswer
(
rcode_
,
status
);
ASSERT_EQ
(
0
,
rcode_
);
CfgMgr
::
instance
().
commit
();
// Prepare discover packet. Server should select first subnet for it
Pkt4Ptr
sol
=
Pkt4Ptr
(
new
Pkt4
(
DHCPDISCOVER
,
1234
));
sol
->
setRemoteAddr
(
IOAddress
(
"192.0.2.1"
));
...
...
@@ -2580,7 +2591,8 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
EXPECT_NE
(
"0.0.0.0"
,
addr
.
toText
());
// Get all subnets and use second subnet for verification
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_EQ
(
2
,
subnets
->
size
());
// Advertised address must belong to the second pool (in subnet's range,
...
...
@@ -2979,6 +2991,8 @@ TEST_F(Dhcpv4SrvTest, vendorOptionsORO) {
comment_
=
isc
::
config
::
parseAnswer
(
rcode_
,
x
);
ASSERT_EQ
(
0
,
rcode_
);
CfgMgr
::
instance
().
commit
();
boost
::
shared_ptr
<
Pkt4
>
dis
(
new
Pkt4
(
DHCPDISCOVER
,
1234
));
// Set the giaddr and hops to non-zero address as if it was relayed.
dis
->
setGiaddr
(
IOAddress
(
"192.0.2.1"
));
...
...
@@ -3195,7 +3209,8 @@ TEST_F(Dhcpv4SrvTest, relayOverride) {
ASSERT_NO_THROW
(
configure
(
config
));
// Let's get the subnet configuration objects
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_EQ
(
2
,
subnets
->
size
());
// Let's get them for easy reference
...
...
@@ -3270,7 +3285,8 @@ TEST_F(Dhcpv4SrvTest, relayOverrideAndClientClass) {
// Use this config to set up the server
ASSERT_NO_THROW
(
configure
(
config
));
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getSubnets4
();
const
Subnet4Collection
*
subnets
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets4
()
->
getAll
();
ASSERT_EQ
(
2
,
subnets
->
size
());
// Let's get them for easy reference
...
...
src/bin/dhcp4/tests/dhcp4_test_utils.cc
View file @
feb21c04
...
...
@@ -45,14 +45,14 @@ Dhcpv4SrvTest::Dhcpv4SrvTest()
pool_
=
Pool4Ptr
(
new
Pool4
(
IOAddress
(
"192.0.2.100"
),
IOAddress
(
"192.0.2.110"
)));
subnet_
->
addPool
(
pool_
);