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

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

Issue 2430973004: Landing Recent QUIC changes until 10:38 AM, Oct 17, 2016 UTC-4 (Closed)
Patch Set: Improving flagsaver logging Created 4 years, 2 months 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/simulator_test.cc ('k') | net/quic/test_tools/simulator/traffic_policer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/simulator/traffic_policer.h
diff --git a/net/quic/test_tools/simulator/traffic_policer.h b/net/quic/test_tools/simulator/traffic_policer.h
new file mode 100644
index 0000000000000000000000000000000000000000..caa585594ce702fbe9d2104ad72e91a06f0eca37
--- /dev/null
+++ b/net/quic/test_tools/simulator/traffic_policer.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+#ifndef NET_QUIC_TEST_TOOLS_SIMULATOR_TRAFFIC_POLICER_H_
+#define NET_QUIC_TEST_TOOLS_SIMULATOR_TRAFFIC_POLICER_H_
+
+#include <unordered_map>
+
+#include "net/quic/test_tools/simulator/port.h"
+
+namespace net {
+namespace simulator {
+
+// Traffic policer uses a token bucket to limit the bandwidth of the traffic
+// passing through. It wraps around an input port and exposes an output port.
+// Only the traffic from input to the output is policed, so in case when
+// bidirectional policing is desired, two policers have to be used. The flows
+// are hashed by the source only.
+class TrafficPolicer : public Actor, public ConstrainedPortInterface {
+ public:
+ TrafficPolicer(Simulator* simulator,
+ std::string name,
+ QuicByteCount initial_bucket_size,
+ QuicByteCount max_bucket_size,
+ QuicBandwidth target_bandwidth,
+ Endpoint* input);
+ ~TrafficPolicer() override;
+
+ Endpoint* input() { return input_; }
+ Endpoint* output() { return &output_; }
+
+ void AcceptPacket(std::unique_ptr<Packet> packet) override;
+ QuicTime::Delta TimeUntilAvailable() override;
+
+ void Act() override;
+
+ private:
+ class Output : public Endpoint {
+ public:
+ explicit Output(TrafficPolicer* policer);
+ ~Output() override;
+
+ UnconstrainedPortInterface* GetRxPort() override;
+ void SetTxPort(ConstrainedPortInterface* port) override;
+ void Act() override;
+
+ private:
+ TrafficPolicer* policer_;
+ };
+
+ // Refill the token buckets with all the tokens that have been granted since
+ // |last_refill_time_|.
+ void Refill();
+
+ QuicByteCount initial_bucket_size_;
+ QuicByteCount max_bucket_size_;
+ QuicBandwidth target_bandwidth_;
+
+ // The time at which the token buckets were last refilled.
+ QuicTime last_refill_time_;
+
+ ConstrainedPortInterface* output_tx_port_;
+
+ Endpoint* input_;
+ Output output_;
+
+ // Maps each destination to the number of tokens it has left.
+ std::unordered_map<std::string, QuicByteCount> token_buckets_;
+
+ DISALLOW_COPY_AND_ASSIGN(TrafficPolicer);
+};
+
+} // namespace simulator
+} // namespace net
+
+#endif // NET_QUIC_TEST_TOOLS_SIMULATOR_TRAFFIC_POLICER_H_
« no previous file with comments | « net/quic/test_tools/simulator/simulator_test.cc ('k') | net/quic/test_tools/simulator/traffic_policer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698