Kea: isc::perfdhcp::RateControl Class Reference

| Kea 3.0.2-git

isc::perfdhcp::RateControl Class Reference

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

`#include <rate_control.h>`

## Public Member Functions
| RateControl ()
| Default constructor.
| RateControl (const unsigned int rate)
| Constructor which sets desired rate.
uint64_t | getOutboundMessageCount (bool const waiting_to_exit=false)
| Returns number of messages to be sent "now".
unsigned int | getRate () const
| Returns the rate.
void | setRate (const int rate)
| Sets the new rate.

## Protected Member Functions
boost::posix_time::ptime | currentTime ()
| Convenience function returning current time.

## Protected Attributes
unsigned int | rate_
| Holds a desired rate value.
boost::posix_time::ptime | start_time_
| Holds time of start of testing.
uint64_t | total_pkts_sent_count_
| Holds number of packets send from the beginning.

## 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 19 of file rate_control.cc.

References rate_, and total_pkts_sent_count_.

## ◆ RateControl() [2/2]

isc::perfdhcp::RateControl::RateControl | ( | const unsigned int | rate | ) |

Constructor which sets desired rate.

Parameters

  rate | A desired rate.

Definition at line 23 of file rate_control.cc.

References rate_, and total_pkts_sent_count_.

## Member Function Documentation

## ◆ currentTime()

boost::posix_time::ptime isc::perfdhcp::RateControl::currentTime | ( |  | ) |
| protected

Convenience function returning current time.

Returns
  current time.

Definition at line 66 of file rate_control.cc.

Referenced by getOutboundMessageCount().

## ◆ getOutboundMessageCount()

uint64_t isc::perfdhcp::RateControl::getOutboundMessageCount | ( | bool const | waiting_to_exit = false | ) |

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.

Returns
  A number of messages to be sent immediately.

Definition at line 28 of file rate_control.cc.

References currentTime(), getRate(), start_time_, and total_pkts_sent_count_.

Here is the call graph for this function:

## ◆ getRate()

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

Returns the rate.

Definition at line 75 of file rate_control.h.

References rate_.

Referenced by getOutboundMessageCount().

## ◆ setRate()

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

Sets the new rate.

Parameters

  rate | A new value of rate. This value must not be negative.

Exceptions

  isc::BadValue | if new rate is negative.

Definition at line 71 of file rate_control.cc.

References isc_throw, and rate_.

## Member Data Documentation

## ◆ rate_

unsigned int isc::perfdhcp::RateControl::rate_
| protected

Holds a desired rate value.

Definition at line 93 of file rate_control.h.

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

## ◆ start_time_

boost::posix_time::ptime isc::perfdhcp::RateControl::start_time_
| protected

Holds time of start of testing.

It is used to calculate current request rate. Then this is used to estimate number of packets to send in current cycle.

Definition at line 105 of file rate_control.h.

Referenced by getOutboundMessageCount().

## ◆ total_pkts_sent_count_

uint64_t isc::perfdhcp::RateControl::total_pkts_sent_count_
| protected

Holds number of packets send from the beginning.

It is used to calculate current request rate. Then this is used to estimate number of packets to send in current cycle.

Definition at line 99 of file rate_control.h.

Referenced by RateControl(), RateControl(), and getOutboundMessageCount().

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

- rate_control.h
- rate_control.cc