A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-socket-base.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Georgia Tech Research Corporation
3 * Copyright (c) 2010 Adrian Sai-wah Tam
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 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19 */
20#ifndef TCP_SOCKET_BASE_H
21#define TCP_SOCKET_BASE_H
22
23#include "ipv4-header.h"
24#include "ipv6-header.h"
25#include "tcp-socket-state.h"
26#include "tcp-socket.h"
27
28#include "ns3/data-rate.h"
29#include "ns3/node.h"
30#include "ns3/sequence-number.h"
31#include "ns3/timer.h"
32#include "ns3/traced-value.h"
33
34#include <queue>
35#include <stdint.h>
36
37namespace ns3
38{
39
40class Ipv4EndPoint;
41class Ipv6EndPoint;
42class Node;
43class Packet;
44class TcpL4Protocol;
45class TcpHeader;
46class TcpCongestionOps;
47class TcpRecoveryOps;
48class RttEstimator;
49class TcpRxBuffer;
50class TcpTxBuffer;
51class TcpOption;
52class Ipv4Interface;
53class Ipv6Interface;
54class TcpRateOps;
55
56/**
57 * \ingroup tcp
58 *
59 * \brief Helper class to store RTT measurements
60 */
62{
63 public:
64 /**
65 * \brief Constructor - builds an RttHistory with the given parameters
66 * \param s First sequence number in packet sent
67 * \param c Number of bytes sent
68 * \param t Time this one was sent
69 */
71 /**
72 * \brief Copy constructor
73 * \param h the object to copy
74 */
75 RttHistory(const RttHistory& h); // Copy constructor
76 public:
77 SequenceNumber32 seq; //!< First sequence number in packet sent
78 uint32_t count; //!< Number of bytes sent
79 Time time; //!< Time this one was sent
80 bool retx; //!< True if this has been retransmitted
81};
82
83/**
84 * \ingroup socket
85 * \ingroup tcp
86 *
87 * \brief A base class for implementation of a stream socket using TCP.
88 *
89 * This class contains the essential components of TCP, as well as a sockets
90 * interface for upper layers to call. This class provides connection orientation
91 * and sliding window flow control; congestion control is delegated to subclasses
92 * of TcpCongestionOps. Part of TcpSocketBase is modified from the original
93 * NS-3 TCP socket implementation (TcpSocketImpl) by
94 * Raj Bhattacharjea <raj.b@gatech.edu> of Georgia Tech.
95 *
96 * For IPv4 packets, the TOS set for the socket is used. The Bind and Connect
97 * operations set the TOS for the socket to the value specified in the provided
98 * address. A SocketIpTos tag is only added to the packet if the resulting
99 * TOS is non-null.
100 * Each packet is assigned the priority set for the socket. Setting a TOS
101 * for a socket also sets a priority for the socket (according to the
102 * Socket::IpTos2Priority function). A SocketPriority tag is only added to the
103 * packet if the priority is non-null.
104 *
105 * Congestion state machine
106 * ---------------------------
107 *
108 * The socket maintains two state machines; the TCP one, and another called
109 * "Congestion state machine", which keeps track of the phase we are in. Currently,
110 * ns-3 manages the states:
111 *
112 * - CA_OPEN
113 * - CA_DISORDER
114 * - CA_RECOVERY
115 * - CA_LOSS
116 * - CA_CWR
117 *
118 * For more information, see the TcpCongState_t documentation.
119 *
120 * Congestion control interface
121 * ---------------------------
122 *
123 * Congestion control, unlike older releases of ns-3, has been split from
124 * TcpSocketBase. In particular, each congestion control is now a subclass of
125 * the main TcpCongestionOps class. Switching between congestion algorithm is
126 * now a matter of setting a pointer into the TcpSocketBase class. The idea
127 * and the interfaces are inspired by the Linux operating system, and in
128 * particular from the structure tcp_congestion_ops. The reference paper is
129 * https://www.sciencedirect.com/science/article/abs/pii/S1569190X15300939.
130 *
131 * Transmission Control Block (TCB)
132 * --------------------------------
133 *
134 * The variables needed to congestion control classes to operate correctly have
135 * been moved inside the TcpSocketState class. It contains information on the
136 * congestion window, slow start threshold, segment size and the state of the
137 * Congestion state machine.
138 *
139 * To track the trace inside the TcpSocketState class, a "forward" technique is
140 * used, which consists in chaining callbacks from TcpSocketState to TcpSocketBase
141 * (see for example cWnd trace source).
142 *
143 * Fast retransmit
144 * ----------------
145 *
146 * The fast retransmit enhancement is introduced in RFC 2581 and updated in RFC
147 * 5681. It reduces the time a sender waits before retransmitting a lost segment,
148 * through the assumption that if it receives a certain number of duplicate ACKs,
149 * a segment has been lost and it can be retransmitted. Usually, it is coupled
150 * with the Limited Transmit algorithm, defined in RFC 3042. These algorithms
151 * are included in this class, and they are implemented inside the ProcessAck
152 * method. With the SACK option enabled, the LimitedTransmit algorithm will be
153 * always on, as a consequence of how the information in the received SACK block
154 * is managed.
155 *
156 * The attribute which manages the number of dup ACKs necessary to start the
157 * fast retransmit algorithm is named "ReTxThreshold", and by default is 3.
158 * The parameter is also used in TcpTxBuffer to determine if a packet is lost
159 * (please take a look at TcpTxBuffer documentation to see details) but,
160 * right now, it is assumed to be fixed. In future releases this parameter can
161 * be made dynamic, to reflect the reordering degree of the network. With SACK,
162 * the next sequence to transmit is given by the RFC 6675 algorithm. Without
163 * SACK option, the implementation adds "hints" to TcpTxBuffer to make sure it
164 * returns, as next transmittable sequence, the first lost (or presumed lost)
165 * segment.
166 *
167 * Fast recovery
168 * -------------
169 *
170 * The fast recovery algorithm is introduced RFC 2001, and it avoids to reset
171 * cWnd to 1 segment after sensing a loss on the channel. Instead, a new slow
172 * start threshold value is asked to the congestion control (for instance,
173 * with NewReno the returned amount is half of the previous), and the cWnd is
174 * set equal to such value. Ns-3 does not implement any inflation/deflation to
175 * the congestion window since it uses an evolved method (borrowed from Linux
176 * operating system) to calculate the number of bytes in flight. The fundamental
177 * idea is to subtract from the total bytes in flight the lost/sacked amount
178 * (the segments that have left the network) and to add the retransmitted count.
179 * In this way, congestion window represents the exact number of bytes that
180 * should be in flight. The implementation then decides what to transmit, it
181 * there is space, between new or already transmitted data portion. If a value
182 * of the congestion window with inflation and deflation is needed, there is a
183 * traced source named "CongestionWindowInflated". However, the variable behind
184 * it is not used in the code, but maintained for backward compatibility.
185 *
186 * RTO expiration
187 * --------------
188 *
189 * When the Retransmission Time Out expires, the TCP faces a significant
190 * performance drop. The expiration event is managed in the ReTxTimeout method,
191 * which set the cWnd to 1 segment and starts "from scratch" again. The list
192 * of sent packet is set as lost entirely, and the transmission is re-started
193 * from the SND.UNA sequence number.
194 *
195 * Options management
196 * ------------------
197 *
198 * SYN and SYN-ACK options, which are allowed only at the beginning of the
199 * connection, are managed in the DoForwardUp and SendEmptyPacket methods.
200 * To read all others, we have set up a cycle inside ReadOptions. For adding
201 * them, there is no a unique place, since the options (and the information
202 * available to build them) are scattered around the code. For instance,
203 * the SACK option is built in SendEmptyPacket only under certain conditions.
204 *
205 * SACK
206 * ----
207 *
208 * The SACK generation/management is delegated to the buffer classes, namely
209 * TcpTxBuffer and TcpRxBuffer. In TcpRxBuffer it is managed the creation
210 * of the SACK option from the receiver point of view. It must provide an
211 * accurate (and efficient) representation of the status of the receiver buffer.
212 * On the other side, inside TcpTxBuffer the received options (that contain
213 * the SACK block) are processed and a particular data structure, called Scoreboard,
214 * is filled. Please take a look at TcpTxBuffer and TcpRxBuffer documentation if
215 * you need more information. The reference paper is
216 * https://dl.acm.org/citation.cfm?id=3067666.
217 *
218 */
220{
221 public:
222 /**
223 * Get the type ID.
224 * \brief Get the type ID.
225 * \return the object TypeId
226 */
227 static TypeId GetTypeId();
228
229 /**
230 * \brief Get the instance TypeId
231 * \return the instance TypeId
232 */
233 TypeId GetInstanceTypeId() const override;
234
235 /**
236 * \brief TcpGeneralTest friend class (for tests).
237 * \relates TcpGeneralTest
238 */
239 friend class TcpGeneralTest;
240
241 /**
242 * Create an unbound TCP socket
243 */
245
246 /**
247 * Clone a TCP socket, for use upon receiving a connection request in LISTEN state
248 *
249 * \param sock the original Tcp Socket
250 */
251 TcpSocketBase(const TcpSocketBase& sock);
252 ~TcpSocketBase() override;
253
254 // Set associated Node, TcpL4Protocol, RttEstimator to this socket
255
256 /**
257 * \brief Set the associated node.
258 * \param node the node
259 */
260 virtual void SetNode(Ptr<Node> node);
261
262 /**
263 * \brief Set the associated TCP L4 protocol.
264 * \param tcp the TCP L4 protocol
265 */
266 virtual void SetTcp(Ptr<TcpL4Protocol> tcp);
267
268 /**
269 * \brief Set the associated RTT estimator.
270 * \param rtt the RTT estimator
271 */
272 virtual void SetRtt(Ptr<RttEstimator> rtt);
273
274 /**
275 * \brief Sets the Minimum RTO.
276 * \param minRto The minimum RTO.
277 */
278 void SetMinRto(Time minRto);
279
280 /**
281 * \brief Get the Minimum RTO.
282 * \return The minimum RTO.
283 */
284 Time GetMinRto() const;
285
286 /**
287 * \brief Sets the Clock Granularity (used in RTO calcs).
288 * \param clockGranularity The Clock Granularity
289 */
290 void SetClockGranularity(Time clockGranularity);
291
292 /**
293 * \brief Get the Clock Granularity (used in RTO calcs).
294 * \return The Clock Granularity.
295 */
297
298 /**
299 * \brief Get a pointer to the Tx buffer
300 * \return a pointer to the tx buffer
301 */
303
304 /**
305 * \brief Get a pointer to the Rx buffer
306 * \return a pointer to the rx buffer
307 */
309
310 /**
311 * \brief Set the retransmission threshold (dup ack threshold for a fast retransmit)
312 * \param retxThresh the threshold
313 */
314 void SetRetxThresh(uint32_t retxThresh);
315
316 /**
317 * \brief Get the retransmission threshold (dup ack threshold for a fast retransmit)
318 * \return the threshold
319 */
321 {
322 return m_retxThresh;
323 }
324
325 /**
326 * \brief Callback pointer for pacing rate trace chaining
327 */
329
330 /**
331 * \brief Callback pointer for cWnd trace chaining
332 */
334
335 /**
336 * \brief Callback pointer for cWndInfl trace chaining
337 */
339
340 /**
341 * \brief Callback pointer for ssTh trace chaining
342 */
344
345 /**
346 * \brief Callback pointer for congestion state trace chaining
347 */
349
350 /**
351 * \brief Callback pointer for ECN state trace chaining
352 */
354
355 /**
356 * \brief Callback pointer for high tx mark chaining
357 */
359
360 /**
361 * \brief Callback pointer for next tx sequence chaining
362 */
364
365 /**
366 * \brief Callback pointer for bytesInFlight trace chaining
367 */
369
370 /**
371 * \brief Callback pointer for RTT trace chaining
372 */
374
375 /**
376 * \brief Callback function to hook to TcpSocketState pacing rate
377 * \param oldValue old pacing rate value
378 * \param newValue new pacing rate value
379 */
380 void UpdatePacingRateTrace(DataRate oldValue, DataRate newValue) const;
381
382 /**
383 * \brief Callback function to hook to TcpSocketState congestion window
384 * \param oldValue old cWnd value
385 * \param newValue new cWnd value
386 */
387 void UpdateCwnd(uint32_t oldValue, uint32_t newValue) const;
388
389 /**
390 * \brief Callback function to hook to TcpSocketState inflated congestion window
391 * \param oldValue old cWndInfl value
392 * \param newValue new cWndInfl value
393 */
394 void UpdateCwndInfl(uint32_t oldValue, uint32_t newValue) const;
395
396 /**
397 * \brief Callback function to hook to TcpSocketState slow start threshold
398 * \param oldValue old ssTh value
399 * \param newValue new ssTh value
400 */
401 void UpdateSsThresh(uint32_t oldValue, uint32_t newValue) const;
402
403 /**
404 * \brief Callback function to hook to TcpSocketState congestion state
405 * \param oldValue old congestion state value
406 * \param newValue new congestion state value
407 */
409 TcpSocketState::TcpCongState_t newValue) const;
410
411 /**
412 * \brief Callback function to hook to EcnState state
413 * \param oldValue old ecn state value
414 * \param newValue new ecn state value
415 */
417 TcpSocketState::EcnState_t newValue) const;
418
419 /**
420 * \brief Callback function to hook to TcpSocketState high tx mark
421 * \param oldValue old high tx mark
422 * \param newValue new high tx mark
423 */
424 void UpdateHighTxMark(SequenceNumber32 oldValue, SequenceNumber32 newValue) const;
425
426 /**
427 * \brief Callback function to hook to TcpSocketState next tx sequence
428 * \param oldValue old nextTxSeq value
429 * \param newValue new nextTxSeq value
430 */
431 void UpdateNextTxSequence(SequenceNumber32 oldValue, SequenceNumber32 newValue) const;
432
433 /**
434 * \brief Callback function to hook to TcpSocketState bytes inflight
435 * \param oldValue old bytesInFlight value
436 * \param newValue new bytesInFlight value
437 */
438 void UpdateBytesInFlight(uint32_t oldValue, uint32_t newValue) const;
439
440 /**
441 * \brief Callback function to hook to TcpSocketState rtt
442 * \param oldValue old rtt value
443 * \param newValue new rtt value
444 */
445 void UpdateRtt(Time oldValue, Time newValue) const;
446
447 /**
448 * \brief Install a congestion control algorithm on this socket
449 *
450 * \param algo Algorithm to be installed
451 */
453
454 /**
455 * \brief Install a recovery algorithm on this socket
456 *
457 * \param recovery Algorithm to be installed
458 */
460
461 /**
462 * \brief Mark ECT(0) codepoint
463 *
464 * \param tos the TOS byte to modify
465 * \return TOS with ECT(0) codepoint set
466 */
467 inline uint8_t MarkEcnEct0(uint8_t tos) const
468 {
469 return ((tos & 0xfc) | 0x02);
470 }
471
472 /**
473 * \brief Mark ECT(1) codepoint
474 *
475 * \param tos the TOS byte to modify
476 * \return TOS with ECT(1) codepoint set
477 */
478 inline uint8_t MarkEcnEct1(uint8_t tos) const
479 {
480 return ((tos & 0xfc) | 0x01);
481 }
482
483 /**
484 * \brief Mark CE codepoint
485 *
486 * \param tos the TOS byte to modify
487 * \return TOS with CE codepoint set
488 */
489 inline uint8_t MarkEcnCe(uint8_t tos) const
490 {
491 return ((tos & 0xfc) | 0x03);
492 }
493
494 /**
495 * \brief Clears ECN bits from TOS
496 *
497 * \param tos the TOS byte to modify
498 * \return TOS without ECN bits
499 */
500 inline uint8_t ClearEcnBits(uint8_t tos) const
501 {
502 return tos & 0xfc;
503 }
504
505 /**
506 * \brief Checks if TOS has no ECN codepoints
507 *
508 * \param tos the TOS byte to check
509 * \return true if TOS does not have any ECN codepoints set; otherwise false
510 */
511 inline bool CheckNoEcn(uint8_t tos) const
512 {
513 return ((tos & 0x03) == 0x00);
514 }
515
516 /**
517 * \brief Checks for ECT(0) codepoint
518 *
519 * \param tos the TOS byte to check
520 * \return true if TOS has ECT(0) codepoint set; otherwise false
521 */
522 inline bool CheckEcnEct0(uint8_t tos) const
523 {
524 return ((tos & 0x03) == 0x02);
525 }
526
527 /**
528 * \brief Checks for ECT(1) codepoint
529 *
530 * \param tos the TOS byte to check
531 * \return true if TOS has ECT(1) codepoint set; otherwise false
532 */
533 inline bool CheckEcnEct1(uint8_t tos) const
534 {
535 return ((tos & 0x03) == 0x01);
536 }
537
538 /**
539 * \brief Checks for CE codepoint
540 *
541 * \param tos the TOS byte to check
542 * \return true if TOS has CE codepoint set; otherwise false
543 */
544 inline bool CheckEcnCe(uint8_t tos) const
545 {
546 return ((tos & 0x03) == 0x03);
547 }
548
549 /**
550 * \brief mark ECN code point
551 *
552 * \param tos the TOS byte to modify
553 * \param codePoint the codepoint to use
554 * \return TOS with specified ECN code point
555 */
556 inline uint8_t MarkEcnCodePoint(const uint8_t tos,
557 const TcpSocketState::EcnCodePoint_t codePoint) const
558 {
559 return ((tos & 0xfc) | codePoint);
560 }
561
562 /**
563 * \brief Set ECN mode of use on the socket
564 *
565 * \param useEcn Mode of ECN to use.
566 */
568
569 /**
570 * \brief Enable or disable pacing
571 * \param pacing Boolean to enable or disable pacing
572 */
573 void SetPacingStatus(bool pacing);
574
575 /**
576 * \brief Enable or disable pacing of the initial window
577 * \param paceWindow Boolean to enable or disable pacing of the initial window
578 */
579 void SetPaceInitialWindow(bool paceWindow);
580
581 // Necessary implementations of null functions from ns3::Socket
582 SocketErrno GetErrno() const override; // returns m_errno
583 SocketType GetSocketType() const override; // returns socket type
584 Ptr<Node> GetNode() const override; // returns m_node
585 int Bind() override; // Bind a socket by setting up endpoint in TcpL4Protocol
586 int Bind6() override; // Bind a socket by setting up endpoint in TcpL4Protocol
587 int Bind(const Address& address) override; // ... endpoint of specific addr or port
588 int Connect(
589 const Address& address) override; // Setup endpoint and call ProcessAction() to connect
590 int Listen()
591 override; // Verify the socket is in a correct state and call ProcessAction() to listen
592 int Close() override; // Close by app: Kill socket upon tx buffer emptied
593 int ShutdownSend() override; // Assert the m_shutdownSend flag to prevent send to network
594 int ShutdownRecv() override; // Assert the m_shutdownRecv flag to prevent forward to app
595 int Send(Ptr<Packet> p, uint32_t flags) override; // Call by app to send data to network
596 int SendTo(Ptr<Packet> p,
597 uint32_t flags,
598 const Address& toAddress) override; // Same as Send(), toAddress is insignificant
599 Ptr<Packet> Recv(uint32_t maxSize,
600 uint32_t flags) override; // Return a packet to be forwarded to app
601 Ptr<Packet> RecvFrom(uint32_t maxSize, uint32_t flags, Address& fromAddress)
602 override; // ... and write the remote address at fromAddress
603 uint32_t GetTxAvailable() const override; // Available Tx buffer size
605 const override; // Available-to-read data size, i.e. value of m_rxAvailable
606 int GetSockName(Address& address) const override; // Return local addr:port in address
607 int GetPeerName(Address& address) const override;
608 void BindToNetDevice(Ptr<NetDevice> netdevice) override; // NetDevice with my m_endPoint
609
610 /**
611 * TracedCallback signature for tcp packet transmission or reception events.
612 *
613 * \param [in] packet The packet.
614 * \param [in] header The TcpHeader
615 * \param [in] socket This socket
616 */
617 typedef void (*TcpTxRxTracedCallback)(const Ptr<const Packet> packet,
618 const TcpHeader& header,
619 const Ptr<const TcpSocketBase> socket);
620
621 protected:
622 // Implementing ns3::TcpSocket -- Attribute get/set
623 // inherited, no need to doc
624
625 void SetSndBufSize(uint32_t size) override;
626 uint32_t GetSndBufSize() const override;
627 void SetRcvBufSize(uint32_t size) override;
628 uint32_t GetRcvBufSize() const override;
629 void SetSegSize(uint32_t size) override;
630 uint32_t GetSegSize() const override;
631 void SetInitialSSThresh(uint32_t threshold) override;
632 uint32_t GetInitialSSThresh() const override;
633 void SetInitialCwnd(uint32_t cwnd) override;
634 uint32_t GetInitialCwnd() const override;
635 void SetConnTimeout(Time timeout) override;
636 Time GetConnTimeout() const override;
637 void SetSynRetries(uint32_t count) override;
638 uint32_t GetSynRetries() const override;
639 void SetDataRetries(uint32_t retries) override;
640 uint32_t GetDataRetries() const override;
641 void SetDelAckTimeout(Time timeout) override;
642 Time GetDelAckTimeout() const override;
643 void SetDelAckMaxCount(uint32_t count) override;
644 uint32_t GetDelAckMaxCount() const override;
645 void SetTcpNoDelay(bool noDelay) override;
646 bool GetTcpNoDelay() const override;
647 void SetPersistTimeout(Time timeout) override;
648 Time GetPersistTimeout() const override;
649 bool SetAllowBroadcast(bool allowBroadcast) override;
650 bool GetAllowBroadcast() const override;
651
652 // Helper functions: Connection set up
653
654 /**
655 * \brief Common part of the two Bind(), i.e. set callback and remembering local addr:port
656 *
657 * \returns 0 on success, -1 on failure
658 */
659 int SetupCallback();
660
661 /**
662 * \brief Perform the real connection tasks: Send SYN if allowed, RST if invalid
663 *
664 * \returns 0 on success
665 */
666 int DoConnect();
667
668 /**
669 * \brief Schedule-friendly wrapper for Socket::NotifyConnectionSucceeded()
670 */
671 void ConnectionSucceeded();
672
673 /**
674 * \brief Configure the endpoint to a local address. Called by Connect() if Bind() didn't
675 * specify one.
676 *
677 * \returns 0 on success
678 */
679 int SetupEndpoint();
680
681 /**
682 * \brief Configure the endpoint v6 to a local address. Called by Connect() if Bind() didn't
683 * specify one.
684 *
685 * \returns 0 on success
686 */
687 int SetupEndpoint6();
688
689 /**
690 * \brief Complete a connection by forking the socket
691 *
692 * This function is called only if a SYN received in LISTEN state. After
693 * TcpSocketBase cloned, allocate a new end point to handle the incoming
694 * connection and send a SYN+ACK to complete the handshake.
695 *
696 * \param p the packet triggering the fork
697 * \param tcpHeader the TCP header of the triggering packet
698 * \param fromAddress the address of the remote host
699 * \param toAddress the address the connection is directed to
700 */
701 virtual void CompleteFork(Ptr<Packet> p,
702 const TcpHeader& tcpHeader,
703 const Address& fromAddress,
704 const Address& toAddress);
705
706 // Helper functions: Transfer operation
707
708 /**
709 * \brief Checks whether the given TCP segment is valid or not.
710 *
711 * \param seq the sequence number of packet's TCP header
712 * \param tcpHeaderSize the size of packet's TCP header
713 * \param tcpPayloadSize the size of TCP payload
714 * \return true if the TCP segment is valid
715 */
716 bool IsValidTcpSegment(const SequenceNumber32 seq,
717 const uint32_t tcpHeaderSize,
718 const uint32_t tcpPayloadSize);
719
720 /**
721 * \brief Called by the L3 protocol when it received a packet to pass on to TCP.
722 *
723 * \param packet the incoming packet
724 * \param header the packet's IPv4 header
725 * \param port the remote port
726 * \param incomingInterface the incoming interface
727 */
728 void ForwardUp(Ptr<Packet> packet,
729 Ipv4Header header,
730 uint16_t port,
731 Ptr<Ipv4Interface> incomingInterface);
732
733 /**
734 * \brief Called by the L3 protocol when it received a packet to pass on to TCP.
735 *
736 * \param packet the incoming packet
737 * \param header the packet's IPv6 header
738 * \param port the remote port
739 * \param incomingInterface the incoming interface
740 */
741 void ForwardUp6(Ptr<Packet> packet,
742 Ipv6Header header,
743 uint16_t port,
744 Ptr<Ipv6Interface> incomingInterface);
745
746 /**
747 * \brief Called by TcpSocketBase::ForwardUp{,6}().
748 *
749 * Get a packet from L3. This is the real function to handle the
750 * incoming packet from lower layers. This is
751 * wrapped by ForwardUp() so that this function can be overloaded by daughter
752 * classes.
753 *
754 * \param packet the incoming packet
755 * \param fromAddress the address of the sender of packet
756 * \param toAddress the address of the receiver of packet (hopefully, us)
757 */
758 virtual void DoForwardUp(Ptr<Packet> packet,
759 const Address& fromAddress,
760 const Address& toAddress);
761
762 /**
763 * \brief Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
764 *
765 * \param icmpSource the ICMP source address
766 * \param icmpTtl the ICMP Time to Live
767 * \param icmpType the ICMP Type
768 * \param icmpCode the ICMP Code
769 * \param icmpInfo the ICMP Info
770 */
771 void ForwardIcmp(Ipv4Address icmpSource,
772 uint8_t icmpTtl,
773 uint8_t icmpType,
774 uint8_t icmpCode,
775 uint32_t icmpInfo);
776
777 /**
778 * \brief Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
779 *
780 * \param icmpSource the ICMP source address
781 * \param icmpTtl the ICMP Time to Live
782 * \param icmpType the ICMP Type
783 * \param icmpCode the ICMP Code
784 * \param icmpInfo the ICMP Info
785 */
786 void ForwardIcmp6(Ipv6Address icmpSource,
787 uint8_t icmpTtl,
788 uint8_t icmpType,
789 uint8_t icmpCode,
790 uint32_t icmpInfo);
791
792 /**
793 * \brief Send as much pending data as possible according to the Tx window.
794 *
795 * Note that this function did not implement the PSH flag.
796 *
797 * \param withAck forces an ACK to be sent
798 * \returns the number of packets sent
799 */
800 uint32_t SendPendingData(bool withAck = false);
801
802 /**
803 * \brief Extract at most maxSize bytes from the TxBuffer at sequence seq, add the
804 * TCP header, and send to TcpL4Protocol
805 *
806 * \param seq the sequence number
807 * \param maxSize the maximum data block to be transmitted (in bytes)
808 * \param withAck forces an ACK to be sent
809 * \returns the number of bytes sent
810 */
811 virtual uint32_t SendDataPacket(SequenceNumber32 seq, uint32_t maxSize, bool withAck);
812
813 /**
814 * \brief Send a empty packet that carries a flag, e.g., ACK
815 *
816 * \param flags the packet's flags
817 */
818 virtual void SendEmptyPacket(uint8_t flags);
819
820 /**
821 * \brief Send reset and tear down this socket
822 */
823 void SendRST();
824
825 /**
826 * \brief Check if a sequence number range is within the rx window
827 *
828 * \param head start of the Sequence window
829 * \param tail end of the Sequence window
830 * \returns true if it is in range
831 */
832 bool OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const;
833
834 // Helper functions: Connection close
835
836 /**
837 * \brief Close a socket by sending RST, FIN, or FIN+ACK, depend on the current state
838 *
839 * \returns 0 on success
840 */
841 int DoClose();
842
843 /**
844 * \brief Peacefully close the socket by notifying the upper layer and deallocate end point
845 */
846 void CloseAndNotify();
847
848 /**
849 * \brief Kill this socket by zeroing its attributes (IPv4)
850 *
851 * This is a callback function configured to m_endpoint in
852 * SetupCallback(), invoked when the endpoint is destroyed.
853 */
854 void Destroy();
855
856 /**
857 * \brief Kill this socket by zeroing its attributes (IPv6)
858 *
859 * This is a callback function configured to m_endpoint in
860 * SetupCallback(), invoked when the endpoint is destroyed.
861 */
862 void Destroy6();
863
864 /**
865 * \brief Deallocate m_endPoint and m_endPoint6
866 */
867 void DeallocateEndPoint();
868
869 /**
870 * \brief Received a FIN from peer, notify rx buffer
871 *
872 * \param p the packet
873 * \param tcpHeader the packet's TCP header
874 */
875 void PeerClose(Ptr<Packet> p, const TcpHeader& tcpHeader);
876
877 /**
878 * \brief FIN is in sequence, notify app and respond with a FIN
879 */
880 void DoPeerClose();
881
882 /**
883 * \brief Cancel all timer when endpoint is deleted
884 */
885 void CancelAllTimers();
886
887 /**
888 * \brief Move from CLOSING or FIN_WAIT_2 to TIME_WAIT state
889 */
890 void TimeWait();
891
892 // State transition functions
893
894 /**
895 * \brief Received a packet upon ESTABLISHED state.
896 *
897 * This function is mimicking the role of tcp_rcv_established() in tcp_input.c in Linux kernel.
898 *
899 * \param packet the packet
900 * \param tcpHeader the packet's TCP header
901 */
903 const TcpHeader& tcpHeader); // Received a packet upon ESTABLISHED state
904
905 /**
906 * \brief Received a packet upon LISTEN state.
907 *
908 * \param packet the packet
909 * \param tcpHeader the packet's TCP header
910 * \param fromAddress the source address
911 * \param toAddress the destination address
912 */
913 void ProcessListen(Ptr<Packet> packet,
914 const TcpHeader& tcpHeader,
915 const Address& fromAddress,
916 const Address& toAddress);
917
918 /**
919 * \brief Received a packet upon SYN_SENT
920 *
921 * \param packet the packet
922 * \param tcpHeader the packet's TCP header
923 */
924 void ProcessSynSent(Ptr<Packet> packet, const TcpHeader& tcpHeader);
925
926 /**
927 * \brief Received a packet upon SYN_RCVD.
928 *
929 * \param packet the packet
930 * \param tcpHeader the packet's TCP header
931 * \param fromAddress the source address
932 * \param toAddress the destination address
933 */
934 void ProcessSynRcvd(Ptr<Packet> packet,
935 const TcpHeader& tcpHeader,
936 const Address& fromAddress,
937 const Address& toAddress);
938
939 /**
940 * \brief Received a packet upon CLOSE_WAIT, FIN_WAIT_1, FIN_WAIT_2
941 *
942 * \param packet the packet
943 * \param tcpHeader the packet's TCP header
944 */
945 void ProcessWait(Ptr<Packet> packet, const TcpHeader& tcpHeader);
946
947 /**
948 * \brief Received a packet upon CLOSING
949 *
950 * \param packet the packet
951 * \param tcpHeader the packet's TCP header
952 */
953 void ProcessClosing(Ptr<Packet> packet, const TcpHeader& tcpHeader);
954
955 /**
956 * \brief Received a packet upon LAST_ACK
957 *
958 * \param packet the packet
959 * \param tcpHeader the packet's TCP header
960 */
961 void ProcessLastAck(Ptr<Packet> packet, const TcpHeader& tcpHeader);
962
963 // Window management
964
965 /**
966 * \brief Return count of number of unacked bytes
967 *
968 * The difference between SND.UNA and HighTx
969 *
970 * \returns count of number of unacked bytes
971 */
972 virtual uint32_t UnAckDataCount() const;
973
974 /**
975 * \brief Return total bytes in flight
976 *
977 * Does not count segments lost and SACKed (or dupACKed)
978 *
979 * \returns total bytes in flight
980 */
981 virtual uint32_t BytesInFlight() const;
982
983 /**
984 * \brief Return the max possible number of unacked bytes
985 * \returns the max possible number of unacked bytes
986 */
987 virtual uint32_t Window() const;
988
989 /**
990 * \brief Return unfilled portion of window
991 * \return unfilled portion of window
992 */
993 virtual uint32_t AvailableWindow() const;
994
995 /**
996 * \brief The amount of Rx window announced to the peer
997 * \param scale indicate if the window should be scaled. True for
998 * almost all cases, except when we are sending a SYN
999 * \returns size of Rx window announced to the peer
1000 */
1001 virtual uint16_t AdvertisedWindowSize(bool scale = true) const;
1002
1003 /**
1004 * \brief Update the receiver window (RWND) based on the value of the
1005 * window field in the header.
1006 *
1007 * This method suppresses updates unless one of the following three
1008 * conditions holds: 1) segment contains new data (advancing the right
1009 * edge of the receive buffer), 2) segment does not contain new data
1010 * but the segment acks new data (highest sequence number acked advances),
1011 * or 3) the advertised window is larger than the current send window
1012 *
1013 * \param header TcpHeader from which to extract the new window value
1014 */
1015 void UpdateWindowSize(const TcpHeader& header);
1016
1017 // Manage data tx/rx
1018
1019 /**
1020 * \brief Call CopyObject<> to clone me
1021 * \returns a copy of the socket
1022 */
1023 virtual Ptr<TcpSocketBase> Fork();
1024
1025 /**
1026 * \brief Received an ACK packet
1027 * \param packet the packet
1028 * \param tcpHeader the packet's TCP header
1029 */
1030 virtual void ReceivedAck(Ptr<Packet> packet, const TcpHeader& tcpHeader);
1031
1032 /**
1033 * \brief Process a received ack
1034 * \param ackNumber ack number
1035 * \param scoreboardUpdated if true indicates that the scoreboard has been
1036 * \param oldHeadSequence value of HeadSequence before ack
1037 * updated with SACK information
1038 * \param currentDelivered The number of bytes (S)ACKed
1039 */
1040 virtual void ProcessAck(const SequenceNumber32& ackNumber,
1041 bool scoreboardUpdated,
1042 uint32_t currentDelivered,
1043 const SequenceNumber32& oldHeadSequence);
1044
1045 /**
1046 * \brief Recv of a data, put into buffer, call L7 to get it if necessary
1047 * \param packet the packet
1048 * \param tcpHeader the packet's TCP header
1049 */
1050 virtual void ReceivedData(Ptr<Packet> packet, const TcpHeader& tcpHeader);
1051
1052 /**
1053 * \brief Take into account the packet for RTT estimation
1054 * \param tcpHeader the packet's TCP header
1055 */
1056 virtual void EstimateRtt(const TcpHeader& tcpHeader);
1057
1058 /**
1059 * \brief Update the RTT history, when we send TCP segments
1060 *
1061 * \param seq The sequence number of the TCP segment
1062 * \param sz The segment's size
1063 * \param isRetransmission Whether or not the segment is a retransmission
1064 */
1065
1066 virtual void UpdateRttHistory(const SequenceNumber32& seq, uint32_t sz, bool isRetransmission);
1067
1068 /**
1069 * \brief Update buffers w.r.t. ACK
1070 * \param seq the sequence number
1071 * \param resetRTO indicates if RTO should be reset
1072 */
1073 virtual void NewAck(const SequenceNumber32& seq, bool resetRTO);
1074
1075 /**
1076 * \brief Dupack management
1077 *
1078 * \param currentDelivered Current (S)ACKed bytes
1079 */
1080 void DupAck(uint32_t currentDelivered);
1081
1082 /**
1083 * \brief Enter CA_CWR state upon receipt of an ECN Echo
1084 *
1085 * \param currentDelivered Currently (S)ACKed bytes
1086 */
1087 void EnterCwr(uint32_t currentDelivered);
1088
1089 /**
1090 * \brief Enter the CA_RECOVERY, and retransmit the head
1091 *
1092 * \param currentDelivered Currently (S)ACKed bytes
1093 */
1094 void EnterRecovery(uint32_t currentDelivered);
1095
1096 /**
1097 * \brief An RTO event happened
1098 */
1099 virtual void ReTxTimeout();
1100
1101 /**
1102 * \brief Action upon delay ACK timeout, i.e. send an ACK
1103 */
1104 virtual void DelAckTimeout();
1105
1106 /**
1107 * \brief Timeout at LAST_ACK, close the connection
1108 */
1109 virtual void LastAckTimeout();
1110
1111 /**
1112 * \brief Send 1 byte probe to get an updated window size
1113 */
1114 virtual void PersistTimeout();
1115
1116 /**
1117 * \brief Retransmit the first segment marked as lost, without considering
1118 * available window nor pacing.
1119 */
1120 void DoRetransmit();
1121
1122 /** \brief Add options to TcpHeader
1123 *
1124 * Test each option, and if it is enabled on our side, add it
1125 * to the header
1126 *
1127 * \param tcpHeader TcpHeader to add options to
1128 */
1129 void AddOptions(TcpHeader& tcpHeader);
1130
1131 /**
1132 * \brief Read TCP options before Ack processing
1133 *
1134 * Timestamp and Window scale are managed in other pieces of code.
1135 *
1136 * \param tcpHeader Header of the segment
1137 * \param [out] bytesSacked Number of bytes SACKed, or 0
1138 */
1139 void ReadOptions(const TcpHeader& tcpHeader, uint32_t* bytesSacked);
1140
1141 /**
1142 * \brief Return true if the specified option is enabled
1143 *
1144 * \param kind kind of TCP option
1145 * \return true if the option is enabled
1146 */
1147 bool IsTcpOptionEnabled(uint8_t kind) const;
1148
1149 /**
1150 * \brief Read and parse the Window scale option
1151 *
1152 * Read the window scale option (encoded logarithmically) and save it.
1153 * Per RFC 1323, the value can't exceed 14.
1154 *
1155 * \param option Window scale option read from the header
1156 */
1157 void ProcessOptionWScale(const Ptr<const TcpOption> option);
1158 /**
1159 * \brief Add the window scale option to the header
1160 *
1161 * Calculate our factor from the rxBuffer max size, and add it
1162 * to the header.
1163 *
1164 * \param header TcpHeader where the method should add the window scale option
1165 */
1166 void AddOptionWScale(TcpHeader& header);
1167
1168 /**
1169 * \brief Calculate window scale value based on receive buffer space
1170 *
1171 * Calculate our factor from the rxBuffer max size
1172 *
1173 * \returns the Window Scale factor
1174 */
1175 uint8_t CalculateWScale() const;
1176
1177 /**
1178 * \brief Read the SACK PERMITTED option
1179 *
1180 * Currently this is a placeholder, since no operations should be done
1181 * on such option.
1182 *
1183 * \param option SACK PERMITTED option from the header
1184 */
1186
1187 /**
1188 * \brief Read the SACK option
1189 *
1190 * \param option SACK option from the header
1191 * \returns the number of bytes sacked by this option
1192 */
1194
1195 /**
1196 * \brief Add the SACK PERMITTED option to the header
1197 *
1198 * \param header TcpHeader where the method should add the option
1199 */
1200 void AddOptionSackPermitted(TcpHeader& header);
1201
1202 /**
1203 * \brief Add the SACK option to the header
1204 *
1205 * \param header TcpHeader where the method should add the option
1206 */
1207 void AddOptionSack(TcpHeader& header);
1208
1209 /** \brief Process the timestamp option from other side
1210 *
1211 * Get the timestamp and the echo, then save timestamp (which will
1212 * be the echo value in our out-packets) and save the echoed timestamp,
1213 * to utilize later to calculate RTT.
1214 *
1215 * \see EstimateRtt
1216 * \param option Option from the segment
1217 * \param seq Sequence number of the segment
1218 */
1219 void ProcessOptionTimestamp(const Ptr<const TcpOption> option, const SequenceNumber32& seq);
1220 /**
1221 * \brief Add the timestamp option to the header
1222 *
1223 * Set the timestamp as the lower bits of the Simulator::Now time,
1224 * and the echo value as the last seen timestamp from the other part.
1225 *
1226 * \param header TcpHeader to which add the option to
1227 */
1228 void AddOptionTimestamp(TcpHeader& header);
1229
1230 /**
1231 * \brief Performs a safe subtraction between a and b (a-b)
1232 *
1233 * Safe is used to indicate that, if b>a, the results returned is 0.
1234 *
1235 * \param a first number
1236 * \param b second number
1237 * \return 0 if b>0, (a-b) otherwise
1238 */
1240
1241 /**
1242 * \brief Notify Pacing
1243 */
1244 void NotifyPacingPerformed();
1245
1246 /**
1247 * \brief Return true if packets in the current window should be paced
1248 * \return true if pacing is currently enabled
1249 */
1250 bool IsPacingEnabled() const;
1251
1252 /**
1253 * \brief Dynamically update the pacing rate
1254 */
1255 void UpdatePacingRate();
1256
1257 /**
1258 * \brief Add Tags for the Socket
1259 * \param p Packet
1260 */
1261 void AddSocketTags(const Ptr<Packet>& p) const;
1262
1263 /**
1264 * Get the current value of the receiver's offered window (RCV.WND)
1265 * \note This method exists to expose the value to the TcpTxBuffer
1266 * \return value of receiver's offered window
1267 */
1268 uint32_t GetRWnd() const;
1269
1270 /**
1271 * Get the current value of the receiver's highest (in-sequence) sequence number acked.
1272 * \note This method exists to expose the value to the TcpTxBuffer
1273 * \return value of receiver's highest sequence number acked.
1274 */
1276
1277 protected:
1278 // Counters and events
1279 EventId m_retxEvent{}; //!< Retransmission event
1280 EventId m_lastAckEvent{}; //!< Last ACK timeout event
1281 EventId m_delAckEvent{}; //!< Delayed ACK timeout event
1282 EventId m_persistEvent{}; //!< Persist event: Send 1 byte to probe for a non-zero Rx window
1283 EventId m_timewaitEvent{}; //!< TIME_WAIT expiration event: Move this socket to CLOSED state
1284
1285 // ACK management
1286 uint32_t m_dupAckCount{0}; //!< Dupack counter
1287 uint32_t m_delAckCount{0}; //!< Delayed ACK counter
1288 uint32_t m_delAckMaxCount{0}; //!< Number of packet to fire an ACK before delay timeout
1289
1290 // Nagle algorithm
1291 bool m_noDelay{false}; //!< Set to true to disable Nagle's algorithm
1292
1293 // Retries
1294 uint32_t m_synCount{0}; //!< Count of remaining connection retries
1295 uint32_t m_synRetries{0}; //!< Number of connection attempts
1296 uint32_t m_dataRetrCount{0}; //!< Count of remaining data retransmission attempts
1297 uint32_t m_dataRetries{0}; //!< Number of data retransmission attempts
1298
1299 // Timeouts
1300 TracedValue<Time> m_rto{Seconds(0.0)}; //!< Retransmit timeout
1301 Time m_minRto{Time::Max()}; //!< minimum value of the Retransmit timeout
1302 Time m_clockGranularity{Seconds(0.001)}; //!< Clock Granularity used in RTO calcs
1303 Time m_delAckTimeout{Seconds(0.0)}; //!< Time to delay an ACK
1304 Time m_persistTimeout{Seconds(0.0)}; //!< Time between sending 1-byte probes
1305 Time m_cnTimeout{Seconds(0.0)}; //!< Timeout for connection retry
1306
1307 // History of RTT
1308 std::deque<RttHistory> m_history; //!< List of sent packet
1309
1310 // Connections to other layers of TCP/IP
1311 Ipv4EndPoint* m_endPoint{nullptr}; //!< the IPv4 endpoint
1312 Ipv6EndPoint* m_endPoint6{nullptr}; //!< the IPv6 endpoint
1313 Ptr<Node> m_node; //!< the associated node
1314 Ptr<TcpL4Protocol> m_tcp; //!< the associated TCP L4 protocol
1316 m_icmpCallback; //!< ICMP callback
1318 m_icmpCallback6; //!< ICMPv6 callback
1319
1320 Ptr<RttEstimator> m_rtt; //!< Round trip time estimator
1321
1322 // Tx buffer management
1324
1325 // State-related attributes
1327
1328 mutable SocketErrno m_errno{ERROR_NOTERROR}; //!< Socket error code
1329
1330 bool m_closeNotified{false}; //!< Told app to close socket
1331 bool m_closeOnEmpty{false}; //!< Close socket upon tx buffer emptied
1332 bool m_shutdownSend{false}; //!< Send no longer allowed
1333 bool m_shutdownRecv{false}; //!< Receive no longer allowed
1334 bool m_connected{false}; //!< Connection established
1335 double m_msl{0.0}; //!< Max segment lifetime
1336
1337 // Window management
1338 uint16_t m_maxWinSize{0}; //!< Maximum window size to advertise
1339 uint32_t m_bytesAckedNotProcessed{0}; //!< Bytes acked, but not processed
1340 SequenceNumber32 m_highTxAck{0}; //!< Highest ack sent
1341 TracedValue<uint32_t> m_rWnd{0}; //!< Receiver window (RCV.WND in RFC793)
1342 TracedValue<uint32_t> m_advWnd{0}; //!< Advertised Window size
1343 TracedValue<SequenceNumber32> m_highRxMark{0}; //!< Highest seqno received
1345
1346 // Options
1347 bool m_sackEnabled{true}; //!< RFC SACK option enabled
1348 bool m_winScalingEnabled{true}; //!< Window Scale option enabled (RFC 7323)
1349 uint8_t m_rcvWindShift{0}; //!< Window shift to apply to outgoing segments
1350 uint8_t m_sndWindShift{0}; //!< Window shift to apply to incoming segments
1351 bool m_timestampEnabled{true}; //!< Timestamp option enabled
1352 uint32_t m_timestampToEcho{0}; //!< Timestamp to echo
1353
1354 EventId m_sendPendingDataEvent{}; //!< micro-delay event to send pending data
1355
1356 // Fast Retransmit and Recovery
1358 0}; //!< Previous highest Tx seqnum for fast recovery (set it to initial seq number)
1359 bool m_recoverActive{false}; //!< Whether "m_recover" has been set/activated
1360 //!< It is used to avoid comparing with the old m_recover value
1361 //!< which was set for handling previous congestion event.
1362 uint32_t m_retxThresh{3}; //!< Fast Retransmit threshold
1363 bool m_limitedTx{true}; //!< perform limited transmit
1364
1365 // Transmission Control Block
1366 Ptr<TcpSocketState> m_tcb; //!< Congestion control information
1368 Ptr<TcpRecoveryOps> m_recoveryOps; //!< Recovery Algorithm
1369 Ptr<TcpRateOps> m_rateOps; //!< Rate operations
1370
1371 // Guesses over the other connection end
1372 bool m_isFirstPartialAck{true}; //!< First partial ACK during RECOVERY
1373
1374 // The following two traces pass a packet with a TCP header
1376 const TcpHeader&,
1378 m_txTrace; //!< Trace of transmitted packets
1379
1381 const TcpHeader&,
1383 m_rxTrace; //!< Trace of received packets
1384
1385 // Pacing related variable
1387
1388 // Parameters related to Explicit Congestion Notification
1390 0}; //!< Sequence number of the last received ECN Echo
1392 0}; //!< Sequence number of the last received Congestion Experienced
1393 TracedValue<SequenceNumber32> m_ecnCWRSeq{0}; //!< Sequence number of the last sent CWR
1394};
1395
1396/**
1397 * \ingroup tcp
1398 * TracedValue Callback signature for TcpCongState_t
1399 *
1400 * \param [in] oldValue original value of the traced variable
1401 * \param [in] newValue new value of the traced variable
1402 */
1404 const TcpSocketState::TcpCongState_t newValue);
1405
1406/**
1407 * \ingroup tcp
1408 * TracedValue Callback signature for ECN state trace
1409 *
1410 * \param [in] oldValue original value of the traced variable
1411 * \param [in] newValue new value of the traced variable
1412 */
1414 const TcpSocketState::EcnState_t newValue);
1415
1416} // namespace ns3
1417
1418#endif /* TCP_SOCKET_BASE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
A representation of an internet endpoint/connection.
Packet header for IPv4.
Definition: ipv4-header.h:34
Describes an IPv6 address.
Definition: ipv6-address.h:49
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:35
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Helper class to store RTT measurements.
uint32_t count
Number of bytes sent.
bool retx
True if this has been retransmitted.
Time time
Time this one was sent.
SequenceNumber32 seq
First sequence number in packet sent.
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition: socket.cc:174
SocketType
Enumeration of the possible socket types.
Definition: socket.h:107
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
@ ERROR_NOTERROR
Definition: socket.h:85
General infrastructure for TCP testing.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
A base class for implementation of a stream socket using TCP.
void AddOptionSack(TcpHeader &header)
Add the SACK option to the header.
int GetSockName(Address &address) const override
Get socket address.
Time m_persistTimeout
Time between sending 1-byte probes.
uint16_t m_maxWinSize
Maximum window size to advertise.
uint8_t m_rcvWindShift
Window shift to apply to outgoing segments.
void SetPaceInitialWindow(bool paceWindow)
Enable or disable pacing of the initial window.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
void TimeWait()
Move from CLOSING or FIN_WAIT_2 to TIME_WAIT state.
bool CheckEcnEct1(uint8_t tos) const
Checks for ECT(1) codepoint.
Ptr< TcpCongestionOps > m_congestionControl
Congestion control.
Ptr< TcpTxBuffer > GetTxBuffer() const
Get a pointer to the Tx buffer.
int SetupEndpoint()
Configure the endpoint to a local address.
virtual void LastAckTimeout()
Timeout at LAST_ACK, close the connection.
void ProcessEstablished(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon ESTABLISHED state.
Time m_minRto
minimum value of the Retransmit timeout
uint32_t SendPendingData(bool withAck=false)
Send as much pending data as possible according to the Tx window.
TracedValue< uint32_t > m_advWnd
Advertised Window size.
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_txTrace
Trace of transmitted packets.
SequenceNumber32 m_recover
Previous highest Tx seqnum for fast recovery (set it to initial seq number)
bool m_recoverActive
Whether "m_recover" has been set/activated It is used to avoid comparing with the old m_recover value...
void DoRetransmit()
Retransmit the first segment marked as lost, without considering available window nor pacing.
bool CheckNoEcn(uint8_t tos) const
Checks if TOS has no ECN codepoints.
virtual void SetNode(Ptr< Node > node)
Set the associated node.
int ShutdownRecv() override
uint8_t m_sndWindShift
Window shift to apply to incoming segments.
Ptr< TcpL4Protocol > m_tcp
the associated TCP L4 protocol
Ptr< TcpSocketState > m_tcb
Congestion control information.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
void UpdateSsThresh(uint32_t oldValue, uint32_t newValue) const
Callback function to hook to TcpSocketState slow start threshold.
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_rxTrace
Trace of received packets.
virtual void SetTcp(Ptr< TcpL4Protocol > tcp)
Set the associated TCP L4 protocol.
void EnterRecovery(uint32_t currentDelivered)
Enter the CA_RECOVERY, and retransmit the head.
Time GetMinRto() const
Get the Minimum RTO.
void ProcessSynSent(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon SYN_SENT.
void ForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
void CancelAllTimers()
Cancel all timer when endpoint is deleted.
Time GetDelAckTimeout() const override
Get the time to delay an ACK.
Ptr< TcpRecoveryOps > m_recoveryOps
Recovery Algorithm.
TracedCallback< uint32_t, uint32_t > m_bytesInFlightTrace
Callback pointer for bytesInFlight trace chaining.
uint32_t GetInitialSSThresh() const override
Get the initial Slow Start Threshold.
void NotifyPacingPerformed()
Notify Pacing.
void SetDelAckTimeout(Time timeout) override
Set the time to delay an ACK.
void CloseAndNotify()
Peacefully close the socket by notifying the upper layer and deallocate end point.
uint8_t MarkEcnEct1(uint8_t tos) const
Mark ECT(1) codepoint.
Ptr< TcpRateOps > m_rateOps
Rate operations.
void PeerClose(Ptr< Packet > p, const TcpHeader &tcpHeader)
Received a FIN from peer, notify rx buffer.
int Close() override
Close a socket.
bool m_shutdownSend
Send no longer allowed.
bool IsPacingEnabled() const
Return true if packets in the current window should be paced.
void ProcessOptionWScale(const Ptr< const TcpOption > option)
Read and parse the Window scale option.
bool m_closeOnEmpty
Close socket upon tx buffer emptied.
virtual void ReTxTimeout()
An RTO event happened.
void AddOptionSackPermitted(TcpHeader &header)
Add the SACK PERMITTED option to the header.
TracedValue< Time > m_rto
Retransmit timeout.
uint32_t GetSndBufSize() const override
Get the send buffer size.
virtual void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Recv of a data, put into buffer, call L7 to get it if necessary.
EventId m_timewaitEvent
TIME_WAIT expiration event: Move this socket to CLOSED state.
Ptr< TcpTxBuffer > m_txBuffer
Tx buffer.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_dupAckCount
Dupack counter.
void SetRetxThresh(uint32_t retxThresh)
Set the retransmission threshold (dup ack threshold for a fast retransmit)
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
TracedCallback< SequenceNumber32, SequenceNumber32 > m_nextTxSequenceTrace
Callback pointer for next tx sequence chaining.
void UpdateBytesInFlight(uint32_t oldValue, uint32_t newValue) const
Callback function to hook to TcpSocketState bytes inflight.
EventId m_delAckEvent
Delayed ACK timeout event.
TracedCallback< Time, Time > m_lastRttTrace
Callback pointer for RTT trace chaining.
bool GetTcpNoDelay() const override
Check if Nagle's algorithm is enabled or not.
virtual void SetRtt(Ptr< RttEstimator > rtt)
Set the associated RTT estimator.
TracedCallback< uint32_t, uint32_t > m_cWndTrace
Callback pointer for cWnd trace chaining.
void UpdatePacingRateTrace(DataRate oldValue, DataRate newValue) const
Callback function to hook to TcpSocketState pacing rate.
void SetDataRetries(uint32_t retries) override
Set the number of data transmission retries before giving up.
void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
TracedCallback< TcpSocketState::EcnState_t, TcpSocketState::EcnState_t > m_ecnStateTrace
Callback pointer for ECN state trace chaining.
void SetSynRetries(uint32_t count) override
Set the number of connection retries before giving up.
void ProcessWait(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSE_WAIT, FIN_WAIT_1, FIN_WAIT_2.
SequenceNumber32 m_highTxAck
Highest ack sent.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
bool m_timestampEnabled
Timestamp option enabled.
virtual void PersistTimeout()
Send 1 byte probe to get an updated window size.
TracedValue< TcpStates_t > m_state
TCP state.
int SetupCallback()
Common part of the two Bind(), i.e.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
uint8_t MarkEcnEct0(uint8_t tos) const
Mark ECT(0) codepoint.
Timer m_pacingTimer
Pacing Event.
EventId m_retxEvent
Retransmission event.
uint32_t m_bytesAckedNotProcessed
Bytes acked, but not processed.
void AddOptionTimestamp(TcpHeader &header)
Add the timestamp option to the header.
virtual uint32_t BytesInFlight() const
Return total bytes in flight.
uint32_t GetSegSize() const override
Get the segment size.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
uint32_t m_dataRetries
Number of data retransmission attempts.
double m_msl
Max segment lifetime.
void ProcessLastAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon LAST_ACK.
bool m_limitedTx
perform limited transmit
virtual uint32_t SendDataPacket(SequenceNumber32 seq, uint32_t maxSize, bool withAck)
Extract at most maxSize bytes from the TxBuffer at sequence seq, add the TCP header,...
TracedCallback< TcpSocketState::TcpCongState_t, TcpSocketState::TcpCongState_t > m_congStateTrace
Callback pointer for congestion state trace chaining.
void ProcessSynRcvd(Ptr< Packet > packet, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Received a packet upon SYN_RCVD.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
SocketType GetSocketType() const override
int ShutdownSend() override
TracedValue< SequenceNumber32 > m_ecnCWRSeq
Sequence number of the last sent CWR.
Time GetPersistTimeout() const override
Get the timeout for persistent connection.
void UpdateCwnd(uint32_t oldValue, uint32_t newValue) const
Callback function to hook to TcpSocketState congestion window.
uint32_t m_delAckCount
Delayed ACK counter.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
static uint32_t SafeSubtraction(uint32_t a, uint32_t b)
Performs a safe subtraction between a and b (a-b)
virtual void DelAckTimeout()
Action upon delay ACK timeout, i.e.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
Time m_cnTimeout
Timeout for connection retry.
Time GetClockGranularity() const
Get the Clock Granularity (used in RTO calcs).
bool m_winScalingEnabled
Window Scale option enabled (RFC 7323)
void UpdateEcnState(TcpSocketState::EcnState_t oldValue, TcpSocketState::EcnState_t newValue) const
Callback function to hook to EcnState state.
EventId m_sendPendingDataEvent
micro-delay event to send pending data
uint32_t m_delAckMaxCount
Number of packet to fire an ACK before delay timeout.
uint8_t CalculateWScale() const
Calculate window scale value based on receive buffer space.
virtual void NewAck(const SequenceNumber32 &seq, bool resetRTO)
Update buffers w.r.t.
bool m_closeNotified
Told app to close socket.
int Listen() override
Listen for incoming connections.
void Destroy6()
Kill this socket by zeroing its attributes (IPv6)
uint8_t MarkEcnCe(uint8_t tos) const
Mark CE codepoint.
TracedValue< SequenceNumber32 > m_ecnCESeq
Sequence number of the last received Congestion Experienced.
void SetClockGranularity(Time clockGranularity)
Sets the Clock Granularity (used in RTO calcs).
bool IsValidTcpSegment(const SequenceNumber32 seq, const uint32_t tcpHeaderSize, const uint32_t tcpPayloadSize)
Checks whether the given TCP segment is valid or not.
Time m_clockGranularity
Clock Granularity used in RTO calcs.
void DupAck(uint32_t currentDelivered)
Dupack management.
bool m_shutdownRecv
Receive no longer allowed.
void UpdateCongState(TcpSocketState::TcpCongState_t oldValue, TcpSocketState::TcpCongState_t newValue) const
Callback function to hook to TcpSocketState congestion state.
virtual uint32_t Window() const
Return the max possible number of unacked bytes.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
std::deque< RttHistory > m_history
List of sent packet.
void(* TcpTxRxTracedCallback)(const Ptr< const Packet > packet, const TcpHeader &header, const Ptr< const TcpSocketBase > socket)
TracedCallback signature for tcp packet transmission or reception events.
void ProcessOptionSackPermitted(const Ptr< const TcpOption > option)
Read the SACK PERMITTED option.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
virtual uint32_t AvailableWindow() const
Return unfilled portion of window.
TracedValue< SequenceNumber32 > m_highRxMark
Highest seqno received.
uint8_t ClearEcnBits(uint8_t tos) const
Clears ECN bits from TOS.
void ReadOptions(const TcpHeader &tcpHeader, uint32_t *bytesSacked)
Read TCP options before Ack processing.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
bool m_connected
Connection established.
TracedValue< SequenceNumber32 > m_highRxAckMark
Highest ack received.
void AddOptionWScale(TcpHeader &header)
Add the window scale option to the header.
virtual void SendEmptyPacket(uint8_t flags)
Send a empty packet that carries a flag, e.g., ACK.
void UpdateWindowSize(const TcpHeader &header)
Update the receiver window (RWND) based on the value of the window field in the header.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
uint32_t GetDataRetries() const override
Get the number of data transmission retries before giving up.
int SetupEndpoint6()
Configure the endpoint v6 to a local address.
uint32_t GetRetxThresh() const
Get the retransmission threshold (dup ack threshold for a fast retransmit)
void DeallocateEndPoint()
Deallocate m_endPoint and m_endPoint6.
void Destroy()
Kill this socket by zeroing its attributes (IPv4)
void UpdateHighTxMark(SequenceNumber32 oldValue, SequenceNumber32 newValue) const
Callback function to hook to TcpSocketState high tx mark.
TcpSocketBase()
Create an unbound TCP socket.
void SetInitialSSThresh(uint32_t threshold) override
Set the initial Slow Start Threshold.
TracedCallback< DataRate, DataRate > m_pacingRateTrace
Callback pointer for pacing rate trace chaining.
uint32_t m_timestampToEcho
Timestamp to echo.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
void SetSndBufSize(uint32_t size) override
Set the send buffer size.
virtual Ptr< TcpSocketBase > Fork()
Call CopyObject<> to clone me.
TracedCallback< uint32_t, uint32_t > m_ssThTrace
Callback pointer for ssTh trace chaining.
SocketErrno m_errno
Socket error code.
SocketErrno GetErrno() const override
Get last error number.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
void ProcessClosing(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSING.
bool CheckEcnCe(uint8_t tos) const
Checks for CE codepoint.
TracedCallback< SequenceNumber32, SequenceNumber32 > m_highTxMarkTrace
Callback pointer for high tx mark chaining.
int Connect(const Address &address) override
Initiate a connection to a remote host.
Ptr< Node > m_node
the associated node
void SetSegSize(uint32_t size) override
Set the segment size.
TypeId GetInstanceTypeId() const override
Get the instance TypeId.
uint32_t m_synRetries
Number of connection attempts.
void SetConnTimeout(Time timeout) override
Set the connection timeout.
void SetDelAckMaxCount(uint32_t count) override
Set the number of packet to fire an ACK before delay timeout.
EventId m_lastAckEvent
Last ACK timeout event.
bool IsTcpOptionEnabled(uint8_t kind) const
Return true if the specified option is enabled.
void UpdatePacingRate()
Dynamically update the pacing rate.
EventId m_persistEvent
Persist event: Send 1 byte to probe for a non-zero Rx window.
void SetPacingStatus(bool pacing)
Enable or disable pacing.
void UpdateRtt(Time oldValue, Time newValue) const
Callback function to hook to TcpSocketState rtt.
void SetCongestionControlAlgorithm(Ptr< TcpCongestionOps > algo)
Install a congestion control algorithm on this socket.
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
virtual uint32_t UnAckDataCount() const
Return count of number of unacked bytes.
uint32_t m_dataRetrCount
Count of remaining data retransmission attempts.
void UpdateCwndInfl(uint32_t oldValue, uint32_t newValue) const
Callback function to hook to TcpSocketState inflated congestion window.
Ptr< TcpRxBuffer > GetRxBuffer() const
Get a pointer to the Rx buffer.
void SetPersistTimeout(Time timeout) override
Set the timeout for persistent connection.
void ConnectionSucceeded()
Schedule-friendly wrapper for Socket::NotifyConnectionSucceeded()
bool m_noDelay
Set to true to disable Nagle's algorithm.
uint32_t GetDelAckMaxCount() const override
Get the number of packet to fire an ACK before delay timeout.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
virtual void ProcessAck(const SequenceNumber32 &ackNumber, bool scoreboardUpdated, uint32_t currentDelivered, const SequenceNumber32 &oldHeadSequence)
Process a received ack.
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
virtual void DoForwardUp(Ptr< Packet > packet, const Address &fromAddress, const Address &toAddress)
Called by TcpSocketBase::ForwardUp{,6}().
bool m_isFirstPartialAck
First partial ACK during RECOVERY.
uint8_t MarkEcnCodePoint(const uint8_t tos, const TcpSocketState::EcnCodePoint_t codePoint) const
mark ECN code point
Time m_delAckTimeout
Time to delay an ACK.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
void SetInitialCwnd(uint32_t cwnd) override
Set the initial Congestion Window.
void SetUseEcn(TcpSocketState::UseEcn_t useEcn)
Set ECN mode of use on the socket.
bool CheckEcnEct0(uint8_t tos) const
Checks for ECT(0) codepoint.
void ProcessListen(Ptr< Packet > packet, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Received a packet upon LISTEN state.
uint32_t m_synCount
Count of remaining connection retries.
int DoConnect()
Perform the real connection tasks: Send SYN if allowed, RST if invalid.
uint32_t GetSynRetries() const override
Get the number of connection retries before giving up.
void DoPeerClose()
FIN is in sequence, notify app and respond with a FIN.
void SendRST()
Send reset and tear down this socket.
bool OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const
Check if a sequence number range is within the rx window.
TracedValue< SequenceNumber32 > m_ecnEchoSeq
Sequence number of the last received ECN Echo.
uint32_t m_retxThresh
Fast Retransmit threshold.
uint32_t GetRWnd() const
Get the current value of the receiver's offered window (RCV.WND)
SequenceNumber32 GetHighRxAck() const
Get the current value of the receiver's highest (in-sequence) sequence number acked.
void BindToNetDevice(Ptr< NetDevice > netdevice) override
Bind a socket to specific device.
void EnterCwr(uint32_t currentDelivered)
Enter CA_CWR state upon receipt of an ECN Echo.
virtual void EstimateRtt(const TcpHeader &tcpHeader)
Take into account the packet for RTT estimation.
uint32_t GetInitialCwnd() const override
Get the initial Congestion Window.
TracedValue< uint32_t > m_rWnd
Receiver window (RCV.WND in RFC793)
void ProcessOptionTimestamp(const Ptr< const TcpOption > option, const SequenceNumber32 &seq)
Process the timestamp option from other side.
void SetRcvBufSize(uint32_t size) override
Set the receive buffer size.
void SetTcpNoDelay(bool noDelay) override
Enable/Disable Nagle's algorithm.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
bool m_sackEnabled
RFC SACK option enabled.
void UpdateNextTxSequence(SequenceNumber32 oldValue, SequenceNumber32 newValue) const
Callback function to hook to TcpSocketState next tx sequence.
void SetMinRto(Time minRto)
Sets the Minimum RTO.
Time GetConnTimeout() const override
Get the connection timeout.
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
uint32_t ProcessOptionSack(const Ptr< const TcpOption > option)
Read the SACK option.
void SetRecoveryAlgorithm(Ptr< TcpRecoveryOps > recovery)
Install a recovery algorithm on this socket.
int DoClose()
Close a socket by sending RST, FIN, or FIN+ACK, depend on the current state.
void AddSocketTags(const Ptr< Packet > &p) const
Add Tags for the Socket.
TracedCallback< uint32_t, uint32_t > m_cWndInflTrace
Callback pointer for cWndInfl trace chaining.
uint32_t GetRcvBufSize() const override
Get the receive buffer size.
(abstract) base class of all TcpSockets
Definition: tcp-socket.h:48
EcnCodePoint_t
ECN code points.
UseEcn_t
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn.
TcpCongState_t
Definition of the Congestion state machine.
EcnState_t
Definition of the Ecn state machine.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:297
A simple virtual Timer class.
Definition: timer.h:78
@ CANCEL_ON_DESTROY
This policy cancels the event from the destructor of the Timer or from Suspend().
Definition: timer.h:97
Forward calls to a chain of Callback.
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:44
void(* EcnStatesTracedValueCallback)(const TcpSocketState::EcnState_t oldValue, const TcpSocketState::EcnState_t newValue)
TracedValue Callback signature for ECN state trace.
void(* TcpCongStatesTracedValueCallback)(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
TracedValue Callback signature for TcpCongState_t.
@ CLOSED
Socket is finished
Definition: tcp-socket.h:67
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Time timeout