Skip to content

Commit ce2bc9a

Browse files
authored
BUG: fct (#439)
closes #438
1 parent 4bfe91f commit ce2bc9a

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

source/flow/tcp/tcp_flow.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ TcpFlow::TcpFlow(Id a_id, std::shared_ptr<IConnection> a_conn,
1919
m_src(m_connection->get_sender()),
2020
m_dest(m_connection->get_receiver()),
2121
m_cc(std::move(a_cc)),
22+
m_sending_started(false),
23+
m_init_time(0),
24+
m_last_ack_arrive_time(0),
2225
m_packet_size(a_packet_size),
2326
m_ecn_capable(a_ecn_capable),
2427
m_packets_in_flight(0),
@@ -30,7 +33,6 @@ TcpFlow::TcpFlow(Id a_id, std::shared_ptr<IConnection> a_conn,
3033
if (m_dest.lock() == nullptr) {
3134
throw std::invalid_argument("Receiver for TcpFlow is nullptr");
3235
}
33-
m_init_time = Scheduler::get_instance().get_current_time();
3436
initialize_flag_manager();
3537
}
3638

@@ -39,8 +41,10 @@ SizeByte TcpFlow::get_delivered_data_size() const {
3941
}
4042

4143
TimeNs TcpFlow::get_fct() const {
42-
TimeNs now = Scheduler::get_instance().get_current_time();
43-
return now - m_init_time;
44+
if (!m_sending_started) {
45+
return TimeNs(0);
46+
}
47+
return m_last_ack_arrive_time - m_init_time;
4448
}
4549

4650
std::shared_ptr<IHost> TcpFlow::get_sender() const { return m_src.lock(); }
@@ -72,14 +76,20 @@ Packet TcpFlow::create_packet(PacketNum packet_num) {
7276
}
7377

7478
void TcpFlow::send_packet() {
79+
TimeNs now = Scheduler::get_instance().get_current_time();
80+
81+
if (!m_sending_started) {
82+
m_init_time = now;
83+
m_sending_started = true;
84+
}
85+
7586
if (get_sending_quota() == 0) {
7687
LOG_WARN(
7788
fmt::format("No sending quota for flow {}; packet not sent", m_id));
7889
return;
7990
}
8091
Packet packet = create_packet(m_next_packet_num++);
8192
TimeNs pacing_delay = m_cc->get_pacing_delay();
82-
TimeNs now = Scheduler::get_instance().get_current_time();
8393

8494
if (pacing_delay == TimeNs(0)) {
8595
send_packet_now(std::move(packet));
@@ -182,6 +192,8 @@ void TcpFlow::update(Packet packet) {
182192
return;
183193
}
184194

195+
m_last_ack_arrive_time = current_time;
196+
185197
if (m_acked.contains(packet.packet_num)) {
186198
LOG_WARN(fmt::format("Got duplicate ack number {}; ignored",
187199
packet.packet_num));

source/flow/tcp/tcp_flow.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ 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+
25+
// Returns time elapced from flow start (firsrt call of send_packet)
26+
// to last update call
2427
TimeNs get_fct() const final;
28+
2529
std::shared_ptr<IHost> get_sender() const final;
2630
std::shared_ptr<IHost> get_receiver() const;
2731
Id get_id() const final;
@@ -49,7 +53,6 @@ class TcpFlow : public IFlow, public std::enable_shared_from_this<TcpFlow> {
4953
Packet generate_packet();
5054

5155
TimeNs get_max_timeout() const;
52-
TimeNs m_init_time;
5356
void send_packet_now(Packet packet);
5457
void retransmit_packet(PacketNum packet_num);
5558

@@ -63,6 +66,11 @@ class TcpFlow : public IFlow, public std::enable_shared_from_this<TcpFlow> {
6366
// Congestion control module
6467
std::unique_ptr<ITcpCC> m_cc;
6568

69+
// is send_packet called at least once
70+
bool m_sending_started;
71+
TimeNs m_init_time;
72+
TimeNs m_last_ack_arrive_time;
73+
6674
SizeByte m_packet_size;
6775
bool m_ecn_capable;
6876

0 commit comments

Comments
 (0)