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