A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-socket.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 * 2007 INRIA
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: George F. Riley<riley@ece.gatech.edu>
8 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9 */
10
11#ifndef TCP_SOCKET_H
12#define TCP_SOCKET_H
13
14#include "ns3/callback.h"
15#include "ns3/nstime.h"
16#include "ns3/object.h"
17#include "ns3/ptr.h"
18#include "ns3/socket.h"
19#include "ns3/traced-callback.h"
20
21namespace ns3
22{
23
24class Node;
25class Packet;
26
27/**
28 * @ingroup socket
29 * @ingroup tcp
30 *
31 * @brief (abstract) base class of all TcpSockets
32 *
33 * This class exists solely for hosting TcpSocket attributes that can
34 * be reused across different implementations.
35 */
36class TcpSocket : public Socket
37{
38 public:
39 /**
40 * Get the type ID.
41 * @brief Get the type ID.
42 * @return the object TypeId
43 */
44 static TypeId GetTypeId();
45
46 TcpSocket();
47 ~TcpSocket() override;
48
49 /**
50 * @ingroup tcp
51 * @brief Names of the 11 TCP states
52 *
53 */
55 {
56 CLOSED = 0, /**< Socket is finished */
57 LISTEN, /**< Listening for a connection */
58 SYN_SENT, /**< Sent a connection request, waiting for ack */
59 SYN_RCVD, /**< Received a connection request, sent ack,
60 * waiting for final ack in three-way handshake. */
61 ESTABLISHED, /**< Connection established */
62 CLOSE_WAIT, /**< Remote side has shutdown and is waiting for
63 * us to finish writing our data and to shutdown
64 * (we have to close() to move on to LAST_ACK) */
65 LAST_ACK, /**< Our side has shutdown after remote has
66 * shutdown. There may still be data in our
67 * buffer that we have to finish sending */
68 FIN_WAIT_1, /**< Our side has shutdown, waiting to complete
69 * transmission of remaining buffered data */
70 FIN_WAIT_2, /**< All buffered data sent, waiting for remote to shutdown */
71 CLOSING, /**< Both sides have shutdown but we still have
72 * data we have to finish sending */
73 TIME_WAIT, /**< Timeout to catch resent junk before entering
74 * closed, can only be entered from FIN_WAIT2
75 * or CLOSING. Required because the other end
76 * may not have gotten our last ACK causing it
77 * to retransmit the data packet (which we ignore) */
78 LAST_STATE /**< Last state, used only in debug messages */
79 };
80
81 /**
82 * @brief Literal names of TCP states for use in log messages
83 */
84 static const char* const TcpStateName[TcpSocket::LAST_STATE];
85
86 private:
87 // Indirect the attribute setting and getting through private virtual methods
88
89 /**
90 * @brief Set the send buffer size.
91 * @param size the buffer size (in bytes)
92 */
93 virtual void SetSndBufSize(uint32_t size) = 0;
94
95 /**
96 * @brief Get the send buffer size.
97 * @returns the buffer size (in bytes)
98 */
99 virtual uint32_t GetSndBufSize() const = 0;
100
101 /**
102 * @brief Set the receive buffer size.
103 * @param size the buffer size (in bytes)
104 */
105 virtual void SetRcvBufSize(uint32_t size) = 0;
106
107 /**
108 * @brief Get the receive buffer size.
109 * @returns the buffer size (in bytes)
110 */
111 virtual uint32_t GetRcvBufSize() const = 0;
112
113 /**
114 * @brief Set the segment size.
115 * @param size the segment size (in bytes)
116 */
117 virtual void SetSegSize(uint32_t size) = 0;
118
119 /**
120 * @brief Get the segment size.
121 * @returns the segment size (in bytes)
122 */
123 virtual uint32_t GetSegSize() const = 0;
124
125 /**
126 * @brief Set the initial Slow Start Threshold.
127 * @param threshold the Slow Start Threshold (in bytes)
128 */
129 virtual void SetInitialSSThresh(uint32_t threshold) = 0;
130
131 /**
132 * @brief Get the initial Slow Start Threshold.
133 * @returns the Slow Start Threshold (in bytes)
134 */
135 virtual uint32_t GetInitialSSThresh() const = 0;
136
137 /**
138 * @brief Set the initial Congestion Window.
139 * @param cwnd the initial congestion window (in segments)
140 */
141 virtual void SetInitialCwnd(uint32_t cwnd) = 0;
142
143 /**
144 * @brief Get the initial Congestion Window.
145 * @returns the initial congestion window (in segments)
146 */
147 virtual uint32_t GetInitialCwnd() const = 0;
148
149 /**
150 * @brief Set the connection timeout.
151 * @param timeout the connection timeout
152 */
153 virtual void SetConnTimeout(Time timeout) = 0;
154
155 /**
156 * @brief Get the connection timeout.
157 * @returns the connection timeout
158 */
159 virtual Time GetConnTimeout() const = 0;
160
161 /**
162 * @brief Set the number of connection retries before giving up.
163 * @param count the number of connection retries
164 */
165 virtual void SetSynRetries(uint32_t count) = 0;
166
167 /**
168 * @brief Get the number of connection retries before giving up.
169 * @returns the number of connection retries
170 */
171 virtual uint32_t GetSynRetries() const = 0;
172
173 /**
174 * @brief Set the number of data transmission retries before giving up.
175 * @param retries the number of data transmission retries
176 */
177 virtual void SetDataRetries(uint32_t retries) = 0;
178
179 /**
180 * @brief Get the number of data transmission retries before giving up.
181 * @returns the number of data transmission retries
182 */
183 virtual uint32_t GetDataRetries() const = 0;
184
185 /**
186 * @brief Set the time to delay an ACK.
187 * @param timeout the time to delay an ACK
188 */
189 virtual void SetDelAckTimeout(Time timeout) = 0;
190
191 /**
192 * @brief Get the time to delay an ACK.
193 * @returns the time to delay an ACK
194 */
195 virtual Time GetDelAckTimeout() const = 0;
196
197 /**
198 * @brief Set the number of packet to fire an ACK before delay timeout.
199 * @param count the umber of packet to fire an ACK before delay timeout
200 */
201 virtual void SetDelAckMaxCount(uint32_t count) = 0;
202
203 /**
204 * @brief Get the number of packet to fire an ACK before delay timeout.
205 * @returns the number of packet to fire an ACK before delay timeout
206 */
207 virtual uint32_t GetDelAckMaxCount() const = 0;
208
209 /**
210 * @brief Enable/Disable Nagle's algorithm.
211 * @param noDelay true to DISABLE Nagle's algorithm
212 */
213 virtual void SetTcpNoDelay(bool noDelay) = 0;
214
215 /**
216 * @brief Check if Nagle's algorithm is enabled or not.
217 * @returns true if Nagle's algorithm is DISABLED
218 */
219 virtual bool GetTcpNoDelay() const = 0;
220
221 /**
222 * @brief Set the timeout for persistent connection
223 *
224 * When the timeout expires, send 1-byte data to probe for the window
225 * size at the receiver when the local knowledge tells that the
226 * receiver has zero window size
227 *
228 * @param timeout the persistent timeout
229 */
230 virtual void SetPersistTimeout(Time timeout) = 0;
231
232 /**
233 * @brief Get the timeout for persistent connection
234 *
235 * When the timeout expires, send 1-byte data to probe for the window
236 * size at the receiver when the local knowledge tells that the
237 * receiver has zero window size
238 *
239 * @returns the persistent timeout
240 */
241 virtual Time GetPersistTimeout() const = 0;
242};
243
244/**
245 * @ingroup tcp
246 * TracedValue Callback signature for TcpStates_t
247 *
248 * @param [in] oldValue original value of the traced variable
249 * @param [in] newValue new value of the traced variable
250 */
252 const TcpSocket::TcpStates_t newValue);
253
254} // namespace ns3
255
256#endif /* TCP_SOCKET_H */
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
(abstract) base class of all TcpSockets
Definition tcp-socket.h:37
virtual void SetInitialSSThresh(uint32_t threshold)=0
Set the initial Slow Start Threshold.
virtual uint32_t GetDataRetries() const =0
Get the number of data transmission retries before giving up.
virtual uint32_t GetRcvBufSize() const =0
Get the receive buffer size.
~TcpSocket() override
virtual uint32_t GetSndBufSize() const =0
Get the send buffer size.
virtual void SetRcvBufSize(uint32_t size)=0
Set the receive buffer size.
static const char *const TcpStateName[TcpSocket::LAST_STATE]
Literal names of TCP states for use in log messages.
Definition tcp-socket.h:84
virtual Time GetPersistTimeout() const =0
Get the timeout for persistent connection.
virtual uint32_t GetInitialCwnd() const =0
Get the initial Congestion Window.
virtual uint32_t GetDelAckMaxCount() const =0
Get the number of packet to fire an ACK before delay timeout.
virtual void SetDelAckMaxCount(uint32_t count)=0
Set the number of packet to fire an ACK before delay timeout.
virtual void SetPersistTimeout(Time timeout)=0
Set the timeout for persistent connection.
virtual Time GetDelAckTimeout() const =0
Get the time to delay an ACK.
virtual uint32_t GetSynRetries() const =0
Get the number of connection retries before giving up.
virtual uint32_t GetInitialSSThresh() const =0
Get the initial Slow Start Threshold.
virtual void SetSegSize(uint32_t size)=0
Set the segment size.
virtual void SetSndBufSize(uint32_t size)=0
Set the send buffer size.
virtual uint32_t GetSegSize() const =0
Get the segment size.
virtual void SetDataRetries(uint32_t retries)=0
Set the number of data transmission retries before giving up.
static TypeId GetTypeId()
Get the type ID.
Definition tcp-socket.cc:43
virtual void SetDelAckTimeout(Time timeout)=0
Set the time to delay an ACK.
virtual void SetConnTimeout(Time timeout)=0
Set the connection timeout.
virtual void SetTcpNoDelay(bool noDelay)=0
Enable/Disable Nagle's algorithm.
virtual void SetInitialCwnd(uint32_t cwnd)=0
Set the initial Congestion Window.
virtual bool GetTcpNoDelay() const =0
Check if Nagle's algorithm is enabled or not.
virtual void SetSynRetries(uint32_t count)=0
Set the number of connection retries before giving up.
virtual Time GetConnTimeout() const =0
Get the connection timeout.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TcpStates_t
Names of the 11 TCP states.
Definition tcp-socket.h:55
void(* TcpStatesTracedValueCallback)(const TcpSocket::TcpStates_t oldValue, const TcpSocket::TcpStates_t newValue)
TracedValue Callback signature for TcpStates_t.
Definition tcp-socket.h:251
@ ESTABLISHED
Connection established
Definition tcp-socket.h:61
@ FIN_WAIT_2
All buffered data sent, waiting for remote to shutdown.
Definition tcp-socket.h:70
@ LISTEN
Listening for a connection
Definition tcp-socket.h:57
@ LAST_STATE
Last state, used only in debug messages
Definition tcp-socket.h:78
@ CLOSE_WAIT
Remote side has shutdown and is waiting for us to finish writing our data and to shutdown (we have to...
Definition tcp-socket.h:62
@ SYN_SENT
Sent a connection request, waiting for ack
Definition tcp-socket.h:58
@ CLOSED
Socket is finished
Definition tcp-socket.h:56
@ FIN_WAIT_1
Our side has shutdown, waiting to complete transmission of remaining buffered data
Definition tcp-socket.h:68
@ TIME_WAIT
Timeout to catch resent junk before entering closed, can only be entered from FIN_WAIT2 or CLOSING.
Definition tcp-socket.h:73
@ SYN_RCVD
Received a connection request, sent ack, waiting for final ack in three-way handshake.
Definition tcp-socket.h:59
@ LAST_ACK
Our side has shutdown after remote has shutdown.
Definition tcp-socket.h:65
@ CLOSING
Both sides have shutdown but we still have data we have to finish sending
Definition tcp-socket.h:71
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Time timeout