return (idx.erase(option_code));
}
+size_t
+CfgOption::del(const uint32_t vendor_id, const uint16_t option_code) {
+ // Check for presence of options.
+ OptionContainerPtr vendor_options = getAll(vendor_id);
+ if (!vendor_options || vendor_options->empty()) {
+ // There are no options, so there is nothing to do.
+ return (0);
+ }
+
+ auto& idx = vendor_options->get<1>();
+ return (idx.erase(option_code));
+}
+
ElementPtr
CfgOption::toElement() const {
// option-data value is a list of maps
/// it is also deleted from all option instances encapsulating this
/// option space.
///
- /// @param key Option space name or vendor identifier.
+ /// @param option_space Option space name.
/// @param option_code Code of the option to be returned.
///
/// @return Number of deleted options.
- size_t del(const std::string& key, const uint16_t option_code);
+ size_t del(const std::string& option_space, const uint16_t option_code);
+
+ /// @brief Delets vendor option for the specified vendor id.
+ ///
+ /// @param vendor_id Vendor identifier.
+ /// @param option_code Option code.
+ ///
+ /// @return Number of deleted options.
+ size_t del(const uint32_t vendor_id, const uint16_t option_code);
/// @brief Returns a list of configured option space names.
///
}
// This test verifies that an option can be deleted from the configuration.
-TEST_F(CfgOptionTest, del) {
+TEST_F(CfgOptionTest, delFromOptionSpace) {
CfgOption cfg;
generateEncapsulatedOptions(cfg);
ASSERT_NO_THROW(top_level_option = cfg.get(DHCP6_OPTION_SPACE, code));
ASSERT_TRUE(top_level_option.option_);
EXPECT_FALSE(top_level_option.option_->getOption(5));
+ // Other options should remain.
+ EXPECT_TRUE(top_level_option.option_->getOption(1));
}
}
+// This test verifies that a vendor option can be deleted from the configuration.
+TEST_F(CfgOptionTest, delVendorOption) {
+ CfgOption cfg;
+
+ // Create multiple vendor options for vendor id 123.
+ for (uint16_t code = 100; code < 110; ++code) {
+ OptionPtr option(new Option(Option::V6, code, OptionBuffer(1, 0xFF)));
+ ASSERT_NO_THROW(cfg.add(option, false, "vendor-123"));
+ }
+
+ // Make sure that the option we're trying to delete is there.
+ ASSERT_TRUE(cfg.get(123, 105).option_);
+
+ // Delete the option.
+ uint64_t deleted_num;
+ ASSERT_NO_THROW(deleted_num = cfg.del(123, 105));
+ EXPECT_EQ(1, deleted_num);
+
+ // Make sure the option is gone.
+ EXPECT_FALSE(cfg.get(123, 105).option_);
+
+ // Other options, like 107, shouldn't be gone.
+ EXPECT_TRUE(cfg.get(123, 107).option_);
+}
+
// This test verifies that single option can be retrieved from the configuration
// using option code and option space.
TEST_F(CfgOptionTest, get) {