blob: 7095e60306b858333f63004160c35c531ad01fba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// Copyright (c) 2013 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.
#include "net/quic/congestion_control/inter_arrival_state_machine.h"
#include "base/logging.h"
namespace {
const int kIncreaseEventsBeforeDowngradingState = 5;
const int kDecreaseEventsBeforeUpgradingState = 2;
// Note: Can not be higher than kDecreaseEventsBeforeUpgradingState;
const int kLossEventsBeforeUpgradingState = 2;
// Timeout old loss and delay events after this time.
const int kEventTimeoutMs = 10000;
// A reasonable arbitrary chosen value for initial round trip time.
const int kInitialRttMs = 80;
}
namespace net {
InterArrivalStateMachine::InterArrivalStateMachine(const QuicClock* clock)
: clock_(clock),
current_state_(kInterArrivalStateStable),
smoothed_rtt_(QuicTime::Delta::FromMilliseconds(kInitialRttMs)),
decrease_event_count_(0),
last_decrease_event_(QuicTime::Zero()),
increase_event_count_(0),
last_increase_event_(QuicTime::Zero()),
loss_event_count_(0),
last_loss_event_(QuicTime::Zero()),
delay_event_count_(0),
last_delay_event_(QuicTime::Zero()) {
}
InterArrivalState InterArrivalStateMachine::GetInterArrivalState() {
return current_state_;
}
void InterArrivalStateMachine::IncreaseBitrateDecision() {
// Multiple increase event without packet loss or delay events will drive
// state back to stable.
QuicTime current_time = clock_->ApproximateNow();
if (current_time.Subtract(last_increase_event_) < smoothed_rtt_) {
// Less than one RTT have passed; ignore this event.
return;
}
last_increase_event_ = current_time;
increase_event_count_++;
decrease_event_count_ = 0; // Reset previous decrease events.
if (increase_event_count_ < kIncreaseEventsBeforeDowngradingState) {
// Not enough increase events to change state.
return;
}
increase_event_count_ = 0; // Reset increase events.
switch (current_state_) {
case kInterArrivalStateStable:
// Keep this state.
break;
case kInterArrivalStatePacketLoss:
current_state_ = kInterArrivalStateStable;
break;
case kInterArrivalStateDelay:
current_state_ = kInterArrivalStateStable;
break;
case kInterArrivalStateCompetingFlow:
current_state_ = kInterArrivalStateDelay;
break;
case kInterArrivalStateCompetingTcpFLow:
current_state_ = kInterArrivalStateDelay;
break;
}
}
void InterArrivalStateMachine::DecreaseBitrateDecision() {
DCHECK(kDecreaseEventsBeforeUpgradingState >=
kLossEventsBeforeUpgradingState);
QuicTime current_time = clock_->ApproximateNow();
if (current_time.Subtract(last_decrease_event_) < smoothed_rtt_) {
// Less than one RTT have passed; ignore this event.
return;
}
last_decrease_event_ = current_time;
decrease_event_count_++;
increase_event_count_ = 0; // Reset previous increase events.
if (decrease_event_count_ < kDecreaseEventsBeforeUpgradingState) {
// Not enough decrease events to change state.
return;
}
decrease_event_count_ = 0; // Reset decrease events.
switch (current_state_) {
case kInterArrivalStateStable:
if (delay_event_count_ == 0 && loss_event_count_ > 0) {
// No recent delay events; only packet loss events.
current_state_ = kInterArrivalStatePacketLoss;
} else {
current_state_ = kInterArrivalStateDelay;
}
break;
case kInterArrivalStatePacketLoss:
// Keep this state.
break;
case kInterArrivalStateDelay:
if (loss_event_count_ >= kLossEventsBeforeUpgradingState) {
// We have packet loss events. Assume fighting with TCP.
current_state_ = kInterArrivalStateCompetingTcpFLow;
} else {
current_state_ = kInterArrivalStateCompetingFlow;
}
break;
case kInterArrivalStateCompetingFlow:
if (loss_event_count_ >= kLossEventsBeforeUpgradingState) {
// We have packet loss events. Assume fighting with TCP.
current_state_ = kInterArrivalStateCompetingTcpFLow;
}
break;
case kInterArrivalStateCompetingTcpFLow:
// Keep this state.
break;
}
}
void InterArrivalStateMachine::set_rtt(QuicTime::Delta rtt) {
smoothed_rtt_ = rtt;
}
bool InterArrivalStateMachine::PacketLossEvent() {
QuicTime current_time = clock_->ApproximateNow();
if (current_time.Subtract(last_loss_event_) < smoothed_rtt_) {
// Less than one RTT have passed; ignore this event.
return false;
}
last_loss_event_ = current_time;
loss_event_count_++;
if (current_time.Subtract(last_delay_event_) >
QuicTime::Delta::FromMilliseconds(kEventTimeoutMs)) {
// Delay event have timed out.
delay_event_count_ = 0;
}
return true;
}
bool InterArrivalStateMachine::IncreasingDelayEvent() {
QuicTime current_time = clock_->ApproximateNow();
if (current_time.Subtract(last_delay_event_) < smoothed_rtt_) {
// Less than one RTT have passed; ignore this event.
return false;
}
last_delay_event_ = current_time;
delay_event_count_++;
if (current_time.Subtract(last_loss_event_) >
QuicTime::Delta::FromMilliseconds(kEventTimeoutMs)) {
// Loss event have timed out.
loss_event_count_ = 0;
}
return true;
}
} // namespace net
|