Kea  1.5.0
isc::perfdhcp::RateControl Class Reference

A message sending rate control class for perfdhcp. More...

#include <rate_control.h>

Public Member Functions

 RateControl ()
 Default constructor. More...
 
 RateControl (const int rate, const int aggressivity)
 Constructor which sets desired rate and aggressivity. More...
 
int getAggressivity () const
 Returns the value of aggressivity. More...
 
boost::posix_time::ptime getDue () const
 Returns current due time to send next message. More...
 
uint64_t getOutboundMessageCount ()
 Returns number of messages to be sent "now". More...
 
int getRate () const
 Returns the rate. More...
 
bool isLateSent () const
 Returns the value of the late send flag. More...
 
void setAggressivity (const int aggressivity)
 Sets the value of aggressivity. More...
 
void setRate (const int rate)
 Sets the new rate. More...
 
void setRelativeDue (const int offset)
 Sets the value of the due time. More...
 
void updateSendTime ()
 Sets the timestamp of the last sent message to current time. More...
 

Protected Member Functions

void updateSendDue ()
 Calculates the send due. More...
 

Static Protected Member Functions

static boost::posix_time::ptime currentTime ()
 Convenience function returning current time. More...
 

Protected Attributes

int aggressivity_
 Holds an aggressivity value. More...
 
boost::posix_time::ptime last_sent_
 Holds a timestamp when the last message was sent. More...
 
bool late_sent_
 A flag which indicates that the calculated due time is in the past. More...
 
int rate_
 Holds a desired rate value. More...
 
boost::posix_time::ptime send_due_
 Holds a timestamp when the next message should be sent. More...
 

Detailed Description

A message sending rate control class for perfdhcp.

This class provides the means to control the rate at which messages of the specific type are sent by perfdhcp. Each message type, for which the desired rate can be specified, has a corresponding RateControl object. So, the perfdhcp is using up to three objects of this type at the same time, to control the rate of the following messages being sent:

  • Discover(DHCPv4) or Solicit (DHCPv6)
  • Renew (DHCPv6) or Request (DHCPv4) to renew leases.
  • Release

The purpose of the RateControl class is to track the due time for sending next message (or bunch of messages) to keep outbound rate of particular messages at the desired level. The due time is calculated using the desired rate value and the timestamp when the last message of the particular type has been sent. That puts the responsibility on the TestControl class to invoke the RateControl::updateSendDue, every time the message is sent.

The RateControl object returns the number of messages to be sent at the time. The number returned is 0, if perfdhcp shouldn't send any messages yet, or 1 (sometimes more) if the send due time has been reached.

Definition at line 38 of file rate_control.h.

Constructor & Destructor Documentation

◆ RateControl() [1/2]

isc::perfdhcp::RateControl::RateControl ( )

Default constructor.

Definition at line 17 of file rate_control.cc.

◆ RateControl() [2/2]

isc::perfdhcp::RateControl::RateControl ( const int  rate,
const int  aggressivity 
)

Constructor which sets desired rate and aggressivity.

Parameters
rateA desired rate.
aggressivityA desired aggressivity.

Definition at line 22 of file rate_control.cc.

References aggressivity_, isc_throw, and rate_.

Member Function Documentation

◆ currentTime()

boost::posix_time::ptime isc::perfdhcp::RateControl::currentTime ( )
staticprotected

Convenience function returning current time.

Returns
current time.

Definition at line 82 of file rate_control.cc.

Referenced by getOutboundMessageCount(), setRelativeDue(), updateSendDue(), and updateSendTime().

◆ getAggressivity()

int isc::perfdhcp::RateControl::getAggressivity ( ) const
inline

Returns the value of aggressivity.

Definition at line 51 of file rate_control.h.

References aggressivity_.

Referenced by getOutboundMessageCount().

◆ getDue()

boost::posix_time::ptime isc::perfdhcp::RateControl::getDue ( ) const
inline

Returns current due time to send next message.

Definition at line 56 of file rate_control.h.

References send_due_.

Referenced by isc::perfdhcp::TestControl::getCurrentTimeout().

◆ getOutboundMessageCount()

uint64_t isc::perfdhcp::RateControl::getOutboundMessageCount ( )

Returns number of messages to be sent "now".

This function calculates how many messages of the given type should be sent immediately when the call to the function returns, to catch up with the desired message rate.

The value returned depends on the due time calculated with the RateControl::updateSendDue function and the current time. If the due time has been hit, the non-zero number of messages is returned. If the due time hasn't been hit, the number returned is 0.

If the rate is non-zero, the number of messages to be sent is calculated as follows:

num = duration * rate

where duration is a time period between the due time to send next set of messages and current time. The duration is expressed in seconds with the fractional part having 6 or 9 digits (depending on the timer resolution). If the calculated value is equal to 0, it is rounded to 1, so as at least one message is sent.

The value of aggressivity limits the maximal number of messages to be sent one after another. If the number of messages calculated with the equation above exceeds the aggressivity, this function will return the value equal to aggressivity.

If the rate is not specified (equal to 0), the value calculated by this function is equal to aggressivity.

Returns
A number of messages to be sent immediately.

Definition at line 36 of file rate_control.cc.

References currentTime(), getAggressivity(), getRate(), send_due_, and updateSendDue().

Referenced by isc::perfdhcp::TestControl::run().

+ Here is the call graph for this function:

◆ getRate()

int isc::perfdhcp::RateControl::getRate ( ) const
inline

Returns the rate.

Definition at line 94 of file rate_control.h.

References rate_.

Referenced by getOutboundMessageCount(), and updateSendDue().

◆ isLateSent()

bool isc::perfdhcp::RateControl::isLateSent ( ) const
inline

Returns the value of the late send flag.

The flag returned by this function indicates whether the new due time calculated by the RateControl::updateSendDue is in the past. This value is used by the TestControl object to increment the counter of the late sent messages in the StatsMgr.

Definition at line 104 of file rate_control.h.

References late_sent_.

Referenced by isc::perfdhcp::TestControl::checkLateMessages().

◆ setAggressivity()

void isc::perfdhcp::RateControl::setAggressivity ( const int  aggressivity)

Sets the value of aggressivity.

Parameters
aggressivityA new value of aggressivity. This value must be a positive integer.
Exceptions
isc::BadValueif new value is not a positive integer.

Definition at line 123 of file rate_control.cc.

References aggressivity_, and isc_throw.

Referenced by isc::perfdhcp::TestControl::reset().

◆ setRate()

void isc::perfdhcp::RateControl::setRate ( const int  rate)

Sets the new rate.

Parameters
rateA new value of rate. This value must not be negative.
Exceptions
isc::BadValueif new rate is negative.

Definition at line 132 of file rate_control.cc.

References isc_throw, and rate_.

Referenced by isc::perfdhcp::TestControl::reset().

◆ setRelativeDue()

void isc::perfdhcp::RateControl::setRelativeDue ( const int  offset)

Sets the value of the due time.

This function is intended for unit testing. It manipulates the value of the due time. The parameter passed to this function specifies the (positive or negative) number of seconds relative to current time.

Parameters
offsetA number of seconds relative to current time which constitutes the new due time.

Definition at line 141 of file rate_control.cc.

References currentTime(), and send_due_.

+ Here is the call graph for this function:

◆ updateSendDue()

void isc::perfdhcp::RateControl::updateSendDue ( )
protected

Calculates the send due.

This function calculates the send due timestamp using the current time and desired rate. The due timestamp is calculated as a sum of the timestamp when the last message was sent and the reciprocal of the rate in micro or nanoseconds (depending on the timer resolution). If the rate is not specified, the duration between two consecutive sends is one timer tick.

Definition at line 87 of file rate_control.cc.

References currentTime(), getRate(), isc_throw, last_sent_, late_sent_, and send_due_.

Referenced by getOutboundMessageCount().

+ Here is the call graph for this function:

◆ updateSendTime()

void isc::perfdhcp::RateControl::updateSendTime ( )

Sets the timestamp of the last sent message to current time.

Definition at line 148 of file rate_control.cc.

References currentTime(), and last_sent_.

Referenced by isc::perfdhcp::TestControl::sendDiscover4(), isc::perfdhcp::TestControl::sendMessageFromReply(), isc::perfdhcp::TestControl::sendRequestFromAck(), and isc::perfdhcp::TestControl::sendSolicit6().

+ Here is the call graph for this function:

Member Data Documentation

◆ aggressivity_

int isc::perfdhcp::RateControl::aggressivity_
protected

Holds an aggressivity value.

Definition at line 158 of file rate_control.h.

Referenced by getAggressivity(), RateControl(), and setAggressivity().

◆ last_sent_

boost::posix_time::ptime isc::perfdhcp::RateControl::last_sent_
protected

Holds a timestamp when the last message was sent.

Definition at line 155 of file rate_control.h.

Referenced by updateSendDue(), and updateSendTime().

◆ late_sent_

bool isc::perfdhcp::RateControl::late_sent_
protected

A flag which indicates that the calculated due time is in the past.

Definition at line 165 of file rate_control.h.

Referenced by isLateSent(), and updateSendDue().

◆ rate_

int isc::perfdhcp::RateControl::rate_
protected

Holds a desired rate value.

Definition at line 161 of file rate_control.h.

Referenced by getRate(), RateControl(), and setRate().

◆ send_due_

boost::posix_time::ptime isc::perfdhcp::RateControl::send_due_
protected

Holds a timestamp when the next message should be sent.

Definition at line 152 of file rate_control.h.

Referenced by getDue(), getOutboundMessageCount(), setRelativeDue(), and updateSendDue().


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