Commit 8ef97b33 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[4106] Added unit test for the DHCP4o6 IPC.

parent 22a8c0b3
......@@ -17,6 +17,7 @@
#include <dhcp/dhcp6.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/option6_addrlst.h>
#include <dhcp/option_custom.h>
#include <dhcp/option_string.h>
#include <dhcp/option_vendor.h>
#include <dhcpsrv/dhcp4o6_ipc.h>
......@@ -140,6 +141,7 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() {
// Get interface name and remote address
pkt->unpack();
OptionVendorPtr vendor =
boost::dynamic_pointer_cast<OptionVendor>(pkt->getOption(D6O_VENDOR_OPTS));
if (!vendor || vendor->getVendorId() != ENTERPRISE_ID_ISC) {
......@@ -154,19 +156,15 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() {
if (!iface) {
return (Pkt6Ptr());
}
Option6AddrLstPtr srcs =
boost::dynamic_pointer_cast<Option6AddrLst>(vendor->getOption(ISC_V6_4O6_SRC_ADDRESS));
OptionCustomPtr srcs =
boost::dynamic_pointer_cast<OptionCustom>(vendor->getOption(ISC_V6_4O6_SRC_ADDRESS));
if (!srcs) {
return (Pkt6Ptr());
}
Option6AddrLst::AddressContainer addrs = srcs->getAddresses();
if (addrs.size() != 1) {
return (Pkt6Ptr());
}
// Update the packet and return it
static_cast<void>(pkt->delOption(D6O_VENDOR_OPTS));
pkt->setRemoteAddr(addrs[0]);
pkt->setRemoteAddr(srcs->readAddress());
pkt->setIface(iface->getName());
pkt->setIndex(iface->getIndex());
return (pkt);
......
......@@ -82,6 +82,7 @@ libdhcpsrv_unittests_SOURCES += d2_udp_unittest.cc
libdhcpsrv_unittests_SOURCES += daemon_unittest.cc
libdhcpsrv_unittests_SOURCES += database_connection_unittest.cc
libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
libdhcpsrv_unittests_SOURCES += dhcp4o6_ipc_unittest.cc
libdhcpsrv_unittests_SOURCES += expiration_config_parser_unittest.cc
libdhcpsrv_unittests_SOURCES += host_mgr_unittest.cc
libdhcpsrv_unittests_SOURCES += host_unittest.cc
......
// Copyright (C) 2014, 2015 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 <dhcp/iface_mgr.h>
#include <dhcp/pkt6.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcpsrv/dhcp4o6_ipc.h>
#include <boost/bind.hpp>
#include <gtest/gtest.h>
using namespace isc::dhcp;
using namespace isc::dhcp::test;
namespace {
const uint16_t TEST_PORT = 12345;
class TestIpc : public Dhcp4o6IpcBase {
public:
TestIpc(const uint16_t port, const int side);
virtual void open();
Pkt6Ptr getPktReceived() const {
return (pkt_received_);
}
private:
void receiveHandler();
uint16_t port_;
int side_;
Pkt6Ptr pkt_received_;
};
TestIpc::TestIpc(const uint16_t port, const int side)
: port_(port), side_(side), pkt_received_() {
}
void
TestIpc::open() {
socket_fd_ = Dhcp4o6IpcBase::open(port_, side_);
if (socket_fd_ >= 0) {
IfaceMgr::instance().addExternalSocket(socket_fd_,
boost::bind(&TestIpc::receiveHandler, this));
}
}
void
TestIpc::receiveHandler() {
pkt_received_ = receive();
}
class Dhcp4o6IpcBaseTest : public ::testing::Test {
public:
Dhcp4o6IpcBaseTest();
private:
IfaceMgrTestConfig iface_mgr_test_config_;
};
Dhcp4o6IpcBaseTest::Dhcp4o6IpcBaseTest()
: iface_mgr_test_config_(true) {
}
TEST_F(Dhcp4o6IpcBaseTest, basic) {
TestIpc ipc4(TEST_PORT, 4);
TestIpc ipc6(TEST_PORT, 6);
ASSERT_NO_THROW(ipc4.open());
ASSERT_NO_THROW(ipc6.open());
Pkt6Ptr pkt(new Pkt6(DHCPV6_DHCPV4_QUERY, 1234));
pkt->setIface("eth0");
ASSERT_NO_THROW(ipc6.send(pkt));
ASSERT_NO_THROW(IfaceMgr::instance().receive6(1, 0));
Pkt6Ptr pkt_received = ipc4.getPktReceived();
ASSERT_TRUE(pkt_received);
}
} // end of anonymous namespace
Supports Markdown
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