Commit 09e8ac90 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2320] Pkt4::delOption() implemented.

parent 20419496
......@@ -369,6 +369,16 @@ Pkt4::getOption(uint8_t type) {
return boost::shared_ptr<isc::dhcp::Option>(); // NULL
}
bool
Pkt4::delOption(uint8_t type) {
isc::dhcp::Option::OptionCollection::iterator x = options_.find(type);
if (x!=options_.end()) {
options_.erase(x);
return (true); // delete successful
}
return (false); // can't find option to be deleted
}
void
Pkt4::updateTimestamp() {
timestamp_ = boost::posix_time::microsec_clock::universal_time();
......
......@@ -325,6 +325,11 @@ public:
boost::shared_ptr<Option>
getOption(uint8_t opt_type);
/// @brief Deletes specified option
/// @param type option type to be deleted
/// @return true if anything was deleted, false otherwise
bool delOption(uint8_t type);
/// @brief Returns interface name.
///
/// Returns interface name over which packet was received or is
......
......@@ -530,6 +530,12 @@ TEST(Pkt4Test, options) {
EXPECT_EQ(0, memcmp(ptr, v4Opts, sizeof(v4Opts)));
EXPECT_EQ(DHO_END, static_cast<uint8_t>(*(ptr + sizeof(v4Opts))));
// delOption() checks
EXPECT_TRUE(pkt->getOption(12)); // Sanity check: option 12 is still there
EXPECT_TRUE(pkt->delOption(12)); // We should be able to remove it
EXPECT_FALSE(pkt->getOption(12)); // It should not be there anymore
EXPECT_FALSE(pkt->delOption(12)); // And removal should fail
EXPECT_NO_THROW(
delete pkt;
);
......
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