Kea 2.7.0
isc::perfdhcp::PerfSocket Class Reference

Socket wrapper structure. More...

#include <perf_socket.h>

+ Inheritance diagram for isc::perfdhcp::PerfSocket:

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PerfSocket()

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_.

+ Here is the call graph for this function:

◆ ~PerfSocket()

isc::perfdhcp::PerfSocket::~PerfSocket ( )
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_.

+ Here is the call graph for this function:

Member Function Documentation

◆ getIface()

IfacePtr isc::perfdhcp::PerfSocket::getIface ( )
overridevirtual

Get interface from IfaceMgr.

Returns
shared pointer to Iface.

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().

+ Here is the call graph for this function:

◆ initSocketData()

void isc::perfdhcp::PerfSocket::initSocketData ( )
protected

Initialize socket data.

This method initializes members of the class that Interface Manager holds: interface name, local address.

Exceptions
isc::BadValueif 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().

+ Here is the call graph for this function:

◆ openSocket()

int isc::perfdhcp::PerfSocket::openSocket ( CommandOptions & options) const
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.

Exceptions
isc::BadValueif socket can't be created for given interface, local address or remote address.
isc::InvalidOperationif broadcast option can't be set for the v4 socket or if multicast option can't be set for the v6 socket.
isc::Unexpectedif internal unexpected error occurred.
Returns
socket descriptor.
Todo
: find out why port 68 is wrong here.

Definition at line 30 of file perf_socket.cc.

References isc::dhcp::IfaceMgr::instance(), and isc_throw.

Referenced by PerfSocket().

+ Here is the call graph for this function:

◆ receive4()

Pkt4Ptr isc::perfdhcp::PerfSocket::receive4 ( uint32_t timeout_sec,
uint32_t timeout_usec )
overridevirtual

Receive DHCPv4 packet from interface.

Parameters
timeout_secnumber of seconds for waiting for a packet,
timeout_usecnumber of microseconds for waiting for a packet,
Returns
received packet or nullptr if timed out

Implements isc::perfdhcp::BasePerfSocket.

Definition at line 150 of file perf_socket.cc.

References isc::dhcp::IfaceMgr::instance(), and isc::perfdhcp::ExchangeStats::malformed_pkts_.

+ Here is the call graph for this function:

◆ receive6()

Pkt6Ptr isc::perfdhcp::PerfSocket::receive6 ( uint32_t timeout_sec,
uint32_t timeout_usec )
overridevirtual

Receive DHCPv6 packet from interface.

Parameters
timeout_secnumber of seconds for waiting for a packet,
timeout_usecnumber of microseconds for waiting for a packet,
Returns
received packet or nullptr if timed out

Implements isc::perfdhcp::BasePerfSocket.

Definition at line 165 of file perf_socket.cc.

References isc::dhcp::IfaceMgr::instance(), and isc::perfdhcp::ExchangeStats::malformed_pkts_.

+ Here is the call graph for this function:

◆ send() [1/2]

bool isc::perfdhcp::PerfSocket::send ( const dhcp::Pkt4Ptr & pkt)
overridevirtual

Send DHCPv4 packet through interface.

Parameters
pkta packet for sending
Returns
true if operation succeeded

Implements isc::perfdhcp::BasePerfSocket.

Definition at line 180 of file perf_socket.cc.

References isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

◆ send() [2/2]

bool isc::perfdhcp::PerfSocket::send ( const dhcp::Pkt6Ptr & pkt)
overridevirtual

Send DHCPv6 packet through interface.

Parameters
pkta packet for sending
Returns
true if operation succeeded

Implements isc::perfdhcp::BasePerfSocket.

Definition at line 185 of file perf_socket.cc.

References isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: