BIND 10 trac1446, updated. 932e38a12ca938afa18563e89efb5931dbd63576 [trac1446] renamed libdhcp.cc to libdhcp++.cc and libdhcp.h to libdhcp++.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 2 20:01:48 UTC 2011
The branch, trac1446 has been updated
via 932e38a12ca938afa18563e89efb5931dbd63576 (commit)
via 55e89adf8bff6709a86b3331b809a47662b7a05b (commit)
from f9cbe6fb6e0a3d3dc03218429f530e6c01920169 (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 932e38a12ca938afa18563e89efb5931dbd63576
Author: Jeremy C. Reed <jreed at ISC.org>
Date: Fri Dec 2 13:49:23 2011 -0600
[trac1446] renamed libdhcp.cc to libdhcp++.cc and libdhcp.h to libdhcp++.h
and renamed libdhcp_unittest to libdhcp++_unittest
(but didn't change LibDHCP within code)
commit 55e89adf8bff6709a86b3331b809a47662b7a05b
Author: Jeremy C. Reed <jreed at ISC.org>
Date: Fri Dec 2 12:40:54 2011 -0600
[trac1446] rename libdhcp.la to libdhcp++.la
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp6/Makefile.am | 2 +-
src/bin/dhcp6/tests/Makefile.am | 2 +-
src/lib/dhcp/Makefile.am | 26 ++++++++++----------
src/lib/dhcp/README | 4 +-
src/lib/dhcp/{libdhcp.cc => libdhcp++.cc} | 2 +-
src/lib/dhcp/{libdhcp.h => libdhcp++.h} | 0
src/lib/dhcp/option.cc | 2 +-
src/lib/dhcp/option6_addrlst.cc | 2 +-
src/lib/dhcp/option6_ia.cc | 2 +-
src/lib/dhcp/option6_iaaddr.cc | 2 +-
src/lib/dhcp/pkt4.cc | 2 +-
src/lib/dhcp/pkt6.cc | 2 +-
src/lib/dhcp/tests/Makefile.am | 3 +-
.../{libdhcp_unittest.cc => libdhcp++_unittest.cc} | 2 +-
14 files changed, 27 insertions(+), 26 deletions(-)
rename src/lib/dhcp/{libdhcp.cc => libdhcp++.cc} (99%)
rename src/lib/dhcp/{libdhcp.h => libdhcp++.h} (100%)
rename src/lib/dhcp/tests/{libdhcp_unittest.cc => libdhcp++_unittest.cc} (99%)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp6/Makefile.am b/src/bin/dhcp6/Makefile.am
index b0f8cd9..fd59c68 100644
--- a/src/bin/dhcp6/Makefile.am
+++ b/src/bin/dhcp6/Makefile.am
@@ -35,7 +35,7 @@ pkglibexec_PROGRAMS = b10-dhcp6
b10_dhcp6_SOURCES = main.cc iface_mgr.cc dhcp6_srv.cc
b10_dhcp6_SOURCES += iface_mgr.h dhcp6_srv.h
-b10_dhcp6_LDADD = $(top_builddir)/src/lib/dhcp/libdhcp.la
+b10_dhcp6_LDADD = $(top_builddir)/src/lib/dhcp/libdhcp++.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/log/liblog.la
diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am
index 985368e..1f1407b 100644
--- a/src/bin/dhcp6/tests/Makefile.am
+++ b/src/bin/dhcp6/tests/Makefile.am
@@ -56,7 +56,7 @@ dhcp6_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
dhcp6_unittests_LDADD = $(GTEST_LDADD)
dhcp6_unittests_LDADD += $(SQLITE_LIBS)
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
-dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp.la
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp++.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
endif
diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am
index 64dda17..7e1602e 100644
--- a/src/lib/dhcp/Makefile.am
+++ b/src/lib/dhcp/Makefile.am
@@ -7,20 +7,20 @@ AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
-lib_LTLIBRARIES = libdhcp.la
-libdhcp_la_SOURCES =
-libdhcp_la_SOURCES += libdhcp.cc libdhcp.h
-libdhcp_la_SOURCES += option.cc option.h
-libdhcp_la_SOURCES += option6_ia.cc option6_ia.h
-libdhcp_la_SOURCES += option6_iaaddr.cc option6_iaaddr.h
-libdhcp_la_SOURCES += option6_addrlst.cc option6_addrlst.h
-libdhcp_la_SOURCES += dhcp6.h dhcp4.h
-libdhcp_la_SOURCES += pkt6.cc pkt6.h
-libdhcp_la_SOURCES += pkt4.cc pkt4.h
+lib_LTLIBRARIES = libdhcp++.la
+libdhcp___la_SOURCES =
+libdhcp___la_SOURCES += libdhcp++.cc libdhcp++.h
+libdhcp___la_SOURCES += option.cc option.h
+libdhcp___la_SOURCES += option6_ia.cc option6_ia.h
+libdhcp___la_SOURCES += option6_iaaddr.cc option6_iaaddr.h
+libdhcp___la_SOURCES += option6_addrlst.cc option6_addrlst.h
+libdhcp___la_SOURCES += dhcp6.h dhcp4.h
+libdhcp___la_SOURCES += pkt6.cc pkt6.h
+libdhcp___la_SOURCES += pkt4.cc pkt4.h
EXTRA_DIST = README
#EXTRA_DIST += log_messages.mes
-libdhcp_la_CXXFLAGS = $(AM_CXXFLAGS)
-libdhcp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
-libdhcp_la_LIBADD = $(top_builddir)/src/lib/util/libutil.la
+libdhcp___la_CXXFLAGS = $(AM_CXXFLAGS)
+libdhcp___la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
+libdhcp___la_LIBADD = $(top_builddir)/src/lib/util/libutil.la
diff --git a/src/lib/dhcp/README b/src/lib/dhcp/README
index 6c5353d..6bd6384 100644
--- a/src/lib/dhcp/README
+++ b/src/lib/dhcp/README
@@ -1,4 +1,4 @@
-This directory holds implementation for libdhcp.
+This directory holds implementation for libdhcp++.
Basic Ideas
@@ -8,4 +8,4 @@ Basic Ideas
Notes
=====
This work just begun. Don't expect to see much useful code here.
-We are working on it.
\ No newline at end of file
+We are working on it.
diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc
new file mode 100644
index 0000000..579c77c
--- /dev/null
+++ b/src/lib/dhcp/libdhcp++.cc
@@ -0,0 +1,170 @@
+// Copyright (C) 2011 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 <boost/shared_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <util/buffer.h>
+#include <dhcp/libdhcp++.h>
+#include "config.h"
+#include <dhcp/dhcp6.h>
+#include <dhcp/option.h>
+#include <dhcp/option6_ia.h>
+#include <dhcp/option6_iaaddr.h>
+
+using namespace std;
+using namespace isc::dhcp;
+using namespace isc::util;
+
+// static array with factories for options
+std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
+
+unsigned int
+LibDHCP::unpackOptions6(const boost::shared_array<uint8_t> buf,
+ unsigned int buf_len,
+ unsigned int offset, unsigned int parse_len,
+ isc::dhcp::Option::OptionCollection& options) {
+ if (offset + parse_len > buf_len) {
+ isc_throw(OutOfRange, "Option parse failed. Tried to parse "
+ << parse_len << " bytes at offset " << offset
+ << ": out of buffer");
+ }
+ unsigned int end = offset + parse_len;
+
+ while (offset +4 <= end) {
+ uint16_t opt_type = buf[offset]*256 + buf[offset+1];
+ offset += 2;
+ uint16_t opt_len = buf[offset]*256 + buf[offset+1];
+ offset += 2;
+
+ if (offset + opt_len > end ) {
+ cout << "Option " << opt_type << " truncated." << endl;
+ return (offset);
+ }
+ boost::shared_ptr<Option> opt;
+ switch (opt_type) {
+ case D6O_IA_NA:
+ case D6O_IA_PD:
+ // cout << "Creating Option6IA" << endl;
+ opt = boost::shared_ptr<Option>(new Option6IA(opt_type,
+ buf, buf_len,
+ offset,
+ opt_len));
+ break;
+ case D6O_IAADDR:
+ // cout << "Creating Option6IAAddr" << endl;
+ opt = boost::shared_ptr<Option>(new Option6IAAddr(opt_type,
+ buf, buf_len,
+ offset, opt_len));
+ break;
+ default:
+ // cout << "Creating Option" << endl;
+ opt = boost::shared_ptr<Option>(new Option(Option::V6,
+ opt_type,
+ buf,
+ offset,
+ opt_len));
+ break;
+ }
+ // add option to options
+ options.insert(pair<int, boost::shared_ptr<Option> >(opt_type, opt));
+ offset += opt_len;
+ }
+
+ return (offset);
+}
+
+void
+LibDHCP::unpackOptions4(const std::vector<uint8_t>& buf,
+ isc::dhcp::Option::OptionCollection& options) {
+ size_t offset = 0;
+
+ // 2 - header of DHCPv4 option
+ while (offset + 2 <= buf.size()) {
+ uint8_t opt_type = buf[offset++];
+ uint8_t opt_len = buf[offset++];
+ if (offset + opt_len > buf.size() ) {
+ isc_throw(OutOfRange, "Option parse failed. Tried to parse "
+ << offset + opt_len << " bytes from " << buf.size()
+ << "-byte long buffer.");
+ }
+
+ boost::shared_ptr<Option> opt;
+ switch(opt_type) {
+ default:
+ opt = boost::shared_ptr<Option>(new Option(Option::V4, opt_type,
+ buf.begin()+offset,
+ buf.begin()+offset+opt_len));
+ }
+
+ options.insert(pair<int, boost::shared_ptr<Option> >(opt_type, opt));
+ offset += opt_len;
+ }
+}
+
+unsigned int
+LibDHCP::packOptions6(boost::shared_array<uint8_t> data,
+ unsigned int data_len,
+ unsigned int offset,
+ const isc::dhcp::Option::OptionCollection& options) {
+ try {
+ for (Option::OptionCollection::const_iterator it = options.begin();
+ it != options.end();
+ ++it) {
+ unsigned short opt_len = (*it).second->len();
+ if (offset + opt_len > data_len) {
+ isc_throw(OutOfRange, "Failed to build option " <<
+ (*it).first << ": out of buffer");
+ }
+ offset = it->second->pack(data, data_len, offset);
+ }
+ }
+ catch (const Exception& e) {
+ cout << "Packet build failed (Option build failed)." << endl;
+ throw;
+ }
+ return (offset);
+}
+
+void
+LibDHCP::packOptions(isc::util::OutputBuffer& buf,
+ const Option::OptionCollection& options) {
+ for (Option::OptionCollection::const_iterator it = options.begin();
+ it != options.end();
+ ++it) {
+ it->second->pack4(buf);
+ }
+}
+
+
+bool
+LibDHCP::OptionFactoryRegister(Option::Universe u,
+ unsigned short opt_type,
+ Option::Factory * factory) {
+ switch (u) {
+ case Option::V6: {
+ if (v6factories_.find(opt_type)!=v6factories_.end()) {
+ isc_throw(BadValue, "There is already DHCPv6 factory registered "
+ << "for option type " << opt_type);
+ }
+ v6factories_[opt_type]=factory;
+ return true;
+ }
+ case Option::V4:
+ default:{
+ isc_throw(BadValue, "This universe type is not supported yet.");
+ return false; // never happens
+ }
+ }
+
+}
diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h
new file mode 100644
index 0000000..468e6bb
--- /dev/null
+++ b/src/lib/dhcp/libdhcp++.h
@@ -0,0 +1,103 @@
+// Copyright (C) 2011 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 LIBDHCP_H_
+#define LIBDHCP_H_
+
+#include <iostream>
+#include <util/buffer.h>
+#include <dhcp/pkt6.h>
+
+namespace isc {
+namespace dhcp {
+
+class LibDHCP {
+
+public:
+ /// Builds collection of options.
+ ///
+ /// Builds raw (on-wire) data for provided collection of options.
+ ///
+ /// @param buf shared pointer to buffer. Data will be stored there.
+ /// @param buf_len buffer length. Used for buffer overflow protection.
+ /// @param offset Offset from beginning of the buffer, where store options
+ /// @param options collection of options to store to
+ ///
+ /// @return offset to the first unused byte in buffer (next one after last
+ /// used byte)
+ ///
+ static unsigned int
+ packOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
+ unsigned int offset,
+ const isc::dhcp::Option::OptionCollection& options);
+
+
+ /// @brief Stores options in a buffer.
+ ///
+ /// Stores all options defined in options containers in a on-wire
+ /// format in output buffer specified by buf.
+ ///
+ /// May throw different exceptions if option assembly fails. There
+ /// may be different reasons (option too large, option malformed,
+ /// too many options etc.)
+ ///
+ /// @param buf
+ /// @param options
+ static void
+ packOptions(isc::util::OutputBuffer& buf,
+ const isc::dhcp::Option::OptionCollection& options);
+
+ static void
+ unpackOptions4(const std::vector<uint8_t>& buf,
+ isc::dhcp::Option::OptionCollection& options);
+ ///
+ /// Parses provided buffer and creates Option objects.
+ ///
+ /// Parses provided buf array and stores created Option objects
+ /// in options container.
+ ///
+ /// @param buf Buffer to be parsed.
+ /// @param offset Specifies offset for the first option.
+ /// @param options Reference to option container. Options will be
+ /// put here.
+ ///
+ /// @return offset to first byte after last parsed option
+ ///
+ static unsigned int
+ unpackOptions6(const boost::shared_array<uint8_t> buf, unsigned int buf_len,
+ unsigned int offset, unsigned int parse_len,
+ isc::dhcp::Option::OptionCollection& options_);
+
+ ///
+ /// Registers factory method that produces options of specific option types.
+ ///
+ /// @param u universe of the option (V4 or V6)
+ /// @param opt_type option-type
+ /// @param factory function pointer
+ ///
+ /// @return true, if registration was successful, false otherwise
+ ///
+ static bool
+ OptionFactoryRegister(Option::Universe u,
+ unsigned short type,
+ Option::Factory * factory);
+protected:
+ // pointers to factories that produce DHCPv6 options
+ static std::map<unsigned short, Option::Factory*> v6factories_;
+};
+
+}
+}
+
+#endif
diff --git a/src/lib/dhcp/libdhcp.cc b/src/lib/dhcp/libdhcp.cc
deleted file mode 100644
index b95a427..0000000
--- a/src/lib/dhcp/libdhcp.cc
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (C) 2011 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 <boost/shared_array.hpp>
-#include <boost/shared_ptr.hpp>
-#include <util/buffer.h>
-#include <dhcp/libdhcp.h>
-#include "config.h"
-#include <dhcp/dhcp6.h>
-#include <dhcp/option.h>
-#include <dhcp/option6_ia.h>
-#include <dhcp/option6_iaaddr.h>
-
-using namespace std;
-using namespace isc::dhcp;
-using namespace isc::util;
-
-// static array with factories for options
-std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
-
-unsigned int
-LibDHCP::unpackOptions6(const boost::shared_array<uint8_t> buf,
- unsigned int buf_len,
- unsigned int offset, unsigned int parse_len,
- isc::dhcp::Option::OptionCollection& options) {
- if (offset + parse_len > buf_len) {
- isc_throw(OutOfRange, "Option parse failed. Tried to parse "
- << parse_len << " bytes at offset " << offset
- << ": out of buffer");
- }
- unsigned int end = offset + parse_len;
-
- while (offset +4 <= end) {
- uint16_t opt_type = buf[offset]*256 + buf[offset+1];
- offset += 2;
- uint16_t opt_len = buf[offset]*256 + buf[offset+1];
- offset += 2;
-
- if (offset + opt_len > end ) {
- cout << "Option " << opt_type << " truncated." << endl;
- return (offset);
- }
- boost::shared_ptr<Option> opt;
- switch (opt_type) {
- case D6O_IA_NA:
- case D6O_IA_PD:
- // cout << "Creating Option6IA" << endl;
- opt = boost::shared_ptr<Option>(new Option6IA(opt_type,
- buf, buf_len,
- offset,
- opt_len));
- break;
- case D6O_IAADDR:
- // cout << "Creating Option6IAAddr" << endl;
- opt = boost::shared_ptr<Option>(new Option6IAAddr(opt_type,
- buf, buf_len,
- offset, opt_len));
- break;
- default:
- // cout << "Creating Option" << endl;
- opt = boost::shared_ptr<Option>(new Option(Option::V6,
- opt_type,
- buf,
- offset,
- opt_len));
- break;
- }
- // add option to options
- options.insert(pair<int, boost::shared_ptr<Option> >(opt_type, opt));
- offset += opt_len;
- }
-
- return (offset);
-}
-
-void
-LibDHCP::unpackOptions4(const std::vector<uint8_t>& buf,
- isc::dhcp::Option::OptionCollection& options) {
- size_t offset = 0;
-
- // 2 - header of DHCPv4 option
- while (offset + 2 <= buf.size()) {
- uint8_t opt_type = buf[offset++];
- uint8_t opt_len = buf[offset++];
- if (offset + opt_len > buf.size() ) {
- isc_throw(OutOfRange, "Option parse failed. Tried to parse "
- << offset + opt_len << " bytes from " << buf.size()
- << "-byte long buffer.");
- }
-
- boost::shared_ptr<Option> opt;
- switch(opt_type) {
- default:
- opt = boost::shared_ptr<Option>(new Option(Option::V4, opt_type,
- buf.begin()+offset,
- buf.begin()+offset+opt_len));
- }
-
- options.insert(pair<int, boost::shared_ptr<Option> >(opt_type, opt));
- offset += opt_len;
- }
-}
-
-unsigned int
-LibDHCP::packOptions6(boost::shared_array<uint8_t> data,
- unsigned int data_len,
- unsigned int offset,
- const isc::dhcp::Option::OptionCollection& options) {
- try {
- for (Option::OptionCollection::const_iterator it = options.begin();
- it != options.end();
- ++it) {
- unsigned short opt_len = (*it).second->len();
- if (offset + opt_len > data_len) {
- isc_throw(OutOfRange, "Failed to build option " <<
- (*it).first << ": out of buffer");
- }
- offset = it->second->pack(data, data_len, offset);
- }
- }
- catch (const Exception& e) {
- cout << "Packet build failed (Option build failed)." << endl;
- throw;
- }
- return (offset);
-}
-
-void
-LibDHCP::packOptions(isc::util::OutputBuffer& buf,
- const Option::OptionCollection& options) {
- for (Option::OptionCollection::const_iterator it = options.begin();
- it != options.end();
- ++it) {
- it->second->pack4(buf);
- }
-}
-
-
-bool
-LibDHCP::OptionFactoryRegister(Option::Universe u,
- unsigned short opt_type,
- Option::Factory * factory) {
- switch (u) {
- case Option::V6: {
- if (v6factories_.find(opt_type)!=v6factories_.end()) {
- isc_throw(BadValue, "There is already DHCPv6 factory registered "
- << "for option type " << opt_type);
- }
- v6factories_[opt_type]=factory;
- return true;
- }
- case Option::V4:
- default:{
- isc_throw(BadValue, "This universe type is not supported yet.");
- return false; // never happens
- }
- }
-
-}
diff --git a/src/lib/dhcp/libdhcp.h b/src/lib/dhcp/libdhcp.h
deleted file mode 100644
index 468e6bb..0000000
--- a/src/lib/dhcp/libdhcp.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (C) 2011 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 LIBDHCP_H_
-#define LIBDHCP_H_
-
-#include <iostream>
-#include <util/buffer.h>
-#include <dhcp/pkt6.h>
-
-namespace isc {
-namespace dhcp {
-
-class LibDHCP {
-
-public:
- /// Builds collection of options.
- ///
- /// Builds raw (on-wire) data for provided collection of options.
- ///
- /// @param buf shared pointer to buffer. Data will be stored there.
- /// @param buf_len buffer length. Used for buffer overflow protection.
- /// @param offset Offset from beginning of the buffer, where store options
- /// @param options collection of options to store to
- ///
- /// @return offset to the first unused byte in buffer (next one after last
- /// used byte)
- ///
- static unsigned int
- packOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
- unsigned int offset,
- const isc::dhcp::Option::OptionCollection& options);
-
-
- /// @brief Stores options in a buffer.
- ///
- /// Stores all options defined in options containers in a on-wire
- /// format in output buffer specified by buf.
- ///
- /// May throw different exceptions if option assembly fails. There
- /// may be different reasons (option too large, option malformed,
- /// too many options etc.)
- ///
- /// @param buf
- /// @param options
- static void
- packOptions(isc::util::OutputBuffer& buf,
- const isc::dhcp::Option::OptionCollection& options);
-
- static void
- unpackOptions4(const std::vector<uint8_t>& buf,
- isc::dhcp::Option::OptionCollection& options);
- ///
- /// Parses provided buffer and creates Option objects.
- ///
- /// Parses provided buf array and stores created Option objects
- /// in options container.
- ///
- /// @param buf Buffer to be parsed.
- /// @param offset Specifies offset for the first option.
- /// @param options Reference to option container. Options will be
- /// put here.
- ///
- /// @return offset to first byte after last parsed option
- ///
- static unsigned int
- unpackOptions6(const boost::shared_array<uint8_t> buf, unsigned int buf_len,
- unsigned int offset, unsigned int parse_len,
- isc::dhcp::Option::OptionCollection& options_);
-
- ///
- /// Registers factory method that produces options of specific option types.
- ///
- /// @param u universe of the option (V4 or V6)
- /// @param opt_type option-type
- /// @param factory function pointer
- ///
- /// @return true, if registration was successful, false otherwise
- ///
- static bool
- OptionFactoryRegister(Option::Universe u,
- unsigned short type,
- Option::Factory * factory);
-protected:
- // pointers to factories that produce DHCPv6 options
- static std::map<unsigned short, Option::Factory*> v6factories_;
-};
-
-}
-}
-
-#endif
diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc
index daef288..a30f0bc 100644
--- a/src/lib/dhcp/option.cc
+++ b/src/lib/dhcp/option.cc
@@ -22,7 +22,7 @@
#include "util/io_utilities.h"
#include "dhcp/option.h"
-#include "dhcp/libdhcp.h"
+#include "dhcp/libdhcp++.h"
using namespace std;
using namespace isc::dhcp;
diff --git a/src/lib/dhcp/option6_addrlst.cc b/src/lib/dhcp/option6_addrlst.cc
index fc981fa..b762019 100644
--- a/src/lib/dhcp/option6_addrlst.cc
+++ b/src/lib/dhcp/option6_addrlst.cc
@@ -19,7 +19,7 @@
#include "asiolink/io_address.h"
#include "util/io_utilities.h"
-#include "dhcp/libdhcp.h"
+#include "dhcp/libdhcp++.h"
#include "dhcp/option6_addrlst.h"
#include "dhcp/dhcp6.h"
diff --git a/src/lib/dhcp/option6_ia.cc b/src/lib/dhcp/option6_ia.cc
index 46daee1..1f8062f 100644
--- a/src/lib/dhcp/option6_ia.cc
+++ b/src/lib/dhcp/option6_ia.cc
@@ -17,7 +17,7 @@
#include <sstream>
#include "exceptions/exceptions.h"
-#include "dhcp/libdhcp.h"
+#include "dhcp/libdhcp++.h"
#include "dhcp/option6_ia.h"
#include "dhcp/dhcp6.h"
#include "util/io_utilities.h"
diff --git a/src/lib/dhcp/option6_iaaddr.cc b/src/lib/dhcp/option6_iaaddr.cc
index 4177714..fcfe727 100644
--- a/src/lib/dhcp/option6_iaaddr.cc
+++ b/src/lib/dhcp/option6_iaaddr.cc
@@ -17,7 +17,7 @@
#include <sstream>
#include "exceptions/exceptions.h"
-#include "dhcp/libdhcp.h"
+#include "dhcp/libdhcp++.h"
#include "dhcp/option6_iaaddr.h"
#include "dhcp/dhcp6.h"
#include "asiolink/io_address.h"
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index ba07a10..8f51880 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -13,7 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <dhcp/pkt4.h>
-#include <dhcp/libdhcp.h>
+#include <dhcp/libdhcp++.h>
#include <dhcp/dhcp4.h>
#include <exceptions/exceptions.h>
#include <asiolink/io_address.h>
diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc
index 84c5729..ff27d5e 100644
--- a/src/lib/dhcp/pkt6.cc
+++ b/src/lib/dhcp/pkt6.cc
@@ -15,7 +15,7 @@
#include "dhcp/dhcp6.h"
#include "dhcp/pkt6.h"
-#include "dhcp/libdhcp.h"
+#include "dhcp/libdhcp++.h"
#include "exceptions/exceptions.h"
#include <iostream>
#include <sstream>
diff --git a/src/lib/dhcp/tests/Makefile.am b/src/lib/dhcp/tests/Makefile.am
index 01799da..477b0e4 100644
--- a/src/lib/dhcp/tests/Makefile.am
+++ b/src/lib/dhcp/tests/Makefile.am
@@ -14,7 +14,8 @@ TESTS =
if HAVE_GTEST
TESTS += libdhcp_unittests
libdhcp_unittests_SOURCES = run_unittests.cc
-libdhcp_unittests_SOURCES += ../libdhcp.h ../libdhcp.cc libdhcp_unittest.cc
+libdhcp_unittests_SOURCES += ../libdhcp++.h ../libdhcp++.cc
+libdhcp_unittests_SOURCES += libdhcp++_unittest.cc
libdhcp_unittests_SOURCES += ../option6_iaaddr.h ../option6_iaaddr.cc option6_iaaddr_unittest.cc
libdhcp_unittests_SOURCES += ../option6_ia.h ../option6_ia.cc option6_ia_unittest.cc
libdhcp_unittests_SOURCES += ../option6_addrlst.h ../option6_addrlst.cc option6_addrlst_unittest.cc
diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc
new file mode 100644
index 0000000..ee3b873
--- /dev/null
+++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc
@@ -0,0 +1,234 @@
+// Copyright (C) 2011 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 <config.h>
+#include <iostream>
+#include <sstream>
+#include <arpa/inet.h>
+#include <gtest/gtest.h>
+#include <util/buffer.h>
+#include <dhcp/libdhcp++.h>
+#include "config.h"
+
+using namespace std;
+using namespace isc;
+using namespace isc::dhcp;
+using namespace isc::util;
+
+namespace {
+class LibDhcpTest : public ::testing::Test {
+public:
+ LibDhcpTest() {
+ }
+};
+
+static const uint8_t packed[] = {
+ 0, 12, 0, 5, 100, 101, 102, 103, 104, // opt1 (9 bytes)
+ 0, 13, 0, 3, 105, 106, 107, // opt2 (7 bytes)
+ 0, 14, 0, 2, 108, 109, // opt3 (6 bytes)
+ 1, 0, 0, 4, 110, 111, 112, 113, // opt4 (8 bytes)
+ 1, 1, 0, 1, 114 // opt5 (5 bytes)
+};
+
+TEST(LibDhcpTest, packOptions6) {
+ boost::shared_array<uint8_t> buf(new uint8_t[512]);
+ isc::dhcp::Option::OptionCollection opts; // list of options
+
+ // generate content for options
+ for (int i = 0; i < 64; i++) {
+ buf[i]=i+100;
+ }
+
+ boost::shared_ptr<Option> opt1(new Option(Option::V6, 12, buf, 0, 5));
+ boost::shared_ptr<Option> opt2(new Option(Option::V6, 13, buf, 5, 3));
+ boost::shared_ptr<Option> opt3(new Option(Option::V6, 14, buf, 8, 2));
+ boost::shared_ptr<Option> opt4(new Option(Option::V6,256, buf,10, 4));
+ boost::shared_ptr<Option> opt5(new Option(Option::V6,257, buf,14, 1));
+
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt1));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt2));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt3));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt4));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt5));
+
+ unsigned int offset;
+ EXPECT_NO_THROW ({
+ offset = LibDHCP::packOptions6(buf, 512, 100, opts);
+ });
+ EXPECT_EQ(135, offset); // options should take 35 bytes
+ EXPECT_EQ(0, memcmp(&buf[100], packed, 35) );
+}
+
+TEST(LibDhcpTest, unpackOptions6) {
+
+ // just couple of random options
+ // Option is used as a simple option implementation
+ // More advanced uses are validated in tests dedicated for
+ // specific derived classes.
+ isc::dhcp::Option::OptionCollection options; // list of options
+
+ // we can't use packed directly, as shared_array would try to
+ // free it eventually
+ boost::shared_array<uint8_t> buf(new uint8_t[512]);
+ memcpy(&buf[0], packed, 35);
+
+ unsigned int offset;
+ EXPECT_NO_THROW ({
+ offset = LibDHCP::unpackOptions6(buf, 512, 0, 35, options);
+ });
+
+ EXPECT_EQ(35, offset); // parsed first 35 bytes (offset 0..34)
+ EXPECT_EQ(options.size(), 5); // there should be 5 options
+
+ isc::dhcp::Option::OptionCollection::const_iterator x = options.find(12);
+ ASSERT_FALSE(x == options.end()); // option 1 should exist
+ EXPECT_EQ(12, x->second->getType()); // this should be option 12
+ ASSERT_EQ(9, x->second->len()); // it should be of length 9
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+4, 5)); // data len=5
+
+ x = options.find(13);
+ ASSERT_FALSE(x == options.end()); // option 13 should exist
+ EXPECT_EQ(13, x->second->getType()); // this should be option 13
+ ASSERT_EQ(7, x->second->len()); // it should be of length 7
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+13, 3)); // data len=3
+
+ x = options.find(14);
+ ASSERT_FALSE(x == options.end()); // option 3 should exist
+ EXPECT_EQ(14, x->second->getType()); // this should be option 14
+ ASSERT_EQ(6, x->second->len()); // it should be of length 6
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+20, 2)); // data len=2
+
+ x = options.find(256);
+ ASSERT_FALSE(x == options.end()); // option 256 should exist
+ EXPECT_EQ(256, x->second->getType()); // this should be option 256
+ ASSERT_EQ(8, x->second->len()); // it should be of length 7
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+26, 4)); // data len=4
+
+ x = options.find(257);
+ ASSERT_FALSE(x == options.end()); // option 257 should exist
+ EXPECT_EQ(257, x->second->getType()); // this should be option 257
+ ASSERT_EQ(5, x->second->len()); // it should be of length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+34, 1)); // data len=1
+
+ x = options.find(0);
+ EXPECT_TRUE(x == options.end()); // option 0 not found
+
+ x = options.find(1); // 1 is htons(256) on little endians. Worth checking
+ EXPECT_TRUE(x == options.end()); // option 1 not found
+
+ x = options.find(2);
+ EXPECT_TRUE(x == options.end()); // option 2 not found
+
+ x = options.find(32000);
+ EXPECT_TRUE(x == options.end()); // option 32000 not found
+}
+
+
+static uint8_t v4Opts[] = {
+ 12, 3, 0, 1, 2,
+ 13, 3, 10, 11, 12,
+ 14, 3, 20, 21, 22,
+ 254, 3, 30, 31, 32,
+ 128, 3, 40, 41, 42
+};
+
+TEST(LibDhcpTest, packOptions4) {
+
+ vector<uint8_t> payload[5];
+ for (int i = 0; i < 5; i++) {
+ payload[i].resize(3);
+ payload[i][0] = i*10;
+ payload[i][1] = i*10+1;
+ payload[i][2] = i*10+2;
+ }
+
+ boost::shared_ptr<Option> opt1(new Option(Option::V4, 12, payload[0]));
+ boost::shared_ptr<Option> opt2(new Option(Option::V4, 13, payload[1]));
+ boost::shared_ptr<Option> opt3(new Option(Option::V4, 14, payload[2]));
+ boost::shared_ptr<Option> opt4(new Option(Option::V4,254, payload[3]));
+ boost::shared_ptr<Option> opt5(new Option(Option::V4,128, payload[4]));
+
+ isc::dhcp::Option::OptionCollection opts; // list of options
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt1));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt2));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt3));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt4));
+ opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt5));
+
+ vector<uint8_t> expVect(v4Opts, v4Opts + sizeof(v4Opts));
+
+ OutputBuffer buf(100);
+ EXPECT_NO_THROW (
+ LibDHCP::packOptions(buf, opts);
+ );
+ ASSERT_EQ(buf.getLength(), sizeof(v4Opts));
+ EXPECT_EQ(0, memcmp(v4Opts, buf.getData(), sizeof(v4Opts)));
+
+}
+
+TEST(LibDhcpTest, unpackOptions4) {
+
+ vector<uint8_t> packed(v4Opts, v4Opts + sizeof(v4Opts));
+ isc::dhcp::Option::OptionCollection options; // list of options
+
+ ASSERT_NO_THROW(
+ LibDHCP::unpackOptions4(packed, options);
+ );
+
+ isc::dhcp::Option::OptionCollection::const_iterator x = options.find(12);
+ ASSERT_FALSE(x == options.end()); // option 1 should exist
+ EXPECT_EQ(12, x->second->getType()); // this should be option 12
+ ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
+ EXPECT_EQ(5, x->second->len()); // total option length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+2, 3)); // data len=3
+
+ x = options.find(13);
+ ASSERT_FALSE(x == options.end()); // option 1 should exist
+ EXPECT_EQ(13, x->second->getType()); // this should be option 13
+ ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
+ EXPECT_EQ(5, x->second->len()); // total option length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+7, 3)); // data len=3
+
+ x = options.find(14);
+ ASSERT_FALSE(x == options.end()); // option 3 should exist
+ EXPECT_EQ(14, x->second->getType()); // this should be option 14
+ ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
+ EXPECT_EQ(5, x->second->len()); // total option length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+12, 3)); // data len=3
+
+ x = options.find(254);
+ ASSERT_FALSE(x == options.end()); // option 3 should exist
+ EXPECT_EQ(254, x->second->getType()); // this should be option 254
+ ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
+ EXPECT_EQ(5, x->second->len()); // total option length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+17, 3)); // data len=3
+
+ x = options.find(128);
+ ASSERT_FALSE(x == options.end()); // option 3 should exist
+ EXPECT_EQ(128, x->second->getType()); // this should be option 254
+ ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
+ EXPECT_EQ(5, x->second->len()); // total option length 5
+ EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+22, 3)); // data len=3
+
+ x = options.find(0);
+ EXPECT_TRUE(x == options.end()); // option 0 not found
+
+ x = options.find(1);
+ EXPECT_TRUE(x == options.end()); // option 1 not found
+
+ x = options.find(2);
+ EXPECT_TRUE(x == options.end()); // option 2 not found
+}
+
+}
diff --git a/src/lib/dhcp/tests/libdhcp_unittest.cc b/src/lib/dhcp/tests/libdhcp_unittest.cc
deleted file mode 100644
index 11b618c..0000000
--- a/src/lib/dhcp/tests/libdhcp_unittest.cc
+++ /dev/null
@@ -1,234 +0,0 @@
-// Copyright (C) 2011 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 <config.h>
-#include <iostream>
-#include <sstream>
-#include <arpa/inet.h>
-#include <gtest/gtest.h>
-#include <util/buffer.h>
-#include <dhcp/libdhcp.h>
-#include "config.h"
-
-using namespace std;
-using namespace isc;
-using namespace isc::dhcp;
-using namespace isc::util;
-
-namespace {
-class LibDhcpTest : public ::testing::Test {
-public:
- LibDhcpTest() {
- }
-};
-
-static const uint8_t packed[] = {
- 0, 12, 0, 5, 100, 101, 102, 103, 104, // opt1 (9 bytes)
- 0, 13, 0, 3, 105, 106, 107, // opt2 (7 bytes)
- 0, 14, 0, 2, 108, 109, // opt3 (6 bytes)
- 1, 0, 0, 4, 110, 111, 112, 113, // opt4 (8 bytes)
- 1, 1, 0, 1, 114 // opt5 (5 bytes)
-};
-
-TEST(LibDhcpTest, packOptions6) {
- boost::shared_array<uint8_t> buf(new uint8_t[512]);
- isc::dhcp::Option::OptionCollection opts; // list of options
-
- // generate content for options
- for (int i = 0; i < 64; i++) {
- buf[i]=i+100;
- }
-
- boost::shared_ptr<Option> opt1(new Option(Option::V6, 12, buf, 0, 5));
- boost::shared_ptr<Option> opt2(new Option(Option::V6, 13, buf, 5, 3));
- boost::shared_ptr<Option> opt3(new Option(Option::V6, 14, buf, 8, 2));
- boost::shared_ptr<Option> opt4(new Option(Option::V6,256, buf,10, 4));
- boost::shared_ptr<Option> opt5(new Option(Option::V6,257, buf,14, 1));
-
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt1));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt2));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt3));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt4));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt5));
-
- unsigned int offset;
- EXPECT_NO_THROW ({
- offset = LibDHCP::packOptions6(buf, 512, 100, opts);
- });
- EXPECT_EQ(135, offset); // options should take 35 bytes
- EXPECT_EQ(0, memcmp(&buf[100], packed, 35) );
-}
-
-TEST(LibDhcpTest, unpackOptions6) {
-
- // just couple of random options
- // Option is used as a simple option implementation
- // More advanced uses are validated in tests dedicated for
- // specific derived classes.
- isc::dhcp::Option::OptionCollection options; // list of options
-
- // we can't use packed directly, as shared_array would try to
- // free it eventually
- boost::shared_array<uint8_t> buf(new uint8_t[512]);
- memcpy(&buf[0], packed, 35);
-
- unsigned int offset;
- EXPECT_NO_THROW ({
- offset = LibDHCP::unpackOptions6(buf, 512, 0, 35, options);
- });
-
- EXPECT_EQ(35, offset); // parsed first 35 bytes (offset 0..34)
- EXPECT_EQ(options.size(), 5); // there should be 5 options
-
- isc::dhcp::Option::OptionCollection::const_iterator x = options.find(12);
- ASSERT_FALSE(x == options.end()); // option 1 should exist
- EXPECT_EQ(12, x->second->getType()); // this should be option 12
- ASSERT_EQ(9, x->second->len()); // it should be of length 9
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+4, 5)); // data len=5
-
- x = options.find(13);
- ASSERT_FALSE(x == options.end()); // option 13 should exist
- EXPECT_EQ(13, x->second->getType()); // this should be option 13
- ASSERT_EQ(7, x->second->len()); // it should be of length 7
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+13, 3)); // data len=3
-
- x = options.find(14);
- ASSERT_FALSE(x == options.end()); // option 3 should exist
- EXPECT_EQ(14, x->second->getType()); // this should be option 14
- ASSERT_EQ(6, x->second->len()); // it should be of length 6
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+20, 2)); // data len=2
-
- x = options.find(256);
- ASSERT_FALSE(x == options.end()); // option 256 should exist
- EXPECT_EQ(256, x->second->getType()); // this should be option 256
- ASSERT_EQ(8, x->second->len()); // it should be of length 7
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+26, 4)); // data len=4
-
- x = options.find(257);
- ASSERT_FALSE(x == options.end()); // option 257 should exist
- EXPECT_EQ(257, x->second->getType()); // this should be option 257
- ASSERT_EQ(5, x->second->len()); // it should be of length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], packed+34, 1)); // data len=1
-
- x = options.find(0);
- EXPECT_TRUE(x == options.end()); // option 0 not found
-
- x = options.find(1); // 1 is htons(256) on little endians. Worth checking
- EXPECT_TRUE(x == options.end()); // option 1 not found
-
- x = options.find(2);
- EXPECT_TRUE(x == options.end()); // option 2 not found
-
- x = options.find(32000);
- EXPECT_TRUE(x == options.end()); // option 32000 not found
-}
-
-
-static uint8_t v4Opts[] = {
- 12, 3, 0, 1, 2,
- 13, 3, 10, 11, 12,
- 14, 3, 20, 21, 22,
- 254, 3, 30, 31, 32,
- 128, 3, 40, 41, 42
-};
-
-TEST(LibDhcpTest, packOptions4) {
-
- vector<uint8_t> payload[5];
- for (int i = 0; i < 5; i++) {
- payload[i].resize(3);
- payload[i][0] = i*10;
- payload[i][1] = i*10+1;
- payload[i][2] = i*10+2;
- }
-
- boost::shared_ptr<Option> opt1(new Option(Option::V4, 12, payload[0]));
- boost::shared_ptr<Option> opt2(new Option(Option::V4, 13, payload[1]));
- boost::shared_ptr<Option> opt3(new Option(Option::V4, 14, payload[2]));
- boost::shared_ptr<Option> opt4(new Option(Option::V4,254, payload[3]));
- boost::shared_ptr<Option> opt5(new Option(Option::V4,128, payload[4]));
-
- isc::dhcp::Option::OptionCollection opts; // list of options
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt1));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt2));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt3));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt4));
- opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt5));
-
- vector<uint8_t> expVect(v4Opts, v4Opts + sizeof(v4Opts));
-
- OutputBuffer buf(100);
- EXPECT_NO_THROW (
- LibDHCP::packOptions(buf, opts);
- );
- ASSERT_EQ(buf.getLength(), sizeof(v4Opts));
- EXPECT_EQ(0, memcmp(v4Opts, buf.getData(), sizeof(v4Opts)));
-
-}
-
-TEST(LibDhcpTest, unpackOptions4) {
-
- vector<uint8_t> packed(v4Opts, v4Opts + sizeof(v4Opts));
- isc::dhcp::Option::OptionCollection options; // list of options
-
- ASSERT_NO_THROW(
- LibDHCP::unpackOptions4(packed, options);
- );
-
- isc::dhcp::Option::OptionCollection::const_iterator x = options.find(12);
- ASSERT_FALSE(x == options.end()); // option 1 should exist
- EXPECT_EQ(12, x->second->getType()); // this should be option 12
- ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
- EXPECT_EQ(5, x->second->len()); // total option length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+2, 3)); // data len=3
-
- x = options.find(13);
- ASSERT_FALSE(x == options.end()); // option 1 should exist
- EXPECT_EQ(13, x->second->getType()); // this should be option 13
- ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
- EXPECT_EQ(5, x->second->len()); // total option length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+7, 3)); // data len=3
-
- x = options.find(14);
- ASSERT_FALSE(x == options.end()); // option 3 should exist
- EXPECT_EQ(14, x->second->getType()); // this should be option 14
- ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
- EXPECT_EQ(5, x->second->len()); // total option length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+12, 3)); // data len=3
-
- x = options.find(254);
- ASSERT_FALSE(x == options.end()); // option 3 should exist
- EXPECT_EQ(254, x->second->getType()); // this should be option 254
- ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
- EXPECT_EQ(5, x->second->len()); // total option length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+17, 3)); // data len=3
-
- x = options.find(128);
- ASSERT_FALSE(x == options.end()); // option 3 should exist
- EXPECT_EQ(128, x->second->getType()); // this should be option 254
- ASSERT_EQ(3, x->second->getData().size()); // it should be of length 3
- EXPECT_EQ(5, x->second->len()); // total option length 5
- EXPECT_EQ(0, memcmp(&x->second->getData()[0], v4Opts+22, 3)); // data len=3
-
- x = options.find(0);
- EXPECT_TRUE(x == options.end()); // option 0 not found
-
- x = options.find(1);
- EXPECT_TRUE(x == options.end()); // option 1 not found
-
- x = options.find(2);
- EXPECT_TRUE(x == options.end()); // option 2 not found
-}
-
-}
More information about the bind10-changes
mailing list