Commit 7e66a9d1 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[5030] SubnetID a parameter of parse method rather than ctor.

parent 1bd9870c
......@@ -152,9 +152,8 @@ public:
// Parse Host Reservations for this subnet if any.
ConstElementPtr reservations = subnet->get("reservations");
if (reservations) {
HostReservationsListParser<HostReservationParser4>
parser(subnet_->getID());
parser.parse(reservations);
HostReservationsListParser<HostReservationParser4> parser;
parser.parse(subnet_->getID(), reservations);
}
}
......
......@@ -385,9 +385,8 @@ public:
// Parse Host Reservations for this subnet if any.
ConstElementPtr reservations = subnet->get("reservations");
if (reservations) {
HostReservationsListParser<HostReservationParser6>
parser(subnet_->getID());
parser.parse(reservations);
HostReservationsListParser<HostReservationParser6> parser;
parser.parse(subnet_->getID(), reservations);
}
}
}
......
......@@ -94,18 +94,15 @@ getSupportedParams6(const bool identifiers_only = false) {
namespace isc {
namespace dhcp {
HostReservationParser::HostReservationParser(const SubnetID& subnet_id)
: SimpleParser(), subnet_id_(subnet_id) {
}
void
HostReservationParser::parse(isc::data::ConstElementPtr reservation_data) {
parseInternal(reservation_data);
HostReservationParser::parse(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data) {
parseInternal(subnet_id, reservation_data);
}
void
HostReservationParser::parseInternal(isc::data::ConstElementPtr reservation_data) {
HostReservationParser::parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data) {
std::string identifier;
std::string identifier_name;
std::string hostname;
......@@ -186,15 +183,12 @@ HostReservationParser::isSupportedParameter(const std::string& param_name) const
return (getSupportedParameters(false).count(param_name) > 0);
}
HostReservationParser4::HostReservationParser4(const SubnetID& subnet_id)
: HostReservationParser(subnet_id) {
}
void
HostReservationParser4::parseInternal(isc::data::ConstElementPtr reservation_data) {
HostReservationParser::parseInternal(reservation_data);
HostReservationParser4::parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data) {
HostReservationParser::parseInternal(subnet_id, reservation_data);
host_->setIPv4SubnetID(subnet_id_);
host_->setIPv4SubnetID(subnet_id);
BOOST_FOREACH(ConfigPair element, reservation_data->mapValue()) {
// For 'option-data' element we will use another parser which
......@@ -248,15 +242,12 @@ HostReservationParser4::getSupportedParameters(const bool identifiers_only) cons
return (getSupportedParams4(identifiers_only));
}
HostReservationParser6::HostReservationParser6(const SubnetID& subnet_id)
: HostReservationParser(subnet_id) {
}
void
HostReservationParser6::parseInternal(isc::data::ConstElementPtr reservation_data) {
HostReservationParser::parseInternal(reservation_data);
HostReservationParser6::parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data) {
HostReservationParser::parseInternal(subnet_id, reservation_data);
host_->setIPv6SubnetID(subnet_id_);
host_->setIPv6SubnetID(subnet_id);
BOOST_FOREACH(ConfigPair element, reservation_data->mapValue()) {
// Parse option values. Note that the configuration option parser
......
......@@ -18,22 +18,19 @@ namespace dhcp {
class HostReservationParser : public isc::data::SimpleParser {
public:
/// @brief Constructor.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
explicit HostReservationParser(const SubnetID& subnet_id);
/// @brief Destructor.
virtual ~HostReservationParser() { }
/// @brief Parses a single entry for host reservation.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
/// @param reservation_data Data element holding map with a host
/// reservation configuration.
///
/// @throw DhcpConfigError If the configuration is invalid.
void parse(isc::data::ConstElementPtr reservation_data);
void parse(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data);
protected:
......@@ -42,11 +39,14 @@ protected:
/// This method is called by @ref parse and it can be overriden in the
/// derived classes to provide class specific parsing logic.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
/// @param reservation_data Data element holding map with a host
/// reservation configuration.
///
/// @throw DhcpConfigError If the configuration is invalid.
virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
virtual void parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data);
/// @brief Inserts @c host_ object to the staging configuration.
///
......@@ -84,9 +84,6 @@ protected:
virtual const std::set<std::string>&
getSupportedParameters(const bool identifiers_only) const = 0;
/// @brief Identifier of the subnet that the host is connected to.
SubnetID subnet_id_;
/// @brief Holds a pointer to @c Host object representing a parsed
/// host reservation configuration.
HostPtr host_;
......@@ -95,23 +92,18 @@ protected:
/// @brief Parser for a single host reservation for DHCPv4.
class HostReservationParser4 : public HostReservationParser {
public:
/// @brief Constructor.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
HostReservationParser4(const SubnetID& subnet_id);
protected:
/// @brief Parses a single host reservation for DHCPv4.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
/// @param reservation_data Data element holding map with a host
/// reservation configuration.
///
/// @throw DhcpConfigError If the configuration is invalid.
virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
virtual void parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data);
/// @brief Returns set of the supported parameters for DHCPv4.
///
......@@ -126,23 +118,18 @@ protected:
/// @brief Parser for a single host reservation for DHCPv6.
class HostReservationParser6 : public HostReservationParser {
public:
/// @brief Constructor.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
HostReservationParser6(const SubnetID& subnet_id);
protected:
/// @brief Parses a single host reservation for DHCPv6.
///
/// @param subnet_id Identifier of the subnet that the host is
/// connected to.
/// @param reservation_data Data element holding map with a host
/// reservation configuration.
///
/// @throw DhcpConfigError If the configuration is invalid.
virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
virtual void parseInternal(const SubnetID& subnet_id,
isc::data::ConstElementPtr reservation_data);
/// @brief Returns set of the supported parameters for DHCPv6.
///
......
......@@ -24,33 +24,21 @@ template<typename HostReservationParserType>
class HostReservationsListParser : public isc::data::SimpleParser {
public:
/// @brief Constructor.
/// @brief Parses a list of host reservation entries for a subnet.
///
/// @param subnet_id Identifier of the subnet to which the reservations
/// belong.
HostReservationsListParser(const SubnetID& subnet_id)
: subnet_id_(subnet_id) {
}
/// @brief Parses a list of host reservation entries for a subnet.
///
/// @param hr_list Data element holding a list of host reservations.
/// Each host reservation is described by a map object.
///
/// @throw DhcpConfigError If the configuration if any of the reservations
/// is invalid.
void parse(isc::data::ConstElementPtr hr_list) {
void parse(const SubnetID& subnet_id, isc::data::ConstElementPtr hr_list) {
BOOST_FOREACH(data::ConstElementPtr reservation, hr_list->listValue()) {
HostReservationParserType parser(subnet_id_);
parser.parse(reservation);
HostReservationParserType parser;
parser.parse(subnet_id, reservation);
}
}
private:
/// @brief Identifier of the subnet to whic the reservations belong.
SubnetID subnet_id_;
};
}
......
......@@ -116,8 +116,8 @@ protected:
ElementPtr config_element = Element::fromJSON(config);
ParserType parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
ParserType parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
// Retrieve a host.
HostCollection hosts;
......@@ -147,8 +147,8 @@ protected:
ElementPtr config_element = Element::fromJSON(config.str());
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -172,8 +172,8 @@ protected:
template<typename ParserType>
void testInvalidConfig(const std::string& config) const {
ElementPtr config_element = Element::fromJSON(config);
ParserType parser(SubnetID(10));
EXPECT_THROW(parser.parse(config_element), DhcpConfigError);
ParserType parser;
EXPECT_THROW(parser.parse(SubnetID(10), config_element), DhcpConfigError);
}
/// @brief HW Address object used by tests.
......@@ -286,8 +286,8 @@ TEST_F(HostReservationParserTest, dhcp4NoHostname) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -309,8 +309,8 @@ TEST_F(HostReservationParserTest, dhcp4ClientClasses) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -335,8 +335,8 @@ TEST_F(HostReservationParserTest, dhcp4MessageFields) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -422,8 +422,8 @@ TEST_F(HostReservationParserTest, noIPAddress) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -517,8 +517,8 @@ TEST_F(HostReservationParserTest, dhcp6HWaddr) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser6 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -564,8 +564,8 @@ TEST_F(HostReservationParserTest, dhcp6DUID) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(12));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser6 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(12), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -623,8 +623,8 @@ TEST_F(HostReservationParserTest, dhcp6NoHostname) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(12));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser6 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(12), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -659,8 +659,8 @@ TEST_F(HostReservationParserTest, dhcp6ClientClasses) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser6 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -770,8 +770,8 @@ TEST_F(HostReservationParserTest, options4) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser4 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser4 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -827,8 +827,8 @@ TEST_F(HostReservationParserTest, options6) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(10));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationParser6 parser;
ASSERT_NO_THROW(parser.parse(SubnetID(10), config_element));
// One host should have been added to the configuration.
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
......
......@@ -86,8 +86,8 @@ TEST_F(HostReservationsListParserTest, ipv4Reservations) {
ElementPtr config_element = Element::fromJSON(config);
HostReservationsListParser<HostReservationParser4> parser(SubnetID(1));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationsListParser<HostReservationParser4> parser;
ASSERT_NO_THROW(parser.parse(SubnetID(1), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -139,8 +139,8 @@ TEST_F(HostReservationsListParserTest, duplicatedIdentifierValue4) {
ElementPtr config_element = Element::fromJSON(config.str());
HostReservationsListParser<HostReservationParser4> parser(SubnetID(1));
EXPECT_THROW(parser.parse(config_element), DhcpConfigError);
HostReservationsListParser<HostReservationParser4> parser;
EXPECT_THROW(parser.parse(SubnetID(1), config_element), DhcpConfigError);
}
}
......@@ -164,8 +164,8 @@ TEST_F(HostReservationsListParserTest, ipv6Reservations) {
ElementPtr config_element = Element::fromJSON(config);
// Parse configuration.
HostReservationsListParser<HostReservationParser6> parser(SubnetID(2));
ASSERT_NO_THROW(parser.parse(config_element));
HostReservationsListParser<HostReservationParser6> parser;
ASSERT_NO_THROW(parser.parse(SubnetID(2), config_element));
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
HostCollection hosts;
......@@ -231,8 +231,8 @@ TEST_F(HostReservationsListParserTest, duplicatedIdentifierValue6) {
ElementPtr config_element = Element::fromJSON(config.str());
HostReservationsListParser<HostReservationParser6> parser(SubnetID(1));
EXPECT_THROW(parser.parse(config_element), DhcpConfigError);
HostReservationsListParser<HostReservationParser6> parser;
EXPECT_THROW(parser.parse(SubnetID(1), config_element), DhcpConfigError);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment