Skip to content

Commit a05e0ec

Browse files
authored
BUG: Fix delivery rate (#425)
Delivery rate should take into account the pacing delay.
1 parent a4a2f97 commit a05e0ec

9 files changed

Lines changed: 34 additions & 15 deletions

File tree

source/flow/i_flow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class IFlow : public Identifiable {
1616
virtual void send_packet() = 0;
1717
virtual std::shared_ptr<IConnection> get_conn() const = 0;
1818
virtual SizeByte get_delivered_data_size() const = 0;
19+
virtual TimeNs get_fct() const = 0;
1920
virtual std::shared_ptr<IHost> get_sender() const = 0;
2021
virtual std::shared_ptr<IHost> get_receiver() const = 0;
2122
};

source/flow/tcp/tcp_flow.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ TcpFlow::TcpFlow(Id a_id, std::shared_ptr<IConnection> a_conn,
3030
if (m_dest.lock() == nullptr) {
3131
throw std::invalid_argument("Receiver for TcpFlow is nullptr");
3232
}
33+
m_init_time = Scheduler::get_instance().get_current_time();
3334
initialize_flag_manager();
3435
}
3536

3637
SizeByte TcpFlow::get_delivered_data_size() const {
3738
return m_delivered_data_size;
3839
}
3940

41+
TimeNs TcpFlow::get_fct() const {
42+
TimeNs now = Scheduler::get_instance().get_current_time();
43+
return now - m_init_time;
44+
}
45+
4046
std::shared_ptr<IHost> TcpFlow::get_sender() const { return m_src.lock(); }
4147

4248
std::shared_ptr<IHost> TcpFlow::get_receiver() const { return m_dest.lock(); }
@@ -94,6 +100,7 @@ Packet TcpFlow::create_ack(Packet data) {
94100
ack.dest_id = m_src.lock()->get_id();
95101
ack.size = SizeByte(1);
96102
ack.flow = this;
103+
ack.generated_time = data.generated_time;
97104
ack.sent_time = data.sent_time;
98105
ack.delivered_data_size_at_origin = data.delivered_data_size_at_origin;
99106
ack.ttl = M_MAX_TTL;
@@ -198,7 +205,7 @@ void TcpFlow::update(Packet packet) {
198205

199206
SpeedGbps delivery_rate =
200207
(m_delivered_data_size - packet.delivered_data_size_at_origin) /
201-
rtt;
208+
(current_time - packet.generated_time);
202209
MetricsCollector::get_instance().add_delivery_rate(
203210
packet.flow->get_id(), current_time, delivery_rate);
204211

source/flow/tcp/tcp_flow.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TcpFlow : public IFlow, public std::enable_shared_from_this<TcpFlow> {
2121
void update(Packet packet) final;
2222

2323
SizeByte get_delivered_data_size() const final;
24+
TimeNs get_fct() const final;
2425
std::shared_ptr<IHost> get_sender() const final;
2526
std::shared_ptr<IHost> get_receiver() const;
2627
Id get_id() const final;
@@ -48,6 +49,7 @@ class TcpFlow : public IFlow, public std::enable_shared_from_this<TcpFlow> {
4849
Packet generate_packet();
4950

5051
TimeNs get_max_timeout() const;
52+
TimeNs m_init_time;
5153
void send_packet_now(Packet packet);
5254
void retransmit_packet(PacketNum packet_num);
5355

source/packet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
namespace sim {
66

77
Packet::Packet(SizeByte a_size, IFlow* a_flow, Id a_source_id, Id a_dest_id,
8-
TimeNs a_sent_time, SizeByte a_delivered_data_size_at_origin,
8+
TimeNs a_generated_time, TimeNs a_sent_time,
9+
SizeByte a_delivered_data_size_at_origin,
910
bool a_ecn_capable_transport, bool a_congestion_experienced)
1011
: flags(0),
1112
source_id(a_source_id),
1213
dest_id(a_dest_id),
1314
size(a_size),
1415
flow(a_flow),
16+
generated_time(a_generated_time),
1517
sent_time(a_sent_time),
1618
delivered_data_size_at_origin(a_delivered_data_size_at_origin),
1719
ecn_capable_transport(a_ecn_capable_transport),
@@ -32,6 +34,7 @@ std::string Packet::to_string() const {
3234
oss << ", packet_num: " << packet_num;
3335
oss << ", size(byte): " << size;
3436
oss << ", flow: " << (flow ? "set" : "null");
37+
oss << ", generated time: " << generated_time;
3538
oss << ", sent time: " << sent_time;
3639
oss << ", TTL: " << ttl;
3740
oss << ", flags: " << flags.get_bits();

source/packet.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace sim {
1010
struct Packet {
1111
Packet(SizeByte a_size = SizeByte(0), IFlow* a_flow = nullptr,
1212
Id a_source_id = "", Id a_dest_id = "",
13-
TimeNs a_sent_time = TimeNs(0),
13+
TimeNs a_generated_time = TimeNs(0), TimeNs a_sent_time = TimeNs(0),
1414
SizeByte a_delivered_at_origin = SizeByte(0),
1515
bool a_ecn_capable_transport = true,
1616
bool a_congestion_experienced = false);
@@ -24,6 +24,8 @@ struct Packet {
2424
Id dest_id;
2525
SizeByte size;
2626
IFlow* flow;
27+
TimeNs generated_time; // Note: ACK's generated time is the data packet
28+
// generated time
2729
TimeNs sent_time; // Note: ACK's sent time is the data packet sent time
2830
SizeByte delivered_data_size_at_origin; // For ACK this is inherited from
2931
// data packet

source/utils/summary.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44

55
namespace sim {
66

7-
Summary::Summary(std::map<Id, std::map<Id, SizeByte>> a_values)
7+
Summary::Summary(std::map<Id, std::map<Id, SpeedGbps>> a_values)
88
: m_values(std::move(a_values)) {}
99

10-
Summary::Summary(const std::unordered_set<std::shared_ptr<IConnection>>& connections) {
10+
Summary::Summary(
11+
const std::unordered_set<std::shared_ptr<IConnection>>& connections) {
1112
for (const auto& conn : connections) {
1213
Id conn_id = conn->get_id();
1314
auto flows = conn->get_flows();
1415
for (const auto& flow : flows) {
15-
m_values[conn_id].insert(std::make_pair(
16-
flow->get_id(), flow->get_delivered_data_size()));
16+
SpeedGbps throughput =
17+
flow->get_delivered_data_size() / flow->get_fct();
18+
m_values[conn_id].insert(
19+
std::make_pair(flow->get_id(), throughput));
1720
}
1821
}
1922
}
@@ -24,7 +27,7 @@ void Summary::write_to_csv(std::filesystem::path output_path) const {
2427
if (!out) {
2528
throw std::runtime_error("Failed to create file for summary");
2629
}
27-
out << "Conn id, Flow id, Delivered data (bytes)\n";
30+
out << "Conn id, Flow id, Throughput (Gbps)\n";
2831
for (const auto& [conn_id, flows] : m_values) {
2932
for (const auto& [flow_id, value] : flows) {
3033
out << conn_id << ", " << flow_id << ", " << value << "\n";

source/utils/summary.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <filesystem>
33
#include <unordered_set>
44

5-
#include "flow/i_flow.hpp"
65
#include "connection/i_connection.hpp"
6+
#include "flow/i_flow.hpp"
77
#include "types.hpp"
88

99
namespace sim {
@@ -12,13 +12,14 @@ namespace sim {
1212
// Maps flow Ids to count of delivered bytes
1313
class Summary {
1414
public:
15-
Summary(std::map<Id, std::map<Id, SizeByte>> values);
16-
Summary(const std::unordered_set<std::shared_ptr<IConnection>>& connections);
15+
Summary(std::map<Id, std::map<Id, SpeedGbps>> values);
16+
Summary(
17+
const std::unordered_set<std::shared_ptr<IConnection>>& connections);
1718

1819
void write_to_csv(std::filesystem::path output_path) const;
1920

2021
private:
21-
std::map<Id, std::map<Id, SizeByte>> m_values;
22+
std::map<Id, std::map<Id, SpeedGbps>> m_values;
2223
};
2324

2425
} // namespace sim

test/switch/flow_mock.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ void FlowMock::update([[maybe_unused]] sim::Packet packet) {};
99

1010
std::uint32_t FlowMock::get_sending_quota() const { return 1; }
1111
void FlowMock::send_packet() {}
12-
std::shared_ptr<sim::IConnection> FlowMock::get_conn() const {
13-
return nullptr;
14-
}
12+
std::shared_ptr<sim::IConnection> FlowMock::get_conn() const { return nullptr; }
1513
SizeByte FlowMock::get_delivered_data_size() const { return SizeByte(0); }
14+
TimeNs FlowMock::get_fct() const { return TimeNs(0); }
1615

1716
std::shared_ptr<sim::IHost> FlowMock::get_sender() const { return nullptr; }
1817
std::shared_ptr<sim::IHost> FlowMock::get_receiver() const {

test/switch/flow_mock.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class FlowMock : public sim::IFlow {
1414
void send_packet() final;
1515
std::shared_ptr<sim::IConnection> get_conn() const final;
1616
virtual SizeByte get_delivered_data_size() const final;
17+
virtual TimeNs get_fct() const final;
1718

1819
std::shared_ptr<sim::IHost> get_sender() const final;
1920
std::shared_ptr<sim::IHost> get_receiver() const final;

0 commit comments

Comments
 (0)