RTT: Improve millisecond RTT estimates by rounding halway cases up

parent cad15e34
Pipeline #75918 failed with stages
in 6 minutes
......@@ -342,7 +342,7 @@ bool DDP::DnsTcpConnection::process_segment(const Packet& packet, const MemView<
record.m_dns_len = seg_len - 2;
record.m_len = packet.size();
if (m_state >= TcpConnectionState::ESTABLISHED) {
record.m_tcp_rtt = m_rtt.getMillis();
record.m_tcp_rtt = m_rtt.getMillisRounded();
m_rtt = Time(-1);
}
......@@ -378,7 +378,7 @@ bool DDP::DnsTcpConnection::process_segment(const Packet& packet, const MemView<
DnsRecord& msg = parser->get_empty();
fill_record_L3_L4(msg, record);
if (m_state >= TcpConnectionState::ESTABLISHED) {
msg.m_tcp_rtt = m_rtt.getMillis();
msg.m_tcp_rtt = m_rtt.getMillisRounded();
m_rtt = Time(-1);
}
......@@ -474,7 +474,7 @@ bool DDP::DnsTcpConnection::process_segment(const Packet& packet, const MemView<
DnsRecord &msg = parser->get_empty();
fill_record_L3_L4(msg, record);
if (m_state >= TcpConnectionState::ESTABLISHED) {
msg.m_tcp_rtt = m_rtt.getMillis();
msg.m_tcp_rtt = m_rtt.getMillisRounded();
m_rtt = Time(-1);
}
......
......@@ -24,6 +24,7 @@
#pragma once
#include <ctime>
#include <cmath>
#include <cstdint>
#include <type_traits>
......@@ -109,6 +110,15 @@ namespace DDP {
return m_timespec.tv_sec * 1000 + m_timespec.tv_nsec / 1000000;
}
/**
* @brief Convert timestamp to milliseconds rounding halfway cases up
* @return Current rounded timestamp in milliseconds
*/
milliseconds_t getMillisRounded()
{
return m_timespec.tv_sec * 1000 + std::llround(m_timespec.tv_nsec / 1000000.0);
}
/**
* @brief Convert timestamp to microseconds
* @return Current timestamp in microseconds
......@@ -118,6 +128,15 @@ namespace DDP {
return (m_timespec.tv_sec * 1000000) + (m_timespec.tv_nsec / 1000);
}
/**
* @brief Convert timestamp to microseconds rounding halfway cases up
* @return Current rounded timestamp in microseconds
*/
int64_t getMicrosRounded()
{
return (m_timespec.tv_sec * 1000000) + std::llround(m_timespec.tv_nsec / 1000.0);
}
/**
* @brief Get seconds part of the timestamp
* @return Seconds part of the timestamp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment