A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-congestion-ops.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7#ifndef TCPCONGESTIONOPS_H
8#define TCPCONGESTIONOPS_H
9
10#include "tcp-rate-ops.h"
11#include "tcp-socket-state.h"
12
13namespace ns3
14{
15
16/**
17 * \ingroup tcp
18 * \defgroup congestionOps Congestion Control Algorithms.
19 *
20 * The various congestion control algorithms, also known as "TCP flavors".
21 */
22
23/**
24 * \ingroup congestionOps
25 *
26 * \brief Congestion control abstract class
27 *
28 * The design is inspired by what Linux v4.0 does (but it has been
29 * in place for years). The congestion control is split from the main
30 * socket code, and it is a pluggable component. An interface has been defined;
31 * variables are maintained in the TcpSocketState class, while subclasses of
32 * TcpCongestionOps operate over an instance of that class.
33 *
34 * Only three methods have been implemented right now; however, Linux has many others,
35 * which can be added later in ns-3.
36 *
37 * \see IncreaseWindow
38 * \see PktsAcked
39 */
41{
42 public:
43 /**
44 * \brief Get the type ID.
45 * \return the object TypeId
46 */
47 static TypeId GetTypeId();
48
50
51 /**
52 * \brief Copy constructor.
53 * \param other object to copy.
54 */
56
57 ~TcpCongestionOps() override;
58
59 /**
60 * \brief Get the name of the congestion control algorithm
61 *
62 * \return A string identifying the name
63 */
64 virtual std::string GetName() const = 0;
65
66 /**
67 * \brief Set configuration required by congestion control algorithm
68 *
69 * \param tcb internal congestion state
70 */
71 virtual void Init(Ptr<TcpSocketState> tcb [[maybe_unused]])
72 {
73 }
74
75 /**
76 * \brief Get the slow start threshold after a loss event
77 *
78 * Is guaranteed that the congestion control state (\p TcpAckState_t) is
79 * changed BEFORE the invocation of this method.
80 * The implementer should return the slow start threshold (and not change
81 * it directly) because, in the future, the TCP implementation may require to
82 * instantly recover from a loss event (e.g. when there is a network with an high
83 * reordering factor).
84 *
85 * \param tcb internal congestion state
86 * \param bytesInFlight total bytes in flight
87 * \return Slow start threshold
88 */
89 virtual uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight) = 0;
90
91 /**
92 * \brief Congestion avoidance algorithm implementation
93 *
94 * Mimic the function \pname{cong_avoid} in Linux. New segments have been ACKed,
95 * and the congestion control duty is to update the window.
96 *
97 * The function is allowed to change directly cWnd and/or ssThresh.
98 *
99 * \param tcb internal congestion state
100 * \param segmentsAcked count of segments acked
101 */
102 virtual void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
103
104 /**
105 * \brief Timing information on received ACK
106 *
107 * The function is called every time an ACK is received (only one time
108 * also for cumulative ACKs) and contains timing information. It is
109 * optional (congestion controls need not implement it) and the default
110 * implementation does nothing.
111 *
112 * \param tcb internal congestion state
113 * \param segmentsAcked count of segments acked
114 * \param rtt last rtt
115 */
116 virtual void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt);
117
118 /**
119 * \brief Trigger events/calculations specific to a congestion state
120 *
121 * This function mimics the notification function \pname{set_state} in Linux.
122 * The function does not change the congestion state in the tcb; it notifies
123 * the congestion control algorithm that this state is about to be changed.
124 * The tcb->m_congState variable must be separately set; for example:
125 *
126 * \code
127 * m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_RECOVERY);
128 * m_tcb->m_congState = TcpSocketState::CA_RECOVERY;
129 * \endcode
130 *
131 * \param tcb internal congestion state
132 * \param newState new congestion state to which the TCP is going to switch
133 */
135 const TcpSocketState::TcpCongState_t newState);
136
137 /**
138 * \brief Trigger events/calculations on occurrence of congestion window event
139 *
140 * This function mimics the function \pname{cwnd_event} in Linux.
141 * The function is called in case of congestion window events.
142 *
143 * \param tcb internal congestion state
144 * \param event the event which triggered this function
145 */
146 virtual void CwndEvent(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCAEvent_t event);
147
148 /**
149 * \brief Returns true when Congestion Control Algorithm implements CongControl
150 *
151 * \return true if CC implements CongControl function
152 *
153 * This function is the equivalent in C++ of the C checks that are used
154 * in the Linux kernel to see if an optional function has been defined.
155 * Since CongControl is optional, not all congestion controls have it. But,
156 * from the perspective of TcpSocketBase, the behavior is different if
157 * CongControl is present. Therefore, this check should return true for any
158 * congestion controls that implements the CongControl optional function.
159 */
160 virtual bool HasCongControl() const;
161
162 /**
163 * \brief Called when packets are delivered to update cwnd and pacing rate
164 *
165 * This function mimics the function cong_control in Linux. It is allowed to
166 * change directly cWnd and pacing rate.
167 *
168 * \param tcb internal congestion state
169 * \param rc Rate information for the connection
170 * \param rs Rate sample (over a period of time) information
171 */
172 virtual void CongControl(Ptr<TcpSocketState> tcb,
174 const TcpRateOps::TcpRateSample& rs);
175
176 // Present in Linux but not in ns-3 yet:
177 /* call when ack arrives (optional) */
178 // void (*in_ack_event)(struct sock *sk, u32 flags);
179 /* new value of cwnd after loss (optional) */
180 // u32 (*undo_cwnd)(struct sock *sk);
181 /* hook for packet ack accounting (optional) */
182 // void (*pkts_acked)(struct sock *sk, u32 ext, int *attr, union tcp_cc_info *info);
183
184 /**
185 * \brief Copy the congestion control algorithm across sockets
186 *
187 * \return a pointer of the copied object
188 */
190};
191
192/**
193 * \brief The NewReno implementation
194 *
195 * New Reno introduces partial ACKs inside the well-established Reno algorithm.
196 * This and other modifications are described in RFC 6582.
197 *
198 * \see IncreaseWindow
199 */
201{
202 public:
203 /**
204 * \brief Get the type ID.
205 * \return the object TypeId
206 */
207 static TypeId GetTypeId();
208
209 TcpNewReno();
210
211 /**
212 * \brief Copy constructor.
213 * \param sock object to copy.
214 */
215 TcpNewReno(const TcpNewReno& sock);
216
217 ~TcpNewReno() override;
218
219 std::string GetName() const override;
220
221 void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked) override;
222 uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight) override;
223 Ptr<TcpCongestionOps> Fork() override;
224
225 protected:
226 virtual uint32_t SlowStart(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
227 virtual void CongestionAvoidance(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
228};
229
230} // namespace ns3
231
232#endif // TCPCONGESTIONOPS_H
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Congestion control abstract class.
virtual void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Trigger events/calculations on occurrence of congestion window event.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)=0
Get the slow start threshold after a loss event.
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.
static TypeId GetTypeId()
Get the type ID.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
virtual bool HasCongControl() const
Returns true when Congestion Control Algorithm implements CongControl.
virtual void Init(Ptr< TcpSocketState > tcb)
Set configuration required by congestion control algorithm.
virtual Ptr< TcpCongestionOps > Fork()=0
Copy the congestion control algorithm across sockets.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Trigger events/calculations specific to a congestion state.
virtual std::string GetName() const =0
Get the name of the congestion control algorithm.
The NewReno implementation.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Tcp NewReno slow start algorithm.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
std::string GetName() const override
Get the name of the congestion control algorithm.
void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Try to increase the cWnd following the NewReno specification.
static TypeId GetTypeId()
Get the type ID.
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
TcpCAEvent_t
Congestion avoidance events.
TcpCongState_t
Definition of the Congestion state machine.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Information about the connection rate.
Rate Sample structure.