1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 | // Copyright (C) 2014-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef PKT_FILTER6_TEST_STUB_H
#define PKT_FILTER6_TEST_STUB_H
#include <asiolink/io_address.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/pkt_filter6.h>
#include <dhcp/pkt6.h>
namespace isc {
namespace dhcp {
namespace test {
/// @brief An open socket callback that can be use for a testing purposes.
///
/// @param port Port number to bind socket to.
typedef std::function<void(uint16_t port)> PktFilter6OpenSocketCallback;
/// @brief A stub implementation of the PktFilter6 class.
///
/// This class implements abstract methods of the @c isc::dhcp::PktFilter6
/// class. It is used by unit tests, which test protected methods of the
/// @c isc::dhcp::test::PktFilter6 class. The implemented abstract methods are
/// no-op.
class PktFilter6TestStub : public PktFilter6 {
public:
/// @brief Constructor.
PktFilter6TestStub();
/// @brief Simulate opening of the socket.
///
/// This function simulates opening a primary socket. In reality, it doesn't
/// open a socket but the socket descriptor returned in the SocketInfo
/// structure is always set to 0.
///
/// @param iface An interface descriptor.
/// @param addr Address on the interface to be used to send packets.
/// @param port Port number to bind socket to.
/// @param join_multicast A flag which indicates if the socket should be
/// configured to join multicast (if true).
///
/// @note All parameters are ignored.
///
/// @return A SocketInfo structure with the socket descriptor set to 0. The
/// fallback socket descriptor is set to a negative value.
virtual SocketInfo openSocket(const Iface& iface,<--- Function in derived class
const isc::asiolink::IOAddress& addr,
const uint16_t port,
const bool join_multicast);
/// @brief Simulate reception of the DHCPv6 message.
///
/// @param socket_info A structure holding socket information.
///
/// @note All parameters are ignored.
///
/// @return always a NULL object.
virtual Pkt6Ptr receive(const SocketInfo& socket_info);<--- Function in derived class
/// @brief Simulates sending a DHCPv6 message.
///
/// This function does nothing.
///
/// @param iface An interface to be used to send DHCPv6 message.
/// @param port A port used to send a message.
/// @param pkt A DHCPv6 to be sent.
///
/// @note All parameters are ignored.
///
/// @return 0.
virtual int send(const Iface& iface, uint16_t port, const Pkt6Ptr& pkt);<--- Function in derived class
/// @brief Simulate joining IPv6 multicast group on a socket.
///
/// @note All parameters are ignored.
///
/// @param sock A socket descriptor (socket must be bound).
/// @param ifname An interface name (for link-scoped multicast groups).
/// @param mcast A multicast address to join (e.g. "ff02::1:2").
///
/// @return true if multicast join was successful
static bool joinMulticast(int sock, const std::string& ifname,<--- Derived function 'PktFilter6TestStub::joinMulticast'
const std::string & mcast);
/// @brief Set an open socket callback. Use it for testing
/// purposes, e.g. counting the number of calls or throwing an exception.
void setOpenSocketCallback(PktFilter6OpenSocketCallback callback) {
open_socket_callback_ = callback;
}
private:
/// @brief The callback used when opening socket.
PktFilter6OpenSocketCallback open_socket_callback_;
};
} // namespace isc::dhcp::test
} // namespace isc::dhcp
} // namespace isc
#endif // PKT_FILTER6_TEST_STUB_H
|