- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / inter_arrival_state_machine.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // State machine for congestion control. The state is updated by calls from
6 // other modules as they detect events, or decide on taking specific actions.
7 // Events include things like packet loss, or growing delay, while decisions
8 // include decisions to increase or decrease bitrates.
9 // This class should be called for every event and decision made by the
10 // congestion control, this class will coalesce all calls relative to the
11 // smoothed RTT.
12
13 #ifndef NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_STATE_MACHINE_H_
14 #define NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_STATE_MACHINE_H_
15
16 #include "net/base/net_export.h"
17 #include "net/quic/quic_clock.h"
18 #include "net/quic/quic_time.h"
19
20 namespace net {
21
22 //  State transition diagram.
23 //
24 //                     kInterArrivalStatePacketLoss
25 //                                   |
26 //                       kInterArrivalStateStable
27 //                                   |
28 //                       kInterArrivalStateDelay
29 //                           |              |
30 //  kInterArrivalStateCompetingFlow -> kInterArrivalStateCompetingTcpFLow
31
32 enum NET_EXPORT_PRIVATE InterArrivalState {
33   // We are on a network with a delay that is too small to be reliably detected,
34   // such as a local ethernet.
35   kInterArrivalStatePacketLoss = 1,
36   // We are on an underutilized network operating with low delay and low loss.
37   kInterArrivalStateStable = 2,
38   // We are on a network where we can detect delay changes and suffer only
39   // low loss. Nothing indicates that we are competing with another flow.
40   kInterArrivalStateDelay = 3,
41   // We are on a network where we can detect delay changes and suffer only
42   // low loss. We have indications that we are compete with another flow.
43   kInterArrivalStateCompetingFlow = 4,
44   // We are on a network where we can detect delay changes, however we suffer
45   // packet loss due to sharing the bottleneck link with another flow, which is
46   // most likely a TCP flow.
47   kInterArrivalStateCompetingTcpFLow = 5,
48 };
49
50 class NET_EXPORT_PRIVATE InterArrivalStateMachine {
51  public:
52   explicit InterArrivalStateMachine(const QuicClock* clock);
53
54   InterArrivalState GetInterArrivalState();
55
56   // Inter arrival congestion control decided to increase bitrate.
57   void IncreaseBitrateDecision();
58
59   // Inter arrival congestion control decided to decrease bitrate.
60   void DecreaseBitrateDecision();
61
62   // Estimated smoothed round trip time.
63   // This should be called whenever the smoothed RTT estimate is updated.
64   void set_rtt(QuicTime::Delta rtt);
65
66   // This method is called when a packet loss was reported.
67   bool PacketLossEvent();
68
69   // This method is called when we believe that packet transit delay is
70   // increasing, presumably due to a growing queue along the path.
71   bool IncreasingDelayEvent();
72
73  private:
74   const QuicClock* clock_;
75   InterArrivalState current_state_;
76   QuicTime::Delta smoothed_rtt_;
77
78   int decrease_event_count_;
79   QuicTime last_decrease_event_;
80
81   int increase_event_count_;
82   QuicTime last_increase_event_;
83
84   int loss_event_count_;
85   QuicTime last_loss_event_;
86
87   int delay_event_count_;
88   QuicTime last_delay_event_;
89
90   DISALLOW_COPY_AND_ASSIGN(InterArrivalStateMachine);
91 };
92
93 }  // namespace net
94 #endif  // NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_STATE_MACHINE_H_