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