From 0ef99148d2fa323256dcad545678050218607d16 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 11:22:12 +0300 Subject: [PATCH 01/15] Initial version of LinkQueue --- source/link/link.cpp | 6 ++-- source/link/link.hpp | 6 ++-- source/link/packet_queue/link_queue.cpp | 36 +++++++++++++++++++ source/link/packet_queue/link_queue.hpp | 30 ++++++++++++++++ .../link/packet_queue/simple_packet_queue.hpp | 1 - 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 source/link/packet_queue/link_queue.cpp create mode 100644 source/link/packet_queue/link_queue.hpp diff --git a/source/link/link.cpp b/source/link/link.cpp index dd4fcd038c..b14330a539 100644 --- a/source/link/link.cpp +++ b/source/link/link.cpp @@ -15,8 +15,10 @@ Link::Link(Id a_id, std::weak_ptr a_from, m_to(a_to), m_speed_gbps(a_speed_gbps), m_propagation_delay(a_delay), - m_from_egress(a_max_from_egress_buffer_size), - m_to_ingress(a_max_to_ingress_buffer_size) { + m_from_egress(SimplePacketQueue(a_max_from_egress_buffer_size), m_id, + LinkQueueType::FromEgress), + m_to_ingress(SimplePacketQueue(a_max_to_ingress_buffer_size), m_id, + LinkQueueType::ToIngress) { if (a_from.expired() || a_to.expired()) { LOG_WARN("Passed link to device is expired"); } else if (a_speed_gbps == 0) { diff --git a/source/link/link.hpp b/source/link/link.hpp index a23ea459d9..6d607b9722 100644 --- a/source/link/link.hpp +++ b/source/link/link.hpp @@ -4,7 +4,7 @@ #include "event/event.hpp" #include "link/i_link.hpp" -#include "packet_queue/simple_packet_queue.hpp" +#include "packet_queue/link_queue.hpp" namespace sim { @@ -70,10 +70,10 @@ class Link : public ILink, public std::enable_shared_from_this { Time m_propagation_delay; // Queue at the ingress port of the m_to device - SimplePacketQueue m_from_egress; + LinkQueue m_from_egress; // Queue at the egress port of the m_to device - SimplePacketQueue m_to_ingress; + LinkQueue m_to_ingress; }; } // namespace sim diff --git a/source/link/packet_queue/link_queue.cpp b/source/link/packet_queue/link_queue.cpp new file mode 100644 index 0000000000..96ca3aa88a --- /dev/null +++ b/source/link/packet_queue/link_queue.cpp @@ -0,0 +1,36 @@ +#include "link_queue.hpp" + +#include "metrics/metrics_collector.hpp" +#include "scheduler.hpp" +#include "simple_packet_queue.hpp" + +namespace sim { + +LinkQueue::LinkQueue(SimplePacketQueue a_queue, Id a_link_id, + LinkQueueType a_type) + : m_queue(std::move(a_queue)), m_link_id(a_link_id), m_type(a_type) {} + +bool LinkQueue::push(Packet packet) { + bool result = m_queue.push(std::move(packet)); + MetricsCollector::get_instance().add_queue_size( + m_link_id, Scheduler::get_instance().get_current_time(), + m_queue.get_size()); + return result; +} + +Packet LinkQueue::front() { return m_queue.front(); } + +void LinkQueue::pop() { + m_queue.pop(); + MetricsCollector::get_instance().add_queue_size( + m_link_id, Scheduler::get_instance().get_current_time(), + m_queue.get_size()); +} + +Size LinkQueue::get_size() const { return m_queue.get_size(); } + +bool LinkQueue::empty() const { return m_queue.empty(); } + +Size LinkQueue::get_max_size() const { return m_queue.get_max_size(); } + +} // namespace sim \ No newline at end of file diff --git a/source/link/packet_queue/link_queue.hpp b/source/link/packet_queue/link_queue.hpp new file mode 100644 index 0000000000..06518f347b --- /dev/null +++ b/source/link/packet_queue/link_queue.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "simple_packet_queue.hpp" + +namespace sim { + +enum class LinkQueueType { FromEgress, ToIngress }; + +// Class for two types of links: +// eggress queue of sourse link device or +// ingress queue of desination link device +class LinkQueue : public IPacketQueue { +public: + LinkQueue(SimplePacketQueue a_queue, Id a_link_id, LinkQueueType a_type); + ~LinkQueue() = default; + + bool push(Packet packet) final; + Packet front() final; + void pop() final; + + Size get_size() const final; + bool empty() const final; + Size get_max_size() const final; + +private: + SimplePacketQueue m_queue; + Id m_link_id; + LinkQueueType m_type; +}; +} // namespace sim \ No newline at end of file diff --git a/source/link/packet_queue/simple_packet_queue.hpp b/source/link/packet_queue/simple_packet_queue.hpp index e599787395..1edba37dbe 100644 --- a/source/link/packet_queue/simple_packet_queue.hpp +++ b/source/link/packet_queue/simple_packet_queue.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include #include "i_packet_queue.hpp" From cd4ae5e5d861f267014d51c9a815092cda7a2c87 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 11:23:32 +0300 Subject: [PATCH 02/15] Delete useless usage of MetricsCollector in Link --- source/link/link.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/link/link.cpp b/source/link/link.cpp index b14330a539..74064edd09 100644 --- a/source/link/link.cpp +++ b/source/link/link.cpp @@ -1,7 +1,6 @@ #include "link/link.hpp" #include "logger/logger.hpp" -#include "metrics/metrics_collector.hpp" #include "scheduler.hpp" namespace sim { @@ -147,10 +146,6 @@ void Link::arrive(Packet packet) { return; } - MetricsCollector::get_instance().add_queue_size( - get_id(), Scheduler::get_instance().get_current_time(), - m_from_egress.get_size()); - m_to.lock()->notify_about_arrival( Scheduler::get_instance().get_current_time()); LOG_INFO("Packet arrived to the next device. Packet: " + From 2736e471fb57d279e913022c5920c307cf8066fd Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 11:47:52 +0300 Subject: [PATCH 03/15] Started MetricCollector refactoring --- source/metrics/metrics_collector.cpp | 44 +++++++++++++++++++++------- source/metrics/metrics_collector.hpp | 12 +++++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/source/metrics/metrics_collector.cpp b/source/metrics/metrics_collector.cpp index 53bbbf7701..c39add2a6d 100644 --- a/source/metrics/metrics_collector.cpp +++ b/source/metrics/metrics_collector.cpp @@ -27,14 +27,29 @@ void MetricsCollector::add_RTT(Id flow_id, Time time, Time value) { } void MetricsCollector::add_queue_size(Id link_id, Time time, - std::uint32_t value) { - m_queue_size_storage.add_record(std::move(link_id), time, value); + std::uint32_t value, LinkQueueType type) { + switch (type) { + case LinkQueueType::FromEgress: { + m_from_egress_queue_size_storage.add_record(std::move(link_id), + time, value); + break; + } + case LinkQueueType::ToIngress: { + m_to_inress_queue_size_storage.add_record(std::move(link_id), time, + value); + break; + } + default: { + LOG_ERROR(fmt::format("Unexpected LinkQueueSize {}", + static_cast(type))); + } + } } void MetricsCollector::export_metrics_to_files( std::filesystem::path metrics_dir) const { m_RTT_storage.export_to_files(metrics_dir); - m_queue_size_storage.export_to_files(metrics_dir); + m_from_egress_queue_size_storage.export_to_files(metrics_dir); m_cwnd_storage.export_to_files(metrics_dir); m_rate_storage.export_to_files(metrics_dir); } @@ -42,12 +57,9 @@ void MetricsCollector::export_metrics_to_files( // verctor of pairs using PlotMetricsData = std::vector >; -// Draws data from different DataStorage on one plot -static void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, - PlotMetadata metadata) { - if (data.empty()) { - return; - } +// Puts data from different DataStorage on one plot +static matplot::figure_handle put_on_same_plot(PlotMetricsData data, + PlotMetadata metadata) { auto fig = matplot::figure(true); auto ax = fig->current_axes(); ax->hold(matplot::on); @@ -59,6 +71,16 @@ static void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, ax->ylabel(metadata.y_label); ax->title(metadata.title); ax->legend(std::vector()); + return fig; +} + +// Draws data from different DataStorage on one plot +static void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, + PlotMetadata metadata) { + if (data.empty()) { + return; + } + auto fig = put_on_same_plot(data, metadata); matplot::safe_save(fig, path.string()); } @@ -114,7 +136,7 @@ void MetricsCollector::draw_delivery_rate_plot( void MetricsCollector::draw_queue_size_plots( std::filesystem::path dir_path) const { - for (auto& [link_id, values] : m_queue_size_storage.data()) { + for (auto& [link_id, values] : m_from_egress_queue_size_storage.data()) { auto link = IdentifierFactory::get_instance().get_object(link_id); auto fig = values.get_picture( @@ -152,7 +174,7 @@ void MetricsCollector::set_metrics_filter(const std::string& filter) { m_RTT_storage.set_filter(filter); m_cwnd_storage.set_filter(filter); m_rate_storage.set_filter(filter); - m_queue_size_storage.set_filter(filter); + m_from_egress_queue_size_storage.set_filter(filter); } } // namespace sim diff --git a/source/metrics/metrics_collector.hpp b/source/metrics/metrics_collector.hpp index 1ee8a8b516..6c1195ed7e 100644 --- a/source/metrics/metrics_collector.hpp +++ b/source/metrics/metrics_collector.hpp @@ -3,8 +3,8 @@ #include #include +#include "link/packet_queue/link_queue.hpp" #include "multi_id_metrics_storage.hpp" - namespace sim { class MetricsCollector { @@ -14,7 +14,8 @@ class MetricsCollector { void add_cwnd(Id flow_id, Time time, double cwnd); void add_delivery_rate(Id flow_id, Time time, double value); void add_RTT(Id flow_id, Time time, Time value); - void add_queue_size(Id link_id, Time time, std::uint32_t value); + void add_queue_size(Id link_id, Time time, std::uint32_t value, + LinkQueueType type = LinkQueueType::FromEgress); void export_metrics_to_files(std::filesystem::path metrics_dir) const; void draw_metric_plots(std::filesystem::path metrics_dir) const; @@ -37,8 +38,11 @@ class MetricsCollector { MultiIdMetricsStorage m_rate_storage = MultiIdMetricsStorage("rate"); // link_ID --> vector of values - MultiIdMetricsStorage m_queue_size_storage = - MultiIdMetricsStorage("queue_size"); + MultiIdMetricsStorage m_from_egress_queue_size_storage = + MultiIdMetricsStorage("from_egress_queue_size"); + + MultiIdMetricsStorage m_to_inress_queue_size_storage = + MultiIdMetricsStorage("to_ingress_queue_size"); }; } // namespace sim From 5638ec4747919684188498345f98da7e3a0f6d10 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 12:12:43 +0300 Subject: [PATCH 04/15] Maybe final sollution --- source/link/packet_queue/link_queue.cpp | 4 +- source/metrics/metrics_collector.cpp | 54 ++++++++++++++++++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/source/link/packet_queue/link_queue.cpp b/source/link/packet_queue/link_queue.cpp index 96ca3aa88a..07558e1f06 100644 --- a/source/link/packet_queue/link_queue.cpp +++ b/source/link/packet_queue/link_queue.cpp @@ -14,7 +14,7 @@ bool LinkQueue::push(Packet packet) { bool result = m_queue.push(std::move(packet)); MetricsCollector::get_instance().add_queue_size( m_link_id, Scheduler::get_instance().get_current_time(), - m_queue.get_size()); + m_queue.get_size(), m_type); return result; } @@ -24,7 +24,7 @@ void LinkQueue::pop() { m_queue.pop(); MetricsCollector::get_instance().add_queue_size( m_link_id, Scheduler::get_instance().get_current_time(), - m_queue.get_size()); + m_queue.get_size(), m_type); } Size LinkQueue::get_size() const { return m_queue.get_size(); } diff --git a/source/metrics/metrics_collector.cpp b/source/metrics/metrics_collector.cpp index c39add2a6d..c75d411c5e 100644 --- a/source/metrics/metrics_collector.cpp +++ b/source/metrics/metrics_collector.cpp @@ -136,23 +136,59 @@ void MetricsCollector::draw_delivery_rate_plot( void MetricsCollector::draw_queue_size_plots( std::filesystem::path dir_path) const { + // for data from both from_ingress and to_ingress queue sizes + std::map queue_size_data; for (auto& [link_id, values] : m_from_egress_queue_size_storage.data()) { auto link = IdentifierFactory::get_instance().get_object(link_id); - auto fig = values.get_picture( - {"Time, ns", "Values, bytes", - fmt::format("Queue size from {} to {}", link->get_from()->get_id(), - link->get_to()->get_id())}); + std::string curve_name = + fmt::format("{} engress queue size", link->get_from()->get_id()); + queue_size_data[link_id].emplace_back(values, curve_name); + } + + for (auto& [link_id, values] : m_to_inress_queue_size_storage.data()) { + auto link = + IdentifierFactory::get_instance().get_object(link_id); + std::string curve_name = + fmt::format("{} ingress queue size", link->get_to()->get_id()); + queue_size_data[link_id].emplace_back(values, curve_name); + } + for (auto [link_id, data] : queue_size_data) { + auto link = + IdentifierFactory::get_instance().get_object(link_id); + PlotMetadata metadata = { + "Time, ns", "Values, bytes", + fmt::format("Queue size from {} to {}", link->get_from()->get_id(), + link->get_to()->get_id())}; + + auto fig = put_on_same_plot(data, metadata); auto ax = fig->current_axes(); auto limits = ax->xlim(); - matplot::line(0, link->get_max_from_egress_buffer_size(), limits[1], - link->get_max_from_egress_buffer_size()) - ->line_width(1.5) - .color({1.f, 0.0f, 0.0f}); - ax->xlim({0, limits[1]}); + auto draw_gorizontal_line = + [&limits](double line_y, std::initializer_list color) { + matplot::line(0, line_y, limits[1], line_y) + ->line_width(1.5) + .color(color); + }; + + draw_gorizontal_line(link->get_max_from_egress_buffer_size(), + {1.f, 0.f, 0.f}); + draw_gorizontal_line(link->get_max_to_ingress_queue_size(), + {0.f, 1.f, 0.f}); + // matplot::line(0, link->get_max_from_egress_buffer_size(), limits[1], + // link->get_max_from_egress_buffer_size()) + // ->line_width(1.5) + // .color({1.f, 0.0f, 0.0f}); + + // matplot::line(0, link->get_max_to_ingress_queue_size(), limits[1], + // link->get_max_to_ingress_queue_size()) + // ->line_width(1.5) + // .color({1.f, 0.0f, 0.0f}); + + ax->xlim({0, limits[1]}); ax->color("white"); std::filesystem::path plot_path = From 698b57f3c6130573d593be0abc54849b02277567 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 15:04:44 +0300 Subject: [PATCH 05/15] Rerfactoring MetricsCollector::set_filter --- source/main.cpp | 2 +- source/metrics/metrics_collector.cpp | 51 +++++++++++-------- source/metrics/metrics_collector.hpp | 19 +++---- source/metrics/multi_id_metrics_collector.cpp | 13 ++--- source/metrics/multi_id_metrics_storage.hpp | 4 +- 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index bb34e37337..361e26c7dc 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -31,7 +31,7 @@ int main(const int argc, char **argv) { Logger::get_instance().disable_logs(); } - sim::MetricsCollector::get_instance().set_metrics_filter( + sim::MetricsCollector::set_metrics_filter( flags["metrics-filter"].as()); sim::YamlParser parser; diff --git a/source/metrics/metrics_collector.cpp b/source/metrics/metrics_collector.cpp index c75d411c5e..f380456e4e 100644 --- a/source/metrics/metrics_collector.cpp +++ b/source/metrics/metrics_collector.cpp @@ -9,6 +9,18 @@ namespace sim { +std::string MetricsCollector::m_metrics_filter = ".*"; +bool MetricsCollector::m_is_initialised = false; + +MetricsCollector::MetricsCollector() + : m_RTT_storage("rtt", m_metrics_filter), + m_cwnd_storage("cwnd", m_metrics_filter), + m_rate_storage("rate", m_metrics_filter), + m_from_egress_queue_size_storage("queue_size", m_metrics_filter), + m_to_inress_queue_size_storage("queue_size", m_metrics_filter) { + m_is_initialised = true; +} + MetricsCollector& MetricsCollector::get_instance() { static MetricsCollector instance; return instance; @@ -166,27 +178,19 @@ void MetricsCollector::draw_queue_size_plots( auto limits = ax->xlim(); - auto draw_gorizontal_line = - [&limits](double line_y, std::initializer_list color) { - matplot::line(0, line_y, limits[1], line_y) - ->line_width(1.5) - .color(color); - }; + auto draw_gorizontal_line = [&limits]( + double line_y, std::string_view name, + std::initializer_list color) { + matplot::line(0, line_y, limits[1], line_y) + ->line_width(1.5) + .color(color) + .display_name(name); + }; draw_gorizontal_line(link->get_max_from_egress_buffer_size(), - {1.f, 0.f, 0.f}); + "max from egress", {1.f, 0.f, 0.f}); draw_gorizontal_line(link->get_max_to_ingress_queue_size(), - {0.f, 1.f, 0.f}); - - // matplot::line(0, link->get_max_from_egress_buffer_size(), limits[1], - // link->get_max_from_egress_buffer_size()) - // ->line_width(1.5) - // .color({1.f, 0.0f, 0.0f}); - - // matplot::line(0, link->get_max_to_ingress_queue_size(), limits[1], - // link->get_max_to_ingress_queue_size()) - // ->line_width(1.5) - // .color({1.f, 0.0f, 0.0f}); + "max to ingress", {0.f, 0.f, 1.f}); ax->xlim({0, limits[1]}); ax->color("white"); @@ -207,10 +211,13 @@ void MetricsCollector::draw_metric_plots( } void MetricsCollector::set_metrics_filter(const std::string& filter) { - m_RTT_storage.set_filter(filter); - m_cwnd_storage.set_filter(filter); - m_rate_storage.set_filter(filter); - m_from_egress_queue_size_storage.set_filter(filter); + if (m_is_initialised) { + LOG_ERROR(fmt::format( + "Set metrics filter {} when MetricsCollector already initialized " + "with filter {}; no effect", + filter, m_metrics_filter)); + } + m_metrics_filter = filter; } } // namespace sim diff --git a/source/metrics/metrics_collector.hpp b/source/metrics/metrics_collector.hpp index 6c1195ed7e..0ec908e7d2 100644 --- a/source/metrics/metrics_collector.hpp +++ b/source/metrics/metrics_collector.hpp @@ -20,10 +20,10 @@ class MetricsCollector { void export_metrics_to_files(std::filesystem::path metrics_dir) const; void draw_metric_plots(std::filesystem::path metrics_dir) const; - void set_metrics_filter(const std::string& filter); + static void set_metrics_filter(const std::string& filter); private: - MetricsCollector() {} + MetricsCollector(); MetricsCollector(const MetricsCollector&) = delete; MetricsCollector& operator=(const MetricsCollector&) = delete; @@ -32,17 +32,18 @@ class MetricsCollector { void draw_RTT_plot(std::filesystem::path path) const; void draw_queue_size_plots(std::filesystem::path dir_path) const; + static std::string m_metrics_filter; + static bool m_is_initialised; + // flow_ID --> vector of values - MultiIdMetricsStorage m_RTT_storage = MultiIdMetricsStorage("rtt"); - MultiIdMetricsStorage m_cwnd_storage = MultiIdMetricsStorage("cwnd"); - MultiIdMetricsStorage m_rate_storage = MultiIdMetricsStorage("rate"); + MultiIdMetricsStorage m_RTT_storage; + MultiIdMetricsStorage m_cwnd_storage; + MultiIdMetricsStorage m_rate_storage; // link_ID --> vector of values - MultiIdMetricsStorage m_from_egress_queue_size_storage = - MultiIdMetricsStorage("from_egress_queue_size"); + MultiIdMetricsStorage m_from_egress_queue_size_storage; - MultiIdMetricsStorage m_to_inress_queue_size_storage = - MultiIdMetricsStorage("to_ingress_queue_size"); + MultiIdMetricsStorage m_to_inress_queue_size_storage; }; } // namespace sim diff --git a/source/metrics/multi_id_metrics_collector.cpp b/source/metrics/multi_id_metrics_collector.cpp index a7d0c437e6..780de63ea5 100644 --- a/source/metrics/multi_id_metrics_collector.cpp +++ b/source/metrics/multi_id_metrics_collector.cpp @@ -3,13 +3,15 @@ #include "multi_id_metrics_storage.hpp" namespace sim { -MultiIdMetricsStorage::MultiIdMetricsStorage(std::string a_metric_name) - : metric_name(std::move(a_metric_name)) {} +MultiIdMetricsStorage::MultiIdMetricsStorage(std::string a_metric_name, + std::string a_filter) + : metric_name(std::move(a_metric_name)), m_filter(a_filter) {} void MultiIdMetricsStorage::add_record(Id id, Time time, double value) { auto it = m_storage.find(id); if (it == m_storage.end()) { - if (!std::regex_match(get_metrics_filename(id), m_filter)) { + std::string filename = get_metrics_filename(id); + if (!std::regex_match(filename, m_filter)) { m_storage[id] = std::nullopt; } else { MetricsStorage new_storage; @@ -39,11 +41,6 @@ std::unordered_map MultiIdMetricsStorage::data() const { } return result; } - -void MultiIdMetricsStorage::set_filter(std::string filter) { - m_filter = std::regex(filter); -} - std::string MultiIdMetricsStorage::get_metrics_filename(Id id) const { return fmt::format("{}/{}.txt", metric_name, id); } diff --git a/source/metrics/multi_id_metrics_storage.hpp b/source/metrics/multi_id_metrics_storage.hpp index 4ba0d05a2a..18259d00f2 100644 --- a/source/metrics/multi_id_metrics_storage.hpp +++ b/source/metrics/multi_id_metrics_storage.hpp @@ -9,15 +9,13 @@ namespace sim { class MultiIdMetricsStorage { public: - MultiIdMetricsStorage(std::string a_metric_name); + MultiIdMetricsStorage(std::string a_metric_name, std::string a_filter); void add_record(Id id, Time time, double value); void export_to_files(std::filesystem::path output_dir_path) const; std::unordered_map data() const; - void set_filter(std::string filter); - private: std::string get_metrics_filename(Id id) const; From 0af0b24ab27a07beec43cfb0f77e3fff5d5d0937 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 15:40:54 +0300 Subject: [PATCH 06/15] Add LinkQueueSizeStorage class --- source/link/packet_queue/link_queue.cpp | 13 +++ source/link/packet_queue/link_queue.hpp | 2 + source/metrics/draw_plots.cpp | 33 ++++++ source/metrics/draw_plots.hpp | 17 +++ source/metrics/links_queue_size_storage.cpp | 104 +++++++++++++++++ source/metrics/links_queue_size_storage.hpp | 35 ++++++ source/metrics/metrics_collector.cpp | 121 ++------------------ source/metrics/metrics_collector.hpp | 5 +- source/metrics/metrics_storage.hpp | 8 +- source/metrics/multi_id_metrics_storage.hpp | 2 +- source/metrics/plot_metadata.hpp | 13 +++ source/utils/filesystem.hpp | 1 + 12 files changed, 234 insertions(+), 120 deletions(-) create mode 100644 source/metrics/draw_plots.cpp create mode 100644 source/metrics/draw_plots.hpp create mode 100644 source/metrics/links_queue_size_storage.cpp create mode 100644 source/metrics/links_queue_size_storage.hpp create mode 100644 source/metrics/plot_metadata.hpp diff --git a/source/link/packet_queue/link_queue.cpp b/source/link/packet_queue/link_queue.cpp index 07558e1f06..b96e71bb22 100644 --- a/source/link/packet_queue/link_queue.cpp +++ b/source/link/packet_queue/link_queue.cpp @@ -6,6 +6,19 @@ namespace sim { +std::string to_string(LinkQueueType type) { + switch (type) { + case LinkQueueType::FromEgress: + return "from_ingress_queue_size"; + case LinkQueueType::ToIngress: + return "to_ingress_queue_size"; + default: + LOG_ERROR(fmt::format("Undefined link queue type: {}", + static_cast(type))); + return "queue_size"; + } +} + LinkQueue::LinkQueue(SimplePacketQueue a_queue, Id a_link_id, LinkQueueType a_type) : m_queue(std::move(a_queue)), m_link_id(a_link_id), m_type(a_type) {} diff --git a/source/link/packet_queue/link_queue.hpp b/source/link/packet_queue/link_queue.hpp index 06518f347b..34703f103c 100644 --- a/source/link/packet_queue/link_queue.hpp +++ b/source/link/packet_queue/link_queue.hpp @@ -6,6 +6,8 @@ namespace sim { enum class LinkQueueType { FromEgress, ToIngress }; +std::string to_string(LinkQueueType type); + // Class for two types of links: // eggress queue of sourse link device or // ingress queue of desination link device diff --git a/source/metrics/draw_plots.cpp b/source/metrics/draw_plots.cpp new file mode 100644 index 0000000000..8770459eac --- /dev/null +++ b/source/metrics/draw_plots.cpp @@ -0,0 +1,33 @@ +#include "draw_plots.hpp" + +#include "utils/safe_matplot.hpp" + +namespace sim { + +void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, + PlotMetadata metadata) { + if (data.empty()) { + return; + } + auto fig = put_on_same_plot(data, metadata); + + matplot::safe_save(fig, path.string()); +} + +matplot::figure_handle put_on_same_plot(PlotMetricsData data, + PlotMetadata metadata) { + auto fig = matplot::figure(true); + auto ax = fig->current_axes(); + ax->hold(matplot::on); + + for (auto& [values, name] : data) { + values.draw_on_plot(fig, name); + } + ax->xlabel(metadata.x_label); + ax->ylabel(metadata.y_label); + ax->title(metadata.title); + ax->legend(std::vector()); + return fig; +} + +} // namespace sim \ No newline at end of file diff --git a/source/metrics/draw_plots.hpp b/source/metrics/draw_plots.hpp new file mode 100644 index 0000000000..12a07a0bc4 --- /dev/null +++ b/source/metrics/draw_plots.hpp @@ -0,0 +1,17 @@ +#pragma once +#include + +#include "metrics_storage.hpp" + +namespace sim { + +using PlotMetricsData = std::vector >; + +// Puts data from different DataStorage on one plot +matplot::figure_handle put_on_same_plot(PlotMetricsData data, + PlotMetadata metadata); + +// Draws data from different DataStorage on one plot +void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, + PlotMetadata metadata); +} // namespace sim diff --git a/source/metrics/links_queue_size_storage.cpp b/source/metrics/links_queue_size_storage.cpp new file mode 100644 index 0000000000..73a90446f6 --- /dev/null +++ b/source/metrics/links_queue_size_storage.cpp @@ -0,0 +1,104 @@ +#include "links_queue_size_storage.hpp" + +#include "draw_plots.hpp" +#include "link/i_link.hpp" +#include "multi_id_metrics_storage.hpp" +#include "utils/safe_matplot.hpp" + +namespace sim { + +LinksQueueSizeStorage::LinksQueueSizeStorage(std::string a_filter) + : m_filter(a_filter) {} + +void LinksQueueSizeStorage::add_record(Id id, LinkQueueType type, Time time, + double value) { + std::pair key = std::make_pair(id, type); + auto it = m_storage.find(key); + if (it == m_storage.end()) { + std::string filename = get_metrics_filename(id, type); + if (!std::regex_match(filename, m_filter)) { + m_storage[std::move(key)] = std::nullopt; + } else { + MetricsStorage new_storage; + new_storage.add_record(time, value); + m_storage.emplace(std::move(key), std::move(new_storage)); + } + } else if (it->second.has_value()) { + it->second->add_record(time, value); + } +} + +void LinksQueueSizeStorage::export_to_files( + std::filesystem::path output_dir_path) const { + for (auto& [key, values] : m_storage) { + auto [id, type] = key; + if (values) { + values->export_to_file(output_dir_path / + get_metrics_filename(id, type)); + } + } +} + +void LinksQueueSizeStorage::draw_plots( + std::filesystem::path output_dir_path) const { + // for data from both from_ingress and to_ingress queue sizes + std::map queue_size_data; + for (auto& [key, values] : data()) { + auto [link_id, type] = key; + std::string curve_name = to_string(type); + std::replace(curve_name.begin(), curve_name.end(), '_', ' '); + queue_size_data[link_id].emplace_back(values, curve_name); + } + for (auto [link_id, data] : queue_size_data) { + auto link = + IdentifierFactory::get_instance().get_object(link_id); + PlotMetadata metadata = { + "Time, ns", "Values, bytes", + fmt::format("Queue size from {} to {}", link->get_from()->get_id(), + link->get_to()->get_id())}; + + auto fig = put_on_same_plot(data, metadata); + auto ax = fig->current_axes(); + + auto limits = ax->xlim(); + + auto draw_gorizontal_line = [&limits]( + double line_y, std::string_view name, + std::initializer_list color) { + matplot::line(0, line_y, limits[1], line_y) + ->line_width(1.5) + .color(color) + .display_name(name); + }; + + draw_gorizontal_line(link->get_max_from_egress_buffer_size(), + "max from egress", {1.f, 0.f, 0.f}); + draw_gorizontal_line(link->get_max_to_ingress_queue_size(), + "max to ingress", {0.f, 0.f, 1.f}); + + ax->xlim({0, limits[1]}); + ax->color("white"); + + std::filesystem::path plot_path = + output_dir_path / fmt::format("{}.svg", link_id); + + matplot::safe_save(fig, plot_path.string()); + } +} + +std::map, MetricsStorage> +LinksQueueSizeStorage::data() const { + std::map, MetricsStorage> result; + for (auto [id, maybe_storage] : m_storage) { + if (maybe_storage) { + result[id] = maybe_storage.value(); + } + } + return result; +} + +std::string LinksQueueSizeStorage::get_metrics_filename( + Id id, LinkQueueType type) const { + return fmt::format("{}/{}.txt", to_string(type), id); +} +} // namespace sim \ No newline at end of file diff --git a/source/metrics/links_queue_size_storage.hpp b/source/metrics/links_queue_size_storage.hpp new file mode 100644 index 0000000000..0a4dba51db --- /dev/null +++ b/source/metrics/links_queue_size_storage.hpp @@ -0,0 +1,35 @@ +#pragma once +#include +#include +#include +#include +#include + +#include "link/packet_queue/link_queue.hpp" +#include "metrics_storage.hpp" +#include "types.hpp" + +namespace sim { +class LinksQueueSizeStorage { +public: + LinksQueueSizeStorage(std::string filter); + + void add_record(Id id, LinkQueueType type, Time time, double value); + void export_to_files(std::filesystem::path output_dir_path) const; + void draw_plots(std::filesystem::path output_dir_path) const; + + std::map, MetricsStorage> data() const; + +private: + std::string get_metrics_filename(Id id, LinkQueueType type) const; + + // If m_storage does not contain some id, there was no check is metrics file + // name for id correspond to m_filter + // If m_storage[id] = std::nullopt, this check was failed + // Otherwice, check was succseed + std::map, std::optional> + m_storage; + + std::regex m_filter; +}; +} // namespace sim \ No newline at end of file diff --git a/source/metrics/metrics_collector.cpp b/source/metrics/metrics_collector.cpp index f380456e4e..6259375e85 100644 --- a/source/metrics/metrics_collector.cpp +++ b/source/metrics/metrics_collector.cpp @@ -2,6 +2,7 @@ #include +#include "draw_plots.hpp" #include "flow/i_flow.hpp" #include "link/i_link.hpp" #include "utils/identifier_factory.hpp" @@ -16,8 +17,7 @@ MetricsCollector::MetricsCollector() : m_RTT_storage("rtt", m_metrics_filter), m_cwnd_storage("cwnd", m_metrics_filter), m_rate_storage("rate", m_metrics_filter), - m_from_egress_queue_size_storage("queue_size", m_metrics_filter), - m_to_inress_queue_size_storage("queue_size", m_metrics_filter) { + m_links_queue_size_storage(m_metrics_filter) { m_is_initialised = true; } @@ -40,63 +40,17 @@ void MetricsCollector::add_RTT(Id flow_id, Time time, Time value) { void MetricsCollector::add_queue_size(Id link_id, Time time, std::uint32_t value, LinkQueueType type) { - switch (type) { - case LinkQueueType::FromEgress: { - m_from_egress_queue_size_storage.add_record(std::move(link_id), - time, value); - break; - } - case LinkQueueType::ToIngress: { - m_to_inress_queue_size_storage.add_record(std::move(link_id), time, - value); - break; - } - default: { - LOG_ERROR(fmt::format("Unexpected LinkQueueSize {}", - static_cast(type))); - } - } + m_links_queue_size_storage.add_record(link_id, type, time, value); } void MetricsCollector::export_metrics_to_files( std::filesystem::path metrics_dir) const { m_RTT_storage.export_to_files(metrics_dir); - m_from_egress_queue_size_storage.export_to_files(metrics_dir); + m_links_queue_size_storage.export_to_files(metrics_dir); m_cwnd_storage.export_to_files(metrics_dir); m_rate_storage.export_to_files(metrics_dir); } -// verctor of pairs -using PlotMetricsData = std::vector >; - -// Puts data from different DataStorage on one plot -static matplot::figure_handle put_on_same_plot(PlotMetricsData data, - PlotMetadata metadata) { - auto fig = matplot::figure(true); - auto ax = fig->current_axes(); - ax->hold(matplot::on); - - for (auto& [values, name] : data) { - values.draw_on_plot(fig, name); - } - ax->xlabel(metadata.x_label); - ax->ylabel(metadata.y_label); - ax->title(metadata.title); - ax->legend(std::vector()); - return fig; -} - -// Draws data from different DataStorage on one plot -static void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, - PlotMetadata metadata) { - if (data.empty()) { - return; - } - auto fig = put_on_same_plot(data, metadata); - - matplot::safe_save(fig, path.string()); -} - void MetricsCollector::draw_cwnd_plot(std::filesystem::path path) const { PlotMetricsData data; std::transform( @@ -113,10 +67,11 @@ void MetricsCollector::draw_cwnd_plot(std::filesystem::path path) const { {"Time, ns", "CWND, packets", "CWND"}); } -void MetricsCollector::draw_RTT_plot(std::filesystem::path path) const { +void MetricsCollector::draw_delivery_rate_plot( + std::filesystem::path path) const { PlotMetricsData data; std::transform( - begin(m_RTT_storage.data()), end(m_RTT_storage.data()), + begin(m_rate_storage.data()), end(m_rate_storage.data()), std::back_inserter(data), [](auto const& pair) { auto flow = IdentifierFactory::get_instance().get_object(pair.first); @@ -126,14 +81,13 @@ void MetricsCollector::draw_RTT_plot(std::filesystem::path path) const { return std::make_pair(pair.second, name); }); draw_on_same_plot(path, std::move(data), - {"Time, ns", "RTT, ns", "Round Trip Time"}); + {"Time, ns", "Values, Gbps", "Delivery rate"}); } -void MetricsCollector::draw_delivery_rate_plot( - std::filesystem::path path) const { +void MetricsCollector::draw_RTT_plot(std::filesystem::path path) const { PlotMetricsData data; std::transform( - begin(m_rate_storage.data()), end(m_rate_storage.data()), + begin(m_RTT_storage.data()), end(m_RTT_storage.data()), std::back_inserter(data), [](auto const& pair) { auto flow = IdentifierFactory::get_instance().get_object(pair.first); @@ -143,63 +97,12 @@ void MetricsCollector::draw_delivery_rate_plot( return std::make_pair(pair.second, name); }); draw_on_same_plot(path, std::move(data), - {"Time, ns", "Values, Gbps", "Delivery rate"}); + {"Time, ns", "RTT, ns", "Round Trip Time"}); } void MetricsCollector::draw_queue_size_plots( std::filesystem::path dir_path) const { - // for data from both from_ingress and to_ingress queue sizes - std::map queue_size_data; - for (auto& [link_id, values] : m_from_egress_queue_size_storage.data()) { - auto link = - IdentifierFactory::get_instance().get_object(link_id); - std::string curve_name = - fmt::format("{} engress queue size", link->get_from()->get_id()); - queue_size_data[link_id].emplace_back(values, curve_name); - } - - for (auto& [link_id, values] : m_to_inress_queue_size_storage.data()) { - auto link = - IdentifierFactory::get_instance().get_object(link_id); - std::string curve_name = - fmt::format("{} ingress queue size", link->get_to()->get_id()); - queue_size_data[link_id].emplace_back(values, curve_name); - } - for (auto [link_id, data] : queue_size_data) { - auto link = - IdentifierFactory::get_instance().get_object(link_id); - PlotMetadata metadata = { - "Time, ns", "Values, bytes", - fmt::format("Queue size from {} to {}", link->get_from()->get_id(), - link->get_to()->get_id())}; - - auto fig = put_on_same_plot(data, metadata); - auto ax = fig->current_axes(); - - auto limits = ax->xlim(); - - auto draw_gorizontal_line = [&limits]( - double line_y, std::string_view name, - std::initializer_list color) { - matplot::line(0, line_y, limits[1], line_y) - ->line_width(1.5) - .color(color) - .display_name(name); - }; - - draw_gorizontal_line(link->get_max_from_egress_buffer_size(), - "max from egress", {1.f, 0.f, 0.f}); - draw_gorizontal_line(link->get_max_to_ingress_queue_size(), - "max to ingress", {0.f, 0.f, 1.f}); - - ax->xlim({0, limits[1]}); - ax->color("white"); - - std::filesystem::path plot_path = - dir_path / fmt::format("{}.svg", link_id); - - matplot::safe_save(fig, plot_path.string()); - } + m_links_queue_size_storage.draw_plots(dir_path); } void MetricsCollector::draw_metric_plots( diff --git a/source/metrics/metrics_collector.hpp b/source/metrics/metrics_collector.hpp index 0ec908e7d2..56a1982f97 100644 --- a/source/metrics/metrics_collector.hpp +++ b/source/metrics/metrics_collector.hpp @@ -4,6 +4,7 @@ #include #include "link/packet_queue/link_queue.hpp" +#include "links_queue_size_storage.hpp" #include "multi_id_metrics_storage.hpp" namespace sim { @@ -41,9 +42,7 @@ class MetricsCollector { MultiIdMetricsStorage m_rate_storage; // link_ID --> vector of values - MultiIdMetricsStorage m_from_egress_queue_size_storage; - - MultiIdMetricsStorage m_to_inress_queue_size_storage; + LinksQueueSizeStorage m_links_queue_size_storage; }; } // namespace sim diff --git a/source/metrics/metrics_storage.hpp b/source/metrics/metrics_storage.hpp index f2fb54388b..33ef4fd95a 100644 --- a/source/metrics/metrics_storage.hpp +++ b/source/metrics/metrics_storage.hpp @@ -2,18 +2,12 @@ #include #include -#include +#include "plot_metadata.hpp" #include "types.hpp" namespace sim { -struct PlotMetadata { - std::string x_label; - std::string y_label; - std::string title; -}; - class MetricsStorage { public: void add_record(Time time, double value); diff --git a/source/metrics/multi_id_metrics_storage.hpp b/source/metrics/multi_id_metrics_storage.hpp index 18259d00f2..70b96d9c8e 100644 --- a/source/metrics/multi_id_metrics_storage.hpp +++ b/source/metrics/multi_id_metrics_storage.hpp @@ -5,7 +5,7 @@ #include #include "metrics_storage.hpp" - + namespace sim { class MultiIdMetricsStorage { public: diff --git a/source/metrics/plot_metadata.hpp b/source/metrics/plot_metadata.hpp new file mode 100644 index 0000000000..a83d46f15f --- /dev/null +++ b/source/metrics/plot_metadata.hpp @@ -0,0 +1,13 @@ +#pragma once +#include +#include +#include + +namespace sim { + +struct PlotMetadata { + std::string x_label; + std::string y_label; + std::string title; +}; +} // namespace sim \ No newline at end of file diff --git a/source/utils/filesystem.hpp b/source/utils/filesystem.hpp index 2af9832e02..b1e6edcf56 100644 --- a/source/utils/filesystem.hpp +++ b/source/utils/filesystem.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include From 62522959fb1d8a10f8f9c93cc96b1aae922b38fb Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Thu, 17 Jul 2025 17:09:21 +0300 Subject: [PATCH 07/15] Merged queue_size metrics --- source/metrics/links_queue_size_storage.cpp | 20 +++---- source/metrics/links_queue_size_storage.hpp | 2 +- source/metrics/metrics_storage.cpp | 5 ++ source/metrics/metrics_storage.hpp | 1 + source/metrics/write_to_csv.cpp | 59 +++++++++++++++++++++ source/metrics/write_to_csv.hpp | 18 +++++++ 6 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 source/metrics/write_to_csv.cpp create mode 100644 source/metrics/write_to_csv.hpp diff --git a/source/metrics/links_queue_size_storage.cpp b/source/metrics/links_queue_size_storage.cpp index 73a90446f6..e42ee106aa 100644 --- a/source/metrics/links_queue_size_storage.cpp +++ b/source/metrics/links_queue_size_storage.cpp @@ -4,6 +4,7 @@ #include "link/i_link.hpp" #include "multi_id_metrics_storage.hpp" #include "utils/safe_matplot.hpp" +#include "write_to_csv.hpp" namespace sim { @@ -15,7 +16,7 @@ void LinksQueueSizeStorage::add_record(Id id, LinkQueueType type, Time time, std::pair key = std::make_pair(id, type); auto it = m_storage.find(key); if (it == m_storage.end()) { - std::string filename = get_metrics_filename(id, type); + std::string filename = get_metrics_filename(id); if (!std::regex_match(filename, m_filter)) { m_storage[std::move(key)] = std::nullopt; } else { @@ -30,12 +31,14 @@ void LinksQueueSizeStorage::add_record(Id id, LinkQueueType type, Time time, void LinksQueueSizeStorage::export_to_files( std::filesystem::path output_dir_path) const { - for (auto& [key, values] : m_storage) { + std::map > > + multi_id_storage; + for (const auto& [key, values] : data()) { auto [id, type] = key; - if (values) { - values->export_to_file(output_dir_path / - get_metrics_filename(id, type)); - } + multi_id_storage[id].emplace_back(values, to_string(type)); + } + for (auto [id, storages] : multi_id_storage) { + write_to_csv(storages, output_dir_path / get_metrics_filename(id)); } } @@ -97,8 +100,7 @@ LinksQueueSizeStorage::data() const { return result; } -std::string LinksQueueSizeStorage::get_metrics_filename( - Id id, LinkQueueType type) const { - return fmt::format("{}/{}.txt", to_string(type), id); +std::string LinksQueueSizeStorage::get_metrics_filename(Id id) const { + return fmt::format("queue_size/{}.csv", id); } } // namespace sim \ No newline at end of file diff --git a/source/metrics/links_queue_size_storage.hpp b/source/metrics/links_queue_size_storage.hpp index 0a4dba51db..2a414046e8 100644 --- a/source/metrics/links_queue_size_storage.hpp +++ b/source/metrics/links_queue_size_storage.hpp @@ -21,7 +21,7 @@ class LinksQueueSizeStorage { std::map, MetricsStorage> data() const; private: - std::string get_metrics_filename(Id id, LinkQueueType type) const; + std::string get_metrics_filename(Id id) const; // If m_storage does not contain some id, there was no check is metrics file // name for id correspond to m_filter diff --git a/source/metrics/metrics_storage.cpp b/source/metrics/metrics_storage.cpp index 095bb096c7..7fc772447c 100644 --- a/source/metrics/metrics_storage.cpp +++ b/source/metrics/metrics_storage.cpp @@ -9,6 +9,11 @@ namespace sim { void MetricsStorage::add_record(Time time, double value) { m_records.emplace_back(time, value); } + +std::vector > MetricsStorage::get_records() const { + return m_records; +} + void MetricsStorage::export_to_file(std::filesystem::path path) const { utils::create_all_directories(path); std::ofstream output_file(path); diff --git a/source/metrics/metrics_storage.hpp b/source/metrics/metrics_storage.hpp index 33ef4fd95a..e7810e2192 100644 --- a/source/metrics/metrics_storage.hpp +++ b/source/metrics/metrics_storage.hpp @@ -11,6 +11,7 @@ namespace sim { class MetricsStorage { public: void add_record(Time time, double value); + std::vector > get_records() const; void export_to_file(std::filesystem::path path) const; matplot::figure_handle get_picture(PlotMetadata metadata) const; diff --git a/source/metrics/write_to_csv.cpp b/source/metrics/write_to_csv.cpp new file mode 100644 index 0000000000..072eb58087 --- /dev/null +++ b/source/metrics/write_to_csv.cpp @@ -0,0 +1,59 @@ +#include "write_to_csv.hpp" + +#include +#include +#include + +#include "utils/filesystem.hpp" +namespace sim { + +// by list of pairs (metrics storage, metric name) generates csv table and +// writes it to output_path +void write_to_csv( + const std::vector >& storages, + std::filesystem::path output_path) { + size_t count_storages = storages.size(); + // values[time][i] is a value of metric for i-th storage at time time; + // If there were no measurement at time, values[time][i] = + // std::numeric_limits::quiet_NaN() + std::map > values; + double nan = std::numeric_limits::quiet_NaN(); + std::vector default_values(count_storages, nan); + for (size_t i = 0; i < count_storages; i++) { + for (const auto& [time, value] : storages[i].first.get_records()) { + if (values.find(time) == values.end()) { + values[time] = default_values; + } + values[time][i] = value; + } + } + + std::vector previous_time_row = default_values; + // push values by time using increasing order of keys (time) in std::map + for (auto& [time, time_values] : values) { + for (size_t i = 0; i < count_storages; i++) { + if (std::isnan(time_values[i])) { + time_values[i] = previous_time_row[i]; + } else { + previous_time_row[i] = time_values[i]; + } + } + } + + utils::create_all_directories(output_path); + std::ofstream out(output_path); + out << "Time"; + for (size_t i = 0; i < count_storages; i++) { + out << ',' << storages[i].second; + } + out << '\n'; + for (const auto& [time, time_values] : values) { + out << time; + for (auto value : time_values) { + out << ',' << value; + } + out << '\n'; + } +} + +} // namespace sim \ No newline at end of file diff --git a/source/metrics/write_to_csv.hpp b/source/metrics/write_to_csv.hpp new file mode 100644 index 0000000000..b1710162be --- /dev/null +++ b/source/metrics/write_to_csv.hpp @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include +#include +#include + +#include "metrics_storage.hpp" +#include "utils/filesystem.hpp" +namespace sim { + +// by list of pairs (metrics storage, metric name) generates csv table and +// writes it to output_path +void write_to_csv( + const std::vector >& storages, + std::filesystem::path output_path); + +} // namespace sim \ No newline at end of file From 40197b45af1f1f5f27b92e7c3dd86aca2d398c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Fri, 18 Jul 2025 14:11:58 +0300 Subject: [PATCH 08/15] Update source/metrics/write_to_csv.cpp Co-authored-by: Ivan Shanygin <88805084+AntoxaBarin@users.noreply.github.com> --- source/metrics/write_to_csv.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/metrics/write_to_csv.cpp b/source/metrics/write_to_csv.cpp index 072eb58087..548b48ab11 100644 --- a/source/metrics/write_to_csv.cpp +++ b/source/metrics/write_to_csv.cpp @@ -1,7 +1,6 @@ #include "write_to_csv.hpp" #include -#include #include #include "utils/filesystem.hpp" From 710ecc68baf5977ead735128295857f33d75d739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Fri, 18 Jul 2025 14:12:09 +0300 Subject: [PATCH 09/15] Update source/metrics/plot_metadata.hpp Co-authored-by: Ivan Shanygin <88805084+AntoxaBarin@users.noreply.github.com> --- source/metrics/plot_metadata.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/metrics/plot_metadata.hpp b/source/metrics/plot_metadata.hpp index a83d46f15f..4f62b3d35e 100644 --- a/source/metrics/plot_metadata.hpp +++ b/source/metrics/plot_metadata.hpp @@ -1,7 +1,5 @@ #pragma once -#include #include -#include namespace sim { From 459bac42cbbb5c68acb15bb9aab7e0cade94aa52 Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Tue, 22 Jul 2025 14:25:02 +0300 Subject: [PATCH 10/15] Add const to front --- source/link/packet_queue/i_packet_queue.hpp | 2 +- source/link/packet_queue/link_queue.cpp | 2 +- source/link/packet_queue/link_queue.hpp | 2 +- source/link/packet_queue/simple_packet_queue.cpp | 2 +- source/link/packet_queue/simple_packet_queue.hpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/link/packet_queue/i_packet_queue.hpp b/source/link/packet_queue/i_packet_queue.hpp index 1a724a1ad2..1eb1bf06cb 100644 --- a/source/link/packet_queue/i_packet_queue.hpp +++ b/source/link/packet_queue/i_packet_queue.hpp @@ -8,7 +8,7 @@ class IPacketQueue { virtual ~IPacketQueue() = default; virtual bool push(Packet packet) = 0; - virtual Packet front() = 0; + virtual Packet front() const = 0; virtual void pop() = 0; virtual bool empty() const = 0; diff --git a/source/link/packet_queue/link_queue.cpp b/source/link/packet_queue/link_queue.cpp index b96e71bb22..380c971bcd 100644 --- a/source/link/packet_queue/link_queue.cpp +++ b/source/link/packet_queue/link_queue.cpp @@ -31,7 +31,7 @@ bool LinkQueue::push(Packet packet) { return result; } -Packet LinkQueue::front() { return m_queue.front(); } +Packet LinkQueue::front() const { return m_queue.front(); } void LinkQueue::pop() { m_queue.pop(); diff --git a/source/link/packet_queue/link_queue.hpp b/source/link/packet_queue/link_queue.hpp index 34703f103c..eed255d56c 100644 --- a/source/link/packet_queue/link_queue.hpp +++ b/source/link/packet_queue/link_queue.hpp @@ -17,7 +17,7 @@ class LinkQueue : public IPacketQueue { ~LinkQueue() = default; bool push(Packet packet) final; - Packet front() final; + Packet front() const final; void pop() final; Size get_size() const final; diff --git a/source/link/packet_queue/simple_packet_queue.cpp b/source/link/packet_queue/simple_packet_queue.cpp index 5d3ee745ef..86fc5ef2c8 100644 --- a/source/link/packet_queue/simple_packet_queue.cpp +++ b/source/link/packet_queue/simple_packet_queue.cpp @@ -13,7 +13,7 @@ bool SimplePacketQueue::push(Packet packet) { return true; } -Packet SimplePacketQueue::front() { +Packet SimplePacketQueue::front() const { if (m_queue.empty()) { throw std::runtime_error("Can not get front packet from empty queue"); } diff --git a/source/link/packet_queue/simple_packet_queue.hpp b/source/link/packet_queue/simple_packet_queue.hpp index 1edba37dbe..69161c2bcb 100644 --- a/source/link/packet_queue/simple_packet_queue.hpp +++ b/source/link/packet_queue/simple_packet_queue.hpp @@ -13,7 +13,7 @@ class SimplePacketQueue : public IPacketQueue { // returns true on succseed (remaining space is enought), false // otherwice bool push(Packet packet) final; - Packet front() final; + Packet front() const final; void pop() final; Size get_size() const final; From 0365ad250c4a6fb1700e05024e88d4ed7d59862a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:22:26 +0300 Subject: [PATCH 11/15] Apply suggestion from @ArtyomPeshkov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Артём Пешков <47276660+ArtyomPeshkov@users.noreply.github.com> --- source/link/link.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/link/link.cpp b/source/link/link.cpp index ffced632a0..3231296992 100644 --- a/source/link/link.cpp +++ b/source/link/link.cpp @@ -14,9 +14,9 @@ Link::Link(Id a_id, std::weak_ptr a_from, std::weak_ptr a_to, m_to(a_to), m_speed(a_speed), m_propagation_delay(a_delay), - m_from_egress(SimplePacketQueue(a_max_from_egress_buffer_size), m_id, + m_from_egress(SimplePacketQueue(a_max_from_egress_buffer_size), a_id, LinkQueueType::FromEgress), - m_to_ingress(SimplePacketQueue(a_max_to_ingress_buffer_size), m_id, + m_to_ingress(SimplePacketQueue(a_max_to_ingress_buffer_size), a_id, LinkQueueType::ToIngress) { if (a_from.expired() || a_to.expired()) { LOG_WARN("Passed link to device is expired"); From fd85b2761e6c12559f37ddf6141db03677381b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:22:37 +0300 Subject: [PATCH 12/15] Apply suggestion from @ArtyomPeshkov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Артём Пешков <47276660+ArtyomPeshkov@users.noreply.github.com> --- source/metrics/multi_id_metrics_storage.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/metrics/multi_id_metrics_storage.hpp b/source/metrics/multi_id_metrics_storage.hpp index aa8164a68f..626e7eef3b 100644 --- a/source/metrics/multi_id_metrics_storage.hpp +++ b/source/metrics/multi_id_metrics_storage.hpp @@ -5,7 +5,6 @@ #include #include "metrics_storage.hpp" - namespace sim { class MultiIdMetricsStorage { public: From 48c96ebe8759adff20a54f58efcc6a9d498c0b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:22:54 +0300 Subject: [PATCH 13/15] Apply suggestion from @ArtyomPeshkov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Артём Пешков <47276660+ArtyomPeshkov@users.noreply.github.com> --- source/metrics/write_to_csv.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/metrics/write_to_csv.cpp b/source/metrics/write_to_csv.cpp index bcb8d22c6a..a39f02d6c8 100644 --- a/source/metrics/write_to_csv.cpp +++ b/source/metrics/write_to_csv.cpp @@ -6,8 +6,6 @@ #include "utils/filesystem.hpp" namespace sim { -// by list of pairs (metrics storage, metric name) generates csv table and -// writes it to output_path void write_to_csv( const std::vector >& storages, std::filesystem::path output_path) { From d1fb2dd027efe951b0f2206fec7169eba26a2781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A0=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= <112890673+PaulRalnikov@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:02:24 +0300 Subject: [PATCH 14/15] Update source/metrics/write_to_csv.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Артём Пешков <47276660+ArtyomPeshkov@users.noreply.github.com> --- source/metrics/write_to_csv.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/metrics/write_to_csv.cpp b/source/metrics/write_to_csv.cpp index a39f02d6c8..37cacfbdf0 100644 --- a/source/metrics/write_to_csv.cpp +++ b/source/metrics/write_to_csv.cpp @@ -3,7 +3,6 @@ #include #include -#include "utils/filesystem.hpp" namespace sim { void write_to_csv( From 6d2b13f9fbfb1f8e235272dd303e83a82854c6ee Mon Sep 17 00:00:00 2001 From: Pavel Ralnikov Date: Wed, 30 Jul 2025 15:09:08 +0300 Subject: [PATCH 15/15] Change LinkQueue constructor agrument list --- source/link/link.cpp | 4 ++-- source/link/packet_queue/link_queue.cpp | 4 ++-- source/link/packet_queue/link_queue.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/link/link.cpp b/source/link/link.cpp index 3231296992..5a40a6217b 100644 --- a/source/link/link.cpp +++ b/source/link/link.cpp @@ -14,9 +14,9 @@ Link::Link(Id a_id, std::weak_ptr a_from, std::weak_ptr a_to, m_to(a_to), m_speed(a_speed), m_propagation_delay(a_delay), - m_from_egress(SimplePacketQueue(a_max_from_egress_buffer_size), a_id, + m_from_egress(a_max_from_egress_buffer_size, a_id, LinkQueueType::FromEgress), - m_to_ingress(SimplePacketQueue(a_max_to_ingress_buffer_size), a_id, + m_to_ingress(a_max_to_ingress_buffer_size, a_id, LinkQueueType::ToIngress) { if (a_from.expired() || a_to.expired()) { LOG_WARN("Passed link to device is expired"); diff --git a/source/link/packet_queue/link_queue.cpp b/source/link/packet_queue/link_queue.cpp index bd36376e79..b10024705a 100644 --- a/source/link/packet_queue/link_queue.cpp +++ b/source/link/packet_queue/link_queue.cpp @@ -19,9 +19,9 @@ std::string to_string(LinkQueueType type) { } } -LinkQueue::LinkQueue(SimplePacketQueue a_queue, Id a_link_id, +LinkQueue::LinkQueue(SizeByte a_queue_size, Id a_link_id, LinkQueueType a_type) - : m_queue(std::move(a_queue)), m_link_id(a_link_id), m_type(a_type) {} + : m_queue(a_queue_size), m_link_id(a_link_id), m_type(a_type) {} bool LinkQueue::push(Packet packet) { bool result = m_queue.push(std::move(packet)); diff --git a/source/link/packet_queue/link_queue.hpp b/source/link/packet_queue/link_queue.hpp index 29f414fd9b..fed5ccaa40 100644 --- a/source/link/packet_queue/link_queue.hpp +++ b/source/link/packet_queue/link_queue.hpp @@ -13,7 +13,7 @@ std::string to_string(LinkQueueType type); // ingress queue of desination link device class LinkQueue : public IPacketQueue { public: - LinkQueue(SimplePacketQueue a_queue, Id a_link_id, LinkQueueType a_type); + LinkQueue(SizeByte a_max_size, Id a_link_id, LinkQueueType a_type); ~LinkQueue() = default; bool push(Packet packet) final;