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