|
@@ -21,6 +21,7 @@
|
|
|
#include <dhcp/option_string.h>
|
|
|
#include <dhcp/option_vendor.h>
|
|
|
#include <dhcpsrv/dhcp4o6_ipc.h>
|
|
|
+#include <dhcpsrv/testutils/dhcp4o6_test_ipc.h>
|
|
|
#include <boost/bind.hpp>
|
|
|
#include <boost/function.hpp>
|
|
|
#include <gtest/gtest.h>
|
|
@@ -43,92 +44,8 @@ const uint16_t TEST_ITERATIONS = 10;
|
|
|
/// @brief Type definition for the function creating DHCP message.
|
|
|
typedef boost::function<Pkt6Ptr(const uint16_t, const uint16_t)> CreateMsgFun;
|
|
|
|
|
|
-/// @brief Implements a simple IPC for the test.
|
|
|
-class TestIpc : public Dhcp4o6IpcBase {
|
|
|
-public:
|
|
|
-
|
|
|
- /// @brief Constructor.
|
|
|
- ///
|
|
|
- /// @param port Desired port.
|
|
|
- /// @param endpoint_type Type of the IPC endpoint. It should be 4 or 6.
|
|
|
- TestIpc(const uint16_t port, const EndpointType& endpoint_type);
|
|
|
-
|
|
|
- /// @brief Sets new port to be used with @c open.
|
|
|
- ///
|
|
|
- /// @param desired_port New desired port.
|
|
|
- void setDesiredPort(const uint16_t desired_port) {
|
|
|
- desired_port_ = desired_port;
|
|
|
- }
|
|
|
-
|
|
|
- /// @brief Opens the IPC socket and registers it in @c IfaceMgr.
|
|
|
- ///
|
|
|
- /// This method opens the IPC socket and registers it as external
|
|
|
- /// socket in the IfaceMgr. The @c TestIpc::receiveHandler is used as a
|
|
|
- /// callback to be called by the @c IfaceMgr when the data is received
|
|
|
- /// over the socket.
|
|
|
- virtual void open();
|
|
|
-
|
|
|
- /// @brief Retrieve port which socket is bound to.
|
|
|
- uint16_t getPort() const {
|
|
|
- return (port_);
|
|
|
- }
|
|
|
-
|
|
|
- /// @brief Retrieve socket descriptor.
|
|
|
- int getSocketFd() const {
|
|
|
- return (socket_fd_);
|
|
|
- }
|
|
|
-
|
|
|
- /// @brief Pops and returns a received message.
|
|
|
- ///
|
|
|
- /// @return Pointer to the received message over the IPC.
|
|
|
- Pkt6Ptr popPktReceived() {
|
|
|
- // Copy the received message.
|
|
|
- Pkt6Ptr pkt_copy(pkt_received_);
|
|
|
- // Set the received message to NULL (pop).
|
|
|
- pkt_received_.reset();
|
|
|
- // Return the copy.
|
|
|
- return (pkt_copy);
|
|
|
- }
|
|
|
-
|
|
|
-private:
|
|
|
-
|
|
|
- /// @brief Callback for the IPC socket.
|
|
|
- ///
|
|
|
- /// This callback is called by the @c IfaceMgr when the data is received
|
|
|
- /// over the IPC socket.
|
|
|
- void receiveHandler();
|
|
|
-
|
|
|
- /// @brief Port number.
|
|
|
- uint16_t desired_port_;
|
|
|
-
|
|
|
- /// @brief Endpoint type, i.e. 4 or 6.
|
|
|
- EndpointType endpoint_type_;
|
|
|
-
|
|
|
- /// @brief Pointer to the last received message.
|
|
|
- Pkt6Ptr pkt_received_;
|
|
|
-};
|
|
|
-
|
|
|
-TestIpc::TestIpc(const uint16_t port, const EndpointType& endpoint_type)
|
|
|
- : desired_port_(port), endpoint_type_(endpoint_type), pkt_received_() {
|
|
|
-}
|
|
|
-
|
|
|
-void
|
|
|
-TestIpc::open() {
|
|
|
- // Use the base IPC to open the socket.
|
|
|
- socket_fd_ = Dhcp4o6IpcBase::open(desired_port_, endpoint_type_);
|
|
|
- // If the socket has been opened correctly, register it in the @c IfaceMgr.
|
|
|
- if (socket_fd_ != -1) {
|
|
|
- IfaceMgr& iface_mgr = IfaceMgr::instance();
|
|
|
- iface_mgr.addExternalSocket(socket_fd_,
|
|
|
- boost::bind(&TestIpc::receiveHandler,
|
|
|
- this));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void
|
|
|
-TestIpc::receiveHandler() {
|
|
|
- pkt_received_ = receive();
|
|
|
-}
|
|
|
+/// @brief Define short name for test IPC class.
|
|
|
+typedef Dhcp4o6TestIpc TestIpc;
|
|
|
|
|
|
/// @brief Test fixture class for @c Dhcp4o6IpcBase.
|
|
|
class Dhcp4o6IpcBaseTest : public ::testing::Test {
|