Commit a146bf15 authored by Marcin Siodelski's avatar Marcin Siodelski

[2313] Added OptionSpace6 class that holds enterprise numbers.

parent 810c95b1
......@@ -42,5 +42,22 @@ OptionSpace::validateName(const std::string& name) {
return (false);
OptionSpace6::OptionSpace6(const std::string& name)
: OptionSpace(name),
enterprise_number_(0) {
OptionSpace6::OptionSpace6(const std::string& name,
const uint32_t enterprise_id)
: OptionSpace(name, true),
enterprise_number_(enterprise_id) {
OptionSpace6::setVendorSpace(const uint32_t enterprise_id) {
enterprise_number_ = enterprise_id;
} // end of isc::dhcp namespace
} // end of isc namespace
......@@ -18,6 +18,7 @@
#include <exceptions/exceptions.h>
#include <boost/shared_ptr.hpp>
#include <map>
#include <stdint.h>
#include <string>
namespace isc {
......@@ -63,6 +64,11 @@ public:
/// correct.
OptionSpace(const std::string& name, const bool vendor_space = false);
/// @brief Mark option space as non-vendor space.
void clearVendorSpace() {
vendor_space_ = false;
/// @brief Return option space name.
/// @return option space name.
......@@ -74,12 +80,9 @@ public:
/// the vendor space.
bool isVendorSpace() const { return (vendor_space_); }
/// @brief Mark option space as vendor space or non-vendor space.
/// @param vendor_space a boolean value indicating that this option
/// space is a vendor space (true) or non-vendor space (false).
void setVendorSpace(const bool vendor_space) {
vendor_space_ = vendor_space;
/// @brief Mark option space as vendor space.
void setVendorSpace() {
vendor_space_ = true;
/// @brief Checks that the provided option space name is valid.
......@@ -101,6 +104,48 @@ private:
/// @brief DHCPv6 option space.
/// This class extends the base class with support for enterprise numbers.
/// The enterprise numbers are assigned by IANA to various organizations
/// and they are carried as uint32_t integers in DHCPv6 Vendor Specific
/// Information Options (VSIO). For more information refer to RFC3315.
/// All option spaces that group VSIO options must have enterprise number
/// set. It can be set using a constructor or \ref setVendorSpace function.
class OptionSpace6 : public OptionSpace {
/// @brief Constructor for non-vendor-specific options.
/// This constructor marks option space as non-vendor specific.
/// @param name option space name.
OptionSpace6(const std::string& name);
/// @brief Constructor for vendor-specific options.
/// This constructor marks option space as vendor specific and sets
/// enterprise number to a given value.
/// @param name option space name.
/// @param enterprise_number enterprise number.
OptionSpace6(const std::string& name, const uint32_t enterprise_number);
/// @brief Return enterprise number for the option space.
/// @return enterprise number.
uint32_t getEnterpriseNumber() const { return (enterprise_number_); }
/// @brief Mark option space as VSIO option space.
/// @param enterprise_number enterprise number.
void setVendorSpace(const uint32_t enterprise_number);
uint32_t enterprise_number_; ///< IANA assigned enterprise number.
} // namespace isc::dhcp
} // namespace isc
......@@ -50,7 +50,7 @@ TEST(OptionSpaceTest, setVendorSpace) {
// Override the vendor space flag.
......@@ -92,4 +92,52 @@ TEST(OptionSpaceTest, validateName) {
// The purpose of this test is to verify that the constructors of the
// OptionSpace6 class set the class members to correct values.
TEST(OptionSpace6Test, constructor) {
// Create some option space and do not specify enterprise number.
// In such case the vendor space flag is expected to be
// set to false.
OptionSpace6 space1("abcd");
EXPECT_EQ("abcd", space1.getName());
// Create an option space and specify an enterprise number. In this
// case the vendor space flag is expected to be set to true and the
// enterprise number should be set to a desired value.
OptionSpace6 space2("abcd", 2145);
EXPECT_EQ("abcd", space2.getName());
EXPECT_EQ(2145, space2.getEnterpriseNumber());
// Verify that constructors throw an exception when invalid option
// space name has been specified.
EXPECT_THROW(OptionSpace6("isc dhcp"), InvalidOptionSpace);
EXPECT_THROW(OptionSpace6("isc%dhcp", 2145), InvalidOptionSpace);
// The purpose of this test is to verify an option space can be marked
// vendor option space and enterprise number can be set.
TEST(OptionSpace6Test, setVendorSpace) {
OptionSpace6 space("isc");
EXPECT_EQ("isc", space.getName());
// Mark it vendor option space and set enterprise id.
EXPECT_EQ(1234, space.getEnterpriseNumber());
// Override the enterprise number to make sure and make sure that
// the new number is returned by the object.
EXPECT_EQ(2345, space.getEnterpriseNumber());
// Clear the vendor option space flag.
}; // end of anonymous namespace
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