A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-dctcp.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Shravya K.S. <shravya.ks0@gmail.com>
7 *
8 */
9
10#include "tcp-dctcp.h"
11
12#include "tcp-socket-state.h"
13
14#include "ns3/abort.h"
15#include "ns3/log.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("TcpDctcp");
21
23
24TypeId
26{
27 static TypeId tid =
28 TypeId("ns3::TcpDctcp")
30 .AddConstructor<TcpDctcp>()
31 .SetGroupName("Internet")
32 .AddAttribute("DctcpShiftG",
33 "Parameter G for updating dctcp_alpha",
34 DoubleValue(0.0625),
37 .AddAttribute("DctcpAlphaOnInit",
38 "Initial alpha value",
39 DoubleValue(1.0),
42 .AddAttribute("UseEct0",
43 "Use ECT(0) for ECN codepoint, if false use ECT(1)",
44 BooleanValue(true),
47 .AddTraceSource("CongestionEstimate",
48 "Update sender-side congestion estimate state",
50 "ns3::TcpDctcp::CongestionEstimateTracedCallback");
51 return tid;
52}
53
54std::string
56{
57 return "TcpDctcp";
58}
59
61 : TcpLinuxReno(),
62 m_ackedBytesEcn(0),
63 m_ackedBytesTotal(0),
64 m_priorRcvNxt(SequenceNumber32(0)),
65 m_priorRcvNxtFlag(false),
66 m_nextSeq(SequenceNumber32(0)),
67 m_nextSeqFlag(false),
68 m_ceState(false),
69 m_delayedAckReserved(false),
70 m_initialized(false)
71{
72 NS_LOG_FUNCTION(this);
73}
74
76 : TcpLinuxReno(sock),
77 m_ackedBytesEcn(sock.m_ackedBytesEcn),
78 m_ackedBytesTotal(sock.m_ackedBytesTotal),
79 m_priorRcvNxt(sock.m_priorRcvNxt),
80 m_priorRcvNxtFlag(sock.m_priorRcvNxtFlag),
81 m_alpha(sock.m_alpha),
82 m_nextSeq(sock.m_nextSeq),
83 m_nextSeqFlag(sock.m_nextSeqFlag),
84 m_ceState(sock.m_ceState),
85 m_delayedAckReserved(sock.m_delayedAckReserved),
86 m_g(sock.m_g),
87 m_useEct0(sock.m_useEct0),
88 m_initialized(sock.m_initialized)
89{
90 NS_LOG_FUNCTION(this);
91}
92
97
100{
101 NS_LOG_FUNCTION(this);
102 return CopyObject<TcpDctcp>(this);
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << tcb);
109 NS_LOG_INFO(this << "Enabling DctcpEcn for DCTCP");
110 tcb->m_useEcn = TcpSocketState::On;
111 tcb->m_ecnMode = TcpSocketState::DctcpEcn;
112 tcb->m_ectCodePoint = m_useEct0 ? TcpSocketState::Ect0 : TcpSocketState::Ect1;
114 m_initialized = true;
115}
116
117// Step 9, Section 3.3 of RFC 8257. GetSsThresh() is called upon
118// entering the CWR state, and then later, when CWR is exited,
119// cwnd is set to ssthresh (this value). bytesInFlight is ignored.
122{
123 NS_LOG_FUNCTION(this << tcb << bytesInFlight);
124 return static_cast<uint32_t>((1 - m_alpha / 2.0) * tcb->m_cWnd);
125}
126
127void
129{
130 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
131 m_ackedBytesTotal += segmentsAcked * tcb->m_segmentSize;
132 if (tcb->m_ecnState == TcpSocketState::ECN_ECE_RCVD)
133 {
134 m_ackedBytesEcn += segmentsAcked * tcb->m_segmentSize;
135 }
136 if (!m_nextSeqFlag)
137 {
138 m_nextSeq = tcb->m_nextTxSequence;
139 m_nextSeqFlag = true;
140 }
141 if (tcb->m_lastAckedSeq >= m_nextSeq)
142 {
143 double bytesEcn = 0.0; // Corresponds to variable M in RFC 8257
144 if (m_ackedBytesTotal > 0)
145 {
146 bytesEcn = static_cast<double>(m_ackedBytesEcn * 1.0 / m_ackedBytesTotal);
147 }
148 m_alpha = (1.0 - m_g) * m_alpha + m_g * bytesEcn;
150 NS_LOG_INFO(this << "bytesEcn " << bytesEcn << ", m_alpha " << m_alpha);
151 Reset(tcb);
152 }
153}
154
155void
157{
158 NS_LOG_FUNCTION(this << alpha);
159 NS_ABORT_MSG_IF(m_initialized, "DCTCP has already been initialized");
160 m_alpha = alpha;
161}
162
163void
165{
166 NS_LOG_FUNCTION(this << tcb);
167 m_nextSeq = tcb->m_nextTxSequence;
168 m_ackedBytesEcn = 0;
170}
171
172void
174{
175 NS_LOG_FUNCTION(this << tcb);
177 {
178 SequenceNumber32 tmpRcvNxt;
179 /* Save current NextRxSequence. */
180 tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
181
182 /* Generate previous ACK without ECE */
183 tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
184 tcb->m_sendEmptyPacketCallback(TcpHeader::ACK);
185
186 /* Recover current RcvNxt. */
187 tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
188 }
189
191 {
192 m_priorRcvNxtFlag = true;
193 }
194 m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
195 m_ceState = true;
196 tcb->m_ecnState = TcpSocketState::ECN_CE_RCVD;
197}
198
199void
201{
202 NS_LOG_FUNCTION(this << tcb);
204 {
205 SequenceNumber32 tmpRcvNxt;
206 /* Save current NextRxSequence. */
207 tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
208
209 /* Generate previous ACK with ECE */
210 tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
211 tcb->m_sendEmptyPacketCallback(TcpHeader::ACK | TcpHeader::ECE);
212
213 /* Recover current RcvNxt. */
214 tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
215 }
216
218 {
219 m_priorRcvNxtFlag = true;
220 }
221 m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
222 m_ceState = false;
223
224 if (tcb->m_ecnState.Get() == TcpSocketState::ECN_CE_RCVD ||
225 tcb->m_ecnState.Get() == TcpSocketState::ECN_SENDING_ECE)
226 {
227 tcb->m_ecnState = TcpSocketState::ECN_IDLE;
228 }
229}
230
231void
233{
234 NS_LOG_FUNCTION(this << tcb << event);
235 switch (event)
236 {
239 {
241 }
242 break;
245 {
246 m_delayedAckReserved = false;
247 }
248 break;
249 default:
250 /* Don't care for the rest. */
251 break;
252 }
253}
254
255void
257{
258 NS_LOG_FUNCTION(this << tcb << event);
259 switch (event)
260 {
262 CeState0to1(tcb);
263 break;
265 CeState1to0(tcb);
266 break;
269 UpdateAckReserved(tcb, event);
270 break;
271 default:
272 /* Don't care for the rest. */
273 break;
274 }
275}
276
277} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
An implementation of DCTCP.
Definition tcp-dctcp.h:32
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition tcp-dctcp.cc:99
static TypeId GetTypeId()
Get the type ID.
Definition tcp-dctcp.cc:25
SequenceNumber32 m_priorRcvNxt
Sequence number of the first missing byte in data.
Definition tcp-dctcp.h:125
double m_alpha
Parameter used to estimate the amount of network congestion.
Definition tcp-dctcp.h:127
double m_g
Estimation gain.
Definition tcp-dctcp.h:133
bool m_initialized
Whether DCTCP has been initialized.
Definition tcp-dctcp.h:135
bool m_ceState
DCTCP Congestion Experienced state.
Definition tcp-dctcp.h:131
bool m_priorRcvNxtFlag
Variable used in setting the value of m_priorRcvNxt for first time.
Definition tcp-dctcp.h:126
void InitializeDctcpAlpha(double alpha)
Initialize the value of m_alpha.
Definition tcp-dctcp.cc:156
SequenceNumber32 m_nextSeq
TCP sequence number threshold for beginning a new observation window.
Definition tcp-dctcp.h:129
uint32_t m_ackedBytesEcn
Number of acked bytes which are marked.
Definition tcp-dctcp.h:123
void Init(Ptr< TcpSocketState > tcb) override
Set configuration required by congestion control algorithm, This method will force DctcpEcn mode and ...
Definition tcp-dctcp.cc:106
TcpDctcp()
Create an unbound tcp socket.
Definition tcp-dctcp.cc:60
void Reset(Ptr< TcpSocketState > tcb)
Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq.
Definition tcp-dctcp.cc:164
uint32_t m_ackedBytesTotal
Total number of acked bytes.
Definition tcp-dctcp.h:124
bool m_nextSeqFlag
Variable used in setting the value of m_nextSeq for first time.
Definition tcp-dctcp.h:130
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition tcp-dctcp.cc:55
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition tcp-dctcp.cc:121
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition tcp-dctcp.cc:128
void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event) override
Trigger events/calculations on occurrence of congestion window event.
Definition tcp-dctcp.cc:256
void CeState1to0(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to false.
Definition tcp-dctcp.cc:200
void UpdateAckReserved(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Updates the value of m_delayedAckReserved.
Definition tcp-dctcp.cc:232
bool m_delayedAckReserved
Delayed Ack state.
Definition tcp-dctcp.h:132
TracedCallback< uint32_t, uint32_t, double > m_traceCongestionEstimate
Callback pointer for congestion state update.
Definition tcp-dctcp.h:139
bool m_useEct0
Use ECT(0) for ECN codepoint.
Definition tcp-dctcp.h:134
void CeState0to1(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to true.
Definition tcp-dctcp.cc:173
~TcpDctcp() override
Destructor.
Definition tcp-dctcp.cc:93
Reno congestion control algorithm.
void SetSuppressIncreaseIfCwndLimited(bool value)
TcpSocketBase follows the Linux way of setting a flag 'isCwndLimited' when BytesInFlight() >= 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.
@ DctcpEcn
ECN functionality as described in RFC 8257.
@ 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.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32