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