A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-socket-state.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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#ifndef TCP_SOCKET_STATE_H
18#define TCP_SOCKET_STATE_H
19
20#include "tcp-rx-buffer.h"
21
22#include "ns3/data-rate.h"
23#include "ns3/object.h"
24#include "ns3/sequence-number.h"
25#include "ns3/traced-value.h"
26
27namespace ns3
28{
29
30/**
31 * \brief Data structure that records the congestion state of a connection
32 *
33 * In this data structure, basic information that should be passed between
34 * socket and the congestion control algorithm are saved. Through the code,
35 * it will be referred as Transmission Control Block (TCB), but there are some
36 * differences. In the RFCs, the TCB contains all the variables that defines
37 * a connection, while we preferred to maintain in this class only the values
38 * that should be exchanged between socket and other parts, like congestion
39 * control algorithms.
40 *
41 */
42class TcpSocketState : public Object
43{
44 public:
45 /**
46 * Get the type ID.
47 * \brief Get the type ID.
48 * \return the object TypeId
49 */
50 static TypeId GetTypeId();
51
52 /**
53 * \brief TcpSocketState Constructor
54 */
56 : Object()
57 {
58 }
59
60 /**
61 * \brief Copy constructor.
62 * \param other object to copy.
63 */
64 TcpSocketState(const TcpSocketState& other);
65
66 /**
67 * \brief Definition of the Congestion state machine
68 *
69 * The design of this state machine is taken from Linux v4.0, but it has been
70 * maintained in the Linux mainline from ages. It basically avoids to maintain
71 * a lot of boolean variables, and it allows to check the transitions from
72 * different algorithm in a cleaner way.
73 *
74 * These states represent the situation from a congestion control point of view:
75 * in fact, apart the CA_OPEN state, the other states represent a situation in
76 * which there is a congestion, and different actions should be taken,
77 * depending on the case.
78 *
79 */
81 {
82 CA_OPEN, //!< Normal state, no dubious events
83 CA_DISORDER, //!< In all the respects it is "Open",
84 //!< but requires a bit more attention. It is entered when we see some SACKs or
85 //!< dupacks. It is split of "Open".
86 CA_CWR, //!< cWnd was reduced due to some congestion notification event, such as ECN,
87 //!< ICMP source quench, local device congestion.
88 CA_RECOVERY, //!< CWND was reduced, we are fast-retransmitting.
89 CA_LOSS, //!< CWND was reduced due to RTO timeout or SACK reneging.
90 CA_LAST_STATE //!< Used only in debug messages
91 };
92
93 // Note: "not triggered" events are currently not triggered by the code.
94 /**
95 * \brief Congestion avoidance events
96 */
98 {
99 CA_EVENT_TX_START, //!< first transmit when no packets in flight
100 CA_EVENT_CWND_RESTART, //!< congestion window restart. Not triggered
101 CA_EVENT_COMPLETE_CWR, //!< end of congestion recovery
102 CA_EVENT_LOSS, //!< loss timeout
103 CA_EVENT_ECN_NO_CE, //!< ECT set, but not CE marked. Not triggered
104 CA_EVENT_ECN_IS_CE, //!< received CE marked IP packet. Not triggered
105 CA_EVENT_DELAYED_ACK, //!< Delayed ack is sent
106 CA_EVENT_NON_DELAYED_ACK, //!< Non-delayed ack is sent
107 };
108
109 /**
110 * \brief Parameter value related to ECN enable/disable functionality
111 * similar to sysctl for tcp_ecn. Currently value 2 from
112 * https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
113 * is not implemented.
114 */
116 {
117 Off = 0, //!< Disable
118 On = 1, //!< Enable
119 AcceptOnly = 2, //!< Enable only when the peer endpoint is ECN capable
120 };
121
122 /**
123 * \brief ECN code points
124 */
126 {
127 NotECT = 0, //!< Unmarkable
128 Ect1 = 1, //!< Markable
129 Ect0 = 2, //!< Markable
130 CongExp = 3, //!< Marked
131 };
132
133 /**
134 * \brief ECN Modes
135 */
137 {
138 ClassicEcn, //!< ECN functionality as described in RFC 3168.
139 DctcpEcn, //!< ECN functionality as described in RFC 8257. Note: this mode is specific to
140 //!< DCTCP.
141 };
142
143 /**
144 * \brief Definition of the Ecn state machine
145 *
146 */
148 {
149 ECN_DISABLED = 0, //!< ECN disabled traffic
150 ECN_IDLE, //!< ECN is enabled but currently there is no action pertaining to ECE or CWR to
151 //!< be taken
152 ECN_CE_RCVD, //!< Last packet received had CE bit set in IP header
153 ECN_SENDING_ECE, //!< Receiver sends an ACK with ECE bit set in TCP header
154 ECN_ECE_RCVD, //!< Last ACK received had ECE bit set in TCP header
155 ECN_CWR_SENT //!< Sender has reduced the congestion window, and sent a packet with CWR bit
156 //!< set in TCP header. This state is used for tracing.
157 };
158
159 /**
160 * \brief Literal names of TCP states for use in log messages
161 */
163
164 /**
165 * \brief Literal names of ECN states for use in log messages
166 */
167 static const char* const EcnStateName[TcpSocketState::ECN_CWR_SENT + 1];
168
169 // Congestion control
170 TracedValue<uint32_t> m_cWnd{0}; //!< Congestion window
172 0}; //!< Inflated congestion window trace (used only for backward compatibility purpose)
173 TracedValue<uint32_t> m_ssThresh{0}; //!< Slow start threshold
174 uint32_t m_initialCWnd{0}; //!< Initial cWnd value
175 uint32_t m_initialSsThresh{0}; //!< Initial Slow Start Threshold value
176
177 // Recovery
178 // This variable is used for implementing following flag of Linux: FLAG_RETRANS_DATA_ACKED
179 // and is used only during a recovery phase to keep track of acknowledgement of retransmitted
180 // packet.
181 bool m_isRetransDataAcked{false}; //!< Retransmitted data is ACKed if true
182
183 // Segment
184 uint32_t m_segmentSize{0}; //!< Segment size
185 SequenceNumber32 m_lastAckedSeq{0}; //!< Last sequence ACKed
186
187 TracedValue<TcpCongState_t> m_congState{CA_OPEN}; //!< State in the Congestion state machine
188
190 ECN_DISABLED}; //!< Current ECN State, represented as combination of EcnState values
191
192 TracedValue<SequenceNumber32> m_highTxMark{0}; //!< Highest seqno ever sent, regardless of ReTx
194 0}; //!< Next seqnum to be sent (SND.NXT), ReTx pushes it back
195
196 uint32_t m_rcvTimestampValue{0}; //!< Receiver Timestamp value
197 uint32_t m_rcvTimestampEchoReply{0}; //!< Sender Timestamp echoed by the receiver
198
199 // Pacing related variables
200 bool m_pacing{false}; //!< Pacing status
201 DataRate m_maxPacingRate{0}; //!< Max Pacing rate
202 TracedValue<DataRate> m_pacingRate{0}; //!< Current Pacing rate
203 uint16_t m_pacingSsRatio{0}; //!< SS pacing ratio
204 uint16_t m_pacingCaRatio{0}; //!< CA pacing ratio
205 bool m_paceInitialWindow{false}; //!< Enable/Disable pacing for the initial window
206
207 Time m_minRtt{Time::Max()}; //!< Minimum RTT observed throughout the connection
208
209 TracedValue<uint32_t> m_bytesInFlight{0}; //!< Bytes in flight
210 TracedValue<Time> m_lastRtt{Seconds(0.0)}; //!< Last RTT sample collected
211
212 Ptr<TcpRxBuffer> m_rxBuffer; //!< Rx buffer (reordering buffer)
213
215 UseEcn_t m_useEcn{Off}; //!< Socket ECN capability
216
217 EcnCodePoint_t m_ectCodePoint{Ect0}; //!< ECT code point to use
218
220 0}; //!< The number of bytes acked and sacked as indicated by the current ACK received. This
221 //!< is similar to acked_sacked variable in Linux
222
223 /**
224 * \brief Get cwnd in segments rather than bytes
225 *
226 * \return Congestion window in segments
227 */
229 {
230 return m_cWnd / m_segmentSize;
231 }
232
233 /**
234 * \brief Get slow start thresh in segments rather than bytes
235 *
236 * \return Slow start threshold in segments
237 */
239 {
240 return m_ssThresh / m_segmentSize;
241 }
242
243 /**
244 * Callback to send an empty packet
245 */
247};
248
249namespace TracedValueCallback
250{
251
252/**
253 * \ingroup tcp
254 * TracedValue Callback signature for TcpCongState_t
255 *
256 * \param [in] oldValue original value of the traced variable
257 * \param [in] newValue new value of the traced variable
258 */
259typedef void (*TcpCongState)(const TcpSocketState::TcpCongState_t oldValue,
260 const TcpSocketState::TcpCongState_t newValue);
261
262/**
263 * \ingroup tcp
264 * TracedValue Callback signature for EcnState_t
265 *
266 * \param [in] oldValue original value of the traced variable
267 * \param [in] newValue new value of the traced variable
268 */
269typedef void (*EcnState)(const TcpSocketState::EcnState_t oldValue,
270 const TcpSocketState::EcnState_t newValue);
271
272} // namespace TracedValueCallback
273
274} // namespace ns3
275
276#endif /* TCP_SOCKET_STATE_H */
Callback template class.
Definition: callback.h:438
Class for representing data rates.
Definition: data-rate.h:89
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
Data structure that records the congestion state of a connection.
EcnCodePoint_t
ECN code points.
uint32_t m_segmentSize
Segment size.
TcpCAEvent_t
Congestion avoidance events.
@ CA_EVENT_ECN_IS_CE
received CE marked IP packet.
@ CA_EVENT_ECN_NO_CE
ECT set, but not CE marked.
@ CA_EVENT_DELAYED_ACK
Delayed ack is sent.
@ CA_EVENT_NON_DELAYED_ACK
Non-delayed ack is sent.
@ CA_EVENT_COMPLETE_CWR
end of congestion recovery
@ CA_EVENT_CWND_RESTART
congestion window restart.
@ CA_EVENT_LOSS
loss timeout
@ CA_EVENT_TX_START
first transmit when no packets in flight
Time m_minRtt
Minimum RTT observed throughout the connection.
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
uint32_t m_initialSsThresh
Initial Slow Start Threshold value.
EcnMode_t m_ecnMode
ECN mode.
Callback< void, uint8_t > m_sendEmptyPacketCallback
Callback to send an empty packet.
TracedValue< DataRate > m_pacingRate
Current Pacing rate.
UseEcn_t
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn.
@ AcceptOnly
Enable only when the peer endpoint is ECN capable.
TracedValue< TcpCongState_t > m_congState
State in the Congestion state machine.
bool m_paceInitialWindow
Enable/Disable pacing for the initial window.
DataRate m_maxPacingRate
Max Pacing rate.
UseEcn_t m_useEcn
Socket ECN capability.
bool m_pacing
Pacing status.
static TypeId GetTypeId()
Get the type ID.
bool m_isRetransDataAcked
Retransmitted data is ACKed if true.
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
static const char *const TcpCongStateName[TcpSocketState::CA_LAST_STATE]
Literal names of TCP states for use in log messages.
TcpCongState_t
Definition of the Congestion state machine.
@ CA_RECOVERY
CWND was reduced, we are fast-retransmitting.
@ CA_DISORDER
In all the respects it is "Open", but requires a bit more attention.
@ CA_LAST_STATE
Used only in debug messages.
@ CA_CWR
cWnd was reduced due to some congestion notification event, such as ECN, ICMP source quench,...
@ CA_LOSS
CWND was reduced due to RTO timeout or SACK reneging.
@ CA_OPEN
Normal state, no dubious events.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
@ DctcpEcn
ECN functionality as described in RFC 8257.
@ ClassicEcn
ECN functionality as described in RFC 3168.
TracedValue< uint32_t > m_cWnd
Congestion window.
uint32_t m_initialCWnd
Initial cWnd value.
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
TracedValue< Time > m_lastRtt
Last RTT sample collected.
EcnState_t
Definition of the Ecn state machine.
@ ECN_CWR_SENT
Sender has reduced the congestion window, and sent a packet with CWR bit set in TCP header.
@ ECN_DISABLED
ECN disabled traffic.
@ ECN_ECE_RCVD
Last ACK received had ECE bit set in TCP header.
@ ECN_IDLE
ECN is enabled but currently there is no action pertaining to ECE or CWR to be taken.
@ ECN_CE_RCVD
Last packet received had CE bit set in IP header.
@ ECN_SENDING_ECE
Receiver sends an ACK with ECE bit set in TCP header.
TcpSocketState()
TcpSocketState Constructor.
TracedValue< uint32_t > m_bytesInFlight
Bytes in flight.
TracedValue< uint32_t > m_cWndInfl
Inflated congestion window trace (used only for backward compatibility purpose)
uint32_t GetSsThreshInSegments() const
Get slow start thresh in segments rather than bytes.
uint16_t m_pacingCaRatio
CA pacing ratio.
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
uint32_t m_lastAckedSackedBytes
The number of bytes acked and sacked as indicated by the current ACK received.
uint16_t m_pacingSsRatio
SS pacing ratio.
static const char *const EcnStateName[TcpSocketState::ECN_CWR_SENT+1]
Literal names of ECN states for use in log messages.
TracedValue< EcnState_t > m_ecnState
Current ECN State, represented as combination of EcnState values.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
EcnCodePoint_t m_ectCodePoint
ECT code point to use.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:297
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
void(* TcpCongState)(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
TracedValue Callback signature for TcpCongState_t.
void(* EcnState)(const TcpSocketState::EcnState_t oldValue, const TcpSocketState::EcnState_t newValue)
TracedValue Callback signature for EcnState_t.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.