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 Set rate operation required by the congestion control algorithm
77 *
78 * @param rateOps a pointer to the rate operation object used to manage rate control
79 */
80 virtual void SetRateOps(Ptr<TcpRateOps> rateOps [[maybe_unused]])
81 {
82 }
83
84 /**
85 * @brief Get the slow start threshold after a loss event
86 *
87 * Is guaranteed that the congestion control state (\p TcpAckState_t) is
88 * changed BEFORE the invocation of this method.
89 * The implementer should return the slow start threshold (and not change
90 * it directly) because, in the future, the TCP implementation may require to
91 * instantly recover from a loss event (e.g. when there is a network with an high
92 * reordering factor).
93 *
94 * @param tcb internal congestion state
95 * @param bytesInFlight total bytes in flight
96 * @return Slow start threshold
97 */
98 virtual uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight) = 0;
99
100 /**
101 * @brief Congestion avoidance algorithm implementation
102 *
103 * Mimic the function \pname{cong_avoid} in Linux. New segments have been ACKed,
104 * and the congestion control duty is to update the window.
105 *
106 * The function is allowed to change directly cWnd and/or ssThresh.
107 *
108 * @param tcb internal congestion state
109 * @param segmentsAcked count of segments acked
110 */
111 virtual void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
112
113 /**
114 * @brief Timing information on received ACK
115 *
116 * The function is called every time an ACK is received (only one time
117 * also for cumulative ACKs) and contains timing information. It is
118 * optional (congestion controls need not implement it) and the default
119 * implementation does nothing.
120 *
121 * @param tcb internal congestion state
122 * @param segmentsAcked count of segments acked
123 * @param rtt last rtt
124 */
125 virtual void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt);
126
127 /**
128 * @brief Trigger events/calculations specific to a congestion state
129 *
130 * This function mimics the notification function \pname{set_state} in Linux.
131 * The function does not change the congestion state in the tcb; it notifies
132 * the congestion control algorithm that this state is about to be changed.
133 * The tcb->m_congState variable must be separately set; for example:
134 *
135 * @code
136 * m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_RECOVERY);
137 * m_tcb->m_congState = TcpSocketState::CA_RECOVERY;
138 * @endcode
139 *
140 * @param tcb internal congestion state
141 * @param newState new congestion state to which the TCP is going to switch
142 */
144 const TcpSocketState::TcpCongState_t newState);
145
146 /**
147 * @brief Trigger events/calculations on occurrence of congestion window event
148 *
149 * This function mimics the function \pname{cwnd_event} in Linux.
150 * The function is called in case of congestion window events.
151 *
152 * @param tcb internal congestion state
153 * @param event the event which triggered this function
154 */
155 virtual void CwndEvent(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCAEvent_t event);
156
157 /**
158 * @brief Returns true when Congestion Control Algorithm implements CongControl
159 *
160 * @return true if CC implements CongControl function
161 *
162 * This function is the equivalent in C++ of the C checks that are used
163 * in the Linux kernel to see if an optional function has been defined.
164 * Since CongControl is optional, not all congestion controls have it. But,
165 * from the perspective of TcpSocketBase, the behavior is different if
166 * CongControl is present. Therefore, this check should return true for any
167 * congestion controls that implements the CongControl optional function.
168 */
169 virtual bool HasCongControl() const;
170
171 /**
172 * @brief Called when packets are delivered to update cwnd and pacing rate
173 *
174 * This function mimics the function cong_control in Linux. It is allowed to
175 * change directly cWnd and pacing rate.
176 *
177 * @param tcb internal congestion state
178 * @param rc Rate information for the connection
179 * @param rs Rate sample (over a period of time) information
180 */
181 virtual void CongControl(Ptr<TcpSocketState> tcb,
183 const TcpRateOps::TcpRateSample& rs);
184
185 // Present in Linux but not in ns-3 yet:
186 /* call when ack arrives (optional) */
187 // void (*in_ack_event)(struct sock *sk, u32 flags);
188 /* new value of cwnd after loss (optional) */
189 // u32 (*undo_cwnd)(struct sock *sk);
190 /* hook for packet ack accounting (optional) */
191 // void (*pkts_acked)(struct sock *sk, u32 ext, int *attr, union tcp_cc_info *info);
192
193 /**
194 * @brief Copy the congestion control algorithm across sockets
195 *
196 * @return a pointer of the copied object
197 */
199};
200
201/**
202 * @brief The NewReno implementation
203 *
204 * New Reno introduces partial ACKs inside the well-established Reno algorithm.
205 * This and other modifications are described in RFC 6582.
206 *
207 * @see IncreaseWindow
208 */
210{
211 public:
212 /**
213 * @brief Get the type ID.
214 * @return the object TypeId
215 */
216 static TypeId GetTypeId();
217
218 TcpNewReno();
219
220 /**
221 * @brief Copy constructor.
222 * @param sock object to copy.
223 */
224 TcpNewReno(const TcpNewReno& sock);
225
226 ~TcpNewReno() override;
227
228 std::string GetName() const override;
229
230 void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked) override;
231 uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight) override;
232 Ptr<TcpCongestionOps> Fork() override;
233
234 protected:
235 virtual uint32_t SlowStart(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
236 virtual void CongestionAvoidance(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
237};
238
239} // namespace ns3
240
241#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 void SetRateOps(Ptr< TcpRateOps > rateOps)
Set rate operation required by the congestion control algorithm.
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:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Information about the connection rate.
Rate Sample structure.