Overte C++ Documentation
TCPVegasCC.h
1 //
2 // TCPVegasCC.h
3 // libraries/networking/src/udt
4 //
5 // Created by Stephen Birarda on 2016-09-20.
6 // Copyright 2016 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #pragma once
13 
14 #ifndef hifi_TCPVegasCC_h
15 #define hifi_TCPVegasCC_h
16 
17 #include <map>
18 
19 #include "CongestionControl.h"
20 #include "Constants.h"
21 
22 namespace udt {
23 
24 
25 class TCPVegasCC : public CongestionControl {
26 public:
27  TCPVegasCC();
28 
29  virtual bool onACK(SequenceNumber ackNum, p_high_resolution_clock::time_point receiveTime) override;
30  virtual void onTimeout() override {};
31 
32  virtual void onPacketSent(int wireSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint) override;
33  virtual void onPacketReSent(int wireSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint) override;
34 
35  virtual int estimatedTimeout() const override;
36 
37 protected:
38  virtual void performCongestionAvoidance(SequenceNumber ack);
39  virtual void setInitialSendSequenceNumber(SequenceNumber seqNum) override { _lastACK = seqNum - 1; }
40 private:
41  bool calculateRTT(p_high_resolution_clock::time_point sendTime, p_high_resolution_clock::time_point receiveTime);
42  bool needsFastRetransmit(SequenceNumber ack, bool wasDuplicateACK);
43 
44  bool isCongestionWindowLimited();
45  void performRenoCongestionAvoidance(SequenceNumber ack);
46 
47  struct SentPacketData {
48  SentPacketData(SequenceNumber seqNum, p_high_resolution_clock::time_point tPoint)
49  : sequenceNumber(seqNum), timePoint(tPoint) {};
50 
51  SequenceNumber sequenceNumber;
52  p_high_resolution_clock::time_point timePoint;
53  bool wasResent { false };
54  };
55 
56  using PacketTimeList = std::vector<SentPacketData>;
57  PacketTimeList _sentPacketDatas; // association of sequence numbers to sent time, for RTT calc
58 
59  p_high_resolution_clock::time_point _lastAdjustmentTime; // Time of last congestion control adjustment
60 
61  bool _slowStart { true }; // Marker for slow start phase
62 
63  SequenceNumber _lastACK; // Sequence number of last packet that was ACKed
64 
65  int _numACKSinceFastRetransmit { 3 }; // Number of ACKs received since fast re-transmit, default avoids immediate re-transmit
66 
67  int _currentMinRTT; // Current min RTT during last RTT (since last congestion avoidance check), in microseconds
68  int _baseRTT; // Lowest RTT during connection, in microseconds
69  int _ewmaRTT { -1 }; // Exponential weighted moving average RTT
70  int _rttVariance { 0 }; // Variance in collected RTT values
71 
72  int _numRTTs { 0 }; // Number of RTTs calculated during the last RTT (since last performed congestion avoidance)
73 
74  int _ackAICount { 0 }; // Counter for number of ACKs received for Reno additive increase
75  int _duplicateACKCount { 0 }; // Counter for duplicate ACKs received
76 
77  int _slowStartOddAdjust { 0 }; // Marker for every window adjustment every other RTT in slow-start
78 };
79 
80 }
81 
82 
83 
84 
85 
86 #endif // hifi_TCPVegasCC_h