|
@@ -1,16 +1,8 @@
|
|
// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
|
|
// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
|
|
//
|
|
//
|
|
-// Permission to use, copy, modify, and/or distribute this software for any
|
|
+// This Source Code Form is subject to the terms of the Mozilla Public
|
|
-// purpose with or without fee is hereby granted, provided that the above
|
|
+// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
-// copyright notice and this permission notice appear in all copies.
|
|
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
-//
|
|
|
|
-// 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 <config.h>
|
|
#include <dhcp/iface_mgr.h>
|
|
#include <dhcp/iface_mgr.h>
|
|
@@ -42,7 +34,7 @@ const uint16_t TEST_PORT = 12345;
|
|
const uint16_t TEST_ITERATIONS = 10;
|
|
const uint16_t TEST_ITERATIONS = 10;
|
|
|
|
|
|
/// @brief Type definition for the function creating DHCP message.
|
|
/// @brief Type definition for the function creating DHCP message.
|
|
-typedef boost::function<Pkt6Ptr(const uint16_t, const uint16_t)> CreateMsgFun;
|
|
+typedef boost::function<Pkt6Ptr(uint16_t, uint16_t)> CreateMsgFun;
|
|
|
|
|
|
/// @brief Define short name for test IPC class.
|
|
/// @brief Define short name for test IPC class.
|
|
typedef Dhcp4o6TestIpc TestIpc;
|
|
typedef Dhcp4o6TestIpc TestIpc;
|
|
@@ -65,7 +57,7 @@ protected:
|
|
/// @param prefix Prefix.
|
|
/// @param prefix Prefix.
|
|
/// @param postfix Postfix.
|
|
/// @param postfix Postfix.
|
|
/// @return String representing concatenated prefix and postfix.
|
|
/// @return String representing concatenated prefix and postfix.
|
|
- static std::string concatenate(const std::string& prefix, const uint16_t postfix);
|
|
+ static std::string concatenate(const std::string& prefix, uint16_t postfix);
|
|
|
|
|
|
/// @brief Creates an instance of the DHCPv4o6 message.
|
|
/// @brief Creates an instance of the DHCPv4o6 message.
|
|
////
|
|
////
|
|
@@ -77,19 +69,20 @@ protected:
|
|
/// the "eth0" will be used, for odd postfix values "eth1" will be used.
|
|
/// the "eth0" will be used, for odd postfix values "eth1" will be used.
|
|
///
|
|
///
|
|
/// @return Pointer to the created message.
|
|
/// @return Pointer to the created message.
|
|
- static Pkt6Ptr createDHCPv4o6Message(const uint16_t msg_type,
|
|
+ static Pkt6Ptr createDHCPv4o6Message(uint16_t msg_type,
|
|
- const uint16_t postfix = 0);
|
|
+ uint16_t postfix = 0);
|
|
|
|
|
|
/// @brief Creates an instance of the DHCPv4o6 message with vendor option.
|
|
/// @brief Creates an instance of the DHCPv4o6 message with vendor option.
|
|
///
|
|
///
|
|
/// @param msg_type Message type.
|
|
/// @param msg_type Message type.
|
|
/// @param postfix Postfix to be appended to the remote address. See the
|
|
/// @param postfix Postfix to be appended to the remote address. See the
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
|
|
+ /// @param enterprise_id Enterprise ID for the vendor option.
|
|
///
|
|
///
|
|
/// @return Pointer to the created message.
|
|
/// @return Pointer to the created message.
|
|
- static Pkt6Ptr createDHCPv4o6MsgWithVendorOption(const uint16_t msg_type,
|
|
+ static Pkt6Ptr createDHCPv4o6MsgWithVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix,
|
|
+ uint16_t postfix,
|
|
- const uint32_t enterprise_id);
|
|
+ uint32_t enterprise_id);
|
|
|
|
|
|
/// @brief Creates an instance of the DHCPv4o6 message with ISC
|
|
/// @brief Creates an instance of the DHCPv4o6 message with ISC
|
|
/// vendor option.
|
|
/// vendor option.
|
|
@@ -102,8 +95,8 @@ protected:
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
///
|
|
///
|
|
/// @return Pointer to the created message.
|
|
/// @return Pointer to the created message.
|
|
- static Pkt6Ptr createDHCPv4o6MsgWithISCVendorOption(const uint16_t msg_type,
|
|
+ static Pkt6Ptr createDHCPv4o6MsgWithISCVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix);
|
|
+ uint16_t postfix);
|
|
|
|
|
|
/// @brief Creates an instance of the DHCPv4o6 message with vendor
|
|
/// @brief Creates an instance of the DHCPv4o6 message with vendor
|
|
/// option holding enterprise id of 32000.
|
|
/// option holding enterprise id of 32000.
|
|
@@ -117,23 +110,24 @@ protected:
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
/// documentation of @c createDHCPv4o6Message for details.
|
|
///
|
|
///
|
|
/// @return Pointer to the created message.
|
|
/// @return Pointer to the created message.
|
|
- static Pkt6Ptr createDHCPv4o6MsgWithAnyVendorOption(const uint16_t msg_type,
|
|
+ static Pkt6Ptr createDHCPv4o6MsgWithAnyVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix);
|
|
+ uint16_t postfix);
|
|
|
|
|
|
/// @brief Creates an instance of the DHCPv4o6 Message option.
|
|
/// @brief Creates an instance of the DHCPv4o6 Message option.
|
|
///
|
|
///
|
|
/// @param src Type of the source endpoint. It can be 4 or 6.
|
|
/// @param src Type of the source endpoint. It can be 4 or 6.
|
|
/// @return Pointer to the instance of the option.
|
|
/// @return Pointer to the instance of the option.
|
|
- static OptionPtr createDHCPv4MsgOption(const TestIpc::EndpointType& src);
|
|
+ static OptionPtr createDHCPv4MsgOption(TestIpc::EndpointType src);
|
|
|
|
|
|
/// @brief Tests sending and receiving packets over the IPC.
|
|
/// @brief Tests sending and receiving packets over the IPC.
|
|
///
|
|
///
|
|
/// @param iterations_num Number of packets to be sent over the IPC.
|
|
/// @param iterations_num Number of packets to be sent over the IPC.
|
|
/// @param src Type of the source IPC endpoint. It can be 4 or 6.
|
|
/// @param src Type of the source IPC endpoint. It can be 4 or 6.
|
|
/// @param dest Type of the destination IPC endpoint. It can be 4 or 6.
|
|
/// @param dest Type of the destination IPC endpoint. It can be 4 or 6.
|
|
- void testSendReceive(const uint16_t iterations_num,
|
|
+ /// @param create_msg_fun Function called to create the packet.
|
|
- const TestIpc::EndpointType& src,
|
|
+ void testSendReceive(uint16_t iterations_num,
|
|
- const TestIpc::EndpointType& dest,
|
|
+ TestIpc::EndpointType src,
|
|
|
|
+ TestIpc::EndpointType dest,
|
|
const CreateMsgFun& create_msg_fun);
|
|
const CreateMsgFun& create_msg_fun);
|
|
|
|
|
|
/// @brief Tests that error is reported when invalid message is received.
|
|
/// @brief Tests that error is reported when invalid message is received.
|
|
@@ -154,15 +148,15 @@ Dhcp4o6IpcBaseTest::Dhcp4o6IpcBaseTest()
|
|
|
|
|
|
std::string
|
|
std::string
|
|
Dhcp4o6IpcBaseTest::concatenate(const std::string& prefix,
|
|
Dhcp4o6IpcBaseTest::concatenate(const std::string& prefix,
|
|
- const uint16_t postfix) {
|
|
+ uint16_t postfix) {
|
|
std::ostringstream s;
|
|
std::ostringstream s;
|
|
s << prefix << postfix;
|
|
s << prefix << postfix;
|
|
return (s.str());
|
|
return (s.str());
|
|
}
|
|
}
|
|
|
|
|
|
Pkt6Ptr
|
|
Pkt6Ptr
|
|
-Dhcp4o6IpcBaseTest::createDHCPv4o6Message(const uint16_t msg_type,
|
|
+Dhcp4o6IpcBaseTest::createDHCPv4o6Message(uint16_t msg_type,
|
|
- const uint16_t postfix) {
|
|
+ uint16_t postfix) {
|
|
// Create the DHCPv4o6 message.
|
|
// Create the DHCPv4o6 message.
|
|
Pkt6Ptr pkt(new Pkt6(msg_type, 0));
|
|
Pkt6Ptr pkt(new Pkt6(msg_type, 0));
|
|
|
|
|
|
@@ -180,7 +174,7 @@ Dhcp4o6IpcBaseTest::createDHCPv4o6Message(const uint16_t msg_type,
|
|
pkt->setRemoteAddr(IOAddress(concatenate("2001:db8:1::", postfix)));
|
|
pkt->setRemoteAddr(IOAddress(concatenate("2001:db8:1::", postfix)));
|
|
|
|
|
|
// Determine the endpoint type using the message type.
|
|
// Determine the endpoint type using the message type.
|
|
- const TestIpc::EndpointType src = (msg_type == DHCPV6_DHCPV4_QUERY) ?
|
|
+ TestIpc::EndpointType src = (msg_type == DHCPV6_DHCPV4_QUERY) ?
|
|
TestIpc::ENDPOINT_TYPE_V6 : TestIpc::ENDPOINT_TYPE_V4;
|
|
TestIpc::ENDPOINT_TYPE_V6 : TestIpc::ENDPOINT_TYPE_V4;
|
|
|
|
|
|
// Add DHCPv4 Message option to make sure it is conveyed by the IPC.
|
|
// Add DHCPv4 Message option to make sure it is conveyed by the IPC.
|
|
@@ -190,9 +184,9 @@ Dhcp4o6IpcBaseTest::createDHCPv4o6Message(const uint16_t msg_type,
|
|
}
|
|
}
|
|
|
|
|
|
Pkt6Ptr
|
|
Pkt6Ptr
|
|
-Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithVendorOption(const uint16_t msg_type,
|
|
+Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix,
|
|
+ uint16_t postfix,
|
|
- const uint32_t enterprise_id) {
|
|
+ uint32_t enterprise_id) {
|
|
Pkt6Ptr pkt = createDHCPv4o6Message(msg_type, postfix);
|
|
Pkt6Ptr pkt = createDHCPv4o6Message(msg_type, postfix);
|
|
|
|
|
|
// Create vendor option with ISC enterprise id.
|
|
// Create vendor option with ISC enterprise id.
|
|
@@ -208,19 +202,19 @@ Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithVendorOption(const uint16_t msg_type,
|
|
}
|
|
}
|
|
|
|
|
|
Pkt6Ptr
|
|
Pkt6Ptr
|
|
-Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithISCVendorOption(const uint16_t msg_type,
|
|
+Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithISCVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix) {
|
|
+ uint16_t postfix) {
|
|
return (createDHCPv4o6MsgWithVendorOption(msg_type, postfix, ENTERPRISE_ID_ISC));
|
|
return (createDHCPv4o6MsgWithVendorOption(msg_type, postfix, ENTERPRISE_ID_ISC));
|
|
}
|
|
}
|
|
|
|
|
|
Pkt6Ptr
|
|
Pkt6Ptr
|
|
-Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithAnyVendorOption(const uint16_t msg_type,
|
|
+Dhcp4o6IpcBaseTest::createDHCPv4o6MsgWithAnyVendorOption(uint16_t msg_type,
|
|
- const uint16_t postfix) {
|
|
+ uint16_t postfix) {
|
|
return (createDHCPv4o6MsgWithVendorOption(msg_type, postfix, 32000));
|
|
return (createDHCPv4o6MsgWithVendorOption(msg_type, postfix, 32000));
|
|
}
|
|
}
|
|
|
|
|
|
OptionPtr
|
|
OptionPtr
|
|
-Dhcp4o6IpcBaseTest::createDHCPv4MsgOption(const TestIpc::EndpointType& src) {
|
|
+Dhcp4o6IpcBaseTest::createDHCPv4MsgOption(TestIpc::EndpointType src) {
|
|
// Create the DHCPv4 message.
|
|
// Create the DHCPv4 message.
|
|
Pkt4Ptr pkt(new Pkt4(src == TestIpc::ENDPOINT_TYPE_V4 ? DHCPACK : DHCPREQUEST,
|
|
Pkt4Ptr pkt(new Pkt4(src == TestIpc::ENDPOINT_TYPE_V4 ? DHCPACK : DHCPREQUEST,
|
|
1234));
|
|
1234));
|
|
@@ -236,9 +230,9 @@ Dhcp4o6IpcBaseTest::createDHCPv4MsgOption(const TestIpc::EndpointType& src) {
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
void
|
|
-Dhcp4o6IpcBaseTest::testSendReceive(const uint16_t iterations_num,
|
|
+Dhcp4o6IpcBaseTest::testSendReceive(uint16_t iterations_num,
|
|
- const TestIpc::EndpointType& src,
|
|
+ TestIpc::EndpointType src,
|
|
- const TestIpc::EndpointType& dest,
|
|
+ TestIpc::EndpointType dest,
|
|
const CreateMsgFun& create_msg_fun) {
|
|
const CreateMsgFun& create_msg_fun) {
|
|
// Create IPC instances representing the source and destination endpoints.
|
|
// Create IPC instances representing the source and destination endpoints.
|
|
TestIpc ipc_src(TEST_PORT, src);
|
|
TestIpc ipc_src(TEST_PORT, src);
|
|
@@ -248,7 +242,7 @@ Dhcp4o6IpcBaseTest::testSendReceive(const uint16_t iterations_num,
|
|
ASSERT_NO_THROW(ipc_src.open());
|
|
ASSERT_NO_THROW(ipc_src.open());
|
|
ASSERT_NO_THROW(ipc_dest.open());
|
|
ASSERT_NO_THROW(ipc_dest.open());
|
|
|
|
|
|
- // Depnding if we're sending from DHCPv6 to DHCPv4 or the opposite
|
|
+ // Depending if we're sending from DHCPv6 to DHCPv4 or the opposite
|
|
// direction we use different message type. This is not really required
|
|
// direction we use different message type. This is not really required
|
|
// for testing IPC, but it better simulates the real use case.
|
|
// for testing IPC, but it better simulates the real use case.
|
|
uint16_t msg_type = (src == TestIpc::ENDPOINT_TYPE_V6 ? DHCPV6_DHCPV4_QUERY :
|
|
uint16_t msg_type = (src == TestIpc::ENDPOINT_TYPE_V6 ? DHCPV6_DHCPV4_QUERY :
|
|
@@ -437,40 +431,17 @@ TEST_F(Dhcp4o6IpcBaseTest, openError) {
|
|
ASSERT_NE(-1, ipc_bound.getSocketFd());
|
|
ASSERT_NE(-1, ipc_bound.getSocketFd());
|
|
|
|
|
|
ipc.setDesiredPort(TEST_PORT + 10);
|
|
ipc.setDesiredPort(TEST_PORT + 10);
|
|
-#if defined(OS_LINUX)
|
|
|
|
- // Linux has a silly interpretation of SO_REUSEADDR so we use
|
|
|
|
- // another way to raise an error.
|
|
|
|
- ipc.setDesiredPort(65535);
|
|
|
|
-#endif
|
|
|
|
ASSERT_THROW(ipc.open(), isc::dhcp::Dhcp4o6IpcError);
|
|
ASSERT_THROW(ipc.open(), isc::dhcp::Dhcp4o6IpcError);
|
|
|
|
|
|
EXPECT_EQ(sock_fd, ipc.getSocketFd());
|
|
EXPECT_EQ(sock_fd, ipc.getSocketFd());
|
|
EXPECT_EQ(TEST_PORT, ipc.getPort());
|
|
EXPECT_EQ(TEST_PORT, ipc.getPort());
|
|
|
|
|
|
ASSERT_NO_THROW(ipc_bound.close());
|
|
ASSERT_NO_THROW(ipc_bound.close());
|
|
-#if defined(OS_LINUX)
|
|
|
|
- // Restore the expected value
|
|
|
|
- ipc.setDesiredPort(TEST_PORT + 10);
|
|
|
|
-#endif
|
|
|
|
ASSERT_NO_THROW(ipc.open());
|
|
ASSERT_NO_THROW(ipc.open());
|
|
EXPECT_NE(-1, ipc.getSocketFd());
|
|
EXPECT_NE(-1, ipc.getSocketFd());
|
|
EXPECT_EQ(TEST_PORT + 10, ipc.getPort());
|
|
EXPECT_EQ(TEST_PORT + 10, ipc.getPort());
|
|
}
|
|
}
|
|
|
|
|
|
-// This test verifies that the IPC returns an error when trying to bind
|
|
|
|
-// to the out of range port.
|
|
|
|
-TEST_F(Dhcp4o6IpcBaseTest, invalidPortError4) {
|
|
|
|
- TestIpc ipc(65535, TestIpc::ENDPOINT_TYPE_V4);
|
|
|
|
- EXPECT_THROW(ipc.open(), Dhcp4o6IpcError);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// This test verifies that the IPC returns an error when trying to bind
|
|
|
|
-// to the out of range port.
|
|
|
|
-TEST_F(Dhcp4o6IpcBaseTest, invalidPortError6) {
|
|
|
|
- TestIpc ipc(65535, TestIpc::ENDPOINT_TYPE_V6);
|
|
|
|
- EXPECT_THROW(ipc.open(), Dhcp4o6IpcError);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// This test verifies that receiving packet over the IPC fails when there
|
|
// This test verifies that receiving packet over the IPC fails when there
|
|
// is no vendor option present.
|
|
// is no vendor option present.
|
|
TEST_F(Dhcp4o6IpcBaseTest, receiveWithoutVendorOption) {
|
|
TEST_F(Dhcp4o6IpcBaseTest, receiveWithoutVendorOption) {
|