12 #include <boost/date_time/posix_time/posix_time.hpp>
25 const StatsMgr& stats_mgr(tc_.getStatsMgr());
29 auto begin_it = std::get<0>(sent_packets_its);
30 auto end_it = std::get<1>(sent_packets_its);
32 auto& retrans = retransmissions_[xchg_type];
33 auto& start_times = start_times_[xchg_type];
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 if (r_it != retrans.end()) {
48 start_time = (*start_times.find(trans_id)).second;
49 current_pkt_resent_cnt = (*r_it).second;
51 start_times[trans_id] = start_time;
55 int delay = (1 << current_pkt_resent_cnt);
60 delay +=
random() % 2000 - 1000;
63 auto now = microsec_clock::universal_time();
64 if (now - start_time > milliseconds(delay)) {
65 current_cycle_resent_cnt++;
69 if (options_.getIpVersion() == 4) {
70 Pkt4Ptr pkt4 = boost::dynamic_pointer_cast<
Pkt4>(pkt);
73 Pkt6Ptr pkt6 = boost::dynamic_pointer_cast<
Pkt6>(pkt);
80 current_pkt_resent_cnt++;
81 retrans[trans_id] = current_pkt_resent_cnt;
84 if (current_cycle_resent_cnt > 0) {
85 auto now = microsec_clock::universal_time();
86 std::cout << now <<
" " << xchg_type <<
": still waiting for "
87 << still_left_cnt <<
" answers, resent " << current_cycle_resent_cnt
88 <<
", retrying " << retrans.size() << std::endl;
90 return still_left_cnt;
96 AvalancheScen::run() {
108 uint32_t clients_num = options_.getClientsNum() == 0 ?
109 1 : options_.getClientsNum();
111 StatsMgr& stats_mgr(tc_.getStatsMgr());
115 auto start = microsec_clock::universal_time();
118 tc_.sendPackets(clients_num);
120 auto now = microsec_clock::universal_time();
121 auto prev_cycle_time = now;
125 tc_.consumeReceivedPackets();
129 now = microsec_clock::universal_time();
134 if (now - prev_cycle_time > milliseconds(200)) {
135 prev_cycle_time = now;
136 int still_left_cnt = 0;
137 still_left_cnt += resendPackets(stage1_xchg_);
138 if (options_.getExchangeMode() == CommandOptions::DORA_SARR) {
139 still_left_cnt += resendPackets(stage2_xchg_);
142 if (still_left_cnt == 0) {
147 if (tc_.interrupted()) {
152 auto stop = microsec_clock::universal_time();
153 boost::posix_time::time_period duration(start, stop);
160 if (options_.testDiags(
't')) {
161 stats_mgr.printTimestamps();
165 if (options_.testDiags(
's') && tc_.serverIdReceived()) {
166 std::cout <<
"Server id: " << tc_.getServerId() << std::endl;
170 if (options_.testDiags(
'e')) {
171 std::cout <<
"Interrupted" << std::endl;
175 if (options_.testDiags(
'l')) {
176 stats_mgr.printLeases();
180 int total_sent_pkts = total_resent_;
181 int total_rcvd_pkts = 0;
183 total_sent_pkts += tc_.getStatsMgr().getSentPacketsNum(stage1_xchg_);
184 total_rcvd_pkts += tc_.getStatsMgr().getRcvdPacketsNum(stage1_xchg_);
187 if (options_.getExchangeMode() == CommandOptions::DORA_SARR) {
188 total_sent_pkts += tc_.getStatsMgr().getSentPacketsNum(stage2_xchg_);
189 total_rcvd_pkts += tc_.getStatsMgr().getRcvdPacketsNum(stage2_xchg_);
192 std::cout <<
"It took " << duration.length() <<
" to provision " << clients_num
193 <<
" clients. " << std::endl
194 <<
"Requests sent + resent: " << total_sent_pkts << std::endl
195 <<
"Requests resent: " << total_resent_ << std::endl
196 <<
"Responses received: " << total_rcvd_pkts << std::endl;
ExchangeType
DHCP packet exchange types.
std::tuple< typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator > getSentPackets(const ExchangeType xchg_type) const
Represents a DHCPv6 packet.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
void setTimestamp(boost::posix_time::ptime ×tamp)
Set packet timestamp.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Represents DHCPv4 packet.
std::vector< uint8_t > random(size_t len)
Generate random value.