Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Unified Diff: net/quic/test_tools/simulator/traffic_policer.cc

Issue 2529293009: Split TrafficPolicer into a generic one-way packet filter class and a policer-specific logic. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/test_tools/simulator/traffic_policer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/simulator/traffic_policer.cc
diff --git a/net/quic/test_tools/simulator/traffic_policer.cc b/net/quic/test_tools/simulator/traffic_policer.cc
index 84ea4db0f24389cb3c2d7fad94bd6cbcd67b02ca..93e1c8d3721486bd08a0dc048a36bb7a0e85ae37 100644
--- a/net/quic/test_tools/simulator/traffic_policer.cc
+++ b/net/quic/test_tools/simulator/traffic_policer.cc
@@ -15,20 +15,14 @@ TrafficPolicer::TrafficPolicer(Simulator* simulator,
QuicByteCount max_bucket_size,
QuicBandwidth target_bandwidth,
Endpoint* input)
- : Actor(simulator, name),
+ : PacketFilter(simulator, name, input),
initial_bucket_size_(initial_bucket_size),
max_bucket_size_(max_bucket_size),
target_bandwidth_(target_bandwidth),
- last_refill_time_(clock_->Now()),
- input_(input),
- output_(this) {
- input_->SetTxPort(this);
-}
+ last_refill_time_(clock_->Now()) {}
TrafficPolicer::~TrafficPolicer() {}
-void TrafficPolicer::Act() {}
-
void TrafficPolicer::Refill() {
QuicTime::Delta time_passed = clock_->Now() - last_refill_time_;
QuicByteCount refill_size = time_passed * target_bandwidth_;
@@ -40,47 +34,27 @@ void TrafficPolicer::Refill() {
last_refill_time_ = clock_->Now();
}
-void TrafficPolicer::AcceptPacket(std::unique_ptr<Packet> packet) {
+bool TrafficPolicer::FilterPacket(const Packet& packet) {
// Refill existing buckets.
Refill();
// Create a new bucket if one does not exist.
- if (token_buckets_.count(packet->destination) == 0) {
+ if (token_buckets_.count(packet.destination) == 0) {
token_buckets_.insert(
- std::make_pair(packet->destination, initial_bucket_size_));
+ std::make_pair(packet.destination, initial_bucket_size_));
}
- auto bucket = token_buckets_.find(packet->destination);
+ auto bucket = token_buckets_.find(packet.destination);
DCHECK(bucket != token_buckets_.end());
// Silently drop the packet on the floor if out of tokens
- if (bucket->second < packet->size) {
- return;
+ if (bucket->second < packet.size) {
+ return false;
}
- bucket->second -= packet->size;
- output_tx_port_->AcceptPacket(std::move(packet));
-}
-
-QuicTime::Delta TrafficPolicer::TimeUntilAvailable() {
- return output_tx_port_->TimeUntilAvailable();
+ bucket->second -= packet.size;
+ return true;
}
-TrafficPolicer::Output::Output(TrafficPolicer* policer)
- : Endpoint(policer->simulator(), policer->name() + " (output port)"),
- policer_(policer) {}
-
-TrafficPolicer::Output::~Output() {}
-
-UnconstrainedPortInterface* TrafficPolicer::Output::GetRxPort() {
- return policer_->input_->GetRxPort();
-}
-
-void TrafficPolicer::Output::SetTxPort(ConstrainedPortInterface* port) {
- policer_->output_tx_port_ = port;
-}
-
-void TrafficPolicer::Output::Act() {}
-
} // namespace simulator
} // namespace net
« no previous file with comments | « net/quic/test_tools/simulator/traffic_policer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698