1 // Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 #include <config.h>
8 #include <dhcp/iface_mgr.h>
9 #include <dhcpsrv/testutils/dhcp4o6_test_ipc.h>
10 #include <functional>
11
12 namespace isc {
13 namespace dhcp {
14 namespace test {
15
Dhcp4o6TestIpc(uint16_t port,EndpointType endpoint_type)16 Dhcp4o6TestIpc::Dhcp4o6TestIpc(uint16_t port, EndpointType endpoint_type)
17 : desired_port_(port), endpoint_type_(endpoint_type), pkt_received_() {
18 }
19
20 void
open()21 Dhcp4o6TestIpc::open() {
22 // Use the base IPC to open the socket.
23 socket_fd_ = Dhcp4o6IpcBase::open(desired_port_, endpoint_type_);
24 // If the socket has been opened correctly, register it in the @c IfaceMgr.
25 // BTW if it has not an exception has been thrown so it is only
26 // a sanity / recommended check.
27 if (socket_fd_ != -1) {
28 IfaceMgr& iface_mgr = IfaceMgr::instance();
29 iface_mgr.addExternalSocket(socket_fd_,
30 std::bind(&Dhcp4o6TestIpc::receiveHandler, this));
31 }
32 }
33
34 void
receiveHandler()35 Dhcp4o6TestIpc::receiveHandler() {
36 pkt_received_ = receive();
37 }
38
39 } // end of isc::dhcp::test namespace
40 } // end of isc::dhcp namespace
41 } // end of isc namespace
42