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

[2526] Renamed Option6Int to OptionInt as this will be used for V4 too.

parent e0003025
......@@ -28,7 +28,7 @@ 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 += option6_int.h
libb10_dhcp___la_SOURCES += option_int.h
libb10_dhcp___la_SOURCES += option6_int_array.h
libb10_dhcp___la_SOURCES += dhcp6.h dhcp4.h
libb10_dhcp___la_SOURCES += pkt6.cc pkt6.h
......
......@@ -17,8 +17,8 @@
#include <dhcp/option6_addrlst.h>
#include <dhcp/option6_ia.h>
#include <dhcp/option6_iaaddr.h>
#include <dhcp/option6_int.h>
#include <dhcp/option6_int_array.h>
#include <dhcp/option_int.h>
#include <dhcp/option_custom.h>
#include <dhcp/option_definition.h>
#include <util/encode/hex.h>
......
......@@ -48,15 +48,15 @@ class OptionDefinition;
/// @brief Pointer to option definition object.
typedef boost::shared_ptr<OptionDefinition> OptionDefinitionPtr;
/// @brief Forward declaration to Option6Int.
/// @brief Forward declaration to OptionInt.
///
/// This forward declaration is needed to access Option6Int class
/// This forward declaration is needed to access OptionInt class
/// without having to include option6_int.h header. This is because
/// this header includes libdhcp++.h and this causes circular
/// inclusion between libdhcp++.h, option_definition.h and
/// option6_int.h.
template<typename T>
class Option6Int;
class OptionInt;
/// @brief Forward declaration to Option6IntArray.
///
......@@ -354,7 +354,7 @@ public:
static OptionPtr factoryInteger(Option::Universe, uint16_t type,
OptionBufferConstIter begin,
OptionBufferConstIter end) {
OptionPtr option(new Option6Int<T>(type, begin, end));
OptionPtr option(new OptionInt<T>(type, begin, end));
return (option);
}
......
......@@ -12,8 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef OPTION6_INT_H
#define OPTION6_INT_H
#ifndef OPTION_INT_H
#define OPTION_INT_H
#include <dhcp/libdhcp++.h>
#include <dhcp/option.h>
......@@ -25,7 +25,7 @@
namespace isc {
namespace dhcp {
/// This template class represents DHCPv6 option with single value.
/// This template class represents DHCP option with single value.
/// This value is of integer type and can be any of the following:
/// - uint8_t,
/// - uint16_t,
......@@ -36,7 +36,7 @@ namespace dhcp {
///
/// @param T data field type (see above).
template<typename T>
class Option6Int: public Option {
class OptionInt: public Option {
public:
/// @brief Constructor.
......@@ -46,7 +46,7 @@ public:
///
/// @throw isc::dhcp::InvalidDataType if data field type provided
/// as template parameter is not a supported integer type.
Option6Int(uint16_t type, T value)
OptionInt(uint16_t type, T value)
: Option(Option::V6, type), value_(value) {
if (!OptionDataTypeTraits<T>::integer_type) {
isc_throw(dhcp::InvalidDataType, "non-integer type");
......@@ -66,7 +66,7 @@ public:
/// @throw isc::OutOfRange if provided buffer is shorter than data size.
/// @throw isc::dhcp::InvalidDataType if data field type provided
/// as template parameter is not a supported integer type.
Option6Int(uint16_t type, OptionBufferConstIter begin,
OptionInt(uint16_t type, OptionBufferConstIter begin,
OptionBufferConstIter end)
: Option(Option::V6, type) {
if (!OptionDataTypeTraits<T>::integer_type) {
......
......@@ -34,7 +34,7 @@ libdhcp___unittests_SOURCES += option6_addrlst_unittest.cc
libdhcp___unittests_SOURCES += option6_ia_unittest.cc
libdhcp___unittests_SOURCES += option6_iaaddr_unittest.cc
libdhcp___unittests_SOURCES += option6_int_array_unittest.cc
libdhcp___unittests_SOURCES += option6_int_unittest.cc
libdhcp___unittests_SOURCES += option_int_unittest.cc
libdhcp___unittests_SOURCES += option_data_types_unittest.cc
libdhcp___unittests_SOURCES += option_definition_unittest.cc
libdhcp___unittests_SOURCES += option_custom_unittest.cc
......
......@@ -20,8 +20,8 @@
#include <dhcp/option6_addrlst.h>
#include <dhcp/option6_ia.h>
#include <dhcp/option6_iaaddr.h>
#include <dhcp/option6_int.h>
#include <dhcp/option6_int_array.h>
#include <dhcp/option_int.h>
#include <dhcp/option_custom.h>
#include <util/buffer.h>
......@@ -314,8 +314,8 @@ TEST_F(LibDhcpTest, unpackOptions6) {
// Option with code 8 is OPTION_ELAPSED_TIME. This option is
// represented by Option6Int<uint16_t> value that holds single
// uint16_t value.
boost::shared_ptr<Option6Int<uint16_t> > opt_elapsed_time =
boost::dynamic_pointer_cast<Option6Int<uint16_t> >(x->second);
boost::shared_ptr<OptionInt<uint16_t> > opt_elapsed_time =
boost::dynamic_pointer_cast<OptionInt<uint16_t> >(x->second);
// This value will be NULL if cast was unsuccessful. This is the case
// when returned option has different type than expected.
ASSERT_TRUE(opt_elapsed_time);
......@@ -627,7 +627,7 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
LibDhcpTest::testStdOptionDefs6(D6O_IA_NA, buf, typeid(Option6IA));
LibDhcpTest::testStdOptionDefs6(D6O_IA_TA, buf,
typeid(Option6Int<uint32_t>));
typeid(OptionInt<uint32_t>));
LibDhcpTest::testStdOptionDefs6(D6O_IAADDR, buf, typeid(Option6IAAddr));
......@@ -635,10 +635,10 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
typeid(Option6IntArray<uint16_t>));
LibDhcpTest::testStdOptionDefs6(D6O_PREFERENCE, buf,
typeid(Option6Int<uint8_t>));
typeid(OptionInt<uint8_t>));
LibDhcpTest::testStdOptionDefs6(D6O_ELAPSED_TIME, buf,
typeid(Option6Int<uint16_t>));
typeid(OptionInt<uint16_t>));
LibDhcpTest::testStdOptionDefs6(D6O_RELAY_MSG, buf, typeid(Option));
......@@ -656,7 +656,7 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
LibDhcpTest::testStdOptionDefs6(D6O_INTERFACE_ID, buf, typeid(Option));
LibDhcpTest::testStdOptionDefs6(D6O_RECONF_MSG, buf,
typeid(Option6Int<uint8_t>));
typeid(OptionInt<uint8_t>));
LibDhcpTest::testStdOptionDefs6(D6O_RECONF_ACCEPT, buf, typeid(Option));
......@@ -692,7 +692,7 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
typeid(Option6AddrLst));
LibDhcpTest::testStdOptionDefs6(D6O_INFORMATION_REFRESH_TIME,
buf, typeid(Option6Int<uint32_t>));
buf, typeid(OptionInt<uint32_t>));
LibDhcpTest::testStdOptionDefs6(D6O_BCMCS_SERVER_D, fqdn_buf,
typeid(OptionCustom));
......@@ -730,7 +730,7 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
LibDhcpTest::testStdOptionDefs6(D6O_CLIENT_DATA, buf, typeid(Option));
LibDhcpTest::testStdOptionDefs6(D6O_CLT_TIME, buf,
typeid(Option6Int<uint32_t>));
typeid(OptionInt<uint32_t>));
LibDhcpTest::testStdOptionDefs6(D6O_LQ_RELAY_DATA, buf,
typeid(OptionCustom));
......
......@@ -21,10 +21,10 @@
#include <dhcp/option6_addrlst.h>
#include <dhcp/option6_ia.h>
#include <dhcp/option6_iaaddr.h>
#include <dhcp/option6_int.h>
#include <dhcp/option6_int_array.h>
#include <dhcp/option_custom.h>
#include <dhcp/option_definition.h>
#include <dhcp/option_int.h>
#include <exceptions/exceptions.h>
#include <boost/pointer_cast.hpp>
......@@ -578,10 +578,10 @@ TEST_F(OptionDefinitionTest, uint8) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_PREFERENCE, OptionBuffer(1, 1));
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint8_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint8_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint8_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint8_t> >(option_v6);
boost::shared_ptr<OptionInt<uint8_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint8_t> >(option_v6);
EXPECT_EQ(1, option_cast_v6->getValue());
// Try to provide zero-length buffer. Expect exception.
......@@ -606,10 +606,10 @@ TEST_F(OptionDefinitionTest, uint8Tokenized) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_PREFERENCE, values);
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint8_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint8_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint8_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint8_t> >(option_v6);
boost::shared_ptr<OptionInt<uint8_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint8_t> >(option_v6);
EXPECT_EQ(123, option_cast_v6->getValue());
// @todo Add more cases for DHCPv4
......@@ -629,10 +629,10 @@ TEST_F(OptionDefinitionTest, uint16) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_ELAPSED_TIME, buf);
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint16_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint16_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint16_t> >(option_v6);
boost::shared_ptr<OptionInt<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint16_t> >(option_v6);
EXPECT_EQ(0x0102, option_cast_v6->getValue());
// Try to provide zero-length buffer. Expect exception.
......@@ -658,10 +658,10 @@ TEST_F(OptionDefinitionTest, uint16Tokenized) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_ELAPSED_TIME, values);
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint16_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint16_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint16_t> >(option_v6);
boost::shared_ptr<OptionInt<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint16_t> >(option_v6);
EXPECT_EQ(1234, option_cast_v6->getValue());
// @todo Add more cases for DHCPv4
......@@ -683,10 +683,10 @@ TEST_F(OptionDefinitionTest, uint32) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_CLT_TIME, buf);
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint32_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint32_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint32_t> >(option_v6);
boost::shared_ptr<OptionInt<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint32_t> >(option_v6);
EXPECT_EQ(0x01020304, option_cast_v6->getValue());
// Try to provide too short buffer. Expect exception.
......@@ -711,10 +711,10 @@ TEST_F(OptionDefinitionTest, uint32Tokenized) {
ASSERT_NO_THROW(
option_v6 = opt_def.optionFactory(Option::V6, D6O_CLT_TIME, values);
);
ASSERT_TRUE(typeid(*option_v6) == typeid(Option6Int<uint32_t>));
ASSERT_TRUE(typeid(*option_v6) == typeid(OptionInt<uint32_t>));
// Validate the value.
boost::shared_ptr<Option6Int<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<Option6Int<uint32_t> >(option_v6);
boost::shared_ptr<OptionInt<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<OptionInt<uint32_t> >(option_v6);
EXPECT_EQ(123456, option_cast_v6->getValue());
// @todo Add more cases for DHCPv4
......
......@@ -17,7 +17,7 @@
#include <dhcp/dhcp6.h>
#include <dhcp/option.h>
#include <dhcp/option6_iaaddr.h>
#include <dhcp/option6_int.h>
#include <dhcp/option_int.h>
#include <util/buffer.h>
#include <boost/pointer_cast.hpp>
......@@ -31,13 +31,13 @@ using namespace isc::util;
namespace {
/// @brief Option6Int test class.
class Option6IntTest : public ::testing::Test {
/// @brief OptionInt test class.
class OptionIntTest : public ::testing::Test {
public:
/// @brief Constructor.
///
/// Initializes the option buffer with some data.
Option6IntTest(): buf_(255), out_buf_(255) {
OptionIntTest(): buf_(255), out_buf_(255) {
for (int i = 0; i < 255; i++) {
buf_[i] = 255 - i;
}
......@@ -52,12 +52,12 @@ public:
template<typename T>
void basicTest8() {
// Create option that conveys single 8 bit integer value.
boost::shared_ptr<Option6Int<T> > opt;
boost::shared_ptr<OptionInt<T> > opt;
// Initialize buffer with this value.
buf_[0] = 0xa1;
// Constructor may throw in case provided buffer is too short.
ASSERT_NO_THROW(
opt = boost::shared_ptr<Option6Int<T> >(new Option6Int<T>(D6O_PREFERENCE,
opt = boost::shared_ptr<OptionInt<T> >(new OptionInt<T>(D6O_PREFERENCE,
buf_.begin(),
buf_.end()))
);
......@@ -96,13 +96,13 @@ public:
template<typename T>
void basicTest16() {
// Create option that conveys single 16-bit integer value.
boost::shared_ptr<Option6Int<T> > opt;
boost::shared_ptr<OptionInt<T> > opt;
// Initialize buffer with uint16_t value.
buf_[0] = 0xa1;
buf_[1] = 0xa2;
// Constructor may throw in case provided buffer is too short.
ASSERT_NO_THROW(
opt = boost::shared_ptr<Option6Int<T> >(new Option6Int<T>(D6O_ELAPSED_TIME,
opt = boost::shared_ptr<OptionInt<T> >(new OptionInt<T>(D6O_ELAPSED_TIME,
buf_.begin(),
buf_.end()))
);
......@@ -141,7 +141,7 @@ public:
template<typename T>
void basicTest32() {
// Create option that conveys single 32-bit integer value.
boost::shared_ptr<Option6Int<T> > opt;
boost::shared_ptr<OptionInt<T> > opt;
// Initialize buffer with 32-bit integer value.
buf_[0] = 0xa1;
buf_[1] = 0xa2;
......@@ -149,7 +149,7 @@ public:
buf_[3] = 0xa4;
// Constructor may throw in case provided buffer is too short.
ASSERT_NO_THROW(
opt = boost::shared_ptr<Option6Int<T> >(new Option6Int<T>(D6O_CLT_TIME,
opt = boost::shared_ptr<OptionInt<T> >(new OptionInt<T>(D6O_CLT_TIME,
buf_.begin(),
buf_.end()))
);
......@@ -187,45 +187,45 @@ public:
/// convey unsigned value. We should maybe extend these tests for
/// signed types too.
TEST_F(Option6IntTest, useInvalidType) {
TEST_F(OptionIntTest, useInvalidType) {
EXPECT_THROW(
boost::scoped_ptr<Option6Int<bool> >(new Option6Int<bool>(D6O_ELAPSED_TIME, 10)),
boost::scoped_ptr<OptionInt<bool> >(new OptionInt<bool>(D6O_ELAPSED_TIME, 10)),
InvalidDataType
);
EXPECT_THROW(
boost::scoped_ptr<Option6Int<int64_t> >(new Option6Int<int64_t>(D6O_ELAPSED_TIME, 10)),
boost::scoped_ptr<OptionInt<int64_t> >(new OptionInt<int64_t>(D6O_ELAPSED_TIME, 10)),
InvalidDataType
);
}
TEST_F(Option6IntTest, basicUint8) {
TEST_F(OptionIntTest, basicUint8) {
basicTest8<uint8_t>();
}
TEST_F(Option6IntTest, basicUint16) {
TEST_F(OptionIntTest, basicUint16) {
basicTest16<uint16_t>();
}
TEST_F(Option6IntTest, basicUint32) {
TEST_F(OptionIntTest, basicUint32) {
basicTest32<uint32_t>();
}
TEST_F(Option6IntTest, basicInt8) {
TEST_F(OptionIntTest, basicInt8) {
basicTest8<int8_t>();
}
TEST_F(Option6IntTest, basicInt16) {
TEST_F(OptionIntTest, basicInt16) {
basicTest16<int16_t>();
}
TEST_F(Option6IntTest, basicInt32) {
TEST_F(OptionIntTest, basicInt32) {
basicTest32<int32_t>();
}
TEST_F(Option6IntTest, setValueUint8) {
boost::shared_ptr<Option6Int<uint8_t> > opt(new Option6Int<uint8_t>(D6O_PREFERENCE, 123));
TEST_F(OptionIntTest, setValueUint8) {
boost::shared_ptr<OptionInt<uint8_t> > opt(new OptionInt<uint8_t>(D6O_PREFERENCE, 123));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(123, opt->getValue());
// Override the value.
......@@ -237,8 +237,8 @@ TEST_F(Option6IntTest, setValueUint8) {
EXPECT_EQ(111, opt->getValue());
}
TEST_F(Option6IntTest, setValueInt8) {
boost::shared_ptr<Option6Int<int8_t> > opt(new Option6Int<int8_t>(D6O_PREFERENCE, -123));
TEST_F(OptionIntTest, setValueInt8) {
boost::shared_ptr<OptionInt<int8_t> > opt(new OptionInt<int8_t>(D6O_PREFERENCE, -123));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(-123, opt->getValue());
// Override the value.
......@@ -251,8 +251,8 @@ TEST_F(Option6IntTest, setValueInt8) {
}
TEST_F(Option6IntTest, setValueUint16) {
boost::shared_ptr<Option6Int<uint16_t> > opt(new Option6Int<uint16_t>(D6O_ELAPSED_TIME, 123));
TEST_F(OptionIntTest, setValueUint16) {
boost::shared_ptr<OptionInt<uint16_t> > opt(new OptionInt<uint16_t>(D6O_ELAPSED_TIME, 123));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(123, opt->getValue());
// Override the value.
......@@ -264,8 +264,8 @@ TEST_F(Option6IntTest, setValueUint16) {
EXPECT_EQ(0x0102, opt->getValue());
}
TEST_F(Option6IntTest, setValueInt16) {
boost::shared_ptr<Option6Int<int16_t> > opt(new Option6Int<int16_t>(D6O_ELAPSED_TIME, -16500));
TEST_F(OptionIntTest, setValueInt16) {
boost::shared_ptr<OptionInt<int16_t> > opt(new OptionInt<int16_t>(D6O_ELAPSED_TIME, -16500));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(-16500, opt->getValue());
// Override the value.
......@@ -277,8 +277,8 @@ TEST_F(Option6IntTest, setValueInt16) {
EXPECT_EQ(-20100, opt->getValue());
}
TEST_F(Option6IntTest, setValueUint32) {
boost::shared_ptr<Option6Int<uint32_t> > opt(new Option6Int<uint32_t>(D6O_CLT_TIME, 123));
TEST_F(OptionIntTest, setValueUint32) {
boost::shared_ptr<OptionInt<uint32_t> > opt(new OptionInt<uint32_t>(D6O_CLT_TIME, 123));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(123, opt->getValue());
// Override the value.
......@@ -290,8 +290,8 @@ TEST_F(Option6IntTest, setValueUint32) {
EXPECT_EQ(0x01020304, opt->getValue());
}
TEST_F(Option6IntTest, setValueint32) {
boost::shared_ptr<Option6Int<int32_t> > opt(new Option6Int<int32_t>(D6O_CLT_TIME, -120100));
TEST_F(OptionIntTest, setValueint32) {
boost::shared_ptr<OptionInt<int32_t> > opt(new OptionInt<int32_t>(D6O_CLT_TIME, -120100));
// Check if constructor intitialized the option value correctly.
EXPECT_EQ(-120100, opt->getValue());
// Override the value.
......@@ -303,12 +303,12 @@ TEST_F(Option6IntTest, setValueint32) {
EXPECT_EQ(-125000, opt->getValue());
}
TEST_F(Option6IntTest, packSuboptions) {
TEST_F(OptionIntTest, packSuboptions) {
// option code is really uint16_t, but using uint8_t
// for easier conversion to uint8_t array.
uint8_t opt_code = 80;
boost::shared_ptr<Option6Int<uint32_t> > opt(new Option6Int<uint32_t>(opt_code, 0x01020304));
boost::shared_ptr<OptionInt<uint32_t> > opt(new OptionInt<uint32_t>(opt_code, 0x01020304));
OptionPtr sub1(new Option(Option::V6, 0xcafe));
boost::shared_ptr<Option6IAAddr> addr1(
......@@ -347,7 +347,7 @@ TEST_F(Option6IntTest, packSuboptions) {
}
TEST_F(Option6IntTest, unpackSuboptions) {
TEST_F(OptionIntTest, unpackSuboptions) {
// option code is really uint16_t, but using uint8_t
// for easier conversion to uint8_t array.
const uint8_t opt_code = 80;
......@@ -373,10 +373,10 @@ TEST_F(Option6IntTest, unpackSuboptions) {
memcpy(&buf_[0], expected, sizeof(expected));
boost::shared_ptr<Option6Int<uint16_t> > opt;
boost::shared_ptr<OptionInt<uint16_t> > opt;
EXPECT_NO_THROW(
opt = boost::shared_ptr<
Option6Int<uint16_t> >(new Option6Int<uint16_t>(opt_code, buf_.begin() + 4,
OptionInt<uint16_t> >(new OptionInt<uint16_t>(opt_code, buf_.begin() + 4,
buf_.begin() + sizeof(expected)));
);
ASSERT_TRUE(opt);
......
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