#endif
#ifndef MYSQL_UPDATE_OPTION_COMMON
-#define MYSQL_UPDATE_OPTION_COMMON(table_prefix, pd_pool_id, ...) \
+#define MYSQL_UPDATE_OPTION_COMMON(table_prefix, server_join, pd_pool_id, ...) \
"UPDATE " #table_prefix "_options AS o " \
- "INNER JOIN " #table_prefix "_options_server AS a" \
- " ON o.option_id = a.option_id " \
- "INNER JOIN " #table_prefix "_server AS s" \
- " ON a.server_id = s.id " \
+ server_join \
"SET" \
" o.code = ?," \
" o.value = ?," \
"WHERE " #__VA_ARGS__
#define MYSQL_UPDATE_OPTION4_WITH_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", s.tag = ? __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp4, \
+ "INNER JOIN dhcp4_options_server AS a" \
+ " ON o.option_id = a.option_id " \
+ "INNER JOIN dhcp4_server AS s" \
+ " ON a.server_id = s.id ", \
+ "", s.tag = ? __VA_ARGS__)
#define MYSQL_UPDATE_OPTION4_NO_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", "", __VA_ARGS__)
#define MYSQL_UPDATE_OPTION6_WITH_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp6, ", o.pd_pool_id = ? ", s.tag = ? __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp6, \
+ "INNER JOIN dhcp6_options_server AS a" \
+ " ON o.option_id = a.option_id " \
+ "INNER JOIN dhcp6_server AS s" \
+ " ON a.server_id = s.id ", \
+ ", o.pd_pool_id = ? ", s.tag = ? __VA_ARGS__)
#define MYSQL_UPDATE_OPTION6_NO_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp6, ", o.pd_pool_id = ? ", __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp6, "", ", o.pd_pool_id = ? ", __VA_ARGS__)
#endif
#ifndef MYSQL_UPDATE_SERVER
"WHERE a.option_def_id IS NULL " #__VA_ARGS__
#endif
-#ifndef MYSQL_DELETE_OPTION
-#define MYSQL_DELETE_OPTION_COMMON(table_prefix, ...) \
+#ifndef MYSQL_DELETE_OPTION_WITH_TAG
+#define MYSQL_DELETE_OPTION_WITH_TAG(table_prefix, ...) \
"DELETE o FROM " #table_prefix "_options AS o " \
"INNER JOIN " #table_prefix "_options_server AS a" \
" ON o.option_id = a.option_id " \
"INNER JOIN " #table_prefix "_server AS s" \
" ON a.server_id = s.id " \
- #__VA_ARGS__
-
-#define MYSQL_DELETE_OPTION_WITH_TAG(table_prefix, ...) \
- MYSQL_DELETE_OPTION_COMMON(table_prefix, WHERE s.tag = ? __VA_ARGS__)
+ "WHERE s.tag = ? " #__VA_ARGS__
+#endif
+#ifndef MYSQL_DELETE_OPTION_NO_TAG
#define MYSQL_DELETE_OPTION_NO_TAG(table_prefix, ...) \
- MYSQL_DELETE_OPTION_COMMON(table_prefix, __VA_ARGS__)
+ "DELETE o FROM " #table_prefix "_options AS o " \
+ #__VA_ARGS__
#endif
#ifndef MYSQL_DELETE_OPTION_UNASSIGNED
"subnet set");
}
+ // The inserted subnet contains two options.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
+
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
- cbptr_->createUpdateOption4(ServerSelector::ALL(), subnet->getID(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(), subnet->getID(),
opt_boot_file_name);
returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
"subnet specific option set");
}
+ // We have added one option to the existing subnet. We should now have
+ // three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
cbptr_->createUpdateOption4(ServerSelector::ALL(), subnet->getID(),
opt_boot_file_name);
- returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
+ returned_subnet = cbptr_->getSubnet4(ServerSelector::ANY(),
subnet->getID());
ASSERT_TRUE(returned_subnet);
returned_opt_boot_file_name =
"subnet specific option set");
}
+ // Updating the option should replace the existing instance with the new
+ // instance. Therefore, we should still have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
// It should succeed for any server.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(), subnet->getID(),
opt_boot_file_name->option_->getType(),
AuditEntry::ModificationType::UPDATE,
"subnet specific option deleted");
}
+
+ // We should have only two options after deleting one of them.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
}
// This test verifies that option can be inserted, updated and deleted
"subnet set");
}
+ // Inserted subnet has two options.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
+
// Add an option into the pool.
const PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.10"));
ASSERT_TRUE(pool);
"pool specific option set");
}
+ // With the newly inserted option we should now have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
// Modify the option and update it in the database.
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
"pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
pool->getFirstAddress(),
AuditEntry::ModificationType::UPDATE,
"pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 2.
+ EXPECT_EQ(2, countRows("dhcp4_options"));
}
// This test verifies that shared network level option can be added,
"shared network set");
}
+ // The inserted shared network has no options.
+ ASSERT_EQ(0, countRows("dhcp4_options"));
+
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
cbptr_->createUpdateOption4(ServerSelector::ALL(),
shared_network->getName(),
"shared network specific option set");
}
+ // One option should now be stored in the database.
+ ASSERT_EQ(1, countRows("dhcp4_options"));
+
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
cbptr_->createUpdateOption4(ServerSelector::ALL(),
shared_network->getName(),
"shared network specific option set");
}
+ // The new option instance should replace the existing option instance,
+ // so we should still have one option.
+ ASSERT_EQ(1, countRows("dhcp4_options"));
+
// Deleting an option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
shared_network->getName(),
AuditEntry::ModificationType::UPDATE,
"shared network specific option deleted");
}
+
+ // After deleting the option we should be back to 0.
+ EXPECT_EQ(0, countRows("dhcp4_options"));
}
"subnet set");
}
+ // The inserted subnet contains four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
opt_posix_timezone);
"subnet specific option set");
}
+ // We have added one option to the existing subnet. We should now have
+ // five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
opt_posix_timezone);
"subnet specific option set");
}
+ // Updating the option should replace the existing instance with the new
+ // instance. Therefore, we should still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// It should succeed for any server.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(), subnet->getID(),
opt_posix_timezone->option_->getType(),
AuditEntry::ModificationType::UPDATE,
"subnet specific option deleted");
}
+
+ // We should have only four options after deleting one of them.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that option can be inserted, updated and deleted
"subnet set");
}
+ // Inserted subnet has four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
// Add an option into the pool.
const PoolPtr pool = subnet->getPool(Lease::TYPE_NA,
IOAddress("2001:db8::10"));
"address pool specific option set");
}
+ // With the newly inserted option we should now have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
"address pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
pool->getFirstAddress(),
AuditEntry::ModificationType::UPDATE,
"address pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 4.
+ EXPECT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that option can be inserted, updated and deleted
"subnet set");
}
+ // Inserted subnet has four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
// Add an option into the pd pool.
const PoolPtr pd_pool = subnet->getPool(Lease::TYPE_PD,
IOAddress("2001:db8:a:10::"));
"prefix delegation pool specific option set");
}
+ // With the newly inserted option we should now have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
"prefix delegation pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
pd_pool->getFirstAddress(),
AuditEntry::ModificationType::UPDATE,
"prefix delegation pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 4.
+ EXPECT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that shared network level option can be added,
"shared network set");
}
+ // The inserted shared network has no options.
+ ASSERT_EQ(0, countRows("dhcp6_options"));
+
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
cbptr_->createUpdateOption6(ServerSelector::ALL(),
shared_network->getName(),
"shared network specific option set");
}
+ // One option should now be stored in the database.
+ ASSERT_EQ(1, countRows("dhcp6_options"));
+
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
cbptr_->createUpdateOption6(ServerSelector::ALL(),
shared_network->getName(),
"shared network specific option set");
}
+ // The new option instance should replace the existing option instance,
+ // so we should still have one option.
+ ASSERT_EQ(1, countRows("dhcp6_options"));
+
// Deleting an option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
shared_network->getName(),
AuditEntry::ModificationType::UPDATE,
"shared network specific option deleted");
}
+
+ // After deleting the option we should be back to 0.
+ EXPECT_EQ(0, countRows("dhcp6_options"));
}
}