BIND 10 trac2490, updated. b24fd3ded0a466be9eac27617952728e44149695 [2490] Added option factory function that takes vector of strings.
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Nov 19 10:18:10 UTC 2012
The branch, trac2490 has been updated
via b24fd3ded0a466be9eac27617952728e44149695 (commit)
from e77b710633d5cf1d34dea5153a0f77b7d1f111b5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b24fd3ded0a466be9eac27617952728e44149695
Author: Marcin Siodelski <marcin at isc.org>
Date: Mon Nov 19 11:18:01 2012 +0100
[2490] Added option factory function that takes vector of strings.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/option_definition.cc | 10 ++++-
src/lib/dhcp/option_definition.h | 29 ++++++++++++-
src/lib/dhcp/tests/option_definition_unittest.cc | 50 +++++++++++++++++++++-
3 files changed, 84 insertions(+), 5 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc
index c85e60a..424a3df 100644
--- a/src/lib/dhcp/option_definition.cc
+++ b/src/lib/dhcp/option_definition.cc
@@ -99,7 +99,7 @@ OptionDefinition::addRecordField(const DataType data_type) {
OptionPtr
OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
OptionBufferConstIter begin,
- OptionBufferConstIter end) {
+ OptionBufferConstIter end) const {
validate();
if (type_ == BINARY_TYPE) {
@@ -138,10 +138,16 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
OptionPtr
OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
- const OptionBuffer& buf) {
+ const OptionBuffer& buf) const {
return (optionFactory(u, type, buf.begin(), buf.end()));
}
+OptionPtr
+OptionDefinition::optionFactory(Option::Universe, uint16_t,
+ const std::vector<std::string>&) const {
+ return (OptionPtr());
+}
+
void
OptionDefinition::sanityCheckUniverse(const Option::Universe expected_universe,
const Option::Universe actual_universe) {
diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h
index 9fa2e41..6ba45d6 100644
--- a/src/lib/dhcp/option_definition.h
+++ b/src/lib/dhcp/option_definition.h
@@ -275,9 +275,10 @@ public:
/// @param end end of the option buffer.
///
/// @return instance of the DHCP option.
+ /// @todo list thrown exceptions.
OptionPtr optionFactory(Option::Universe u, uint16_t type,
OptionBufferConstIter begin,
- OptionBufferConstIter end);
+ OptionBufferConstIter end) const;
/// @brief Option factory.
///
@@ -290,8 +291,32 @@ public:
/// @param buf option buffer.
///
/// @return instance of the DHCP option.
+ /// @todo list thrown exceptions.
OptionPtr optionFactory(Option::Universe u, uint16_t type,
- const OptionBuffer& buf);
+ const OptionBuffer& buf) const;
+
+ /// @brief Option factory.
+ ///
+ /// This function creates an instance of DHCP option using the vector
+ /// of strings which carry data values for option data fields.
+ /// The order of values in the vector corresponds to the order of data
+ /// fields in the option. The supplied string values are cast to
+ /// their actual data types which are determined based on the
+ /// option definition. If cast fails due to type mismatch, an exception
+ /// is thrown. This factory function can be used to create option
+ /// instance when user specified option value in the <b>comma separated
+ /// values</b> format in the configuration database. Provided string
+ /// must be tokenized into the vector of string values and this vector
+ /// can be supplied to this function.
+ ///
+ /// @param universe option universe (V4 or V6).
+ /// @param type option type.
+ /// @param values a vector of values to be used to set data for an option.
+ ///
+ /// @return instance of the DHCP option.
+ /// @todo list thrown exceptions.
+ OptionPtr optionFactory(Option::Universe u, uint16_t type,
+ const std::vector<std::string>& values) const;
/// @brief Factory to create option with address list.
///
diff --git a/src/lib/dhcp/tests/option_definition_unittest.cc b/src/lib/dhcp/tests/option_definition_unittest.cc
index 0ca08ce..cbccfac 100644
--- a/src/lib/dhcp/tests/option_definition_unittest.cc
+++ b/src/lib/dhcp/tests/option_definition_unittest.cc
@@ -135,7 +135,7 @@ TEST_F(OptionDefinitionTest, validate) {
static_cast<OptionDefinition::DataType>(OptionDefinition::UNKNOWN_TYPE
+ 2));
EXPECT_THROW(opt_def3.validate(), isc::OutOfRange);
-
+
// Empty option name is not allowed.
OptionDefinition opt_def4("", D6O_CLIENTID, "string");
EXPECT_THROW(opt_def4.validate(), isc::BadValue);
@@ -197,6 +197,54 @@ TEST_F(OptionDefinitionTest, factoryAddrList6) {
);
}
+// This test checks that a vector of strings, holding IPv6 addresses,
+// can be used to create option instance with the optionFactory function.
+TEST_F(OptionDefinitionTest, factoryTokenizedAddrList6) {
+ OptionDefinition opt_def("OPTION_NIS_SERVERS", D6O_NIS_SERVERS,
+ "ipv6_address", true);
+
+ // Create a vector of some V6 addresses.
+ std::vector<asiolink::IOAddress> addrs;
+ addrs.push_back(asiolink::IOAddress("2001:0db8::ff00:0042:8329"));
+ addrs.push_back(asiolink::IOAddress("2001:0db8::ff00:0042:2319"));
+ addrs.push_back(asiolink::IOAddress("::1"));
+ addrs.push_back(asiolink::IOAddress("::2"));
+
+ // Create a vector of strings representing addresses given above.
+ std::vector<std::string> addrs_str;
+ for (std::vector<asiolink::IOAddress>::const_iterator it = addrs.begin();
+ it != addrs.end(); ++it) {
+ addrs_str.push_back(it->toText());
+ }
+
+ // Create DHCPv6 option using the list of IPv6 addresses given in the
+ // string form.
+ OptionPtr option_v6;
+ ASSERT_NO_THROW(
+ option_v6 = opt_def.optionFactory(Option::V6, D6O_NIS_SERVERS,
+ addrs_str);
+ );
+ // This is temporary check to make this test pass until factory function is
+ // implemented and returns the pointer rather than NULL.
+ ASSERT_FALSE(option_v6);
+
+ /* // Non-null pointer option is supposed to be returned and it
+ // should have Option6AddrLst type.
+ ASSERT_TRUE(option_v6);
+ ASSERT_TRUE(typeid(*option_v6) == typeid(Option6AddrLst));
+ // Cast to the actual option type to get IPv6 addresses from it.
+ boost::shared_ptr<Option6AddrLst> option_cast_v6 =
+ boost::static_pointer_cast<Option6AddrLst>(option_v6);
+ // Check that cast was successful.
+ ASSERT_TRUE(option_cast_v6);
+ // Get the list of parsed addresses from the option object.
+ std::vector<asiolink::IOAddress> addrs_returned =
+ option_cast_v6->getAddresses();
+ // Returned addresses must match the addresses that have been used to create
+ // the option instance.
+ EXPECT_TRUE(std::equal(addrs.begin(), addrs.end(), addrs_returned.begin())); */
+}
+
TEST_F(OptionDefinitionTest, factoryAddrList4) {
OptionDefinition opt_def("OPTION_NAME_SERVERS", D6O_NIS_SERVERS,
"ipv4-address", true);
More information about the bind10-changes
mailing list