12#include <boost/date_time/posix_time/posix_time.hpp>
15using namespace boost::posix_time;
28 auto sent_packets_its = stats_mgr.getSentPackets(xchg_type);
29 auto begin_it = std::get<0>(sent_packets_its);
30 auto end_it = std::get<1>(sent_packets_its);
35 int still_left_cnt = 0;
36 int current_cycle_resent_cnt = 0;
37 for (
auto it = begin_it; it != end_it; ++it) {
41 auto trans_id = pkt->getTransid();
44 auto start_time = pkt->getTimestamp();
45 int current_pkt_resent_cnt = 0;
46 auto r_it = retrans.find(trans_id);
47 auto s_it = start_times.find(trans_id);
48 if (r_it != retrans.end() && s_it != start_times.end()) {
49 start_time = s_it->second;
50 current_pkt_resent_cnt = r_it->second;
52 start_times[trans_id] = start_time;
56 int delay = (1 << current_pkt_resent_cnt);
61 delay += random() % 2000 - 1000;
64 auto now = microsec_clock::universal_time();
65 if (now - start_time > milliseconds(delay)) {
66 current_cycle_resent_cnt++;
71 Pkt4Ptr pkt4 = boost::dynamic_pointer_cast<Pkt4>(pkt);
74 Pkt6Ptr pkt6 = boost::dynamic_pointer_cast<Pkt6>(pkt);
79 pkt->setTimestamp(start_time);
81 current_pkt_resent_cnt++;
82 retrans[trans_id] = current_pkt_resent_cnt;
85 if (current_cycle_resent_cnt > 0) {
86 auto now = microsec_clock::universal_time();
87 std::cout << now <<
" " << xchg_type <<
": still waiting for "
88 << still_left_cnt <<
" answers, resent " << current_cycle_resent_cnt
89 <<
", retrying " << retrans.size() << std::endl;
91 return still_left_cnt;
116 auto start = microsec_clock::universal_time();
121 auto now = microsec_clock::universal_time();
122 auto prev_cycle_time = now;
130 now = microsec_clock::universal_time();
135 if (now - prev_cycle_time > milliseconds(200)) {
136 prev_cycle_time = now;
137 int still_left_cnt = 0;
143 if (still_left_cnt == 0) {
153 auto stop = microsec_clock::universal_time();
154 boost::posix_time::time_period duration(start, stop);
162 stats_mgr.printTimestamps();
172 std::cout <<
"Interrupted" << std::endl;
177 stats_mgr.printLeases();
182 int total_rcvd_pkts = 0;
193 std::cout <<
"It took " << duration.length() <<
" to provision " << clients_num
194 <<
" clients. " << std::endl
195 <<
"Requests sent + resent: " << total_sent_pkts << std::endl
197 <<
"Responses received: " << total_rcvd_pkts << std::endl;
TestControl tc_
Object for controlling sending and receiving packets.
ExchangeType stage2_xchg_
CommandOptions & options_
Reference to commandline options.
ExchangeType stage1_xchg_
std::unordered_map< ExchangeType, std::unordered_map< uint32_t, int >, EnumClassHash > retransmissions_
A map xchg type -> (a map of trans id -> retransmissions count.
int total_resent_
Total number of resent packets.
int run() override
brief\ Run performance test.
int resendPackets(ExchangeType xchg_type)
\brief Resend packets.
std::unordered_map< ExchangeType, std::unordered_map< uint32_t, boost::posix_time::ptime >, EnumClassHash > start_times_
A map xchg type -> (a map of trans id -> time of sending first packet.
virtual bool send(const dhcp::Pkt4Ptr &pkt)=0
See description of this method in PerfSocket class below.
bool testDiags(const char diag)
Find if diagnostic flag has been set.
uint8_t getIpVersion() const
Returns IP version.
uint32_t getClientsNum() const
Returns number of simulated clients.
ExchangeMode getExchangeMode() const
Returns packet exchange mode.
uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const
Return total number of received packets.
uint64_t getSentPacketsNum(const ExchangeType xchg_type) const
Return total number of sent packets.
bool interrupted() const
Get interrupted flag.
std::string getServerId() const
Get received server id.
void start()
Start receiver.
StatsMgr & getStatsMgr()
Get stats manager.
void sendPackets(const uint64_t packets_num, const bool preload=false)
Send number of packets to initiate new exchanges.
void stop()
Stop receiver.
unsigned int consumeReceivedPackets()
Pull packets from receiver and process them.
void printStats() const
Print performance statistics.
bool serverIdReceived() const
Get received server id flag.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
ExchangeType
DHCP packet exchange types.
Defines the logger used by the top-level component of kea-lfc.