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