Commit a0eb24be authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3316] Implemented function to check if specified tuple is in VC option.

parent 20784067
......@@ -89,7 +89,7 @@ OpaqueDataTuple::operator=(const std::string& other) {
}
bool
OpaqueDataTuple::operator==(const std::string& other) {
OpaqueDataTuple::operator==(const std::string& other) const {
return (equals(other));
}
......
......@@ -261,7 +261,7 @@ public:
///
/// @param other String to compare the tuple against.
/// @return true if data carried in the tuple is equal to the string.
bool operator==(const std::string& other);
bool operator==(const std::string& other) const;
/// @brief Inequality operator.
///
......
......@@ -130,6 +130,20 @@ OptionVendorClass::getTuple(const size_t at) const {
return (tuples_[at]);
}
bool
OptionVendorClass::hasTuple(const std::string& tuple_str) const {
// Iterate over existing tuples (there shouldn't be many of them),
// and try to match the searched one.
for (TuplesCollection::const_iterator it = tuples_.begin();
it != tuples_.end(); ++it) {
if (*it == tuple_str) {
return (true);
}
}
return (false);
}
uint16_t
OptionVendorClass::len() {
// The option starts with the header and enterprise id.
......
......@@ -128,6 +128,13 @@ public:
return (tuples_);
}
/// @brief Checks if the Vendor Class holds the opaque data tuple with the
/// specified string.
///
/// @param tuple_str String representation of the tuple being searched.
/// @return true if the specified tuple exists for this option.
bool hasTuple(const std::string& tuple_str) const;
/// @brief Returns the full length of the option, including option header.
virtual uint16_t len();
......
......@@ -74,6 +74,11 @@ TEST(OptionVendorClass, addTuple) {
EXPECT_EQ("xyz", vendor_class.getTuple(0).getText());
EXPECT_EQ("abc", vendor_class.getTuple(1).getText());
// Check that hasTuple correctly identifies existing tuples.
EXPECT_TRUE(vendor_class.hasTuple("xyz"));
EXPECT_TRUE(vendor_class.hasTuple("abc"));
EXPECT_FALSE(vendor_class.hasTuple("other"));
// Attempt to add the tuple with 1 byte long length field should fail
// for DHCPv6 option.
OpaqueDataTuple tuple2(OpaqueDataTuple::LENGTH_1_BYTE);
......
Supports Markdown
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