Kea  1.9.9-git
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. More...
 
virtual ~PerfSocket ()
 Destructor of the socket wrapper class. More...
 
virtual dhcp::IfacePtr getIface () override
 Get interface from IfaceMgr. More...
 
virtual dhcp::Pkt4Ptr receive4 (uint32_t timeout_sec, uint32_t timeout_usec) override
 Receive DHCPv4 packet from interface. More...
 
virtual dhcp::Pkt6Ptr receive6 (uint32_t timeout_sec, uint32_t timeout_usec) override
 Receive DHCPv6 packet from interface. More...
 
virtual bool send (const dhcp::Pkt4Ptr &pkt) override
 Send DHCPv4 packet through interface. More...
 
virtual bool send (const dhcp::Pkt6Ptr &pkt) override
 Send DHCPv6 packet through interface. More...
 
- Public Member Functions inherited from isc::perfdhcp::BasePerfSocket
 BasePerfSocket ()
 Default constructor of BasePerfSocket. More...
 
virtual ~BasePerfSocket ()=default
 Destructor of the socket wrapper class. More...
 
- 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. More...
 

Protected Member Functions

void initSocketData ()
 Initialize socket data. More...
 
int openSocket (CommandOptions &options) const
 Open socket to communicate with DHCP server. More...
 

Additional Inherited Members

- Public Attributes inherited from isc::perfdhcp::BasePerfSocket
uint16_t ifindex_
 Interface index. More...
 
- Public Attributes inherited from isc::dhcp::SocketInfo
isc::asiolink::IOAddress addr_
 
int fallbackfd_
 Fallback socket descriptor. More...
 
uint16_t family_
 socket port More...
 
uint16_t port_
 bound address More...
 
int sockfd_
 IPv4 or IPv6. More...
 

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

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.

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::dhcp::IfaceMgr::getIface(), and isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

Member Function Documentation

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 isc::dhcp::IfaceMgr::instance().

+ Here is the call graph for this function:

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::IfaceMgr::instance(), and isc_throw.

+ Here is the call graph for this function:

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::asiolink::IOAddress::getFamily(), isc::dhcp::IfaceMgr::getIface(), isc::perfdhcp::CommandOptions::getIpVersion(), isc::perfdhcp::CommandOptions::getLocalName(), isc::perfdhcp::CommandOptions::getLocalPort(), isc::perfdhcp::CommandOptions::getServerName(), isc::dhcp::IfaceMgr::instance(), isc::perfdhcp::CommandOptions::isBroadcast(), isc_throw, isc::perfdhcp::CommandOptions::isInterface(), isc::perfdhcp::CommandOptions::isUseRelayedV6(), isc::asiolink::IOAddress::isV6Multicast(), isc::dhcp::IfaceMgr::openSocketFromAddress(), isc::dhcp::IfaceMgr::openSocketFromIface(), and isc::dhcp::IfaceMgr::openSocketFromRemoteAddress().

+ Here is the call graph for this function:

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::dhcp::IfaceMgr::receive4().

+ Here is the call graph for this function:

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::dhcp::IfaceMgr::receive6().

+ Here is the call graph for this function:

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(), and isc::dhcp::IfaceMgr::send().

+ Here is the call graph for this function:

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(), and isc::dhcp::IfaceMgr::send().

+ Here is the call graph for this function:


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