diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-01-12 15:31:50 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-01-22 16:49:59 +0100 |
commit | 1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4 (patch) | |
tree | fc89d85f5dd097dd85a2921ce1382980e012a423 /src/bin/perfdhcp | |
parent | [#3119] replace const auto with auto const (diff) | |
download | kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.tar.xz kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.zip |
[#3119] use range based for loop or BOOST_FOREACH
Diffstat (limited to 'src/bin/perfdhcp')
-rw-r--r-- | src/bin/perfdhcp/pkt_transform.cc | 13 | ||||
-rw-r--r-- | src/bin/perfdhcp/stats_mgr.cc | 16 | ||||
-rw-r--r-- | src/bin/perfdhcp/stats_mgr.h | 79 | ||||
-rw-r--r-- | src/bin/perfdhcp/test_control.cc | 17 | ||||
-rw-r--r-- | src/bin/perfdhcp/test_control.h | 26 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/avalanche_scen_unittest.cc | 1 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/basic_scen_unittest.cc | 1 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/perf_socket_unittest.cc | 5 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/test_control_unittest.cc | 5 |
9 files changed, 70 insertions, 93 deletions
diff --git a/src/bin/perfdhcp/pkt_transform.cc b/src/bin/perfdhcp/pkt_transform.cc index 7aaf9c6c41..d189161c5c 100644 --- a/src/bin/perfdhcp/pkt_transform.cc +++ b/src/bin/perfdhcp/pkt_transform.cc @@ -116,11 +116,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, // If there are any options on the list, we will use provided // options offsets to override them in the output buffer // with new contents. - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { // Get options with their position (offset). boost::shared_ptr<LocalizedOption> option = - boost::dynamic_pointer_cast<LocalizedOption>(it->second); + boost::dynamic_pointer_cast<LocalizedOption>(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } @@ -146,8 +145,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, out_buffer.writeUint8At(buf_data[i], offset + i); } } - } - catch (const Exception&) { + } catch (const Exception&) { isc_throw(isc::BadValue, "failed to pack options into buffer."); } } @@ -155,11 +153,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, void PktTransform::unpackOptions(const OptionBuffer& in_buffer, const OptionCollection& options) { - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { boost::shared_ptr<LocalizedOption> option = - boost::dynamic_pointer_cast<LocalizedOption>(it->second); + boost::dynamic_pointer_cast<LocalizedOption>(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } diff --git a/src/bin/perfdhcp/stats_mgr.cc b/src/bin/perfdhcp/stats_mgr.cc index 1563588f65..1bb655b791 100644 --- a/src/bin/perfdhcp/stats_mgr.cc +++ b/src/bin/perfdhcp/stats_mgr.cc @@ -14,6 +14,7 @@ #include <dhcp/pkt4.h> #include <perfdhcp/stats_mgr.h> #include <perfdhcp/test_control.h> +#include <boost/foreach.hpp> using isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER; using isc::dhcp::DUID; @@ -313,21 +314,16 @@ ExchangeStats::printTimestamps() { using namespace boost::posix_time; // Iterate through all received packets. - for (PktListIterator it = rcvd_packets_.begin(); - it != rcvd_packets_.end(); - ++it) { - PktPtr rcvd_packet = *it; + for (auto const& it : rcvd_packets_) { + PktPtr rcvd_packet = it; PktListTransidHashIndex& idx = archived_packets_.template get<1>(); std::pair<PktListTransidHashIterator, PktListTransidHashIterator> p = idx.equal_range(hashTransid(rcvd_packet)); - for (PktListTransidHashIterator it_archived = p.first; - it_archived != p.second; - ++it_archived) { - if ((*it_archived)->getTransid() == - rcvd_packet->getTransid()) { - PktPtr sent_packet = *it_archived; + BOOST_FOREACH(auto const& it_archived, p) { + if (it_archived->getTransid() == rcvd_packet->getTransid()) { + PktPtr sent_packet = it_archived; // Get sent and received packet times. ptime sent_time = sent_packet->getTimestamp(); ptime rcvd_time = rcvd_packet->getTimestamp(); diff --git a/src/bin/perfdhcp/stats_mgr.h b/src/bin/perfdhcp/stats_mgr.h index 39718e9b79..e5a3619351 100644 --- a/src/bin/perfdhcp/stats_mgr.h +++ b/src/bin/perfdhcp/stats_mgr.h @@ -209,10 +209,8 @@ public: /// \code /// PktList packets_collection(); /// ... # Add elements to the container - /// for (PktListIterator it = packets_collection.begin(); - /// it != packets_collection.end(); - /// ++it) { - /// boost::shared_ptr<Pkt4> pkt = *it; + /// for (auto const& it : packets_collection) { + /// boost::shared_ptr<Pkt4> pkt = it; /// # Do something with packet; /// } /// \endcode @@ -778,10 +776,8 @@ public: /// // \return true, if packet drops occurred. bool droppedPackets() const { - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - if (it->second->getDroppedPacketsNum() > 0) { + for (auto const& it : exchanges_) { + if (it.second->getDroppedPacketsNum() > 0) { return (true); } } @@ -1098,11 +1094,9 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; - std::cout << "***Statistics for: " << it->first + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; + std::cout << "***Statistics for: " << it.first << "***" << std::endl; xchg_stats->printMainStats(); std::cout << std::endl; @@ -1126,35 +1120,36 @@ public: std::ostringstream stream_drops; std::ostringstream stream_reject; std::string sep(""); - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); ++it) { - - if (it != exchanges_.begin()) { + bool first = true; + for (auto const& it : exchanges_) { + if (!first) { if (clean_report) { sep = clean_sep; } else { sep = "/"; } + } else { + first = false; } - stream_sent << sep << it->second->getSentPacketsNum(); - stream_rcvd << sep << it->second->getRcvdPacketsNum(); - stream_drops << sep << it->second->getDroppedPacketsNum(); - stream_reject << sep << it->second->getRejLeasesNum(); + stream_sent << sep << it.second->getSentPacketsNum(); + stream_rcvd << sep << it.second->getRcvdPacketsNum(); + stream_drops << sep << it.second->getDroppedPacketsNum(); + stream_reject << sep << it.second->getRejLeasesNum(); } if (clean_report) { - std::cout << stream_sent.str() - << clean_sep << stream_rcvd.str() - << clean_sep << stream_drops.str() - << clean_sep << stream_reject.str() - << std::endl; + std::cout << stream_sent.str() + << clean_sep << stream_rcvd.str() + << clean_sep << stream_drops.str() + << clean_sep << stream_reject.str() + << std::endl; } else { - std::cout << "sent: " << stream_sent.str() - << "; received: " << stream_rcvd.str() - << "; drops: " << stream_drops.str() - << "; rejected: " << stream_reject.str() - << std::endl; + std::cout << "sent: " << stream_sent.str() + << "; received: " << stream_rcvd.str() + << "; drops: " << stream_drops.str() + << "; rejected: " << stream_reject.str() + << std::endl; } } @@ -1174,12 +1169,10 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; std::cout << "***Timestamps for packets: " - << it->first + << it.first << "***" << std::endl; xchg_stats->printTimestamps(); std::cout << std::endl; @@ -1199,19 +1192,19 @@ public: if (custom_counters_.empty()) { isc_throw(isc::InvalidOperation, "no custom counters specified"); } - for (CustomCountersMapIterator it = custom_counters_.begin(); - it != custom_counters_.end(); - ++it) { - CustomCounterPtr counter = it->second; + for (auto const& it : custom_counters_) { + CustomCounterPtr counter = it.second; std::cout << counter->getName() << ": " << counter->getValue() << std::endl; } } - std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> getSentPackets(const ExchangeType xchg_type) const { + std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> + getSentPackets(const ExchangeType xchg_type) const { ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type); - std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> sent_packets_its = xchg_stats->getSentPackets(); - return(sent_packets_its); + std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> sent_packets_its = + xchg_stats->getSentPackets(); + return (sent_packets_its); } private: diff --git a/src/bin/perfdhcp/test_control.cc b/src/bin/perfdhcp/test_control.cc index 29ef5a87f3..9d33be86aa 100644 --- a/src/bin/perfdhcp/test_control.cc +++ b/src/bin/perfdhcp/test_control.cc @@ -549,9 +549,8 @@ TestControl::initPacketTemplates() { template_packets_v6_.clear(); template_buffers_.clear(); std::vector<std::string> template_files = options_.getTemplateFiles(); - for (std::vector<std::string>::const_iterator it = template_files.begin(); - it != template_files.end(); ++it) { - readPacketTemplate(*it); + for (auto const& it : template_files) { + readPacketTemplate(it); } } @@ -750,13 +749,13 @@ std::string TestControl::vector2Hex(const std::vector<uint8_t>& vec, const std::string& separator /* = "" */) { std::ostringstream stream; - for (std::vector<uint8_t>::const_iterator it = vec.begin(); - it != vec.end(); - ++it) { - if (it == vec.begin()) { - stream << byte2Hex(*it); + bool first = true; + for (auto const& it : vec) { + if (first) { + stream << byte2Hex(it); + first = false; } else { - stream << separator << byte2Hex(*it); + stream << separator << byte2Hex(it); } } return (stream.str()); diff --git a/src/bin/perfdhcp/test_control.h b/src/bin/perfdhcp/test_control.h index 17700cebf2..2ec4e44cec 100644 --- a/src/bin/perfdhcp/test_control.h +++ b/src/bin/perfdhcp/test_control.h @@ -615,10 +615,9 @@ protected: void addUniqeAddr(const std::set<std::string>& current, ExchangeType xchg_type) { switch(xchg_type) { case ExchangeType::SA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::SA); } @@ -626,10 +625,9 @@ protected: break; } case ExchangeType::RR: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RR); } @@ -642,10 +640,9 @@ protected: break; } case ExchangeType::DO: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::DO); } @@ -653,10 +650,9 @@ protected: break; } case ExchangeType::RA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RA); } @@ -677,13 +673,13 @@ protected: /// /// \param addr holding value of unique address. void removeUniqueAddr(const std::set<std::string>& addr) { - for (auto addr_it = addr.begin(); addr_it != addr.end(); ++addr_it) { - auto it = unique_address_.find(*addr_it); + for (auto const& addr_it : addr) { + auto it = unique_address_.find(addr_it); if (it != unique_address_.end()) { unique_address_.erase(it); } - auto it2 = unique_reply_address_.find(*addr_it); + auto it2 = unique_reply_address_.find(addr_it); if (it2 != unique_reply_address_.end()) { unique_reply_address_.erase(it2); } diff --git a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc index d2e119a094..614ca03380 100644 --- a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc @@ -18,7 +18,6 @@ #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/basic_scen_unittest.cc b/src/bin/perfdhcp/tests/basic_scen_unittest.cc index 5240293339..431e8326fc 100644 --- a/src/bin/perfdhcp/tests/basic_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/basic_scen_unittest.cc @@ -17,7 +17,6 @@ #include <dhcp/option6_iaaddr.h> #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/perf_socket_unittest.cc b/src/bin/perfdhcp/tests/perf_socket_unittest.cc index 39a2db99e9..e0d5f1ce2e 100644 --- a/src/bin/perfdhcp/tests/perf_socket_unittest.cc +++ b/src/bin/perfdhcp/tests/perf_socket_unittest.cc @@ -6,8 +6,8 @@ #include <config.h> -#include "command_options_helper.h" -#include "../perf_socket.h" +#include <command_options_helper.h> +#include <perf_socket.h> #include <asiolink/io_address.h> #include <exceptions/exceptions.h> @@ -16,7 +16,6 @@ #include <dhcp/iface_mgr.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/test_control_unittest.cc b/src/bin/perfdhcp/tests/test_control_unittest.cc index 1838a7b1db..f31f25a844 100644 --- a/src/bin/perfdhcp/tests/test_control_unittest.cc +++ b/src/bin/perfdhcp/tests/test_control_unittest.cc @@ -6,8 +6,8 @@ #include <config.h> -#include "command_options_helper.h" -#include "../test_control.h" +#include <command_options_helper.h> +#include <test_control.h> #include <asiolink/io_address.h> #include <exceptions/exceptions.h> @@ -19,7 +19,6 @@ #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <boost/format.hpp> #include <algorithm> |