LEFT | RIGHT |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2007 Georgia Tech Research Corporation |
| 4 * Copyright (c) 2010 Adrian Sai-wah Tam |
| 5 * |
| 6 * This program is free software; you can redistribute it and/or modify |
| 7 * it under the terms of the GNU General Public License version 2 as |
| 8 * published by the Free Software Foundation; |
| 9 * |
| 10 * This program is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 * GNU General Public License for more details. |
| 14 * |
| 15 * You should have received a copy of the GNU General Public License |
| 16 * along with this program; if not, write to the Free Software |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 * |
| 19 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com> |
| 20 */ |
| 21 #ifndef TCP_SOCKET_BASE_H |
| 22 #define TCP_SOCKET_BASE_H |
| 23 |
| 24 #include <stdint.h> |
| 25 #include <queue> |
| 26 #include "ns3/callback.h" |
| 27 #include "ns3/traced-value.h" |
| 28 #include "ns3/tcp-socket.h" |
| 29 #include "ns3/ptr.h" |
| 30 #include "ns3/ipv4-address.h" |
| 31 #include "ns3/ipv4-header.h" |
| 32 #include "ns3/ipv4-interface.h" |
| 33 #include "ns3/ipv6-header.h" |
| 34 #include "ns3/ipv6-interface.h" |
| 35 #include "ns3/event-id.h" |
| 36 #include "tcp-tx-buffer.h" |
| 37 #include "tcp-rx-buffer.h" |
| 38 #include "rtt-estimator.h" |
| 39 |
| 40 namespace ns3 { |
| 41 |
| 42 class Ipv4EndPoint; |
| 43 class Ipv6EndPoint; |
| 44 class Node; |
| 45 class Packet; |
| 46 class TcpL4Protocol; |
| 47 class TcpHeader; |
| 48 class TcpCongestionOps; |
| 49 |
| 50 /** |
| 51 * \ingroup tcp |
| 52 * |
| 53 * \brief Helper class to store RTT measurements |
| 54 */ |
| 55 class RttHistory |
| 56 { |
| 57 public: |
| 58 /** |
| 59 * \brief Constructor - builds an RttHistory with the given parameters |
| 60 * \param s First sequence number in packet sent |
| 61 * \param c Number of bytes sent |
| 62 * \param t Time this one was sent |
| 63 */ |
| 64 RttHistory (SequenceNumber32 s, uint32_t c, Time t); |
| 65 /** |
| 66 * \brief Copy constructor |
| 67 * \param h the object to copy |
| 68 */ |
| 69 RttHistory (const RttHistory& h); // Copy constructor |
| 70 public: |
| 71 SequenceNumber32 seq; //!< First sequence number in packet sent |
| 72 uint32_t count; //!< Number of bytes sent |
| 73 Time time; //!< Time this one was sent |
| 74 bool retx; //!< True if this has been retransmitted |
| 75 }; |
| 76 |
| 77 /// Container for RttHistory objects |
| 78 typedef std::deque<RttHistory> RttHistory_t; |
| 79 |
| 80 /** |
| 81 * \brief Data structure that records the congestion state of a connection |
| 82 * |
| 83 * In this data structure, basic informations that should be passed between |
| 84 * socket and the congestion control algorithm are saved. Through the code, |
| 85 * it will be referred as Transmission Control Block (TCB), but there are some |
| 86 * differencies. In the RFCs, the TCB contains all the variables that defines |
| 87 * a connection, while we preferred to maintain in this class only the values |
| 88 * that should be exchanged between socket and other parts, like congestion |
| 89 * control algorithms. |
| 90 * |
| 91 */ |
| 92 class TcpSocketState : public Object |
| 93 { |
| 94 public: |
| 95 /** |
| 96 * Get the type ID. |
| 97 * \brief Get the type ID. |
| 98 * \return the object TypeId |
| 99 */ |
| 100 static TypeId GetTypeId (void); |
| 101 |
| 102 TcpSocketState (); |
| 103 |
| 104 /** |
| 105 * \brief Copy constructor. |
| 106 * \param other object to copy. |
| 107 */ |
| 108 TcpSocketState (const TcpSocketState &other); |
| 109 |
| 110 /** |
| 111 * \brief Definition of the Congestion state machine |
| 112 * |
| 113 * The design of this state machine is taken from Linux v4.0, but it has been |
| 114 * maintained in the Linux mainline from ages. It basically avoids to maintain |
| 115 * a lot of boolean variables, and it allows to check the transitions from |
| 116 * different algorithm in a cleaner way. |
| 117 * |
| 118 * These states represent the situation from a congestion control point of vie
w: |
| 119 * in fact, apart the CA_OPEN state, the other states represent a situation in |
| 120 * which there is a congestion, and different actions should be taken, |
| 121 * depending on the case. |
| 122 * |
| 123 */ |
| 124 typedef enum |
| 125 { |
| 126 CA_OPEN, /**< Normal state, no dubious events */ |
| 127 CA_DISORDER, /**< In all the respects it is "Open", |
| 128 * but requires a bit more attention. It is entered when |
| 129 * we see some SACKs or dupacks. It is split of "Open" */ |
| 130 CA_CWR, /**< cWnd was reduced due to some Congestion Notification even
t. |
| 131 * It can be ECN, ICMP source quench, local device congestio
n. |
| 132 * Not used in NS-3 right now. */ |
| 133 CA_RECOVERY, /**< CWND was reduced, we are fast-retransmitting. */ |
| 134 CA_LOSS, /**< CWND was reduced due to RTO timeout or SACK reneging. */ |
| 135 CA_LAST_STATE /**< Used only in debug messages */ |
| 136 } TcpCongState_t; |
| 137 |
| 138 /** |
| 139 * \brief Definition of the Ecn state machine |
| 140 * |
| 141 */ |
| 142 typedef enum· |
| 143 { |
| 144 ECN_DISABLED = 0, /**< ECN disabled traffic
*/· |
| 145 ECN_IDLE, /**< ECN is enabled but currently there is no action pert
aining to ECE or CWR to be taken */· |
| 146 ECN_CE_RCVD, /**< This state indicates that the receiver has received a
packet with CE bit set in IP header */ |
| 147 ECN_ECE_SENT, /**< This state indicates that the receiver has sent an AC
K with ECE bit set in TCP header */ |
| 148 ECN_ECE_RCVD, /**< This state indicates that the sender has received an
ACK with ECE bit set in TCP header */ |
| 149 ECN_CWR_SENT /**< This state indicates that the sender has reduced the
congestion window, and sent a packet····· |
| 150 * with CWR bit set in TCP header
*/ |
| 151 } EcnState_t; |
| 152 |
| 153 /** |
| 154 * \ingroup tcp |
| 155 * TracedValue Callback signature for TcpCongState_t |
| 156 * |
| 157 * \param [in] oldValue original value of the traced variable |
| 158 * \param [in] newValue new value of the traced variable |
| 159 */ |
| 160 typedef void (* TcpCongStatesTracedValueCallback)(const TcpCongState_t oldValu
e, |
| 161 const TcpCongState_t newValu
e); |
| 162 |
| 163 /** |
| 164 * \ingroup tcp |
| 165 * TracedValue Callback signature for EcnState_t |
| 166 * |
| 167 * \param [in] oldValue original value of the traced variable |
| 168 * \param [in] newValue new value of the traced variable |
| 169 */ |
| 170 typedef void (* EcnStatesTracedValueCallback)(const EcnState_t oldValue, |
| 171 const EcnState_t newValue); |
| 172 |
| 173 /** |
| 174 * \brief Literal names of TCP states for use in log messages |
| 175 */ |
| 176 static const char* const TcpCongStateName[TcpSocketState::CA_LAST_STATE]; |
| 177 |
| 178 /** |
| 179 * \brief Literal names of ECN states for use in log messages |
| 180 */ |
| 181 static const char* const EcnStateName[TcpSocketState::ECN_CWR_SENT+1]; |
| 182 ·· |
| 183 |
| 184 // Congestion control |
| 185 TracedValue<uint32_t> m_cWnd; //!< Congestion window |
| 186 TracedValue<uint32_t> m_ssThresh; //!< Slow start threshold |
| 187 uint32_t m_initialCWnd; //!< Initial cWnd value |
| 188 uint32_t m_initialSsThresh; //!< Initial Slow Start Threshold va
lue |
| 189 |
| 190 // Segment |
| 191 uint32_t m_segmentSize; //!< Segment size |
| 192 SequenceNumber32 m_lastAckedSeq; //!< Last sequence ACKed |
| 193 |
| 194 TracedValue<TcpCongState_t> m_congState; //!< State in the Congestion state
machine |
| 195 TracedValue<EcnState_t> m_ecnState; //!< Current ECN State, represented
as combination of EcnState values |
| 196 TracedValue<SequenceNumber32> m_highTxMark; //!< Highest seqno ever sent, rega
rdless of ReTx |
| 197 TracedValue<SequenceNumber32> m_nextTxSequence; //!< Next seqnum to be sent (S
ND.NXT), ReTx pushes it back |
| 198 |
| 199 uint32_t m_rcvTimestampValue; //!< Receiver Timestamp value· |
| 200 uint32_t m_rcvTimestampEchoReply; //!< Sender Timestamp echoed b
y the receiver |
| 201 |
| 202 /** |
| 203 * \brief Get cwnd in segments rather than bytes |
| 204 * |
| 205 * \return Congestion window in segments |
| 206 */ |
| 207 uint32_t GetCwndInSegments () const |
| 208 { |
| 209 return m_cWnd / m_segmentSize; |
| 210 } |
| 211 |
| 212 /** |
| 213 * \brief Get slow start thresh in segments rather than bytes |
| 214 * |
| 215 * \return Slow start threshold in segments |
| 216 */ |
| 217 uint32_t GetSsThreshInSegments () const |
| 218 { |
| 219 return m_ssThresh / m_segmentSize; |
| 220 } |
| 221 }; |
| 222 |
| 223 /** |
| 224 * \ingroup socket |
| 225 * \ingroup tcp |
| 226 * |
| 227 * \brief A base class for implementation of a stream socket using TCP. |
| 228 * |
| 229 * This class contains the essential components of TCP, as well as a sockets |
| 230 * interface for upper layers to call. This class provides connection orientatio
n |
| 231 * and sliding window flow control; congestion control is delegated to subclasse
s |
| 232 * of TcpCongestionOps. Part of TcpSocketBase is modified from the original |
| 233 * NS-3 TCP socket implementation (TcpSocketImpl) by |
| 234 * Raj Bhattacharjea <raj.b@gatech.edu> of Georgia Tech. |
| 235 * |
| 236 * For IPv4 packets, the TOS set for the socket is used. The Bind and Connect |
| 237 * operations set the TOS for the socket to the value specified in the provided |
| 238 * address. A SocketIpTos tag is only added to the packet if the resulting |
| 239 * TOS is non-null. |
| 240 * Each packet is assigned the priority set for the socket. Setting a TOS |
| 241 * for a socket also sets a priority for the socket (according to the |
| 242 * Socket::IpTos2Priority function). A SocketPriority tag is only added to the |
| 243 * packet if the priority is non-null. |
| 244 * |
| 245 * Congestion state machine |
| 246 * --------------------------- |
| 247 * |
| 248 * The socket maintains two state machines; the TCP one, and another called |
| 249 * "Congestion state machine", which keeps track of the phase we are in. Current
ly, |
| 250 * ns-3 manages the states: |
| 251 * |
| 252 * - CA_OPEN |
| 253 * - CA_DISORDER |
| 254 * - CA_RECOVERY |
| 255 * - CA_LOSS |
| 256 * |
| 257 * Another one (CA_CWR) is present but not used. For more information, see |
| 258 * the TcpCongState_t documentation. |
| 259 * |
| 260 * Congestion control interface |
| 261 * --------------------------- |
| 262 * |
| 263 * Congestion control, unlike older releases of ns-3, has been split from |
| 264 * TcpSocketBase. In particular, each congestion control is now a subclass of |
| 265 * the main TcpCongestionOps class. Switching between congestion algorithm is |
| 266 * now a matter of setting a pointer into the TcpSocketBase class. The idea |
| 267 * and the interfaces are inspired by the Linux operating system, and in |
| 268 * particular from the structure tcp_congestion_ops. |
| 269 * |
| 270 * Transmission Control Block (TCB) |
| 271 * -------------------------------- |
| 272 * |
| 273 * The variables needed to congestion control classes to operate correctly have |
| 274 * been moved inside the TcpSocketState class. It contains information on the |
| 275 * congestion window, slow start threshold, segment size and the state of the |
| 276 * Congestion state machine. |
| 277 * |
| 278 * To track the trace inside the TcpSocketState class, a "forward" technique is |
| 279 * used, which consists in chaining callbacks from TcpSocketState to TcpSocketBa
se |
| 280 * (see for example cWnd trace source). |
| 281 * |
| 282 * Fast retransmit |
| 283 * ---------------- |
| 284 * |
| 285 * The fast retransmit enhancement is introduced in RFC 2581 and updated in |
| 286 * RFC 5681. It reduces the time a sender waits before retransmitting |
| 287 * a lost segment, through the assumption that if it receives a certain number |
| 288 * of duplicate ACKs, a segment has been lost and it can be retransmitted. |
| 289 * Usually, it is coupled with the Limited Transmit algorithm, defined in |
| 290 * RFC 3042. |
| 291 * |
| 292 * In ns-3, these algorithms are included in this class, and it is implemented i
nside |
| 293 * the ProcessAck method. The attribute which manages the number of dup ACKs |
| 294 * necessary to start the fast retransmit algorithm is named "ReTxThreshold", |
| 295 * and its default value is 3, while the Limited Transmit one can be enabled |
| 296 * by setting the attribute "LimitedTransmit" to true. Before entering the |
| 297 * recovery phase, the method EnterRecovery is called. |
| 298 * |
| 299 * Fast recovery |
| 300 * ------------- |
| 301 * |
| 302 * The fast recovery algorithm is introduced RFC 2001, and it |
| 303 * avoids to reset cWnd to 1 segment after sensing a loss on the channel. Instea
d, |
| 304 * the slow start threshold is halved, and the cWnd is set equal to such value, |
| 305 * plus segments for the cWnd inflation. |
| 306 * |
| 307 * The algorithm is implemented in the ProcessAck method. |
| 308 * |
| 309 * RTO expiration |
| 310 * -------------- |
| 311 * |
| 312 * When the Retransmission Time Out expires, the TCP faces a big performance |
| 313 * drop. The expiration event is managed in ReTxTimeout method, that basically |
| 314 * set the cWnd to 1 segment and start "from scratch" again. |
| 315 * |
| 316 * Options management |
| 317 * ------------------ |
| 318 * |
| 319 * SYN and SYN-ACK options, which are allowed only at the beginning of the |
| 320 * connection, are managed in the DoForwardUp and SendEmptyPacket methods. |
| 321 * To read all others, we have set up a cycle inside ReadOptions. For adding |
| 322 * them, there is no a unique place, since the options (and the information |
| 323 * available to build them) are scattered around the code. For instance, |
| 324 * the SACK option is built in SendEmptyPacket only under certain conditions. |
| 325 * |
| 326 * SACK |
| 327 * ---- |
| 328 * |
| 329 * The SACK generation/management is delegated to the buffer classes, namely |
| 330 * TcpTxBuffer and TcpRxBuffer. Please take a look on their documentation if |
| 331 * you need more informations. |
| 332 * |
| 333 */ |
| 334 class TcpSocketBase : public TcpSocket |
| 335 { |
| 336 public: |
| 337 /** |
| 338 * Get the type ID. |
| 339 * \brief Get the type ID. |
| 340 * \return the object TypeId |
| 341 */ |
| 342 static TypeId GetTypeId (void); |
| 343 |
| 344 /** |
| 345 * \brief Get the instance TypeId |
| 346 * \return the instance TypeId |
| 347 */ |
| 348 virtual TypeId GetInstanceTypeId () const; |
| 349 |
| 350 /** |
| 351 * \brief TcpGeneralTest friend class (for tests). |
| 352 * \relates TcpGeneralTest |
| 353 */ |
| 354 friend class TcpGeneralTest; |
| 355 |
| 356 /** |
| 357 * Create an unbound TCP socket |
| 358 */ |
| 359 TcpSocketBase (void); |
| 360 |
| 361 /** |
| 362 * Clone a TCP socket, for use upon receiving a connection request in LISTEN s
tate |
| 363 * |
| 364 * \param sock the original Tcp Socket |
| 365 */ |
| 366 TcpSocketBase (const TcpSocketBase& sock); |
| 367 virtual ~TcpSocketBase (void); |
| 368 |
| 369 // Set associated Node, TcpL4Protocol, RttEstimator to this socket |
| 370 |
| 371 /** |
| 372 * \brief Set the associated node. |
| 373 * \param node the node |
| 374 */ |
| 375 virtual void SetNode (Ptr<Node> node); |
| 376 |
| 377 /** |
| 378 * \brief Set the associated TCP L4 protocol. |
| 379 * \param tcp the TCP L4 protocol |
| 380 */ |
| 381 virtual void SetTcp (Ptr<TcpL4Protocol> tcp); |
| 382 |
| 383 /** |
| 384 * \brief Set the associated RTT estimator. |
| 385 * \param rtt the RTT estimator |
| 386 */ |
| 387 virtual void SetRtt (Ptr<RttEstimator> rtt); |
| 388 |
| 389 /** |
| 390 * \brief Sets the Minimum RTO. |
| 391 * \param minRto The minimum RTO. |
| 392 */ |
| 393 void SetMinRto (Time minRto); |
| 394 |
| 395 /** |
| 396 * \brief Get the Minimum RTO. |
| 397 * \return The minimum RTO. |
| 398 */ |
| 399 Time GetMinRto (void) const; |
| 400 |
| 401 /** |
| 402 * \brief Sets the Clock Granularity (used in RTO calcs). |
| 403 * \param clockGranularity The Clock Granularity |
| 404 */ |
| 405 void SetClockGranularity (Time clockGranularity); |
| 406 |
| 407 /** |
| 408 * \brief Get the Clock Granularity (used in RTO calcs). |
| 409 * \return The Clock Granularity. |
| 410 */ |
| 411 Time GetClockGranularity (void) const; |
| 412 |
| 413 /** |
| 414 * \brief Get a pointer to the Tx buffer |
| 415 * \return a pointer to the tx buffer |
| 416 */ |
| 417 Ptr<TcpTxBuffer> GetTxBuffer (void) const; |
| 418 |
| 419 /** |
| 420 * \brief Get a pointer to the Rx buffer |
| 421 * \return a pointer to the rx buffer |
| 422 */ |
| 423 Ptr<TcpRxBuffer> GetRxBuffer (void) const; |
| 424 |
| 425 /** |
| 426 * \brief Callback pointer for cWnd trace chaining |
| 427 */ |
| 428 TracedCallback<uint32_t, uint32_t> m_cWndTrace; |
| 429 |
| 430 /** |
| 431 * \brief Callback pointer for ssTh trace chaining |
| 432 */ |
| 433 TracedCallback<uint32_t, uint32_t> m_ssThTrace; |
| 434 |
| 435 /** |
| 436 * \brief Callback pointer for congestion state trace chaining |
| 437 */ |
| 438 TracedCallback<TcpSocketState::TcpCongState_t, TcpSocketState::TcpCongState_t>
m_congStateTrace; |
| 439 · |
| 440 /** |
| 441 * \brief Callback pointer for congestion state trace chaining |
| 442 */ |
| 443 TracedCallback<TcpSocketState::EcnState_t, TcpSocketState::EcnState_t> m_ecnSt
ateTrace; |
| 444 |
| 445 /** |
| 446 * \brief Callback pointer for high tx mark chaining |
| 447 */ |
| 448 TracedCallback <SequenceNumber32, SequenceNumber32> m_highTxMarkTrace; |
| 449 |
| 450 /** |
| 451 * \brief Callback pointer for next tx sequence chaining |
| 452 */ |
| 453 TracedCallback<SequenceNumber32, SequenceNumber32> m_nextTxSequenceTrace; |
| 454 |
| 455 /** |
| 456 * \brief Callback function to hook to TcpSocketState congestion window |
| 457 * \param oldValue old cWnd value |
| 458 * \param newValue new cWnd value |
| 459 */ |
| 460 void UpdateCwnd (uint32_t oldValue, uint32_t newValue); |
| 461 |
| 462 /** |
| 463 * \brief Callback function to hook to TcpSocketState slow start threshold |
| 464 * \param oldValue old ssTh value |
| 465 * \param newValue new ssTh value |
| 466 */ |
| 467 void UpdateSsThresh (uint32_t oldValue, uint32_t newValue); |
| 468 |
| 469 /** |
| 470 * \brief Callback function to hook to TcpSocketState congestion state |
| 471 * \param oldValue old congestion state value |
| 472 * \param newValue new congestion state value |
| 473 */ |
| 474 void UpdateCongState (TcpSocketState::TcpCongState_t oldValue, |
| 475 TcpSocketState::TcpCongState_t newValue); |
| 476 |
| 477 /** |
| 478 * \brief Callback function to hook to EcnState state |
| 479 * \param oldValue old ecn state value |
| 480 * \param newValue new ecn state value |
| 481 */ |
| 482 void UpdateEcnState (TcpSocketState::EcnState_t oldValue, |
| 483 TcpSocketState::EcnState_t newValue); |
| 484 |
| 485 /** |
| 486 * \brief Callback function to hook to TcpSocketState high tx mark |
| 487 * \param oldValue old high tx mark |
| 488 * \param newValue new high tx mark |
| 489 */ |
| 490 void UpdateHighTxMark (SequenceNumber32 oldValue, SequenceNumber32 newValue); |
| 491 |
| 492 /** |
| 493 * \brief Callback function to hook to TcpSocketState next tx sequence |
| 494 * \param oldValue old nextTxSeq value |
| 495 * \param newValue new nextTxSeq value |
| 496 */ |
| 497 void UpdateNextTxSequence (SequenceNumber32 oldValue, SequenceNumber32 newValu
e); |
| 498 |
| 499 /** |
| 500 * \brief Install a congestion control algorithm on this socket |
| 501 * |
| 502 * \param algo Algorithm to be installed |
| 503 */ |
| 504 void SetCongestionControlAlgorithm (Ptr<TcpCongestionOps> algo); |
| 505 |
| 506 /** |
| 507 * \brief Sets the variable m_ecn true to use ECN functionality |
| 508 */ |
| 509 void SetEcn(); |
| 510 |
| 511 // Necessary implementations of null functions from ns3::Socket |
| 512 virtual enum SocketErrno GetErrno (void) const; // returns m_errno |
| 513 virtual enum SocketType GetSocketType (void) const; // returns socket type |
| 514 virtual Ptr<Node> GetNode (void) const; // returns m_node |
| 515 virtual int Bind (void); // Bind a socket by setting up endpoint in TcpL4Pr
otocol |
| 516 virtual int Bind6 (void); // Bind a socket by setting up endpoint in TcpL4P
rotocol |
| 517 virtual int Bind (const Address &address); // ... endpoint of specific
addr or port |
| 518 virtual int Connect (const Address &address); // Setup endpoint and call
ProcessAction() to connect |
| 519 virtual int Listen (void); // Verify the socket is in a correct state and cal
l ProcessAction() to listen |
| 520 virtual int Close (void); // Close by app: Kill socket upon tx buffer emptie
d |
| 521 virtual int ShutdownSend (void); // Assert the m_shutdownSend flag to preve
nt send to network |
| 522 virtual int ShutdownRecv (void); // Assert the m_shutdownRecv flag to preve
nt forward to app |
| 523 virtual int Send (Ptr<Packet> p, uint32_t flags); // Call by app to send data
to network |
| 524 virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress);
// Same as Send(), toAddress is insignificant |
| 525 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); // Return a packe
t to be forwarded to app |
| 526 virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromA
ddress); // ... and write the remote address at fromAddress |
| 527 virtual uint32_t GetTxAvailable (void) const; // Available Tx buffer size |
| 528 virtual uint32_t GetRxAvailable (void) const; // Available-to-read data size,
i.e. value of m_rxAvailable |
| 529 virtual int GetSockName (Address &address) const; // Return local addr:port in
address |
| 530 virtual int GetPeerName (Address &address) const; |
| 531 virtual void BindToNetDevice (Ptr<NetDevice> netdevice); // NetDevice with my
m_endPoint |
| 532 |
| 533 /** |
| 534 * TracedCallback signature for tcp packet transmission or reception events. |
| 535 * |
| 536 * \param [in] packet The packet. |
| 537 * \param [in] ipv4 |
| 538 * \param [in] interface |
| 539 */ |
| 540 typedef void (* TcpTxRxTracedCallback)(const Ptr<const Packet> packet, const T
cpHeader& header, |
| 541 const Ptr<const TcpSocketBase> socket); |
| 542 |
| 543 protected: |
| 544 // Implementing ns3::TcpSocket -- Attribute get/set |
| 545 // inherited, no need to doc |
| 546 |
| 547 virtual void SetSndBufSize (uint32_t size); |
| 548 virtual uint32_t GetSndBufSize (void) const; |
| 549 virtual void SetRcvBufSize (uint32_t size); |
| 550 virtual uint32_t GetRcvBufSize (void) const; |
| 551 virtual void SetSegSize (uint32_t size); |
| 552 virtual uint32_t GetSegSize (void) const; |
| 553 virtual void SetInitialSSThresh (uint32_t threshold); |
| 554 virtual uint32_t GetInitialSSThresh (void) const; |
| 555 virtual void SetInitialCwnd (uint32_t cwnd); |
| 556 virtual uint32_t GetInitialCwnd (void) const; |
| 557 virtual void SetConnTimeout (Time timeout); |
| 558 virtual Time GetConnTimeout (void) const; |
| 559 virtual void SetSynRetries (uint32_t count); |
| 560 virtual uint32_t GetSynRetries (void) const; |
| 561 virtual void SetDataRetries (uint32_t retries); |
| 562 virtual uint32_t GetDataRetries (void) const; |
| 563 virtual void SetDelAckTimeout (Time timeout); |
| 564 virtual Time GetDelAckTimeout (void) const; |
| 565 virtual void SetDelAckMaxCount (uint32_t count); |
| 566 virtual uint32_t GetDelAckMaxCount (void) const; |
| 567 virtual void SetTcpNoDelay (bool noDelay); |
| 568 virtual bool GetTcpNoDelay (void) const; |
| 569 virtual void SetPersistTimeout (Time timeout); |
| 570 virtual Time GetPersistTimeout (void) const; |
| 571 virtual bool SetAllowBroadcast (bool allowBroadcast); |
| 572 virtual bool GetAllowBroadcast (void) const; |
| 573 |
| 574 |
| 575 |
| 576 // Helper functions: Connection set up |
| 577 |
| 578 /** |
| 579 * \brief Common part of the two Bind(), i.e. set callback and remembering loc
al addr:port |
| 580 * |
| 581 * \returns 0 on success, -1 on failure |
| 582 */ |
| 583 int SetupCallback (void); |
| 584 |
| 585 /** |
| 586 * \brief Perform the real connection tasks: Send SYN if allowed, RST if inval
id |
| 587 * |
| 588 * \returns 0 on success |
| 589 */ |
| 590 int DoConnect (void); |
| 591 |
| 592 /** |
| 593 * \brief Schedule-friendly wrapper for Socket::NotifyConnectionSucceeded() |
| 594 */ |
| 595 void ConnectionSucceeded (void); |
| 596 |
| 597 /** |
| 598 * \brief Configure the endpoint to a local address. Called by Connect() if Bi
nd() didn't specify one. |
| 599 * |
| 600 * \returns 0 on success |
| 601 */ |
| 602 int SetupEndpoint (void); |
| 603 |
| 604 /** |
| 605 * \brief Configure the endpoint v6 to a local address. Called by Connect() if
Bind() didn't specify one. |
| 606 * |
| 607 * \returns 0 on success |
| 608 */ |
| 609 int SetupEndpoint6 (void); |
| 610 |
| 611 /** |
| 612 * \brief Complete a connection by forking the socket |
| 613 * |
| 614 * This function is called only if a SYN received in LISTEN state. After |
| 615 * TcpSocketBase cloned, allocate a new end point to handle the incoming |
| 616 * connection and send a SYN+ACK to complete the handshake. |
| 617 * |
| 618 * \param p the packet triggering the fork |
| 619 * \param tcpHeader the TCP header of the triggering packet |
| 620 * \param fromAddress the address of the remote host |
| 621 * \param toAddress the address the connection is directed to |
| 622 */ |
| 623 virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader, |
| 624 const Address& fromAddress, const Address& toAddres
s); |
| 625 |
| 626 |
| 627 |
| 628 // Helper functions: Transfer operation |
| 629 |
| 630 /** |
| 631 * \brief Called by the L3 protocol when it received a packet to pass on to TC
P. |
| 632 * |
| 633 * \param packet the incoming packet |
| 634 * \param header the packet's IPv4 header |
| 635 * \param port the remote port |
| 636 * \param incomingInterface the incoming interface |
| 637 */ |
| 638 void ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, Ptr<Ipv4
Interface> incomingInterface); |
| 639 |
| 640 /** |
| 641 * \brief Called by the L3 protocol when it received a packet to pass on to TC
P. |
| 642 * |
| 643 * \param packet the incoming packet |
| 644 * \param header the packet's IPv6 header |
| 645 * \param port the remote port |
| 646 * \param incomingInterface the incoming interface |
| 647 */ |
| 648 void ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv
6Interface> incomingInterface); |
| 649 |
| 650 /** |
| 651 * \brief Called by TcpSocketBase::ForwardUp{,6}(). |
| 652 * |
| 653 * Get a packet from L3. This is the real function to handle the |
| 654 * incoming packet from lower layers. This is |
| 655 * wrapped by ForwardUp() so that this function can be overloaded by daughter |
| 656 * classes. |
| 657 * |
| 658 * \param packet the incoming packet |
| 659 * \param fromAddress the address of the sender of packet |
| 660 * \param toAddress the address of the receiver of packet (hopefully, us) |
| 661 */ |
| 662 virtual void DoForwardUp (Ptr<Packet> packet, const Address &fromAddress, |
| 663 const Address &toAddress); |
| 664 |
| 665 /** |
| 666 * \brief Called by the L3 protocol when it received an ICMP packet to pass on
to TCP. |
| 667 * |
| 668 * \param icmpSource the ICMP source address |
| 669 * \param icmpTtl the ICMP Time to Live |
| 670 * \param icmpType the ICMP Type |
| 671 * \param icmpCode the ICMP Code |
| 672 * \param icmpInfo the ICMP Info |
| 673 */ |
| 674 void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, u
int8_t icmpCode, uint32_t icmpInfo); |
| 675 |
| 676 /** |
| 677 * \brief Called by the L3 protocol when it received an ICMPv6 packet to pass
on to TCP. |
| 678 * |
| 679 * \param icmpSource the ICMP source address |
| 680 * \param icmpTtl the ICMP Time to Live |
| 681 * \param icmpType the ICMP Type |
| 682 * \param icmpCode the ICMP Code |
| 683 * \param icmpInfo the ICMP Info |
| 684 */ |
| 685 void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
uint8_t icmpCode, uint32_t icmpInfo); |
| 686 |
| 687 /** |
| 688 * \brief Send as much pending data as possible according to the Tx window. |
| 689 * |
| 690 * Note that this function did not implement the PSH flag. |
| 691 * |
| 692 * \param withAck forces an ACK to be sent |
| 693 * \returns the number of packets sent |
| 694 */ |
| 695 uint32_t SendPendingData (bool withAck = false); |
| 696 |
| 697 /** |
| 698 * \brief Extract at most maxSize bytes from the TxBuffer at sequence seq, add
the |
| 699 * TCP header, and send to TcpL4Protocol |
| 700 * |
| 701 * \param seq the sequence number |
| 702 * \param maxSize the maximum data block to be transmitted (in bytes) |
| 703 * \param withAck forces an ACK to be sent |
| 704 * \returns the number of bytes sent |
| 705 */ |
| 706 virtual uint32_t SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool
withAck); |
| 707 |
| 708 /** |
| 709 * \brief Send a empty packet that carries a flag, e.g., ACK |
| 710 * |
| 711 * \param flags the packet's flags |
| 712 */ |
| 713 virtual void SendEmptyPacket (uint8_t flags); |
| 714 |
| 715 /** |
| 716 * \brief Send reset and tear down this socket |
| 717 */ |
| 718 void SendRST (void); |
| 719 |
| 720 /** |
| 721 * \brief Check if a sequence number range is within the rx window |
| 722 * |
| 723 * \param head start of the Sequence window |
| 724 * \param tail end of the Sequence window |
| 725 * \returns true if it is in range |
| 726 */ |
| 727 bool OutOfRange (SequenceNumber32 head, SequenceNumber32 tail) const; |
| 728 |
| 729 |
| 730 // Helper functions: Connection close |
| 731 |
| 732 /** |
| 733 * \brief Close a socket by sending RST, FIN, or FIN+ACK, depend on the curren
t state |
| 734 * |
| 735 * \returns 0 on success |
| 736 */ |
| 737 int DoClose (void); |
| 738 |
| 739 /** |
| 740 * \brief Peacefully close the socket by notifying the upper layer and dealloc
ate end point |
| 741 */ |
| 742 void CloseAndNotify (void); |
| 743 |
| 744 /** |
| 745 * \brief Kill this socket by zeroing its attributes (IPv4) |
| 746 * |
| 747 * This is a callback function configured to m_endpoint in |
| 748 * SetupCallback(), invoked when the endpoint is destroyed. |
| 749 */ |
| 750 void Destroy (void); |
| 751 |
| 752 /** |
| 753 * \brief Kill this socket by zeroing its attributes (IPv6) |
| 754 * |
| 755 * This is a callback function configured to m_endpoint in |
| 756 * SetupCallback(), invoked when the endpoint is destroyed. |
| 757 */ |
| 758 void Destroy6 (void); |
| 759 |
| 760 /** |
| 761 * \brief Deallocate m_endPoint and m_endPoint6 |
| 762 */ |
| 763 void DeallocateEndPoint (void); |
| 764 |
| 765 /** |
| 766 * \brief Received a FIN from peer, notify rx buffer |
| 767 * |
| 768 * \param p the packet |
| 769 * \param tcpHeader the packet's TCP header |
| 770 */ |
| 771 void PeerClose (Ptr<Packet> p, const TcpHeader& tcpHeader); |
| 772 |
| 773 /** |
| 774 * \brief FIN is in sequence, notify app and respond with a FIN |
| 775 */ |
| 776 void DoPeerClose (void); |
| 777 |
| 778 /** |
| 779 * \brief Cancel all timer when endpoint is deleted |
| 780 */ |
| 781 void CancelAllTimers (void); |
| 782 |
| 783 /** |
| 784 * \brief Move from CLOSING or FIN_WAIT_2 to TIME_WAIT state |
| 785 */ |
| 786 void TimeWait (void); |
| 787 |
| 788 // State transition functions |
| 789 |
| 790 /** |
| 791 * \brief Received a packet upon ESTABLISHED state. |
| 792 * |
| 793 * This function is mimicking the role of tcp_rcv_established() in tcp_input.c
in Linux kernel. |
| 794 * |
| 795 * \param packet the packet |
| 796 * \param tcpHeader the packet's TCP header |
| 797 */ |
| 798 void ProcessEstablished (Ptr<Packet> packet, const TcpHeader& tcpHeader); // R
eceived a packet upon ESTABLISHED state |
| 799 |
| 800 /** |
| 801 * \brief Received a packet upon LISTEN state. |
| 802 * |
| 803 * \param packet the packet |
| 804 * \param tcpHeader the packet's TCP header |
| 805 * \param fromAddress the source address |
| 806 * \param toAddress the destination address |
| 807 */ |
| 808 void ProcessListen (Ptr<Packet> packet, const TcpHeader& tcpHeader, |
| 809 const Address& fromAddress, const Address& toAddress); |
| 810 |
| 811 /** |
| 812 * \brief Received a packet upon SYN_SENT |
| 813 * |
| 814 * \param packet the packet |
| 815 * \param tcpHeader the packet's TCP header |
| 816 */ |
| 817 void ProcessSynSent (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 818 |
| 819 /** |
| 820 * \brief Received a packet upon SYN_RCVD. |
| 821 * |
| 822 * \param packet the packet |
| 823 * \param tcpHeader the packet's TCP header |
| 824 * \param fromAddress the source address |
| 825 * \param toAddress the destination address |
| 826 */ |
| 827 void ProcessSynRcvd (Ptr<Packet> packet, const TcpHeader& tcpHeader, |
| 828 const Address& fromAddress, const Address& toAddress); |
| 829 |
| 830 /** |
| 831 * \brief Received a packet upon CLOSE_WAIT, FIN_WAIT_1, FIN_WAIT_2 |
| 832 * |
| 833 * \param packet the packet |
| 834 * \param tcpHeader the packet's TCP header |
| 835 */ |
| 836 void ProcessWait (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 837 |
| 838 /** |
| 839 * \brief Received a packet upon CLOSING |
| 840 * |
| 841 * \param packet the packet |
| 842 * \param tcpHeader the packet's TCP header |
| 843 */ |
| 844 void ProcessClosing (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 845 |
| 846 /** |
| 847 * \brief Received a packet upon LAST_ACK |
| 848 * |
| 849 * \param packet the packet |
| 850 * \param tcpHeader the packet's TCP header |
| 851 */ |
| 852 void ProcessLastAck (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 853 |
| 854 // Window management |
| 855 |
| 856 /** |
| 857 * \brief Return count of number of unacked bytes |
| 858 * |
| 859 * The difference between SND.UNA and HighTx |
| 860 * |
| 861 * \returns count of number of unacked bytes |
| 862 */ |
| 863 virtual uint32_t UnAckDataCount (void) const; |
| 864 |
| 865 /** |
| 866 * \brief Return total bytes in flight |
| 867 * |
| 868 * Does not count segments lost and SACKed (or dupACKed) |
| 869 * |
| 870 * \returns total bytes in flight |
| 871 */ |
| 872 virtual uint32_t BytesInFlight (void) const; |
| 873 |
| 874 /** |
| 875 * \brief Return the max possible number of unacked bytes |
| 876 * \returns the max possible number of unacked bytes |
| 877 */ |
| 878 virtual uint32_t Window (void) const; |
| 879 |
| 880 /** |
| 881 * \brief Return unfilled portion of window |
| 882 * \return unfilled portion of window |
| 883 */ |
| 884 virtual uint32_t AvailableWindow (void) const; |
| 885 |
| 886 /** |
| 887 * \brief The amount of Rx window announced to the peer |
| 888 * \param scale indicate if the window should be scaled. True for |
| 889 * almost all cases, except when we are sending a SYN |
| 890 * \returns size of Rx window announced to the peer |
| 891 */ |
| 892 virtual uint16_t AdvertisedWindowSize (bool scale = true) const; |
| 893 |
| 894 /** |
| 895 * \brief Update the receiver window (RWND) based on the value of the |
| 896 * window field in the header. |
| 897 * |
| 898 * This method suppresses updates unless one of the following three |
| 899 * conditions holds: 1) segment contains new data (advancing the right |
| 900 * edge of the receive buffer), 2) segment does not contain new data |
| 901 * but the segment acks new data (highest sequence number acked advances), |
| 902 * or 3) the advertised window is larger than the current send window |
| 903 * |
| 904 * \param header TcpHeader from which to extract the new window value |
| 905 */ |
| 906 void UpdateWindowSize (const TcpHeader& header); |
| 907 |
| 908 |
| 909 // Manage data tx/rx |
| 910 |
| 911 /** |
| 912 * \brief Call CopyObject<> to clone me |
| 913 * \returns a copy of the socket |
| 914 */ |
| 915 virtual Ptr<TcpSocketBase> Fork (void); |
| 916 |
| 917 /** |
| 918 * \brief Received an ACK packet |
| 919 * \param packet the packet |
| 920 * \param tcpHeader the packet's TCP header |
| 921 */ |
| 922 virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 923 |
| 924 /** |
| 925 * \brief Process a received ack |
| 926 * \param ackNumber ack number |
| 927 * \param scoreboardUpdated if true indicates that the scoreboard has been |
| 928 * updated with SACK information |
| 929 */ |
| 930 virtual void ProcessAck (const SequenceNumber32 &ackNumber, bool scoreboardUpd
ated); |
| 931 |
| 932 /** |
| 933 * \brief Recv of a data, put into buffer, call L7 to get it if necessary |
| 934 * \param packet the packet |
| 935 * \param tcpHeader the packet's TCP header |
| 936 */ |
| 937 virtual void ReceivedData (Ptr<Packet> packet, const TcpHeader& tcpHeader); |
| 938 |
| 939 /** |
| 940 * \brief Take into account the packet for RTT estimation |
| 941 * \param tcpHeader the packet's TCP header |
| 942 */ |
| 943 virtual void EstimateRtt (const TcpHeader& tcpHeader); |
| 944 |
| 945 /** |
| 946 * \brief Update the RTT history, when we send TCP segments |
| 947 * |
| 948 * \param seq The sequence number of the TCP segment |
| 949 * \param sz The segment's size |
| 950 * \param isRetransmission Whether or not the segment is a retransmission |
| 951 */ |
| 952 |
| 953 virtual void UpdateRttHistory (const SequenceNumber32 &seq, uint32_t sz, |
| 954 bool isRetransmission); |
| 955 |
| 956 /** |
| 957 * \brief Update buffers w.r.t. ACK |
| 958 * \param seq the sequence number |
| 959 * \param resetRTO indicates if RTO should be reset |
| 960 */ |
| 961 virtual void NewAck (SequenceNumber32 const& seq, bool resetRTO); |
| 962 |
| 963 /** |
| 964 * \brief Dupack management |
| 965 */ |
| 966 void DupAck (); |
| 967 |
| 968 /** |
| 969 * \brief Limited transmit algorithm |
| 970 */ |
| 971 void LimitedTransmit (); |
| 972 |
| 973 /** |
| 974 * \brief Enter the CA_RECOVERY, and retransmit the head |
| 975 */ |
| 976 void EnterRecovery (); |
| 977 |
| 978 /** |
| 979 * \brief An RTO event happened |
| 980 */ |
| 981 virtual void ReTxTimeout (void); |
| 982 |
| 983 /** |
| 984 * \brief Action upon delay ACK timeout, i.e. send an ACK |
| 985 */ |
| 986 virtual void DelAckTimeout (void); |
| 987 |
| 988 /** |
| 989 * \brief Timeout at LAST_ACK, close the connection |
| 990 */ |
| 991 virtual void LastAckTimeout (void); |
| 992 |
| 993 /** |
| 994 * \brief Send 1 byte probe to get an updated window size |
| 995 */ |
| 996 virtual void PersistTimeout (void); |
| 997 |
| 998 /** |
| 999 * \brief Retransmit the oldest packet |
| 1000 */ |
| 1001 virtual void DoRetransmit (void); |
| 1002 |
| 1003 /** \brief Add options to TcpHeader |
| 1004 * |
| 1005 * Test each option, and if it is enabled on our side, add it |
| 1006 * to the header |
| 1007 * |
| 1008 * \param tcpHeader TcpHeader to add options to |
| 1009 */ |
| 1010 void AddOptions (TcpHeader& tcpHeader); |
| 1011 |
| 1012 /** |
| 1013 * \brief Read TCP options begore Ack processing |
| 1014 * |
| 1015 * Timestamp and Window scale are managed in other pieces of code. |
| 1016 * |
| 1017 * \param tcpHeader Header of the segment |
| 1018 * \param scoreboardUpdated indicates if the scoreboard was updated due to a |
| 1019 * SACK option |
| 1020 */ |
| 1021 void ReadOptions (const TcpHeader &tcpHeader, bool &scoreboardUpdated); |
| 1022 |
| 1023 /** |
| 1024 * \brief Return true if the specified option is enabled |
| 1025 * |
| 1026 * \param kind kind of TCP option |
| 1027 * \return true if the option is enabled |
| 1028 */ |
| 1029 bool IsTcpOptionEnabled (uint8_t kind) const; |
| 1030 |
| 1031 /** |
| 1032 * \brief Read and parse the Window scale option |
| 1033 * |
| 1034 * Read the window scale option (encoded logarithmically) and save it. |
| 1035 * Per RFC 1323, the value can't exceed 14. |
| 1036 * |
| 1037 * \param option Window scale option read from the header |
| 1038 */ |
| 1039 void ProcessOptionWScale (const Ptr<const TcpOption> option); |
| 1040 /** |
| 1041 * \brief Add the window scale option to the header |
| 1042 * |
| 1043 * Calculate our factor from the rxBuffer max size, and add it |
| 1044 * to the header. |
| 1045 * |
| 1046 * \param header TcpHeader where the method should add the window scale option |
| 1047 */ |
| 1048 void AddOptionWScale (TcpHeader& header); |
| 1049 |
| 1050 /** |
| 1051 * \brief Calculate window scale value based on receive buffer space |
| 1052 * |
| 1053 * Calculate our factor from the rxBuffer max size |
| 1054 * |
| 1055 * \returns the Window Scale factor |
| 1056 */ |
| 1057 uint8_t CalculateWScale () const; |
| 1058 |
| 1059 /** |
| 1060 * \brief Read the SACK PERMITTED option |
| 1061 * |
| 1062 * Currently this is a placeholder, since no operations should be done |
| 1063 * on such option. |
| 1064 * |
| 1065 * \param option SACK PERMITTED option from the header |
| 1066 */ |
| 1067 void ProcessOptionSackPermitted (const Ptr<const TcpOption> option); |
| 1068 |
| 1069 /** |
| 1070 * \brief Read the SACK option |
| 1071 * |
| 1072 * \param option SACK option from the header |
| 1073 * \returns true in case of an update to the SACKed blocks |
| 1074 */ |
| 1075 bool ProcessOptionSack (const Ptr<const TcpOption> option); |
| 1076 |
| 1077 /** |
| 1078 * \brief Add the SACK PERMITTED option to the header |
| 1079 * |
| 1080 * \param header TcpHeader where the method should add the option |
| 1081 */ |
| 1082 void AddOptionSackPermitted (TcpHeader &header); |
| 1083 |
| 1084 /** |
| 1085 * \brief Add the SACK option to the header |
| 1086 * |
| 1087 * \param header TcpHeader where the method should add the option |
| 1088 */ |
| 1089 void AddOptionSack (TcpHeader& header); |
| 1090 |
| 1091 /** \brief Process the timestamp option from other side |
| 1092 * |
| 1093 * Get the timestamp and the echo, then save timestamp (which will |
| 1094 * be the echo value in our out-packets) and save the echoed timestamp, |
| 1095 * to utilize later to calculate RTT. |
| 1096 * |
| 1097 * \see EstimateRtt |
| 1098 * \param option Option from the segment |
| 1099 * \param seq Sequence number of the segment |
| 1100 */ |
| 1101 void ProcessOptionTimestamp (const Ptr<const TcpOption> option, |
| 1102 const SequenceNumber32 &seq); |
| 1103 /** |
| 1104 * \brief Add the timestamp option to the header |
| 1105 * |
| 1106 * Set the timestamp as the lower bits of the Simulator::Now time, |
| 1107 * and the echo value as the last seen timestamp from the other part. |
| 1108 * |
| 1109 * \param header TcpHeader to which add the option to |
| 1110 */ |
| 1111 void AddOptionTimestamp (TcpHeader& header); |
| 1112 |
| 1113 /** |
| 1114 * \brief Performs a safe subtraction between a and b (a-b) |
| 1115 * |
| 1116 * Safe is used to indicate that, if b>a, the results returned is 0. |
| 1117 * |
| 1118 * \param a first number |
| 1119 * \param b second number |
| 1120 * \return 0 if b>0, (a-b) otherwise |
| 1121 */ |
| 1122 static uint32_t SafeSubtraction (uint32_t a, uint32_t b); |
| 1123 |
| 1124 protected: |
| 1125 // Counters and events |
| 1126 EventId m_retxEvent; //!< Retransmission event |
| 1127 EventId m_lastAckEvent; //!< Last ACK timeout event |
| 1128 EventId m_delAckEvent; //!< Delayed ACK timeout event |
| 1129 EventId m_persistEvent; //!< Persist event: Send 1 byte to probe
for a non-zero Rx window |
| 1130 EventId m_timewaitEvent; //!< TIME_WAIT expiration event: Move thi
s socket to CLOSED state |
| 1131 uint32_t m_dupAckCount; //!< Dupack counter |
| 1132 uint32_t m_delAckCount; //!< Delayed ACK counter |
| 1133 uint32_t m_delAckMaxCount; //!< Number of packet to fire an ACK befo
re delay timeout |
| 1134 bool m_noDelay; //!< Set to true to disable Nagle's algor
ithm |
| 1135 uint32_t m_synCount; //!< Count of remaining connection retrie
s |
| 1136 uint32_t m_synRetries; //!< Number of connection attempts |
| 1137 uint32_t m_dataRetrCount; //!< Count of remaining data retransmissi
on attempts |
| 1138 uint32_t m_dataRetries; //!< Number of data retransmission attemp
ts |
| 1139 TracedValue<Time> m_rto; //!< Retransmit timeout |
| 1140 Time m_minRto; //!< minimum value of the Retransmit time
out |
| 1141 Time m_clockGranularity; //!< Clock Granularity used in RTO calcs |
| 1142 TracedValue<Time> m_lastRtt; //!< Last RTT sample collected |
| 1143 Time m_delAckTimeout; //!< Time to delay an ACK |
| 1144 Time m_persistTimeout; //!< Time between sending 1-byte probes |
| 1145 Time m_cnTimeout; //!< Timeout for connection retry |
| 1146 RttHistory_t m_history; //!< List of sent packet |
| 1147 |
| 1148 // Connections to other layers of TCP/IP |
| 1149 Ipv4EndPoint* m_endPoint; //!< the IPv4 endpoint |
| 1150 Ipv6EndPoint* m_endPoint6; //!< the IPv6 endpoint |
| 1151 Ptr<Node> m_node; //!< the associated node |
| 1152 Ptr<TcpL4Protocol> m_tcp; //!< the associated TCP L4 protocol |
| 1153 Callback<void, Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
//!< ICMP callback |
| 1154 Callback<void, Ipv6Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback6;
//!< ICMPv6 callback |
| 1155 |
| 1156 Ptr<RttEstimator> m_rtt; //!< Round trip time estimator |
| 1157 |
| 1158 // Rx and Tx buffer management |
| 1159 Ptr<TcpRxBuffer> m_rxBuffer; //!< Rx buffer (reordering buf
fer) |
| 1160 Ptr<TcpTxBuffer> m_txBuffer; //!< Tx buffer |
| 1161 |
| 1162 // State-related attributes |
| 1163 TracedValue<TcpStates_t> m_state; //!< TCP state |
| 1164 mutable enum SocketErrno m_errno; //!< Socket error code |
| 1165 bool m_closeNotified; //!< Told app to close socket |
| 1166 bool m_closeOnEmpty; //!< Close socket upon tx buffer emp
tied |
| 1167 bool m_shutdownSend; //!< Send no longer allowed |
| 1168 bool m_shutdownRecv; //!< Receive no longer allowed |
| 1169 bool m_connected; //!< Connection established |
| 1170 double m_msl; //!< Max segment lifetime |
| 1171 |
| 1172 // Window management |
| 1173 uint16_t m_maxWinSize; //!< Maximum window size to advertise |
| 1174 TracedValue<uint32_t> m_rWnd; //!< Receiver window (RCV.WND in RFC793) |
| 1175 TracedValue<uint32_t> m_advWnd; //!< Advertised Window size |
| 1176 TracedValue<SequenceNumber32> m_highRxMark; //!< Highest seqno received |
| 1177 SequenceNumber32 m_highTxAck; //!< Highest ack sent |
| 1178 TracedValue<SequenceNumber32> m_highRxAckMark; //!< Highest ack received |
| 1179 uint32_t m_bytesAckedNotProcessed; //!< Bytes acked, but
not processed |
| 1180 TracedValue<uint32_t> m_bytesInFlight; //!< Bytes in flight |
| 1181 |
| 1182 // Options |
| 1183 bool m_sackEnabled; //!< RFC SACK option enabled |
| 1184 bool m_winScalingEnabled; //!< Window Scale option enabled (RFC 7323) |
| 1185 uint8_t m_rcvWindShift; //!< Window shift to apply to outgoing segments |
| 1186 uint8_t m_sndWindShift; //!< Window shift to apply to incoming segments |
| 1187 |
| 1188 bool m_timestampEnabled; //!< Timestamp option enabled |
| 1189 uint32_t m_timestampToEcho; //!< Timestamp to echo |
| 1190 |
| 1191 EventId m_sendPendingDataEvent; //!< micro-delay event to send pending data |
| 1192 |
| 1193 // Fast Retransmit and Recovery |
| 1194 SequenceNumber32 m_recover; //!< Previous highest Tx seqnum for fas
t recovery |
| 1195 uint32_t m_retxThresh; //!< Fast Retransmit threshold |
| 1196 bool m_limitedTx; //!< perform limited transmit |
| 1197 |
| 1198 // Transmission Control Block |
| 1199 Ptr<TcpSocketState> m_tcb; //!< Congestion control informatio
ns |
| 1200 Ptr<TcpCongestionOps> m_congestionControl; //!< Congestion control |
| 1201 |
| 1202 // Guesses over the other connection end |
| 1203 bool m_isFirstPartialAck; //!< First partial ACK during RECOVERY |
| 1204 |
| 1205 // The following two traces pass a packet with a TCP header |
| 1206 TracedCallback<Ptr<const Packet>, const TcpHeader&, |
| 1207 Ptr<const TcpSocketBase> > m_txTrace; //!< Trace of transmitted
packets |
1 | 1208 |
2 TracedCallback<Ptr<const Packet>, const TcpHeader&, | 1209 TracedCallback<Ptr<const Packet>, const TcpHeader&, |
3 Ptr<const TcpSocketBase> > m_rxTrace; //!< Trace of received pa
ckets | 1210 Ptr<const TcpSocketBase> > m_rxTrace; //!< Trace of received pa
ckets |
| 1211 |
| 1212 // Parameters related to Explicit Congestion Notification |
| 1213 bool m_ecn; //!< Socket ECN capability |
| 1214 TracedValue<SequenceNumber32> m_ecnEchoSeq; //!< Sequence number of the last r
eceived ECN Echo |
| 1215 TracedValue<SequenceNumber32> m_ecnCESeq; //!< Sequence number of the last r
eceived Congestion Experienced |
| 1216 TracedValue<SequenceNumber32> m_ecnCWRSeq; //!< Sequence number of the last s
ent CWR· |
4 }; | 1217 }; |
5 | 1218 |
6 /** | 1219 /** |
| 1220 * \ingroup tcp |
| 1221 * TracedValue Callback signature for TcpCongState_t |
| 1222 * |
| 1223 * \param [in] oldValue original value of the traced variable |
| 1224 * \param [in] newValue new value of the traced variable |
| 1225 */ |
| 1226 typedef void (* TcpCongStatesTracedValueCallback)(const TcpSocketState::TcpCongS
tate_t oldValue, |
| 1227 const TcpSocketState::TcpCongS
tate_t newValue); |
| 1228 |
| 1229 /** |
| 1230 * \ingroup tcp |
| 1231 * TracedValue Callback signature for EcnsState_t |
| 1232 * |
| 1233 * \param [in] oldValue original value of the traced variable |
| 1234 * \param [in] newValue new value of the traced variable |
| 1235 */ |
| 1236 typedef void (* EcnStatesTracedValueCallback)(const TcpSocketState::EcnState_t o
ldValue, |
| 1237 const TcpSocketState::EcnState
_t newValue); |
| 1238 |
| 1239 } // namespace ns3 |
| 1240 |
| 1241 #endif /* TCP_SOCKET_BASE_H */ |
LEFT | RIGHT |