Commit e702bd6d authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[5305] v4 shared network parser now uses SimpleParser approach.

parent a92d0500
......@@ -24,47 +24,39 @@ namespace dhcp {
SharedNetwork4Ptr
SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
SharedNetwork4Ptr shared_network;
std::string name;
try {
// Shared network is a map.
const auto& element = shared_network_data->mapValue();
// Make sure that the network name has been specified. The name is required
// to create a SharedNetwork4 object.
const auto& name_it = element.find("name");
if (name_it == element.cend()) {
isc_throw(DhcpConfigError, "parameter \"name\" must be specified for"
" a shared network");
std::string name = getString(shared_network_data, "name");
shared_network.reset(new SharedNetwork4(name));
// interface is an optional parameter
if (shared_network_data->contains("interface")) {
shared_network->setIface(getString(shared_network_data, "interface"));
}
shared_network.reset(new SharedNetwork4(name_it->second->stringValue()));
// Iterate over all parameters within the map and assign them to the
// shared network.
for (auto param = element.cbegin(); param != element.cend(); ++param) {
if (param->first == "interface") {
shared_network->setIface(param->second->stringValue());
if (shared_network_data->contains("option-data")) {
auto json = shared_network_data->get("option-data");
// Create parser instance for option-data.
CfgOptionPtr cfg_option = shared_network->getCfgOption();
OptionDataListParser parser(AF_INET);
parser.parse(cfg_option, json);
}
} else if (param->first == "option-data") {
// Create parser instance for option-data.
CfgOptionPtr cfg_option = shared_network->getCfgOption();
OptionDataListParser parser(AF_INET);
parser.parse(cfg_option, param->second);
if (shared_network_data->contains("subnet4")) {
auto json = shared_network_data->get("subnet4");
} else if (param->first == "subnet4") {
// Create parser instance of subnet4.
Subnets4ListConfigParser parser;
Subnet4Collection subnets;
parser.parse(subnets, param->second);
// Create parser instance of subnet4.
Subnets4ListConfigParser parser;
Subnet4Collection subnets;
parser.parse(subnets, json);
// Add all returned subnets into shared network.
for (auto subnet = subnets.cbegin(); subnet != subnets.cend();
++subnet) {
shared_network->add(*subnet);
}
// Add all returned subnets into shared network.
for (auto subnet = subnets.cbegin(); subnet != subnets.cend();
++subnet) {
shared_network->add(*subnet);
}
}
} catch (const std::exception& ex) {
isc_throw(DhcpConfigError, ex.what() << " ("
<< shared_network_data->getPosition() << ")");
......
......@@ -17,7 +17,7 @@ namespace isc {
namespace dhcp {
/// @brief Implements parser for IPv4 shared networks.
class SharedNetwork4Parser {
class SharedNetwork4Parser : isc::data::SimpleParser {
public:
/// @brief Parses shared configuration information for IPv4 shared network.
......@@ -32,7 +32,7 @@ public:
};
/// @brief Implements parser for IPv6 shared networks.
class SharedNetwork6Parser {
class SharedNetwork6Parser : isc::data::SimpleParser {
public:
/// @brief Parses shared configuration information for IPv6 shared network.
......
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