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

Side by Side Diff: net/quic/core/congestion_control/simulation/queue.cc

Issue 2323963002: Implement an event-based simulator for QuicConnection (Closed)
Patch Set: Adding missing files. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 #include "net/quic/core/congestion_control/simulation/queue.h"
2
3 namespace net {
4 namespace simulation {
5
6 Queue::ListenerInterface::~ListenerInterface() {}
7
8 Queue::Queue(Simulator* simulator, std::string name, QuicByteCount capacity)
9 : Actor(simulator, name),
10 capacity_(capacity),
11 bytes_queued_(0),
12 listener_(nullptr) {}
13
14 void Queue::set_tx_port(ConstrainedPortInterface* port) {
15 tx_port_ = port;
16 }
17
18 void Queue::AcceptPacket(std::unique_ptr<Packet> packet) {
19 if (packet->size + bytes_queued_ > capacity_) {
20 DVLOG(1) << "Queue [" << name() << "] has received a packet from ["
21 << packet->source << "] to [" << packet->destination
22 << "] which is over capacity. Dropping it.";
23 DVLOG(1) << "Queue size: " << bytes_queued_ << " out of " << capacity_
24 << ". Packet size: " << packet->size;
25 return;
26 }
27
28 bytes_queued_ += packet->size;
29 queue_.emplace(std::move(packet));
30 ScheduleNextPacketDequeue();
31 }
32
33 void Queue::Act() {
34 DCHECK(!queue_.empty());
35 if (tx_port_->TimeUntilAvailable().IsZero()) {
36 DCHECK(bytes_queued_ >= queue_.front()->size);
37 bytes_queued_ -= queue_.front()->size;
38
39 tx_port_->AcceptPacket(std::move(queue_.front()));
40 queue_.pop();
41 if (listener_ != nullptr) {
42 listener_->OnPacketDequeued();
43 }
44 }
45
46 ScheduleNextPacketDequeue();
47 }
48
49 void Queue::ScheduleNextPacketDequeue() {
50 if (queue_.empty()) {
51 DCHECK_EQ(bytes_queued_, 0);
52 return;
53 }
54
55 Schedule(clock_->Now() + tx_port_->TimeUntilAvailable());
56 }
57
58 } // namespace simulation
59 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698