Browse Source

[2526] Added universe parameter to OptionIntArray ctor.

Marcin Siodelski 12 years ago
parent
commit
f54d04b859

+ 1 - 1
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -352,7 +352,7 @@ TEST_F(Dhcpv6SrvTest, advertiseOptions) {
     // Let's now request option with code 1000.
     // We expect that server will include this option in its reply.
     boost::shared_ptr<OptionIntArray<uint16_t> >
-        option_oro(new OptionIntArray<uint16_t>(D6O_ORO));
+        option_oro(new OptionIntArray<uint16_t>(Option::V6, D6O_ORO));
     // Create vector with two option codes.
     std::vector<uint16_t> codes(2);
     codes[0] = 1000;

+ 4 - 4
src/lib/dhcp/option_definition.cc

@@ -97,19 +97,19 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
                     factoryInteger<int8_t>(u, type, begin, end));
 
         case OPT_UINT16_TYPE:
-            return (array_type_ ? factoryIntegerArray<uint16_t>(type, begin, end) :
+            return (array_type_ ? factoryIntegerArray<uint16_t>(u, type, begin, end) :
                     factoryInteger<uint16_t>(u, type, begin, end));
 
         case OPT_INT16_TYPE:
-            return (array_type_ ? factoryIntegerArray<uint16_t>(type, begin, end) :
+            return (array_type_ ? factoryIntegerArray<uint16_t>(u, type, begin, end) :
                     factoryInteger<int16_t>(u, type, begin, end));
 
         case OPT_UINT32_TYPE:
-            return (array_type_ ? factoryIntegerArray<uint32_t>(type, begin, end) :
+            return (array_type_ ? factoryIntegerArray<uint32_t>(u, type, begin, end) :
                     factoryInteger<uint32_t>(u, type, begin, end));
 
         case OPT_INT32_TYPE:
-            return (array_type_ ? factoryIntegerArray<uint32_t>(type, begin, end) :
+            return (array_type_ ? factoryIntegerArray<uint32_t>(u, type, begin, end) :
                     factoryInteger<int32_t>(u, type, begin, end));
 
         case OPT_IPV4_ADDRESS_TYPE:

+ 4 - 2
src/lib/dhcp/option_definition.h

@@ -361,6 +361,7 @@ public:
 
     /// @brief Factory function to create option with array of integer values.
     ///
+    /// @param universe (V4 or V6).
     /// @param type option type.
     /// @param begin iterator pointing to the beginning of the buffer.
     /// @param end iterator pointing to the end of the buffer.
@@ -368,10 +369,11 @@ public:
     ///
     /// @throw isc::OutOfRange if provided option buffer length is invalid.
     template<typename T>
-    static OptionPtr factoryIntegerArray(uint16_t type,
+    static OptionPtr factoryIntegerArray(Option::Universe u,
+                                         uint16_t type,
                                          OptionBufferConstIter begin,
                                          OptionBufferConstIter end) {
-        OptionPtr option(new OptionIntArray<T>(type, begin, end));
+        OptionPtr option(new OptionIntArray<T>(u, type, begin, end));
         return (option);
     }
 

+ 11 - 7
src/lib/dhcp/option_int_array.h

@@ -51,12 +51,13 @@ public:
     ///
     /// Creates option with empty values vector.
     ///
+    /// @param u universe (V4 or V6).
     /// @param type option type.
     ///
     /// @throw isc::dhcp::InvalidDataType if data field type provided
     /// as template parameter is not a supported integer type.
-    OptionIntArray(uint16_t type)
-        : Option(Option::V6, type),
+    OptionIntArray(const Option::Universe u, const uint16_t type)
+        : Option(u, type),
           values_(0) {
         if (!OptionDataTypeTraits<T>::integer_type) {
             isc_throw(dhcp::InvalidDataType, "non-integer type");
@@ -65,6 +66,7 @@ public:
 
     /// @brief Constructor.
     ///
+    /// @param u universe (V4 or V6).
     /// @param type option type.
     /// @param buf buffer with option data (must not be empty).
     ///
@@ -72,8 +74,9 @@ public:
     /// is not multiple of size of the data type in bytes.
     /// @throw isc::dhcp::InvalidDataType if data field type provided
     /// as template parameter is not a supported integer type.
-    OptionIntArray(uint16_t type, const OptionBuffer& buf)
-        : Option(Option::V6, type) {
+    OptionIntArray(const Option::Universe u, const uint16_t type,
+                   const OptionBuffer& buf)
+        : Option(u, type) {
         if (!OptionDataTypeTraits<T>::integer_type) {
             isc_throw(dhcp::InvalidDataType, "non-integer type");
         }
@@ -86,6 +89,7 @@ public:
     /// may throw exception if \ref unpack function throws during buffer
     /// parsing.
     ///
+    /// @param u universe (V4 or V6).
     /// @param type option type.
     /// @param begin iterator to first byte of option data.
     /// @param end iterator to end of option data (first byte after option end).
@@ -94,9 +98,9 @@ public:
     /// is not multiple of size of the data type in bytes.
     /// @throw isc::dhcp::InvalidDataType if data field type provided
     /// as template parameter is not a supported integer type.
-    OptionIntArray(uint16_t type, OptionBufferConstIter begin,
-                    OptionBufferConstIter end)
-        : Option(Option::V6, type) {
+    OptionIntArray(const Option::Universe u, const uint16_t type,
+                   OptionBufferConstIter begin, OptionBufferConstIter end)
+        : Option(u, type) {
         if (!OptionDataTypeTraits<T>::integer_type) {
             isc_throw(dhcp::InvalidDataType, "non-integer type");
         }

+ 44 - 33
src/lib/dhcp/tests/option_int_array_unittest.cc

@@ -48,9 +48,10 @@ public:
     /// @warning this function does not perform type check. Make
     /// sure that only int8_t or uint8_t type is used.
     ///
+    /// @param u universe (v4 or V6).
     /// @tparam T int8_t or uint8_t.
     template<typename T>
-    void bufferToIntTest8() {
+    void bufferToIntTest8(const Option::Universe u) {
         // Create option that conveys array of multiple uint8_t or int8_t values.
         // In fact there is no need to use this template class for array
         // of uint8_t values because Option class is sufficient - it
@@ -63,14 +64,14 @@ public:
 
         // Constructor throws exception if provided buffer is empty.
         EXPECT_THROW(
-            OptionIntArray<T>(opt_code, buf_.begin(), buf_.begin()),
+            OptionIntArray<T>(u, opt_code, buf_.begin(), buf_.begin()),
             isc::OutOfRange
         );
 
         // Provided buffer is not empty so it should not throw exception.
         ASSERT_NO_THROW(
             opt = boost::shared_ptr<
-                OptionIntArray<T> >(new OptionIntArray<T>(opt_code, buf_.begin(),
+                OptionIntArray<T> >(new OptionIntArray<T>(u, opt_code, buf_.begin(),
                                                           buf_.begin() + opt_len))
         );
 
@@ -120,9 +121,10 @@ public:
     /// @warning this function does not perform type check. Make
     /// sure that only int16_t or uint16_t type is used.
     ///
+    /// @param u universe (V4 or V6).
     /// @tparam T int16_t or uint16_t.
     template<typename T>
-    void bufferToIntTest16() {
+    void bufferToIntTest16(const Option::Universe u) {
         // Create option that conveys array of multiple uint16_t or int16_t values.
         boost::shared_ptr<OptionIntArray<T> > opt;
         const int opt_len = 20;
@@ -130,25 +132,25 @@ public:
 
         // Constructor throws exception if provided buffer is empty.
         EXPECT_THROW(
-            OptionIntArray<T>(opt_code, buf_.begin(), buf_.begin()),
+            OptionIntArray<T>(u, opt_code, buf_.begin(), buf_.begin()),
             isc::OutOfRange
         );
 
         // Constructor throws exception if provided buffer's length is not
         // multiple of 2-bytes.
         EXPECT_THROW(
-            OptionIntArray<T>(opt_code, buf_.begin(), buf_.begin() + 5),
+            OptionIntArray<T>(u, opt_code, buf_.begin(), buf_.begin() + 5),
             isc::OutOfRange
         );
 
         // Now the buffer length is correct.
         ASSERT_NO_THROW(
             opt = boost::shared_ptr<
-                OptionIntArray<T> >(new OptionIntArray<T>(opt_code, buf_.begin(),
+                OptionIntArray<T> >(new OptionIntArray<T>(u, opt_code, buf_.begin(),
                                                           buf_.begin() + opt_len))
         );
 
-        EXPECT_EQ(Option::V6, opt->getUniverse());
+        EXPECT_EQ(u, opt->getUniverse());
         EXPECT_EQ(opt_code, opt->getType());
         // Option should return vector of uint16_t values which should be
         // constructed from the buffer we provided.
@@ -191,9 +193,10 @@ public:
     /// @warning this function does not perform type check. Make
     /// sure that only int32_t or uint32_t type is used.
     ///
+    /// @param u universe (V4 or V6)
     /// @tparam T int32_t or uint32_t.
     template<typename T>
-    void bufferToIntTest32() {
+    void bufferToIntTest32(const Option::Universe u) {
         // Create option that conveys array of multiple uint16_t values.
         boost::shared_ptr<OptionIntArray<T> > opt;
         const int opt_len = 40;
@@ -201,25 +204,25 @@ public:
 
         // Constructor throws exception if provided buffer is empty.
         EXPECT_THROW(
-            OptionIntArray<T>(opt_code, buf_.begin(), buf_.begin()),
+            OptionIntArray<T>(u, opt_code, buf_.begin(), buf_.begin()),
             isc::OutOfRange
         );
 
         // Constructor throws exception if provided buffer's length is not
         // multiple of 4-bytes.
         EXPECT_THROW(
-            OptionIntArray<T>(opt_code, buf_.begin(), buf_.begin() + 9),
+            OptionIntArray<T>(u, opt_code, buf_.begin(), buf_.begin() + 9),
             isc::OutOfRange
         );
 
         // Now the buffer length is correct.
         ASSERT_NO_THROW(
             opt = boost::shared_ptr<
-                OptionIntArray<T> >(new OptionIntArray<T>(opt_code, buf_.begin(),
+                OptionIntArray<T> >(new OptionIntArray<T>(u, opt_code, buf_.begin(),
                                                           buf_.begin() + opt_len))
         );
 
-        EXPECT_EQ(Option::V6, opt->getUniverse());
+        EXPECT_EQ(u, opt->getUniverse());
         EXPECT_EQ(opt_code, opt->getType());
         // Option should return vector of uint32_t values which should be
         // constructed from the buffer we provided.
@@ -272,47 +275,50 @@ TEST_F(OptionIntArrayTest, useInvalidType) {
     const uint16_t opt_code = 80;
     EXPECT_THROW(
         boost::scoped_ptr<
-            OptionIntArray<bool> >(new OptionIntArray<bool>(opt_code, OptionBuffer(5))),
+            OptionIntArray<bool> >(new OptionIntArray<bool>(Option::V6, opt_code,
+                                                            OptionBuffer(5))),
         InvalidDataType
     );
 
     EXPECT_THROW(
         boost::scoped_ptr<
-            OptionIntArray<int64_t> >(new OptionIntArray<int64_t>(opt_code,
+            OptionIntArray<int64_t> >(new OptionIntArray<int64_t>(Option::V6,
+                                                                  opt_code,
                                                                   OptionBuffer(10))),
         InvalidDataType
     );
 
 }
 
-TEST_F(OptionIntArrayTest, bufferToUint8) {
-    bufferToIntTest8<uint8_t>();
+TEST_F(OptionIntArrayTest, bufferToUint8V6) {
+    bufferToIntTest8<uint8_t>(Option::V6);
 }
 
-TEST_F(OptionIntArrayTest, bufferToInt8) {
-    bufferToIntTest8<int8_t>();
+TEST_F(OptionIntArrayTest, bufferToInt8V6) {
+    bufferToIntTest8<int8_t>(Option::V6);
 }
 
-TEST_F(OptionIntArrayTest, bufferToUint16) {
-    bufferToIntTest16<uint16_t>();
+TEST_F(OptionIntArrayTest, bufferToUint16V6) {
+    bufferToIntTest16<uint16_t>(Option::V6);
 }
 
-TEST_F(OptionIntArrayTest, bufferToInt16) {
-    bufferToIntTest16<int16_t>();
+TEST_F(OptionIntArrayTest, bufferToInt16V6) {
+    bufferToIntTest16<int16_t>(Option::V6);
 }
 
-TEST_F(OptionIntArrayTest, bufferToUint32) {
-    bufferToIntTest32<uint32_t>();
+TEST_F(OptionIntArrayTest, bufferToUint32V6) {
+    bufferToIntTest32<uint32_t>(Option::V6);
 }
 
-TEST_F(OptionIntArrayTest, bufferToInt32) {
-    bufferToIntTest32<int32_t>();
+TEST_F(OptionIntArrayTest, bufferToInt32V6) {
+    bufferToIntTest32<int32_t>(Option::V6);
 }
 
 TEST_F(OptionIntArrayTest, setValuesUint8) {
     const uint16_t opt_code = 100;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<uint8_t> > opt(new OptionIntArray<uint8_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<uint8_t> >
+        opt(new OptionIntArray<uint8_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<uint8_t> values;
     for (int i = 0; i < 10; ++i) {
@@ -330,7 +336,8 @@ TEST_F(OptionIntArrayTest, setValuesUint8) {
 TEST_F(OptionIntArrayTest, setValuesInt8) {
     const uint16_t opt_code = 100;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<int8_t> > opt(new OptionIntArray<int8_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<int8_t> >
+        opt(new OptionIntArray<int8_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<int8_t> values;
     for (int i = 0; i < 10; ++i) {
@@ -348,7 +355,8 @@ TEST_F(OptionIntArrayTest, setValuesInt8) {
 TEST_F(OptionIntArrayTest, setValuesUint16) {
     const uint16_t opt_code = 101;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<uint16_t> > opt(new OptionIntArray<uint16_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<uint16_t> >
+        opt(new OptionIntArray<uint16_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<uint16_t> values;
     for (int i = 0; i < 10; ++i) {
@@ -366,7 +374,8 @@ TEST_F(OptionIntArrayTest, setValuesUint16) {
 TEST_F(OptionIntArrayTest, setValuesInt16) {
     const uint16_t opt_code = 101;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<int16_t> > opt(new OptionIntArray<int16_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<int16_t> >
+        opt(new OptionIntArray<int16_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<int16_t> values;
     for (int i = 0; i < 10; ++i) {
@@ -384,7 +393,8 @@ TEST_F(OptionIntArrayTest, setValuesInt16) {
 TEST_F(OptionIntArrayTest, setValuesUint32) {
     const uint32_t opt_code = 101;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<uint32_t> > opt(new OptionIntArray<uint32_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<uint32_t> >
+        opt(new OptionIntArray<uint32_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<uint32_t> values;
     for (int i = 0; i < 10; ++i) {
@@ -402,7 +412,8 @@ TEST_F(OptionIntArrayTest, setValuesUint32) {
 TEST_F(OptionIntArrayTest, setValuesInt32) {
     const uint32_t opt_code = 101;
     // Create option with empty vector of values.
-    boost::shared_ptr<OptionIntArray<int32_t> > opt(new OptionIntArray<int32_t>(opt_code));
+    boost::shared_ptr<OptionIntArray<int32_t> >
+        opt(new OptionIntArray<int32_t>(Option::V6, opt_code));
     // Initialize vector with some data and pass to the option.
     std::vector<int32_t> values;
     for (int i = 0; i < 10; ++i) {