A Discrete-Event Network Simulator
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 Georgia Tech Research Corporation
4  * Copyright (c) 2010 Adrian Sai-wah Tam
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
20  */
21 #ifndef TCP_SOCKET_BASE_H
22 #define TCP_SOCKET_BASE_H
24 #include <stdint.h>
25 #include <queue>
26 #include "ns3/traced-value.h"
27 #include "ns3/tcp-socket.h"
28 #include "ns3/ipv4-header.h"
29 #include "ns3/ipv6-header.h"
30 #include "ns3/timer.h"
31 #include "ns3/sequence-number.h"
32 #include "ns3/data-rate.h"
33 #include "ns3/node.h"
34 #include "ns3/tcp-socket-state.h"
36 namespace ns3 {
38 class Ipv4EndPoint;
39 class Ipv6EndPoint;
40 class Node;
41 class Packet;
42 class TcpL4Protocol;
43 class TcpHeader;
44 class TcpCongestionOps;
45 class TcpRecoveryOps;
46 class RttEstimator;
47 class TcpRxBuffer;
48 class TcpTxBuffer;
49 class TcpOption;
50 class Ipv4Interface;
51 class Ipv6Interface;
52 class TcpRateOps;
60 {
61 public:
68  RttHistory (SequenceNumber32 s, uint32_t c, Time t);
73  RttHistory (const RttHistory& h); // Copy constructor
74 public:
76  uint32_t count;
78  bool retx;
79 };
217 class TcpSocketBase : public TcpSocket
218 {
219 public:
225  static TypeId GetTypeId (void);
231  virtual TypeId GetInstanceTypeId () const;
237  friend class TcpGeneralTest;
242  TcpSocketBase (void);
249  TcpSocketBase (const TcpSocketBase& sock);
250  virtual ~TcpSocketBase (void);
252  // Set associated Node, TcpL4Protocol, RttEstimator to this socket
258  virtual void SetNode (Ptr<Node> node);
264  virtual void SetTcp (Ptr<TcpL4Protocol> tcp);
270  virtual void SetRtt (Ptr<RttEstimator> rtt);
276  void SetMinRto (Time minRto);
282  Time GetMinRto (void) const;
288  void SetClockGranularity (Time clockGranularity);
294  Time GetClockGranularity (void) const;
300  Ptr<TcpTxBuffer> GetTxBuffer (void) const;
306  Ptr<TcpRxBuffer> GetRxBuffer (void) const;
312  void SetRetxThresh (uint32_t retxThresh);
318  uint32_t GetRetxThresh (void) const { return m_retxThresh; }
375  void UpdatePacingRateTrace (DataRate oldValue, DataRate newValue);
382  void UpdateCwnd (uint32_t oldValue, uint32_t newValue);
389  void UpdateCwndInfl (uint32_t oldValue, uint32_t newValue);
396  void UpdateSsThresh (uint32_t oldValue, uint32_t newValue);
412  TcpSocketState::EcnState_t newValue);
419  void UpdateHighTxMark (SequenceNumber32 oldValue, SequenceNumber32 newValue);
426  void UpdateNextTxSequence (SequenceNumber32 oldValue, SequenceNumber32 newValue);
433  void UpdateBytesInFlight (uint32_t oldValue, uint32_t newValue);
440  void UpdateRtt (Time oldValue, Time newValue);
462  inline uint8_t MarkEcnEct0 (uint8_t tos) const
463  {
464  return ((tos & 0xfc) | 0x02);
465  }
473  inline uint8_t MarkEcnEct1 (uint8_t tos) const
474  {
475  return ((tos & 0xfc) | 0x01);
476  }
484  inline uint8_t MarkEcnCe (uint8_t tos) const
485  {
486  return ((tos & 0xfc) | 0x03);
487  }
495  inline uint8_t ClearEcnBits (uint8_t tos) const
496  {
497  return tos & 0xfc;
498  }
506  inline bool CheckNoEcn (uint8_t tos) const
507  {
508  return ((tos & 0x03) == 0x00);
509  }
517  inline bool CheckEcnEct0 (uint8_t tos) const
518  {
519  return ((tos & 0x03) == 0x02);
520  }
528  inline bool CheckEcnEct1 (uint8_t tos) const
529  {
530  return ((tos & 0x03) == 0x01);
531  }
538  inline bool CheckEcnCe (uint8_t tos) const
539  {
540  return ((tos & 0x03) == 0x03);
541  }
550  inline uint8_t MarkEcnCodePoint (const uint8_t tos, const TcpSocketState::EcnCodePoint_t codePoint) const
551  {
552  return ((tos & 0xfc) | codePoint);
553  }
560  void SetUseEcn (TcpSocketState::UseEcn_t useEcn);
566  void SetPacingStatus (bool pacing);
572  void SetPaceInitialWindow (bool paceWindow);
574  // Necessary implementations of null functions from ns3::Socket
575  virtual enum SocketErrno GetErrno (void) const; // returns m_errno
576  virtual enum SocketType GetSocketType (void) const; // returns socket type
577  virtual Ptr<Node> GetNode (void) const; // returns m_node
578  virtual int Bind (void); // Bind a socket by setting up endpoint in TcpL4Protocol
579  virtual int Bind6 (void); // Bind a socket by setting up endpoint in TcpL4Protocol
580  virtual int Bind (const Address &address); // ... endpoint of specific addr or port
581  virtual int Connect (const Address &address); // Setup endpoint and call ProcessAction() to connect
582  virtual int Listen (void); // Verify the socket is in a correct state and call ProcessAction() to listen
583  virtual int Close (void); // Close by app: Kill socket upon tx buffer emptied
584  virtual int ShutdownSend (void); // Assert the m_shutdownSend flag to prevent send to network
585  virtual int ShutdownRecv (void); // Assert the m_shutdownRecv flag to prevent forward to app
586  virtual int Send (Ptr<Packet> p, uint32_t flags); // Call by app to send data to network
587  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress); // Same as Send(), toAddress is insignificant
588  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); // Return a packet to be forwarded to app
589  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); // ... and write the remote address at fromAddress
590  virtual uint32_t GetTxAvailable (void) const; // Available Tx buffer size
591  virtual uint32_t GetRxAvailable (void) const; // Available-to-read data size, i.e. value of m_rxAvailable
592  virtual int GetSockName (Address &address) const; // Return local addr:port in address
593  virtual int GetPeerName (Address &address) const;
594  virtual void BindToNetDevice (Ptr<NetDevice> netdevice); // NetDevice with my m_endPoint
603  typedef void (* TcpTxRxTracedCallback)(const Ptr<const Packet> packet, const TcpHeader& header,
604  const Ptr<const TcpSocketBase> socket);
606 protected:
607  // Implementing ns3::TcpSocket -- Attribute get/set
608  // inherited, no need to doc
610  virtual void SetSndBufSize (uint32_t size);
611  virtual uint32_t GetSndBufSize (void) const;
612  virtual void SetRcvBufSize (uint32_t size);
613  virtual uint32_t GetRcvBufSize (void) const;
614  virtual void SetSegSize (uint32_t size);
615  virtual uint32_t GetSegSize (void) const;
616  virtual void SetInitialSSThresh (uint32_t threshold);
617  virtual uint32_t GetInitialSSThresh (void) const;
618  virtual void SetInitialCwnd (uint32_t cwnd);
619  virtual uint32_t GetInitialCwnd (void) const;
620  virtual void SetConnTimeout (Time timeout);
621  virtual Time GetConnTimeout (void) const;
622  virtual void SetSynRetries (uint32_t count);
623  virtual uint32_t GetSynRetries (void) const;
624  virtual void SetDataRetries (uint32_t retries);
625  virtual uint32_t GetDataRetries (void) const;
626  virtual void SetDelAckTimeout (Time timeout);
627  virtual Time GetDelAckTimeout (void) const;
628  virtual void SetDelAckMaxCount (uint32_t count);
629  virtual uint32_t GetDelAckMaxCount (void) const;
630  virtual void SetTcpNoDelay (bool noDelay);
631  virtual bool GetTcpNoDelay (void) const;
632  virtual void SetPersistTimeout (Time timeout);
633  virtual Time GetPersistTimeout (void) const;
634  virtual bool SetAllowBroadcast (bool allowBroadcast);
635  virtual bool GetAllowBroadcast (void) const;
639  // Helper functions: Connection set up
646  int SetupCallback (void);
653  int DoConnect (void);
658  void ConnectionSucceeded (void);
665  int SetupEndpoint (void);
672  int SetupEndpoint6 (void);
686  virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader,
687  const Address& fromAddress, const Address& toAddress);
691  // Helper functions: Transfer operation
700  bool IsValidTcpSegment (const SequenceNumber32 seq, const uint32_t tcpHeaderSize,
701  const uint32_t tcpPayloadSize);
711  void ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, Ptr<Ipv4Interface> incomingInterface);
721  void ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface);
735  virtual void DoForwardUp (Ptr<Packet> packet, const Address &fromAddress,
736  const Address &toAddress);
747  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo);
758  void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo);
768  uint32_t SendPendingData (bool withAck = false);
779  virtual uint32_t SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool withAck);
786  virtual void SendEmptyPacket (uint8_t flags);
791  void SendRST (void);
800  bool OutOfRange (SequenceNumber32 head, SequenceNumber32 tail) const;
803  // Helper functions: Connection close
810  int DoClose (void);
815  void CloseAndNotify (void);
823  void Destroy (void);
831  void Destroy6 (void);
836  void DeallocateEndPoint (void);
844  void PeerClose (Ptr<Packet> p, const TcpHeader& tcpHeader);
849  void DoPeerClose (void);
854  void CancelAllTimers (void);
859  void TimeWait (void);
861  // State transition functions
871  void ProcessEstablished (Ptr<Packet> packet, const TcpHeader& tcpHeader); // Received a packet upon ESTABLISHED state
881  void ProcessListen (Ptr<Packet> packet, const TcpHeader& tcpHeader,
882  const Address& fromAddress, const Address& toAddress);
890  void ProcessSynSent (Ptr<Packet> packet, const TcpHeader& tcpHeader);
900  void ProcessSynRcvd (Ptr<Packet> packet, const TcpHeader& tcpHeader,
901  const Address& fromAddress, const Address& toAddress);
909  void ProcessWait (Ptr<Packet> packet, const TcpHeader& tcpHeader);
917  void ProcessClosing (Ptr<Packet> packet, const TcpHeader& tcpHeader);
925  void ProcessLastAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
927  // Window management
936  virtual uint32_t UnAckDataCount (void) const;
945  virtual uint32_t BytesInFlight (void) const;
951  virtual uint32_t Window (void) const;
957  virtual uint32_t AvailableWindow (void) const;
965  virtual uint16_t AdvertisedWindowSize (bool scale = true) const;
979  void UpdateWindowSize (const TcpHeader& header);
982  // Manage data tx/rx
988  virtual Ptr<TcpSocketBase> Fork (void);
995  virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
1006  virtual void ProcessAck (const SequenceNumber32 &ackNumber, bool scoreboardUpdated,
1007  uint32_t currentDelivered, const SequenceNumber32 &oldHeadSequence);
1014  virtual void ReceivedData (Ptr<Packet> packet, const TcpHeader& tcpHeader);
1020  virtual void EstimateRtt (const TcpHeader& tcpHeader);
1030  virtual void UpdateRttHistory (const SequenceNumber32 &seq, uint32_t sz,
1031  bool isRetransmission);
1038  virtual void NewAck (SequenceNumber32 const& seq, bool resetRTO);
1045  void DupAck (uint32_t currentDelivered);
1052  void EnterRecovery (uint32_t currentDelivered);
1057  virtual void ReTxTimeout (void);
1062  virtual void DelAckTimeout (void);
1067  virtual void LastAckTimeout (void);
1072  virtual void PersistTimeout (void);
1078  void DoRetransmit (void);
1087  void AddOptions (TcpHeader& tcpHeader);
1097  void ReadOptions (const TcpHeader &tcpHeader, uint32_t *bytesSacked);
1105  bool IsTcpOptionEnabled (uint8_t kind) const;
1115  void ProcessOptionWScale (const Ptr<const TcpOption> option);
1124  void AddOptionWScale (TcpHeader& header);
1133  uint8_t CalculateWScale () const;
1151  uint32_t ProcessOptionSack(const Ptr<const TcpOption> option);
1158  void AddOptionSackPermitted (TcpHeader &header);
1165  void AddOptionSack (TcpHeader& header);
1177  void ProcessOptionTimestamp (const Ptr<const TcpOption> option,
1178  const SequenceNumber32 &seq);
1187  void AddOptionTimestamp (TcpHeader& header);
1198  static uint32_t SafeSubtraction (uint32_t a, uint32_t b);
1203  void NotifyPacingPerformed (void);
1209  bool IsPacingEnabled (void) const;
1216  void UpdatePacingRate (void);
1222  void AddSocketTags (const Ptr<Packet> &p) const;
1229  uint32_t GetRWnd (void) const;
1236  SequenceNumber32 GetHighRxAck (void) const;
1238 protected:
1239  // Counters and events
1246  // ACK management
1247  uint32_t m_dupAckCount {0};
1248  uint32_t m_delAckCount {0};
1249  uint32_t m_delAckMaxCount {0};
1251  // Nagle algorithm
1252  bool m_noDelay {false};
1254  // Retries
1255  uint32_t m_synCount {0};
1256  uint32_t m_synRetries {0};
1257  uint32_t m_dataRetrCount {0};
1258  uint32_t m_dataRetries {0};
1260  // Timeouts
1268  // History of RTT
1269  std::deque<RttHistory> m_history;
1271  // Connections to other layers of TCP/IP
1281  // Tx buffer management
1284  // State-related attributes
1286  mutable enum SocketErrno m_errno {ERROR_NOTERROR};
1287  bool m_closeNotified {false};
1288  bool m_closeOnEmpty {false};
1289  bool m_shutdownSend {false};
1290  bool m_shutdownRecv {false};
1291  bool m_connected {false};
1292  double m_msl {0.0};
1294  // Window management
1295  uint16_t m_maxWinSize {0};
1303  // Options
1304  bool m_sackEnabled {true};
1305  bool m_winScalingEnabled {true};
1306  uint8_t m_rcvWindShift {0};
1307  uint8_t m_sndWindShift {0};
1308  bool m_timestampEnabled {true};
1309  uint32_t m_timestampToEcho {0};
1313  // Fast Retransmit and Recovery
1315  bool m_recoverActive {false};
1316  uint32_t m_retxThresh {3};
1319  bool m_limitedTx {true};
1321  // Transmission Control Block
1327  // Guesses over the other connection end
1328  bool m_isFirstPartialAck {true};
1330  // The following two traces pass a packet with a TCP header
1337  // Pacing related variable
1340  // Parameters related to Explicit Congestion Notification
1344 };
1354  const TcpSocketState::TcpCongState_t newValue);
1364  const TcpSocketState::EcnState_t newValue);
1366 } // namespace ns3
1368 #endif /* TCP_SOCKET_BASE_H */
TracedCallback< SequenceNumber32, SequenceNumber32 > m_highTxMarkTrace
Callback pointer for high tx mark chaining.
void SetCongestionControlAlgorithm(Ptr< TcpCongestionOps > algo)
Install a congestion control algorithm on this socket.
void PeerClose(Ptr< Packet > p, const TcpHeader &tcpHeader)
Received a FIN from peer, notify rx buffer.
bool m_limitedTx
perform limited transmit
void ProcessListen(Ptr< Packet > packet, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Received a packet upon LISTEN state.
TracedValue< uint32_t > m_advWnd
Advertised Window size.
virtual void SetInitialCwnd(uint32_t cwnd)
Set the initial Congestion Window.
virtual int Listen(void)
Listen for incoming connections.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Packet header for IPv6.
Definition: ipv6-header.h:34
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn...
virtual bool GetTcpNoDelay(void) const
Check if Nagle&#39;s algorithm is enabled or not.
void ProcessWait(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSE_WAIT, FIN_WAIT_1, FIN_WAIT_2.
uint32_t m_dataRetries
Number of data retransmission attempts.
virtual void SetInitialSSThresh(uint32_t threshold)
Set the initial Slow Start Threshold.
Callback template class.
Definition: callback.h:1278
bool m_noDelay
Set to true to disable Nagle&#39;s algorithm.
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, and send to TcpL4Protocol.
A simple virtual Timer class.
Definition: timer.h:73
virtual Time GetPersistTimeout(void) const
Get the timeout for persistent connection.
(abstract) base class of all TcpSockets
Definition: tcp-socket.h:47
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
TracedCallback< DataRate, DataRate > m_pacingRateTrace
Callback pointer for pacing rate trace chaining.
virtual ~TcpSocketBase(void)
uint32_t m_dataRetrCount
Count of remaining data retransmission attempts.
uint32_t m_synRetries
Number of connection attempts.
TracedValue< SequenceNumber32 > m_highRxAckMark
Highest ack received.
virtual int ShutdownRecv(void)
Create an unbound TCP socket.
void SetClockGranularity(Time clockGranularity)
Sets the Clock Granularity (used in RTO calcs).
EventId m_retxEvent
Retransmission event.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
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 ProcessOptionSackPermitted(const Ptr< const TcpOption > option)
Read the SACK PERMITTED option.
Forward calls to a chain of Callback.
virtual void SetPersistTimeout(Time timeout)
Set the timeout for persistent connection.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
EventId m_timewaitEvent
TIME_WAIT expiration event: Move this socket to CLOSED state.
void UpdateEcnState(TcpSocketState::EcnState_t oldValue, TcpSocketState::EcnState_t newValue)
Callback function to hook to EcnState state.
uint32_t GetRetxThresh(void) const
Get the retransmission threshold (dup ack threshold for a fast retransmit)
virtual uint32_t GetSndBufSize(void) const
Get the send buffer size.
uint8_t ClearEcnBits(uint8_t tos) const
Clears ECN bits from TOS.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t MarkEcnCodePoint(const uint8_t tos, const TcpSocketState::EcnCodePoint_t codePoint) const
mark ECN code point
void ProcessOptionTimestamp(const Ptr< const TcpOption > option, const SequenceNumber32 &seq)
Process the timestamp option from other side.
void SetUseEcn(TcpSocketState::UseEcn_t useEcn)
Set ECN mode of use on the socket.
virtual Time GetDelAckTimeout(void) const
Get the time to delay an ACK.
void UpdateHighTxMark(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Callback function to hook to TcpSocketState high tx mark.
void SendRST(void)
Send reset and tear down this socket.
virtual uint32_t GetDelAckMaxCount(void) const
Get the number of packet to fire an ACK before delay timeout.
Ptr< TcpSocketState > m_tcb
Congestion control information.
virtual void ProcessAck(const SequenceNumber32 &ackNumber, bool scoreboardUpdated, uint32_t currentDelivered, const SequenceNumber32 &oldHeadSequence)
Process a received ack.
bool m_winScalingEnabled
Window Scale option enabled (RFC 7323)
bool m_timestampEnabled
Timestamp option enabled.
Timer m_pacingTimer
Pacing Event.
uint16_t m_maxWinSize
Maximum window size to advertise.
bool retx
True if this has been retransmitted.
virtual void NewAck(SequenceNumber32 const &seq, bool resetRTO)
Update buffers w.r.t.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
void CancelAllTimers(void)
Cancel all timer when endpoint is deleted.
uint32_t count
Number of bytes sent.
Time m_cnTimeout
Timeout for connection retry.
virtual Time GetConnTimeout(void) const
Get the connection timeout.
EventId m_lastAckEvent
Last ACK timeout event.
void ConnectionSucceeded(void)
Schedule-friendly wrapper for Socket::NotifyConnectionSucceeded()
TracedValue< SequenceNumber32 > m_ecnCESeq
Sequence number of the last received Congestion Experienced.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
ns3::Time timeout
void AddSocketTags(const Ptr< Packet > &p) const
Add Tags for the Socket.
void(* TcpTxRxTracedCallback)(const Ptr< const Packet > packet, const TcpHeader &header, const Ptr< const TcpSocketBase > socket)
TracedCallback signature for tcp packet transmission or reception events.
virtual uint32_t GetInitialSSThresh(void) const
Get the initial Slow Start Threshold.
virtual uint32_t BytesInFlight(void) const
Return total bytes in flight.
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void DoPeerClose(void)
FIN is in sequence, notify app and respond with a FIN.
TracedCallback< TcpSocketState::EcnState_t, TcpSocketState::EcnState_t > m_ecnStateTrace
Callback pointer for ECN state trace chaining.
virtual void PersistTimeout(void)
Send 1 byte probe to get an updated window size.
virtual void SetSynRetries(uint32_t count)
Set the number of connection retries before giving up.
TracedValue< TcpStates_t > m_state
TCP state.
Time GetMinRto(void) const
Get the Minimum RTO.
uint32_t m_delAckMaxCount
Number of packet to fire an ACK before delay timeout.
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
void SetMinRto(Time minRto)
Sets the Minimum RTO.
uint32_t m_delAckCount
Delayed ACK counter.
SequenceNumber32 m_recover
Previous highest Tx seqnum for fast recovery (set it to initial seq number)
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 int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void(* TcpCongStatesTracedValueCallback)(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
TracedValue Callback signature for TcpCongState_t.
Class for representing data rates.
Definition: data-rate.h:88
virtual bool GetAllowBroadcast(void) const
Query whether broadcast datagram transmissions are allowed.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:282
virtual uint32_t GetRcvBufSize(void) const
Get the receive buffer size.
Packet header for IPv4.
Definition: ipv4-header.h:33
void UpdateBytesInFlight(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState bytes inflight.
virtual enum SocketType GetSocketType(void) const
virtual void SetDataRetries(uint32_t retries)
Set the number of data transmission retries before giving up.
Ptr< TcpCongestionOps > m_congestionControl
Congestion control.
Ptr< TcpRateOps > m_rateOps
Rate operations.
Ptr< TcpRxBuffer > GetRxBuffer(void) const
Get a pointer to the Rx buffer.
bool CheckNoEcn(uint8_t tos) const
Checks if TOS has no ECN codepoints.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
uint8_t MarkEcnCe(uint8_t tos) const
Mark CE codepoint.
void UpdateCwnd(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState congestion window.
bool IsTcpOptionEnabled(uint8_t kind) const
Return true if the specified option is enabled.
virtual uint32_t GetSegSize(void) const
Get the segment size.
virtual void EstimateRtt(const TcpHeader &tcpHeader)
Take into account the packet for RTT estimation.
virtual int GetSockName(Address &address) const
Get socket address.
Time time
Time this one was sent.
void ReadOptions(const TcpHeader &tcpHeader, uint32_t *bytesSacked)
Read TCP options before Ack processing.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
Ptr< TcpTxBuffer > m_txBuffer
Tx buffer.
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 OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const
Check if a sequence number range is within the rx window.
bool IsPacingEnabled(void) const
Return true if packets in the current window should be paced.
virtual uint32_t Window(void) const
Return the max possible number of unacked bytes.
void UpdateWindowSize(const TcpHeader &header)
Update the receiver window (RWND) based on the value of the window field in the header.
void AddOptionTimestamp(TcpHeader &header)
Add the timestamp option to the header.
SequenceNumber32 m_highTxAck
Highest ack sent.
TracedCallback< uint32_t, uint32_t > m_cWndTrace
Callback pointer for cWnd trace chaining.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual uint32_t GetSynRetries(void) const
Get the number of connection retries before giving up.
void SetPacingStatus(bool pacing)
Enable or disable pacing.
std::deque< RttHistory > m_history
List of sent packet.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
void SetRetxThresh(uint32_t retxThresh)
Set the retransmission threshold (dup ack threshold for a fast retransmit)
virtual void SetTcpNoDelay(bool noDelay)
Enable/Disable Nagle&#39;s algorithm.
Ptr< TcpRecoveryOps > m_recoveryOps
Recovery Algorithm.
RttHistory(SequenceNumber32 s, uint32_t c, Time t)
Constructor - builds an RttHistory with the given parameters.
void NotifyPacingPerformed(void)
Notify Pacing.
void UpdateCongState(TcpSocketState::TcpCongState_t oldValue, TcpSocketState::TcpCongState_t newValue)
Callback function to hook to TcpSocketState congestion state.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
A base class for implementation of a stream socket using TCP.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
bool m_closeNotified
Told app to close socket.
void ProcessSynSent(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon SYN_SENT.
static uint32_t SafeSubtraction(uint32_t a, uint32_t b)
Performs a safe subtraction between a and b (a-b)
int SetupCallback(void)
Common part of the two Bind(), i.e.
virtual void SetTcp(Ptr< TcpL4Protocol > tcp)
Set the associated TCP L4 protocol.
bool m_isFirstPartialAck
First partial ACK during RECOVERY.
Ptr< TcpL4Protocol > m_tcp
the associated TCP L4 protocol
void SetRecoveryAlgorithm(Ptr< TcpRecoveryOps > recovery)
Install a recovery algorithm on this socket.
void ProcessSynRcvd(Ptr< Packet > packet, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Received a packet upon SYN_RCVD.
Ptr< TcpTxBuffer > GetTxBuffer(void) const
Get a pointer to the Tx buffer.
uint32_t GetRWnd(void) const
Get the current value of the receiver&#39;s offered window (RCV.WND)
virtual int ShutdownSend(void)
uint32_t m_retxThresh
Fast Retransmit threshold.
Definition of the Congestion state machine.
void SetPaceInitialWindow(bool paceWindow)
Enable or disable pacing of the initial window.
This policy cancels the event from the destructor of the Timer or from Suspend(). ...
Definition: timer.h:93
virtual void SetDelAckMaxCount(uint32_t count)
Set the number of packet to fire an ACK before delay timeout.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
int DoConnect(void)
Perform the real connection tasks: Send SYN if allowed, RST if invalid.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
void UpdateNextTxSequence(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Callback function to hook to TcpSocketState next tx sequence.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_dupAckCount
Dupack counter.
void UpdateRtt(Time oldValue, Time newValue)
Callback function to hook to TcpSocketState rtt.
Ptr< Node > m_node
the associated node
virtual uint32_t AvailableWindow(void) const
Return unfilled portion of window.
Definition: first.py:44
void TimeWait(void)
Move from CLOSING or FIN_WAIT_2 to TIME_WAIT state.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual void SetNode(Ptr< Node > node)
Set the associated node.
virtual uint32_t GetDataRetries(void) const
Get the number of data transmission retries before giving up.
TracedCallback< uint32_t, uint32_t > m_bytesInFlightTrace
Callback pointer for bytesInFlight trace chaining.
uint32_t ProcessOptionSack(const Ptr< const TcpOption > option)
Read the SACK option.
void AddOptionSackPermitted(TcpHeader &header)
Add the SACK PERMITTED option to the header.
bool m_recoverActive
Whether "m_recover" has been set/activated It is used to avoid comparing with the old m_recover value...
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
SequenceNumber32 GetHighRxAck(void) const
Get the current value of the receiver&#39;s highest (in-sequence) sequence number acked.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual int Close(void)
Close a socket.
void UpdateCwndInfl(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState inflated congestion window.
TracedValue< SequenceNumber32 > m_ecnCWRSeq
Sequence number of the last sent CWR.
virtual void SetRtt(Ptr< RttEstimator > rtt)
Set the associated RTT estimator.
virtual TypeId GetInstanceTypeId() const
Get the instance TypeId.
double m_msl
Max segment lifetime.
virtual void ReTxTimeout(void)
An RTO event happened.
Time m_minRto
minimum value of the Retransmit timeout
bool CheckEcnEct0(uint8_t tos) const
Checks for ECT(0) codepoint.
virtual void SendEmptyPacket(uint8_t flags)
Send a empty packet that carries a flag, e.g., ACK.
Time m_delAckTimeout
Time to delay an ACK.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
Socket is finished.
Definition: tcp-socket.h:66
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual void SetSndBufSize(uint32_t size)
Set the send buffer size.
virtual void SetDelAckTimeout(Time timeout)
Set the time to delay an ACK.
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void ProcessEstablished(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon ESTABLISHED state.
ECN code points.
General infrastructure for TCP testing.
void ProcessOptionWScale(const Ptr< const TcpOption > option)
Read and parse the Window scale option.
bool m_connected
Connection established.
TracedValue< Time > m_rto
Retransmit timeout.
bool CheckEcnCe(uint8_t tos) const
Checks for CE codepoint.
An identifier for simulation events.
Definition: event-id.h:53
Helper class to store RTT measurements.
uint8_t m_rcvWindShift
Window shift to apply to outgoing segments.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
int DoClose(void)
Close a socket by sending RST, FIN, or FIN+ACK, depend on the current state.
SequenceNumber32 seq
First sequence number in packet sent.
void DupAck(uint32_t currentDelivered)
Dupack management.
TracedValue< SequenceNumber32 > m_ecnEchoSeq
Sequence number of the last received ECN Echo.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
A representation of an IPv6 endpoint/connection.
bool m_sackEnabled
RFC SACK option enabled.
uint32_t m_timestampToEcho
Timestamp to echo.
uint32_t m_synCount
Count of remaining connection retries.
void UpdatePacingRateTrace(DataRate oldValue, DataRate newValue)
Callback function to hook to TcpSocketState pacing rate.
void AddOptionSack(TcpHeader &header)
Add the SACK option to the header.
TracedValue< SequenceNumber32 > m_highRxMark
Highest seqno received.
void ProcessLastAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon LAST_ACK.
TracedCallback< Time, Time > m_lastRttTrace
Callback pointer for RTT trace chaining.
void UpdateSsThresh(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState slow start threshold.
virtual void SetSegSize(uint32_t size)
Set the segment size.
void ProcessClosing(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSING.
Time GetClockGranularity(void) const
Get the Clock Granularity (used in RTO calcs).
uint8_t MarkEcnEct1(uint8_t tos) const
Mark ECT(1) codepoint.
virtual uint32_t GetInitialCwnd(void) const
Get the initial Congestion Window.
virtual void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Recv of a data, put into buffer, call L7 to get it if necessary.
void CloseAndNotify(void)
Peacefully close the socket by notifying the upper layer and deallocate end point.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
virtual void SetRcvBufSize(uint32_t size)
Set the receive buffer size.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
bool m_shutdownRecv
Receive no longer allowed.
TracedCallback< uint32_t, uint32_t > m_ssThTrace
Callback pointer for ssTh trace chaining.
EventId m_sendPendingDataEvent
micro-delay event to send pending data
bool IsValidTcpSegment(const SequenceNumber32 seq, const uint32_t tcpHeaderSize, const uint32_t tcpPayloadSize)
Checks whether the given TCP segment is valid or not.
uint32_t SendPendingData(bool withAck=false)
Send as much pending data as possible according to the Tx window.
virtual void DelAckTimeout(void)
Action upon delay ACK timeout, i.e.
virtual void LastAckTimeout(void)
Timeout at LAST_ACK, close the connection.
void(* EcnStatesTracedValueCallback)(const TcpSocketState::EcnState_t oldValue, const TcpSocketState::EcnState_t newValue)
TracedValue Callback signature for ECN state trace.
uint8_t CalculateWScale() const
Calculate window scale value based on receive buffer space.
uint32_t m_bytesAckedNotProcessed
Bytes acked, but not processed.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
TracedCallback< SequenceNumber32, SequenceNumber32 > m_nextTxSequenceTrace
Callback pointer for next tx sequence chaining.
TracedCallback< uint32_t, uint32_t > m_cWndInflTrace
Callback pointer for cWndInfl trace chaining.
void EnterRecovery(uint32_t currentDelivered)
Enter the CA_RECOVERY, and retransmit the head.
Enumeration of the possible socket types.
Definition: socket.h:104
EventId m_delAckEvent
Delayed ACK timeout event.
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t m_sndWindShift
Window shift to apply to incoming segments.
bool m_shutdownSend
Send no longer allowed.
virtual uint32_t UnAckDataCount(void) const
Return count of number of unacked bytes.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
int SetupEndpoint6(void)
Configure the endpoint v6 to a local address.
Time m_clockGranularity
Clock Granularity used in RTO calcs.
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.
TracedValue< uint32_t > m_rWnd
Receiver window (RCV.WND in RFC793)
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_rxTrace
Trace of received packets.
virtual void DoForwardUp(Ptr< Packet > packet, const Address &fromAddress, const Address &toAddress)
Called by TcpSocketBase::ForwardUp{,6}().
void UpdatePacingRate(void)
Dynamically update the pacing rate.
void DoRetransmit(void)
Retransmit the first segment marked as lost, without considering available window nor pacing...
bool m_closeOnEmpty
Close socket upon tx buffer emptied.
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_txTrace
Trace of transmitted packets.
void AddOptionWScale(TcpHeader &header)
Add the window scale option to the header.
A representation of an internet endpoint/connection.
virtual void SetConnTimeout(Time timeout)
Set the connection timeout.
EventId m_persistEvent
Persist event: Send 1 byte to probe for a non-zero Rx window.
int SetupEndpoint(void)
Configure the endpoint to a local address.
bool CheckEcnEct1(uint8_t tos) const
Checks for ECT(1) codepoint.
uint8_t MarkEcnEct0(uint8_t tos) const
Mark ECT(0) codepoint.
TracedCallback< TcpSocketState::TcpCongState_t, TcpSocketState::TcpCongState_t > m_congStateTrace
Callback pointer for congestion state trace chaining.
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
Definition of the Ecn state machine.
Time m_persistTimeout
Time between sending 1-byte probes.