return (vendor_options_.getItems(vendor_id));
}
+OptionContainerPtr
+CfgOption::getAllCombined(const std::string& option_space) const {
+ auto vendor_id = LibDHCP::optionSpaceToVendorId(option_space);
+ if (vendor_id > 0) {
+ return (getAll(vendor_id));
+ }
+ return (getAll(option_space));
+}
+
size_t
CfgOption::del(const std::string& option_space, const uint16_t option_code) {
// Check for presence of options.
/// container is empty if no options have been found.
OptionContainerPtr getAll(const uint32_t vendor_id) const;
+ /// @brief Returns all non-vendor or vendor options for the specified
+ /// option space.
+ ///
+ /// It combines the output of the @c getAll function variants. When
+ /// option space has the format of "vendor-X", it retrieves the vendor
+ /// options by vendor id, where X must be a 32-bit unsigned integer.
+ /// Otherwise, it fetches non-vendor options.
+ ///
+ /// @param option_space Name of the option space.
+ /// @return Pointer to the container holding returned options. This
+ /// container is empty if no options have been found.
+ OptionContainerPtr getAllCombined(const std::string& option_space) const;
+
/// @brief Returns option for the specified key and option code.
///
/// The key should be a string, in which case it specifies an option space
<< "' is invalid JSON: " << ex.what());
}
}
-
cfg->add(desc, space);
}
"ON h.host_id = o.host_id "
"LEFT JOIN ipv6_reservations AS r "
"ON h.host_id = r.host_id "
- "WHERE h.dhcp6_subnet_id = ? AND h.host_id = "
- "( SELECT host_id FROM ipv6_reservations "
- "WHERE address = ? ) "
+ "WHERE h.dhcp6_subnet_id = ? AND h.host_id IN "
+ "(SELECT host_id FROM ipv6_reservations "
+ "WHERE address = ?) "
"ORDER BY h.host_id, o.option_id, r.reservation_id"},
// Retrieves host information along with the DHCPv4 options associated with
// For each option space retrieve all options and insert them into the
// database.
for (auto space = option_spaces.begin(); space != option_spaces.end(); ++space) {
- OptionContainerPtr options = options_cfg->getAll(*space);
+ OptionContainerPtr options = options_cfg->getAllCombined(*space);
if (options && !options->empty()) {
for (auto opt = options->begin(); opt != options->end(); ++opt) {
addOption(ctx, stindex, *opt, *space, Optional<SubnetID>(), host_id);
"FROM hosts AS h "
"LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
"LEFT JOIN ipv6_reservations AS r ON h.host_id = r.host_id "
- "WHERE h.dhcp6_subnet_id = $1 AND h.host_id = "
+ "WHERE h.dhcp6_subnet_id = $1 AND h.host_id IN "
" (SELECT host_id FROM ipv6_reservations "
" WHERE address = $2) "
"ORDER BY h.host_id, o.option_id, r.reservation_id"
// For each option space retrieve all options and insert them into the
// database.
for (auto space = option_spaces.begin(); space != option_spaces.end(); ++space) {
- OptionContainerPtr options = options_cfg->getAll(*space);
+ OptionContainerPtr options = options_cfg->getAllCombined(*space);
if (options && !options->empty()) {
for (auto opt = options->begin(); opt != options->end(); ++opt) {
addOption(ctx, stindex, *opt, *space, Optional<SubnetID>(), host_id);
++expected_code;
}
- options = cfg.getAll("isc");
+ // Try another function variant.
+ options = cfg.getAllCombined("isc");
ASSERT_TRUE(options);
ASSERT_EQ(7, options->size());
ASSERT_TRUE(options);
ASSERT_EQ(10, options->size());
+ // Make sure we can get vendor options by option space.
+ options = cfg.getAllCombined("vendor-12345678");
+ ASSERT_TRUE(options);
+ ASSERT_EQ(10, options->size());
+
// Validate codes of options added to dhcp6 option space.
uint16_t expected_code = 100;
for (OptionContainer::const_iterator option_desc = options->begin();
options = cfg.getAll(1111111);
ASSERT_TRUE(options);
EXPECT_TRUE(options->empty());
+
+ // Try another function variant.
+ options = cfg.getAll("vendor-1111111");
+ ASSERT_TRUE(options);
+ EXPECT_TRUE(options->empty());
}
// This test verifies that option space names for the vendor options are
#include <database/database_connection.h>
#include <database/db_exceptions.h>
#include <dhcp/dhcp6.h>
+#include <dhcp/docsis3_option_defs.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option4_addrlst.h>
#include <dhcp/option6_addrlst.h>
"3000::2", "3000::3"),
"isc2");
+ desc = createOption<OptionString>(Option::V6, DOCSIS3_V6_TFTP_SERVERS,
+ true, false, true, "3000:1::234");
+ opts->add(desc, "vendor-4491");
+
// Add definitions for DHCPv6 non-standard options.
defs.addItem(OptionDefinitionPtr(new OptionDefinition(
"option-1024", 1024, DHCP6_OPTION_SPACE,
// Let's create a couple of hosts...
HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8:1::", Host::IDENT_DUID, true);
addIPv6Address(host1, "2001:db8:1::10");
+ ASSERT_NO_THROW(addTestOptions(host1, true, DHCP6_ONLY));
+
HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8:2::", Host::IDENT_DUID, true);
addIPv6Address(host2, "2001:db8:1::20");
HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8:3::", Host::IDENT_DUID, true);
// Create a host reservations.
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true, true);
+ addIPv6Address(host, "2001:db8::2");
auto host_id = host->getHostId();
auto subnet_id = host->getIPv6SubnetID();
// Then try to add it again, it should throw an exception because the
// HWADDR is the same.
host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true, false);
+ addIPv6Address(host, "2001:db8::2");
host->setHostId(++host_id);
host->setIPv6SubnetID(subnet_id);
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
// Combine option space names with vendor space names in a single list.
std::list<std::string> option_spaces = cfg2->getOptionSpaceNames();
std::list<std::string> vendor_spaces = cfg2->getVendorIdsSpaceNames();
- option_spaces.insert(option_spaces.end(), vendor_spaces.begin(),
- vendor_spaces.end());
// Make sure that the number of option spaces is equal in both
// configurations.