A Discrete-Event Network Simulator
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 NITK Surathkal
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Vivek Jain <jain.vivek.anand@gmail.com>
19  * Viyom Mittal <viyommittal@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  */
23 #ifndef TCPBBR_H
24 #define TCPBBR_H
26 #include "ns3/tcp-congestion-ops.h"
27 #include "ns3/traced-value.h"
28 #include "ns3/data-rate.h"
29 #include "ns3/random-variable-stream.h"
30 #include "ns3/windowed-filter.h"
34 namespace ns3 {
36 class TcpBbr : public TcpCongestionOps
37 {
38 public:
42  static const uint8_t GAIN_CYCLE_LENGTH = 8;
48  const static double PACING_GAIN_CYCLE [];
53  static TypeId GetTypeId (void);
58  TcpBbr ();
64  TcpBbr (const TcpBbr &sock);
69  typedef enum
70  {
75  } BbrMode_t;
77  typedef WindowedFilter<DataRate,
79  uint32_t,
80  uint32_t>
86  static const char* const BbrModeName[BBR_PROBE_RTT + 1];
94  virtual void SetStream (uint32_t stream);
96  virtual std::string GetName () const;
97  virtual bool HasCongControl () const;
98  virtual void CongControl (Ptr<TcpSocketState> tcb,
100  const TcpRateOps::TcpRateSample &rs);
101  virtual void CongestionStateSet (Ptr<TcpSocketState> tcb,
102  const TcpSocketState::TcpCongState_t newState);
103  virtual void CwndEvent (Ptr<TcpSocketState> tcb,
104  const TcpSocketState::TcpCAEvent_t event);
105  virtual uint32_t GetSsThresh (Ptr<const TcpSocketState> tcb,
106  uint32_t bytesInFlight);
107  virtual Ptr<TcpCongestionOps> Fork ();
109 protected:
119  void AdvanceCyclePhase ();
133  void CheckDrain (Ptr<TcpSocketState> tcb);
139  void CheckFullPipe (const TcpRateOps::TcpRateSample &rs);
151  void EnterDrain ();
156  void EnterProbeBW ();
161  void EnterProbeRTT ();
166  void EnterStartup ();
171  void ExitProbeRTT ();
177  uint32_t GetBbrState ();
183  double GetPacingGain ();
189  double GetCwndGain ();
210  uint32_t InFlight (Ptr<TcpSocketState> tcb, double gain);
215  void InitFullPipe ();
226  void InitRoundCounting ();
254  void RestoreCwnd (Ptr<TcpSocketState> tcb);
275  void SetPacingRate (Ptr<TcpSocketState> tcb, double gain);
327  void SetBbrState (BbrMode_t state);
333  uint32_t AckAggregationCwnd();
342 private:
343  BbrMode_t m_state {BbrMode_t::BBR_STARTUP};
345  uint32_t m_bandwidthWindowLength {0};
346  double m_pacingGain {0};
347  double m_cWndGain {0};
348  double m_highGain {0};
349  bool m_isPipeFilled {false};
350  uint32_t m_minPipeCwnd {0};
351  uint32_t m_roundCount {0};
352  bool m_roundStart {false};
353  uint32_t m_nextRoundDelivered {0};
357  bool m_probeRttRoundDone {false};
358  bool m_packetConservation {false};
359  uint32_t m_priorCwnd {0};
360  bool m_idleRestart {false};
361  uint32_t m_targetCWnd {0};
363  uint32_t m_fullBandwidthCount {0};
365  uint32_t m_sendQuantum {0};
367  uint32_t m_cycleIndex {0};
368  bool m_rtPropExpired {false};
371  bool m_isInitialized {false};
373  uint64_t m_delivered {0};
374  uint32_t m_appLimited {0};
375  uint32_t m_txItemDelivered {0};
376  uint32_t m_extraAckedGain {1};
377  uint32_t m_extraAcked [2] {0, 0};
378  uint32_t m_extraAckedWinRtt {0};
380  uint32_t m_ackEpochAckedResetThresh {1 << 17};
381  uint32_t m_extraAckedIdx {0};
383  uint32_t m_ackEpochAcked {0};
384  bool m_hasSeenRtt {false};
385 };
387 } // namespace ns3
388 #endif // TCPBBR_H
Time m_rtPropStamp
The wall clock time at which the current BBR.RTProp sample was obtained.
Definition: tcp-bbr.h:370
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
uint32_t m_targetCWnd
Target value for congestion window, adapted to the estimated BDP.
Definition: tcp-bbr.h:361
Compares two values.
MaxBandwidthFilter_t m_maxBwFilter
Maximum bandwidth filter.
Definition: tcp-bbr.h:344
void RestoreCwnd(Ptr< TcpSocketState > tcb)
Helper to restore the last-known good congestion window.
Definition: tcp-bbr.cc:387
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-bbr.cc:676
void EnterProbeRTT()
Updates variables specific to BBR_PROBE_RTT state.
Definition: tcp-bbr.cc:364
Time m_rtProp
Estimated two-way round-trip propagation delay of the path, estimated from the windowed minimum recen...
Definition: tcp-bbr.h:364
uint32_t m_cycleIndex
Current index of gain cycle.
Definition: tcp-bbr.h:367
bool m_packetConservation
Enable/Disable packet conservation mode.
Definition: tcp-bbr.h:358
uint32_t m_extraAckedWinRttLength
Window length of extra acked window.
Definition: tcp-bbr.h:379
bool m_isPipeFilled
A boolean that records whether BBR has filled the pipe.
Definition: tcp-bbr.h:349
Congestion avoidance events.
Ramp up sending rate rapidly to fill pipe.
Definition: tcp-bbr.h:71
Tests whether BBR sets correct value of pacing and cwnd gain based on different state.
Definition: tcp-bbr-test.cc:86
static const uint8_t GAIN_CYCLE_LENGTH
The number of phases in the BBR ProbeBW gain cycle.
Definition: tcp-bbr.h:42
virtual void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Trigger events/calculations on occurrence of congestion window event.
Definition: tcp-bbr.cc:744
bool m_hasSeenRtt
Have we seen RTT sample yet?
Definition: tcp-bbr.h:384
uint32_t m_priorCwnd
The last-known good congestion window.
Definition: tcp-bbr.h:359
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-bbr.cc:36
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
double m_highGain
A constant specifying highest gain factor, default is 2.89.
Definition: tcp-bbr.h:348
void CheckFullPipe(const TcpRateOps::TcpRateSample &rs)
Identifies whether pipe or BDP is already full.
Definition: tcp-bbr.cc:291
Time m_probeRttDuration
A constant specifying the minimum duration for which ProbeRTT state, default 200 millisecs.
Definition: tcp-bbr.h:354
void ModulateCwndForProbeRTT(Ptr< TcpSocketState > tcb)
Modulates congestion window in BBR_PROBE_RTT.
Definition: tcp-bbr.cc:546
void UpdateBtlBw(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates maximum bottleneck.
Definition: tcp-bbr.cc:607
uint32_t GetBbrState()
Gets BBR state.
Definition: tcp-bbr.cc:655
uint32_t m_ackEpochAcked
Bytes ACked in sampling epoch.
Definition: tcp-bbr.h:383
uint32_t m_txItemDelivered
The number of bytes already delivered at the time of new packet transmission.
Definition: tcp-bbr.h:375
uint32_t InFlight(Ptr< TcpSocketState > tcb, double gain)
Estimates the target value for congestion window.
Definition: tcp-bbr.cc:235
void InitFullPipe()
Intializes the full pipe estimator.
Definition: tcp-bbr.cc:156
void SaveCwnd(Ptr< const TcpSocketState > tcb)
Helper to remember the last-known good congestion window or the latest congestion window unmodulated ...
Definition: tcp-bbr.cc:373
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-bbr.cc:785
void HandleProbeRTT(Ptr< TcpSocketState > tcb)
Handles the steps for BBR_PROBE_RTT state.
Definition: tcp-bbr.cc:408
Class for representing data rates.
Definition: data-rate.h:88
uint32_t m_extraAckedIdx
Current index in extra acked array.
Definition: tcp-bbr.h:381
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:283
uint32_t AckAggregationCwnd()
Find Cwnd increment based on ack aggregation.
Definition: tcp-bbr.cc:471
void EnterDrain()
Updates variables specific to BBR_DRAIN state.
Definition: tcp-bbr.cc:316
void SetCwnd(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates congestion window based on the network model.
Definition: tcp-bbr.cc:556
Rate Sample structure.
Definition: tcp-rate-ops.h:133
void UpdateModelAndState(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates BBR network model (Maximum bandwidth and minimum RTT).
Definition: tcp-bbr.cc:625
uint32_t m_fullBandwidthCount
Count of full bandwidth recorded consistently.
Definition: tcp-bbr.h:363
Time m_ackEpochTime
Starting of ACK sampling epoch time.
Definition: tcp-bbr.h:382
friend class TcpBbrCheckGainValuesTest
TcpBbrCheckGainValuesTest friend class (for tests).
Definition: tcp-bbr.h:114
void CheckProbeRTT(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
This method handles the steps related to the ProbeRTT state.
Definition: tcp-bbr.cc:435
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-bbr.cc:777
Time m_rtPropFilterLen
A constant specifying the length of the RTProp min filter window, default 10 secs.
Definition: tcp-bbr.h:369
static const char *const BbrModeName[BBR_PROBE_RTT+1]
Literal names of BBR mode for use in log messages.
Definition: tcp-bbr.h:86
uint32_t m_extraAckedGain
Gain factor for adding extra ack to cwnd.
Definition: tcp-bbr.h:376
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Trigger events/calculations specific to a congestion state.
Definition: tcp-bbr.cc:701
void SetBbrState(BbrMode_t state)
Sets BBR state.
Definition: tcp-bbr.cc:647
void UpdateTargetCwnd(Ptr< TcpSocketState > tcb)
Updates target congestion window.
Definition: tcp-bbr.cc:464
bool m_isInitialized
Set to true after first time initializtion variables.
Definition: tcp-bbr.h:371
uint32_t m_appLimited
The index of the last transmitted packet marked as application-limited.
Definition: tcp-bbr.h:374
void UpdateRound(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates round counting related variables.
Definition: tcp-bbr.cc:590
uint32_t m_extraAckedWinRtt
Age of extra acked in rtt.
Definition: tcp-bbr.h:378
Construct a windowed filter.
bool m_idleRestart
When restarting from idle, set it true.
Definition: tcp-bbr.h:360
bool m_roundStart
A boolean that BBR sets to true once per packet-timed round trip.
Definition: tcp-bbr.h:352
Cut inflight to min to probe min_rtt.
Definition: tcp-bbr.h:74
bool IsNextCyclePhase(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Checks whether to move to next value of pacing gain while in BBR_PROBE_BW.
Definition: tcp-bbr.cc:262
Definition of the Congestion state machine.
BBR has the following 4 modes for deciding how fast to send:
Definition: tcp-bbr.h:69
void ExitProbeRTT()
Called on exiting from BBR_PROBE_RTT state, it eithers invoke EnterProbeBW () or EnterStartup () ...
Definition: tcp-bbr.cc:394
bool ModulateCwndForRecovery(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Modulates congestion window in CA_RECOVERY.
Definition: tcp-bbr.cc:529
Discover, share bw: pace around estimated bw.
Definition: tcp-bbr.h:73
uint32_t m_ackEpochAckedResetThresh
Max allowed val for m_ackEpochAcked, after which sampling epoch is reset.
Definition: tcp-bbr.h:380
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AdvanceCyclePhase()
Advances pacing gain using cycle gain algorithm, while in BBR_PROBE_BW state.
Definition: tcp-bbr.cc:253
BbrMode_t m_state
Current state of BBR state machine.
Definition: tcp-bbr.h:343
void UpdateRTprop(Ptr< TcpSocketState > tcb)
Updates minimum RTT.
Definition: tcp-bbr.cc:352
Congestion control abstract class.
double GetPacingGain()
Gets current pacing gain.
Definition: tcp-bbr.cc:669
void CheckDrain(Ptr< TcpSocketState > tcb)
Checks whether its time to enter BBR_DRAIN or BBR_PROBE_BW state.
Definition: tcp-bbr.cc:336
void SetPacingRate(Ptr< TcpSocketState > tcb, double gain)
Updates pacing rate based on network model.
Definition: tcp-bbr.cc:217
void InitRoundCounting()
Intializes the round counting related variables.
Definition: tcp-bbr.cc:147
void SetSendQuantum(Ptr< TcpSocketState > tcb)
Updates send quantum based on the network model.
Definition: tcp-bbr.cc:457
void UpdateAckAggregation(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Estimates max degree of aggregation.
Definition: tcp-bbr.cc:486
Time m_probeRtPropStamp
The wall clock time at which the current BBR.RTProp sample was obtained.
Definition: tcp-bbr.h:355
Time m_probeRttDoneStamp
Time to exit from BBR_PROBE_RTT state.
Definition: tcp-bbr.h:356
uint32_t m_nextRoundDelivered
Denotes the end of a packet-timed round trip.
Definition: tcp-bbr.h:353
Information about the connection rate.
Definition: tcp-rate-ops.h:162
virtual bool HasCongControl() const
Returns true when Congestion Control Algorithm implements CongControl.
Definition: tcp-bbr.cc:682
DataRate m_fullBandwidth
Value of full bandwidth recorded.
Definition: tcp-bbr.h:362
bool m_probeRttRoundDone
True when it is time to exit BBR_PROBE_RTT.
Definition: tcp-bbr.h:357
Ptr< UniformRandomVariable > m_uv
Uniform Random Variable.
Definition: tcp-bbr.h:372
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
uint32_t m_extraAcked[2]
Maximum excess data acked in epoch.
Definition: tcp-bbr.h:377
virtual void SetStream(uint32_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: tcp-bbr.cc:140
uint32_t m_bandwidthWindowLength
A constant specifying the length of the BBR.BtlBw max filter window, default 10 packet-timed round tr...
Definition: tcp-bbr.h:345
static const double PACING_GAIN_CYCLE[]
BBR uses an eight-phase cycle with the given pacing_gain value in the BBR ProbeBW gain cycle...
Definition: tcp-bbr.h:48
Time m_cycleStamp
Last time gain cycle updated.
Definition: tcp-bbr.h:366
uint32_t m_sendQuantum
The maximum size of a data aggregate scheduled and transmitted together.
Definition: tcp-bbr.h:365
double m_pacingGain
The dynamic pacing gain factor.
Definition: tcp-bbr.h:346
uint32_t m_roundCount
Count of packet-timed round trips.
Definition: tcp-bbr.h:351
void EnterStartup()
Updates variables specific to BBR_STARTUP state.
Definition: tcp-bbr.cc:194
Definition: tcp-bbr.cc:81
virtual void CongControl(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateConnection &rc, const TcpRateOps::TcpRateSample &rs)
Called when packets are delivered to update cwnd and pacing rate.
Definition: tcp-bbr.cc:689
WindowedFilter< DataRate, MaxFilter< DataRate >, uint32_t, uint32_t > MaxBandwidthFilter_t
Definition of max bandwidth filter.
Definition: tcp-bbr.h:81
double m_cWndGain
The dynamic congestion window gain factor.
Definition: tcp-bbr.h:347
uint64_t m_delivered
The total amount of data in bytes delivered so far.
Definition: tcp-bbr.h:373
void CheckCyclePhase(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Checks whether to advance pacing gain in BBR_PROBE_BW state, and if allowed calls AdvanceCyclePhase (...
Definition: tcp-bbr.cc:281
uint32_t m_minPipeCwnd
The minimal congestion window value BBR tries to target, default 4 Segment size.
Definition: tcp-bbr.h:350
void HandleRestartFromIdle(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates pacing rate if socket is restarting from idle state.
Definition: tcp-bbr.cc:203
void InitPacingRate(Ptr< TcpSocketState > tcb)
Intializes the pacing rate.
Definition: tcp-bbr.cc:165
void UpdateControlParameters(Ptr< TcpSocketState > tcb, const TcpRateOps::TcpRateSample &rs)
Updates control parameters congestion windowm, pacing rate, send quantum.
Definition: tcp-bbr.cc:638
a unique identifier for an interface.
Definition: type-id.h:58
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
Drain any queue created during startup.
Definition: tcp-bbr.h:72
bool m_rtPropExpired
A boolean recording whether the BBR.RTprop has expired.
Definition: tcp-bbr.h:368
void EnterProbeBW()
Updates variables specific to BBR_PROBE_BW state.
Definition: tcp-bbr.cc:325
double GetCwndGain()
Gets current cwnd gain.
Definition: tcp-bbr.cc:662