Kea 2.7.5
|
Socket wrapper structure. More...
#include <perf_socket.h>
Public Member Functions | |
PerfSocket (CommandOptions &options) | |
Constructor of socket wrapper class. | |
virtual | ~PerfSocket () |
Destructor of the socket wrapper class. | |
virtual dhcp::IfacePtr | getIface () override |
Get interface from IfaceMgr. | |
virtual dhcp::Pkt4Ptr | receive4 (uint32_t timeout_sec, uint32_t timeout_usec) override |
Receive DHCPv4 packet from interface. | |
virtual dhcp::Pkt6Ptr | receive6 (uint32_t timeout_sec, uint32_t timeout_usec) override |
Receive DHCPv6 packet from interface. | |
virtual bool | send (const dhcp::Pkt4Ptr &pkt) override |
Send DHCPv4 packet through interface. | |
virtual bool | send (const dhcp::Pkt6Ptr &pkt) override |
Send DHCPv6 packet through interface. | |
Public Member Functions inherited from isc::perfdhcp::BasePerfSocket | |
BasePerfSocket () | |
Default constructor of BasePerfSocket. | |
virtual | ~BasePerfSocket ()=default |
Destructor of the socket wrapper class. | |
Public Member Functions inherited from isc::dhcp::SocketInfo | |
SocketInfo (const isc::asiolink::IOAddress &addr, const uint16_t port, const int sockfd, const int fallbackfd=-1) | |
SocketInfo constructor. | |
Protected Member Functions | |
void | initSocketData () |
Initialize socket data. | |
int | openSocket (CommandOptions &options) const |
Open socket to communicate with DHCP server. | |
Additional Inherited Members | |
Public Attributes inherited from isc::perfdhcp::BasePerfSocket | |
unsigned int | ifindex_ |
Interface index. | |
Public Attributes inherited from isc::dhcp::SocketInfo | |
isc::asiolink::IOAddress | addr_ |
int | fallbackfd_ |
Fallback socket descriptor. | |
uint16_t | family_ |
socket port | |
uint16_t | port_ |
bound address | |
int | sockfd_ |
IPv4 or IPv6. | |
Socket wrapper structure.
This is the wrapper that holds descriptor of the socket used to run DHCP test. The wrapped socket is closed in the destructor. This prevents resource leaks when function that created the socket ends (normally or when exception occurs). This structure extends parent structure with new field ifindex_ that holds interface index where socket is bound to.
Definition at line 64 of file perf_socket.h.
isc::perfdhcp::PerfSocket::PerfSocket | ( | CommandOptions & | options | ) |
Constructor of socket wrapper class.
This constructor uses provided socket descriptor to find the name of the interface where socket has been bound to.
Definition at line 23 of file perf_socket.cc.
References initSocketData(), openSocket(), and isc::dhcp::SocketInfo::sockfd_.
|
virtual |
Destructor of the socket wrapper class.
Destructor closes wrapped socket.
Definition at line 128 of file perf_socket.cc.
References isc::perfdhcp::BasePerfSocket::ifindex_, isc::dhcp::IfaceMgr::instance(), and isc::dhcp::SocketInfo::sockfd_.
|
overridevirtual |
Get interface from IfaceMgr.
Implements isc::perfdhcp::BasePerfSocket.
Definition at line 190 of file perf_socket.cc.
References getIface(), isc::perfdhcp::BasePerfSocket::ifindex_, and isc::dhcp::IfaceMgr::instance().
Referenced by getIface().
|
protected |
Initialize socket data.
This method initializes members of the class that Interface Manager holds: interface name, local address.
isc::BadValue | if interface for specified socket descriptor does not exist. |
Definition at line 136 of file perf_socket.cc.
References isc::dhcp::SocketInfo::addr_, isc::perfdhcp::BasePerfSocket::ifindex_, isc::dhcp::IfaceMgr::instance(), isc_throw, and isc::dhcp::SocketInfo::sockfd_.
Referenced by PerfSocket().
|
protected |
Open socket to communicate with DHCP server.
Method opens socket and binds it to local address. Function will use either interface name, local address or server address to create a socket, depending on what is available (specified from the command line). If socket can't be created for any reason, exception is thrown. If destination address is broadcast (for DHCPv4) or multicast (for DHCPv6) than broadcast or multicast option is set on the socket. Opened socket is registered and managed by IfaceMgr.
isc::BadValue | if socket can't be created for given interface, local address or remote address. |
isc::InvalidOperation | if broadcast option can't be set for the v4 socket or if multicast option can't be set for the v6 socket. |
isc::Unexpected | if internal unexpected error occurred. |
Definition at line 30 of file perf_socket.cc.
References isc::dhcp::IfaceMgr::instance(), and isc_throw.
Referenced by PerfSocket().
|
overridevirtual |
Receive DHCPv4 packet from interface.
timeout_sec | number of seconds for waiting for a packet, |
timeout_usec | number of microseconds for waiting for a packet, |
Implements isc::perfdhcp::BasePerfSocket.
Definition at line 150 of file perf_socket.cc.
References isc::dhcp::IfaceMgr::instance(), and isc::perfdhcp::ExchangeStats::malformed_pkts_.
|
overridevirtual |
Receive DHCPv6 packet from interface.
timeout_sec | number of seconds for waiting for a packet, |
timeout_usec | number of microseconds for waiting for a packet, |
Implements isc::perfdhcp::BasePerfSocket.
Definition at line 165 of file perf_socket.cc.
References isc::dhcp::IfaceMgr::instance(), and isc::perfdhcp::ExchangeStats::malformed_pkts_.
|
overridevirtual |
Send DHCPv4 packet through interface.
pkt | a packet for sending |
Implements isc::perfdhcp::BasePerfSocket.
Definition at line 180 of file perf_socket.cc.
References isc::dhcp::IfaceMgr::instance().
|
overridevirtual |
Send DHCPv6 packet through interface.
pkt | a packet for sending |
Implements isc::perfdhcp::BasePerfSocket.
Definition at line 185 of file perf_socket.cc.
References isc::dhcp::IfaceMgr::instance().