/// @param ignored first parameter
/// stores global scope parameters, options, option defintions.
Subnet4ConfigParser(const std::string&)
- :SubnetConfigParser("", globalContext()) {
+ :SubnetConfigParser("", globalContext(), IOAddress("0.0.0.0")) {
}
/// @brief Adds the created subnet to a server's configuration.
"Invalid cast in Subnet4ConfigParser::commit");
}
+ // Set relay information if it was parsed
+ if (relay_info_) {
+ sub4ptr->setRelay(*relay_info_);
+ }
+
isc::dhcp::CfgMgr::instance().addSubnet4(sub4ptr);
}
}
parser = new StringParser(config_id, string_values_);
} else if (config_id.compare("pool") == 0) {
parser = new Pool4Parser(config_id, pools_);
+ } else if (config_id.compare("relay") == 0) {
+ parser = new RelayInfoParser(config_id, relay_info_, IOAddress("0.0.0.0"));
} else if (config_id.compare("option-data") == 0) {
parser = new OptionDataListParser(config_id, options_,
global_context_,
"item_default": ""
}
},
-
+ { "item_name": "relay",
+ "item_type": "map",
+ "item_optional": false,
+ "item_default": {},
+ "map_item_spec": [
+ {
+ "item_name": "ip-address",
+ "item_type": "string",
+ "item_optional": false,
+ "item_default": "0.0.0.0"
+ }
+ ]
+ },
{ "item_name": "option-data",
"item_type": "list",
"item_optional": false,
ASSERT_FALSE(CfgMgr::instance().ddnsEnabled());
}
+// This test checks if it is possible to specify relay information
+TEST_F(Dhcp4ParserTest, subnetRelayInfo) {
+
+ ConstElementPtr status;
+
+ // A config with relay information.
+ string config = "{ \"interfaces\": [ \"*\" ],"
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet4\": [ { "
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
+ " \"renew-timer\": 1, "
+ " \"rebind-timer\": 2, "
+ " \"valid-lifetime\": 4,"
+ " \"relay\": { "
+ " \"ip-address\": \"192.0.2.123\""
+ " },"
+ " \"subnet\": \"192.0.2.0/24\" } ],"
+ "\"valid-lifetime\": 4000 }";
+
+ ElementPtr json = Element::fromJSON(config);
+
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
+
+ // returned value should be 0 (configuration success)
+ checkResult(status, 0);
+
+ Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
+ ASSERT_TRUE(subnet);
+ EXPECT_EQ("192.0.2.123", subnet->relay_.addr_.toText());
+}
+
+
}
//****************************** SubnetConfigParser *************************
SubnetConfigParser::SubnetConfigParser(const std::string&,
- ParserContextPtr global_context)
+ ParserContextPtr global_context,
+ const isc::asiolink::IOAddress& default_addr)
: uint32_values_(new Uint32Storage()), string_values_(new StringStorage()),
pools_(new PoolStorage()), options_(new OptionStorage()),
- global_context_(global_context) {
+ global_context_(global_context),
+ relay_info_(new isc::dhcp::Subnet::RelayInfo(default_addr)) {
// The first parameter should always be "subnet", but we don't check
// against that here in case some wants to reuse this parser somewhere.
if (!global_context_) {
public:
/// @brief constructor
- SubnetConfigParser(const std::string&, ParserContextPtr global_context);
+ ///
+ /// @param unusued
+ /// @param global_context
+ /// @param default_addr default IP address (0.0.0.0 for IPv4, :: for IPv6)
+ SubnetConfigParser(const std::string&, ParserContextPtr global_context,
+ const isc::asiolink::IOAddress& default_addr);
/// @brief parses parameter value
///
/// Parsing context which contains global values, options and option
/// definitions.
ParserContextPtr global_context_;
+
+ /// Pointer to relay information
+ isc::dhcp::Subnet::RelayInfoPtr relay_info_;
};
/// @brief Parser for D2ClientConfig