From: Marcin Siodelski Date: Thu, 13 Dec 2012 14:39:51 +0000 (+0100) Subject: [2313] Added new class to represent option space. X-Git-Tag: bind10-1.0.0-rc-release~95^2~21^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd8ac0ce36dee77dc4865239576745db7588db60;p=thirdparty%2Fkea.git [2313] Added new class to represent option space. --- diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am index 571f11d398..7305e0c50d 100644 --- a/src/lib/dhcp/Makefile.am +++ b/src/lib/dhcp/Makefile.am @@ -14,23 +14,23 @@ CLEANFILES = *.gcno *.gcda lib_LTLIBRARIES = libb10-dhcp++.la libb10_dhcp___la_SOURCES = +libb10_dhcp___la_SOURCES += dhcp6.h dhcp4.h libb10_dhcp___la_SOURCES += duid.cc duid.h libb10_dhcp___la_SOURCES += iface_mgr.cc iface_mgr.h libb10_dhcp___la_SOURCES += iface_mgr_bsd.cc libb10_dhcp___la_SOURCES += iface_mgr_linux.cc libb10_dhcp___la_SOURCES += iface_mgr_sun.cc libb10_dhcp___la_SOURCES += libdhcp++.cc libdhcp++.h -libb10_dhcp___la_SOURCES += option.cc option.h -libb10_dhcp___la_SOURCES += option_data_types.cc option_data_types.h -libb10_dhcp___la_SOURCES += option_definition.cc option_definition.h -libb10_dhcp___la_SOURCES += option_custom.cc option_custom.h +libb10_dhcp___la_SOURCES += option4_addrlst.cc option4_addrlst.h libb10_dhcp___la_SOURCES += option6_ia.cc option6_ia.h libb10_dhcp___la_SOURCES += option6_iaaddr.cc option6_iaaddr.h libb10_dhcp___la_SOURCES += option6_addrlst.cc option6_addrlst.h -libb10_dhcp___la_SOURCES += option4_addrlst.cc option4_addrlst.h libb10_dhcp___la_SOURCES += option_int.h libb10_dhcp___la_SOURCES += option_int_array.h -libb10_dhcp___la_SOURCES += dhcp6.h dhcp4.h +libb10_dhcp___la_SOURCES += option.cc option.h +libb10_dhcp___la_SOURCES += option_custom.cc option_custom.h +libb10_dhcp___la_SOURCES += option_data_types.cc option_data_types.h +libb10_dhcp___la_SOURCES += option_definition.cc option_definition.h libb10_dhcp___la_SOURCES += pkt6.cc pkt6.h libb10_dhcp___la_SOURCES += pkt4.cc pkt4.h libb10_dhcp___la_SOURCES += std_option_defs.h diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index b44fa7d415..fc888f6b67 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -27,6 +27,7 @@ libb10_dhcpsrv_la_SOURCES += memfile_lease_mgr.cc memfile_lease_mgr.h if HAVE_MYSQL libb10_dhcpsrv_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h endif +libb10_dhcpsrv_la_SOURCES += option_space.cc option_space.h libb10_dhcpsrv_la_SOURCES += pool.cc pool.h libb10_dhcpsrv_la_SOURCES += subnet.cc subnet.h libb10_dhcpsrv_la_SOURCES += triplet.h diff --git a/src/lib/dhcpsrv/option_space.cc b/src/lib/dhcpsrv/option_space.cc new file mode 100644 index 0000000000..297b8a57e5 --- /dev/null +++ b/src/lib/dhcpsrv/option_space.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +namespace isc { +namespace dhcp { + +OptionSpace::OptionSpace(const std::string& name, const bool vendor_space) + : name_(name), vendor_space_(vendor_space) { +} + +} // end of isc::dhcp namespace +} // end of isc namespace diff --git a/src/lib/dhcpsrv/option_space.h b/src/lib/dhcpsrv/option_space.h new file mode 100644 index 0000000000..3a25c1c2fa --- /dev/null +++ b/src/lib/dhcpsrv/option_space.h @@ -0,0 +1,69 @@ +// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef OPTION_SPACE_H +#define OPTION_SPACE_H + +#include +#include + +namespace isc { +namespace dhcp { + +class OptionSpace; + +typedef boost::shared_ptr OptionSpacePtr; + +/// @brief Option code space. +/// +/// This class represents single option space. The option spaces are used +/// to group DHCP options having unique option codes. The special type +/// of the option space is so called "vendor option space". It groups +/// sub-options being sent within Vendor Encapsulated Options. These are +/// option with code 43 for DHCPv4 and option with code 17 for DHCPv6. +/// The option spaces are assigned to option instances represented by +/// isc::dhcp::Option and other classes derived from it. Each particular +/// option may belong to multiple option spaces. +class OptionSpace { +public: + + /// @brief Constructor. + /// + /// @param name option space name. + /// @param vendor_space boolean value that indicates that the object + /// describes the vendor space. + OptionSpace(const std::string& name, const bool vendor_space = false); + + /// @brief Return option space name. + /// + /// @return option space name. + const std::string& getName() const { return (name_); } + + /// @brief Check if option space is a vendor space. + /// + /// @return boolean value that indicates if the object describes + /// the vendor space. + bool isVendorSpace() const { return (vendor_space_); } + +private: + std::string name_; ///< Holds option space name. + + bool vendor_space_; ///< Is this the vendor space? + +}; + +} // namespace isc::dhcp +} // namespace isc + +#endif // OPTION_SPACE_H diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index 11e1d75c1d..dfe3e785c5 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -36,6 +36,7 @@ libdhcpsrv_unittests_SOURCES += memfile_lease_mgr_unittest.cc if HAVE_MYSQL libdhcpsrv_unittests_SOURCES += mysql_lease_mgr_unittest.cc endif +libdhcpsrv_unittests_SOURCES += option_space_unittest.cc libdhcpsrv_unittests_SOURCES += pool_unittest.cc libdhcpsrv_unittests_SOURCES += schema_copy.h libdhcpsrv_unittests_SOURCES += subnet_unittest.cc diff --git a/src/lib/dhcpsrv/tests/option_space_unittest.cc b/src/lib/dhcpsrv/tests/option_space_unittest.cc new file mode 100644 index 0000000000..011b4db073 --- /dev/null +++ b/src/lib/dhcpsrv/tests/option_space_unittest.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +#include + +#include + +using namespace isc::dhcp; +using namespace isc; + +namespace { + +// The purpose of this test is to verify that the constructor +// creates an object with members initialized to correct values. +TEST(OptionSpaceTest, constructor) { + // Create some option space. + OptionSpace space("isc", true); + EXPECT_EQ("isc", space.getName()); + EXPECT_TRUE(space.isVendorSpace()); + + // Create another object with different values + // to check that the values will change. + OptionSpace space2("abc", false); + EXPECT_EQ("abc", space2.getName()); + EXPECT_FALSE(space2.isVendorSpace()); +} + +}; // end of anonymous namespace