Remove unused PacketLossEstimator class

These metrics were never hooked up to anything.

Bug: webrtc:7028
Change-Id: Id6fdf146de615839820f7ad3805eb42450c76c21
Reviewed-on: https://webrtc-review.googlesource.com/c/120303
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26451}
This commit is contained in:
Zach Stein
2019-01-28 20:07:12 -08:00
committed by Commit Bot
parent 8c8feb9d2b
commit d3be0171b0
6 changed files with 0 additions and 382 deletions

View File

@ -41,8 +41,6 @@ rtc_static_library("rtc_p2p") {
"base/p2p_constants.h",
"base/p2p_transport_channel.cc",
"base/p2p_transport_channel.h",
"base/packet_loss_estimator.cc",
"base/packet_loss_estimator.h",
"base/packet_socket_factory.cc",
"base/packet_socket_factory.h",
"base/packet_transport_interface.h",
@ -158,7 +156,6 @@ if (rtc_include_tests) {
"base/ice_credentials_iterator_unittest.cc",
"base/mdns_message_unittest.cc",
"base/p2p_transport_channel_unittest.cc",
"base/packet_loss_estimator_unittest.cc",
"base/port_allocator_unittest.cc",
"base/port_unittest.cc",
"base/pseudo_tcp_unittest.cc",

View File

@ -1,107 +0,0 @@
/*
* Copyright 2017 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "p2p/base/packet_loss_estimator.h"
#include "rtc_base/checks.h"
namespace cricket {
PacketLossEstimator::PacketLossEstimator(int64_t consider_lost_after_ms,
int64_t forget_after_ms)
: consider_lost_after_ms_(consider_lost_after_ms),
forget_after_ms_(forget_after_ms) {
RTC_DCHECK_LT(consider_lost_after_ms, forget_after_ms);
}
PacketLossEstimator::~PacketLossEstimator() = default;
void PacketLossEstimator::ExpectResponse(std::string id, int64_t sent_time) {
tracked_packets_[id] = PacketInfo{sent_time, false};
// Called to free memory in case the client hasn't called UpdateResponseRate
// in a while.
MaybeForgetOldRequests(sent_time);
}
void PacketLossEstimator::ReceivedResponse(std::string id,
int64_t received_time) {
auto iter = tracked_packets_.find(id);
if (iter != tracked_packets_.end()) {
auto& packet_info = iter->second;
packet_info.response_received = true;
}
// Called to free memory in case the client hasn't called UpdateResponseRate
// in a while.
MaybeForgetOldRequests(received_time);
}
void PacketLossEstimator::UpdateResponseRate(int64_t now) {
int responses_expected = 0;
int responses_received = 0;
for (auto iter = tracked_packets_.begin(); iter != tracked_packets_.end();) {
const auto& packet_info = iter->second;
if (Forget(packet_info, now)) {
iter = tracked_packets_.erase(iter);
continue;
}
if (packet_info.response_received) {
responses_expected += 1;
responses_received += 1;
} else if (ConsiderLost(packet_info, now)) {
responses_expected += 1;
}
++iter;
}
if (responses_expected > 0) {
response_rate_ =
static_cast<double>(responses_received) / responses_expected;
} else {
response_rate_ = 1.0;
}
last_forgot_at_ = now;
}
void PacketLossEstimator::MaybeForgetOldRequests(int64_t now) {
if (now - last_forgot_at_ <= forget_after_ms_) {
return;
}
for (auto iter = tracked_packets_.begin(); iter != tracked_packets_.end();) {
const auto& packet_info = iter->second;
if (Forget(packet_info, now)) {
iter = tracked_packets_.erase(iter);
} else {
++iter;
}
}
last_forgot_at_ = now;
}
bool PacketLossEstimator::ConsiderLost(const PacketInfo& packet_info,
int64_t now) const {
return packet_info.sent_time < now - consider_lost_after_ms_;
}
bool PacketLossEstimator::Forget(const PacketInfo& packet_info,
int64_t now) const {
return now - packet_info.sent_time > forget_after_ms_;
}
std::size_t PacketLossEstimator::tracked_packet_count_for_testing() const {
return tracked_packets_.size();
}
} // namespace cricket

View File

@ -1,85 +0,0 @@
/*
* Copyright 2017 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef P2P_BASE_PACKET_LOSS_ESTIMATOR_H_
#define P2P_BASE_PACKET_LOSS_ESTIMATOR_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <unordered_map>
namespace cricket {
// Estimates the response rate for a series of messages expecting responses.
// Messages and their corresponding responses are identified by a string id.
//
// Responses are considered lost if they are not received within
// |consider_lost_after_ms|. If a response is received after
// |consider_lost_after_ms|, it is still considered as a response.
// Messages sent more than |forget_after_ms| ago are not considered
// anymore. The response rate is initially assumed to be 1.0.
//
// If the current time is 7, |forget_after_ms| is 6, and
// |consider_lost_after_ms| is 2, the response rate considers messages sent
// between times 1 and 5, so only messages in the following window can be
// considered lost:
//
// Time: 0 1 2 3 4 5 6 7
// Wind: <-------> |
//
// Responses received to the right of the window are still counted.
class PacketLossEstimator {
public:
explicit PacketLossEstimator(int64_t consider_lost_after_ms,
int64_t forget_after_ms);
~PacketLossEstimator();
// Registers that a message with the given |id| was sent at |sent_time|.
void ExpectResponse(std::string id, int64_t sent_time);
// Registers a response with the given |id| was received at |received_time|.
void ReceivedResponse(std::string id, int64_t received_time);
// Calculates the current response rate based on the expected and received
// messages. Messages sent more than |forget_after| ms ago will be forgotten.
void UpdateResponseRate(int64_t now);
// Gets the current response rate as updated by UpdateResponseRate.
double get_response_rate() const { return response_rate_; }
std::size_t tracked_packet_count_for_testing() const;
private:
struct PacketInfo {
int64_t sent_time;
bool response_received;
};
// Called periodically by ExpectResponse and ReceivedResponse to manage memory
// usage.
void MaybeForgetOldRequests(int64_t now);
bool ConsiderLost(const PacketInfo&, int64_t now) const;
bool Forget(const PacketInfo&, int64_t now) const;
int64_t consider_lost_after_ms_;
int64_t forget_after_ms_;
int64_t last_forgot_at_ = 0;
std::unordered_map<std::string, PacketInfo> tracked_packets_;
double response_rate_ = 1.0;
};
} // namespace cricket
#endif // P2P_BASE_PACKET_LOSS_ESTIMATOR_H_

View File

@ -1,173 +0,0 @@
/*
* Copyright 2017 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cstdint>
#include <utility>
#include "p2p/base/packet_loss_estimator.h"
#include "test/gtest.h"
using cricket::PacketLossEstimator;
class PacketLossEstimatorTest : public testing::Test {};
TEST_F(PacketLossEstimatorTest, InitialResponseRate) {
PacketLossEstimator ple(5, 100);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, InitialUpdateResponseRate) {
PacketLossEstimator ple(5, 100);
ple.UpdateResponseRate(10);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, ResponseReceived) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.ReceivedResponse("a", 1);
ple.UpdateResponseRate(2);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, ResponseNotConsideredLostYet) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.UpdateResponseRate(2);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, ResponseConsideredLost) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.UpdateResponseRate(10);
EXPECT_EQ(0.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, ResponseLate) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.ReceivedResponse("a", 6);
ple.UpdateResponseRate(10);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, ResponseForgotten) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.UpdateResponseRate(101);
EXPECT_EQ(1.0, ple.get_response_rate());
}
TEST_F(PacketLossEstimatorTest, Lost1_Received1) {
PacketLossEstimator ple(5, 100);
ple.ExpectResponse("a", 0);
ple.ExpectResponse("b", 2);
ple.ReceivedResponse("b", 6);
ple.UpdateResponseRate(7);
EXPECT_EQ(0.5, ple.get_response_rate());
}
static const std::pair<std::string, int64_t> kFivePackets[5] = {{"a", 0},
{"b", 2},
{"c", 4},
{"d", 6},
{"e", 8}};
// Time: 0 1 2 3 4 5 6 7 8 9 10
// Sent: a b c d e |
// Recv: b |
// Wind: --------------> |
TEST_F(PacketLossEstimatorTest, Lost3_Received1_Waiting1) {
PacketLossEstimator ple(3, 100);
for (const auto& p : kFivePackets) {
ple.ExpectResponse(p.first, p.second);
}
ple.ReceivedResponse("b", 3);
ple.UpdateResponseRate(10);
EXPECT_EQ(0.25, ple.get_response_rate());
}
// Time: 0 1 2 3 4 5 6 7 8 9 10
// Sent: a b c d e |
// Recv: e |
// Wind: --------------> |
TEST_F(PacketLossEstimatorTest, Lost4_Early1) {
PacketLossEstimator ple(3, 100);
for (const auto& p : kFivePackets) {
ple.ExpectResponse(p.first, p.second);
}
ple.ReceivedResponse("e", 9);
ple.UpdateResponseRate(10);
// e should be considered, even though its response was received less than
// |consider_lost_after_ms| ago.
EXPECT_EQ(0.2, ple.get_response_rate());
}
// Time: 0 1 2 3 4 5 6 7 8 9 10
// Sent: a b c d e |
// Recv: c |
// Wind: <-------> |
TEST_F(PacketLossEstimatorTest, Forgot2_Received1_Lost1_Waiting1) {
PacketLossEstimator ple(3, 7);
for (const auto& p : kFivePackets) {
ple.ExpectResponse(p.first, p.second);
}
ple.ReceivedResponse("c", 5);
ple.UpdateResponseRate(10);
EXPECT_EQ(0.5, ple.get_response_rate());
}
// Tests that old messages are forgotten if ExpectResponse is called
// |forget_after_ms| after |last_forgot_at|. It is important that ExpectResponse
// and ReceivedResponse forget old messages to avoid |tracked_packets_| growing
// without bound if UpdateResponseRate is never called (or rarely called).
//
// Time: 0 1 2 3 4 5 6
// Sent: a b
// Wind: <------->
TEST_F(PacketLossEstimatorTest, ExpectResponseForgetsOldPackets) {
PacketLossEstimator ple(1, 5);
ple.ExpectResponse("a", 0); // This message will be forgotten.
ple.ExpectResponse("b", 6); // This call should trigger clean up.
// a should be forgotten, b should be tracked.
EXPECT_EQ(1u, ple.tracked_packet_count_for_testing());
}
// Tests that old messages are forgotten if ExpectResponse is called
// |forget_after_ms| after |last_forgot_at|. It is important that ExpectResponse
// and ReceivedResponse forget old messages to avoid |tracked_packets_| growing
// without bound if UpdateResponseRate is never called (or rarely called).
//
// Time: 0 1 2 3 4 5 6
// Sent: a
// Recv: b
// Wind: <------->
TEST_F(PacketLossEstimatorTest, ReceivedResponseForgetsOldPackets) {
PacketLossEstimator ple(1, 5);
ple.ExpectResponse("a", 0); // This message will be forgotten.
ple.ReceivedResponse("b", 6); // This call should trigger clean up.
// a should be forgoten, b should not be tracked (received but not sent).
EXPECT_EQ(0u, ple.tracked_packet_count_for_testing());
}

View File

@ -153,12 +153,6 @@ const int RTT_RATIO = 3; // 3 : 1
// it to a little higher than a total STUN timeout.
const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000;
// For packet loss estimation.
const int64_t kConsiderPacketLostAfter = 3000; // 3 seconds
// For packet loss estimation.
const int64_t kForgetPacketAfter = 30000; // 30 seconds
} // namespace
namespace cricket {
@ -1120,7 +1114,6 @@ Connection::Connection(Port* port,
last_ping_received_(0),
last_data_received_(0),
last_ping_response_received_(0),
packet_loss_estimator_(kConsiderPacketLostAfter, kForgetPacketAfter),
reported_(false),
state_(IceCandidatePairState::WAITING),
time_created_ms_(rtc::TimeMillis()) {
@ -1513,7 +1506,6 @@ void Connection::Ping(int64_t now) {
nomination = nomination_;
}
pings_since_last_response_.push_back(SentPing(req->id(), now, nomination));
packet_loss_estimator_.ExpectResponse(req->id(), now);
RTC_LOG(LS_VERBOSE) << ToString() << ": Sending STUN ping, id="
<< rtc::hex_encode(req->id())
<< ", nomination=" << nomination_;
@ -1710,9 +1702,6 @@ void Connection::OnConnectionRequestResponse(ConnectionRequest* request,
}
ReceivedPingResponse(rtt, request->id());
int64_t time_received = rtc::TimeMillis();
packet_loss_estimator_.ReceivedResponse(request->id(), time_received);
stats_.recv_ping_responses++;
LogCandidatePairEvent(
webrtc::IceCandidatePairEventType::kCheckResponseReceived,

View File

@ -25,7 +25,6 @@
#include "logging/rtc_event_log/ice_logger.h"
#include "p2p/base/candidate_pair_interface.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/packet_loss_estimator.h"
#include "p2p/base/packet_socket_factory.h"
#include "p2p/base/port_interface.h"
#include "p2p/base/stun.h"
@ -837,8 +836,6 @@ class Connection : public CandidatePairInterface,
int64_t receiving_unchanged_since_ = 0;
std::vector<SentPing> pings_since_last_response_;
PacketLossEstimator packet_loss_estimator_;
absl::optional<int> unwritable_timeout_;
absl::optional<int> unwritable_min_checks_;
absl::optional<int> inactive_timeout_;