diff options
author | Michal Nowikowski <godfryd@isc.org> | 2019-02-18 13:30:40 +0100 |
---|---|---|
committer | Michal Nowikowski <godfryd@isc.org> | 2019-02-19 21:54:31 +0100 |
commit | f4a2c50d4aae45c7f83440c8d2015481e93bb7ad (patch) | |
tree | 21132a658102bdef44013798b21248dc3a8205c6 /src/bin/perfdhcp/perf_socket.h | |
parent | perfdhcp avalanche: several improvements (diff) | |
download | kea-f4a2c50d4aae45c7f83440c8d2015481e93bb7ad.tar.xz kea-f4a2c50d4aae45c7f83440c8d2015481e93bb7ad.zip |
perfdhcp avalanche: improvements after review
- CommandOptions is no longer a signleton - this makes testing easier
- added -i option taking into account in Avalanche scen (execute only DO exchange)
- fixed collecting stats in Avalanche scen
- improved TestControl tests, moved some of them to BasicScen tests
- made PerfSocket testable: it has a base class which is used for mocking in TestControl tests
- all references to another singleton, IfaceMgr wrapped into PerfSocket - this makes testing easier
- added unit tests for basic and avalanche scenarios, and perf socket
- added -Werror to prevent ignore warnings
- added more comments
Diffstat (limited to 'src/bin/perfdhcp/perf_socket.h')
-rw-r--r-- | src/bin/perfdhcp/perf_socket.h | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/src/bin/perfdhcp/perf_socket.h b/src/bin/perfdhcp/perf_socket.h index a49cc92e32..83f8b971b8 100644 --- a/src/bin/perfdhcp/perf_socket.h +++ b/src/bin/perfdhcp/perf_socket.h @@ -7,11 +7,34 @@ #ifndef PERF_SOCKET_H #define PERF_SOCKET_H +#include <perfdhcp/command_options.h> + +#include <dhcp/pkt4.h> +#include <dhcp/pkt6.h> #include <dhcp/socket_info.h> +#include <dhcp/iface_mgr.h> namespace isc { namespace perfdhcp { +class BasePerfSocket : public dhcp::SocketInfo { +public: + /// Interface index. + uint16_t ifindex_; + + BasePerfSocket() : + SocketInfo(asiolink::IOAddress("127.0.0.1"), 0, 0), + ifindex_(0) {} + + /// \brief Destructor of the socket wrapper class. + virtual ~BasePerfSocket() = default; + + virtual dhcp::Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec) = 0; + virtual dhcp::Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec) = 0; + virtual bool send(const dhcp::Pkt4Ptr& pkt) = 0; + virtual bool send(const dhcp::Pkt6Ptr& pkt) = 0; + virtual dhcp::IfacePtr getIface() = 0; +}; /// \brief Socket wrapper structure. /// @@ -22,23 +45,52 @@ namespace perfdhcp { /// when exception occurs). This structure extends parent /// structure with new field ifindex_ that holds interface /// index where socket is bound to. -struct PerfSocket : public dhcp::SocketInfo { - /// Interface index. - uint16_t ifindex_; - +class PerfSocket : public BasePerfSocket { +public: /// \brief Constructor of socket wrapper class. /// /// This constructor uses provided socket descriptor to /// find the name of the interface where socket has been /// bound to. - PerfSocket(); + PerfSocket(CommandOptions& options); /// \brief Destructor of the socket wrapper class. /// /// Destructor closes wrapped socket. virtual ~PerfSocket(); -private: + /// \brief Receive DHCPv4 packet from interface. + /// + /// \param timeout_sec number of seconds for waiting for a packet, + /// \param timeout_sec number of microseconds for waiting for a packet, + /// \return received packet or nullptr if timed out + virtual dhcp::Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec) override; + + /// \brief Receive DHCPv6 packet from interface. + /// + /// \param timeout_sec number of seconds for waiting for a packet, + /// \param timeout_sec number of microseconds for waiting for a packet, + /// \return received packet or nullptr if timed out + virtual dhcp::Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec) override; + + /// \brief Send DHCPv4 packet through interface. + /// + /// \param pkt a packet for sending + /// \return true if operation succeeded + virtual bool send(const dhcp::Pkt4Ptr& pkt) override; + + /// \brief Send DHCPv6 packet through interface. + /// + /// \param pkt a packet for sending + /// \return true if operation succeeded + virtual bool send(const dhcp::Pkt6Ptr& pkt) override; + + /// \brief Get interface from IfaceMgr. + /// + /// \return shared pointer to Iface. + virtual dhcp::IfacePtr getIface() override; + +protected: /// \brief Initialize socket data. /// /// This method initializes members of the class that Interface @@ -66,7 +118,7 @@ private: /// for the v6 socket. /// \throw isc::Unexpected if internal unexpected error occurred. /// \return socket descriptor. - int openSocket() const; + int openSocket(CommandOptions& options) const; }; } |