A Discrete-Event Network Simulator
API
tcp-socket-base.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Georgia Tech Research Corporation
3 * Copyright (c) 2010 Adrian Sai-wah Tam
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19 */
20#ifndef TCP_SOCKET_BASE_H
21#define TCP_SOCKET_BASE_H
22
23#include "ns3/data-rate.h"
24#include "ns3/ipv4-header.h"
25#include "ns3/ipv6-header.h"
26#include "ns3/node.h"
27#include "ns3/sequence-number.h"
28#include "ns3/tcp-socket-state.h"
29#include "ns3/tcp-socket.h"
30#include "ns3/timer.h"
31#include "ns3/traced-value.h"
32
33#include <queue>
34#include <stdint.h>
35
36namespace ns3
37{
38
39class Ipv4EndPoint;
40class Ipv6EndPoint;
41class Node;
42class Packet;
43class TcpL4Protocol;
44class TcpHeader;
45class TcpCongestionOps;
46class TcpRecoveryOps;
47class RttEstimator;
48class TcpRxBuffer;
49class TcpTxBuffer;
50class TcpOption;
51class Ipv4Interface;
52class Ipv6Interface;
53class TcpRateOps;
54
61{
62 public:
74 RttHistory(const RttHistory& h); // Copy constructor
75 public:
79 bool retx;
80};
81
219{
220 public:
226 static TypeId GetTypeId();
227
232 TypeId GetInstanceTypeId() const override;
233
238 friend class TcpGeneralTest;
239
244
250 TcpSocketBase(const TcpSocketBase& sock);
251 ~TcpSocketBase() override;
252
253 // Set associated Node, TcpL4Protocol, RttEstimator to this socket
254
259 virtual void SetNode(Ptr<Node> node);
260
265 virtual void SetTcp(Ptr<TcpL4Protocol> tcp);
266
271 virtual void SetRtt(Ptr<RttEstimator> rtt);
272
277 void SetMinRto(Time minRto);
278
283 Time GetMinRto() const;
284
289 void SetClockGranularity(Time clockGranularity);
290
296
302
308
313 void SetRetxThresh(uint32_t retxThresh);
314
320 {
321 return m_retxThresh;
322 }
323
328
333
338
343
348
353
358
363
368
373
379 void UpdatePacingRateTrace(DataRate oldValue, DataRate newValue);
380
386 void UpdateCwnd(uint32_t oldValue, uint32_t newValue);
387
393 void UpdateCwndInfl(uint32_t oldValue, uint32_t newValue);
394
400 void UpdateSsThresh(uint32_t oldValue, uint32_t newValue);
401
409
416
422 void UpdateHighTxMark(SequenceNumber32 oldValue, SequenceNumber32 newValue);
423
430
436 void UpdateBytesInFlight(uint32_t oldValue, uint32_t newValue);
437
443 void UpdateRtt(Time oldValue, Time newValue);
444
451
458
465 inline uint8_t MarkEcnEct0(uint8_t tos) const
466 {
467 return ((tos & 0xfc) | 0x02);
468 }
469
476 inline uint8_t MarkEcnEct1(uint8_t tos) const
477 {
478 return ((tos & 0xfc) | 0x01);
479 }
480
487 inline uint8_t MarkEcnCe(uint8_t tos) const
488 {
489 return ((tos & 0xfc) | 0x03);
490 }
491
498 inline uint8_t ClearEcnBits(uint8_t tos) const
499 {
500 return tos & 0xfc;
501 }
502
509 inline bool CheckNoEcn(uint8_t tos) const
510 {
511 return ((tos & 0x03) == 0x00);
512 }
513
520 inline bool CheckEcnEct0(uint8_t tos) const
521 {
522 return ((tos & 0x03) == 0x02);
523 }
524
531 inline bool CheckEcnEct1(uint8_t tos) const
532 {
533 return ((tos & 0x03) == 0x01);
534 }
535
542 inline bool CheckEcnCe(uint8_t tos) const
543 {
544 return ((tos & 0x03) == 0x03);
545 }
546
554 inline uint8_t MarkEcnCodePoint(const uint8_t tos,
555 const TcpSocketState::EcnCodePoint_t codePoint) const
556 {
557 return ((tos & 0xfc) | codePoint);
558 }
559
566
571 void SetPacingStatus(bool pacing);
572
577 void SetPaceInitialWindow(bool paceWindow);
578
579 // Necessary implementations of null functions from ns3::Socket
580 enum SocketErrno GetErrno() const override; // returns m_errno
581 enum SocketType GetSocketType() const override; // returns socket type
582 Ptr<Node> GetNode() const override; // returns m_node
583 int Bind() override; // Bind a socket by setting up endpoint in TcpL4Protocol
584 int Bind6() override; // Bind a socket by setting up endpoint in TcpL4Protocol
585 int Bind(const Address& address) override; // ... endpoint of specific addr or port
586 int Connect(
587 const Address& address) override; // Setup endpoint and call ProcessAction() to connect
588 int Listen()
589 override; // Verify the socket is in a correct state and call ProcessAction() to listen
590 int Close() override; // Close by app: Kill socket upon tx buffer emptied
591 int ShutdownSend() override; // Assert the m_shutdownSend flag to prevent send to network
592 int ShutdownRecv() override; // Assert the m_shutdownRecv flag to prevent forward to app
593 int Send(Ptr<Packet> p, uint32_t flags) override; // Call by app to send data to network
594 int SendTo(Ptr<Packet> p,
595 uint32_t flags,
596 const Address& toAddress) override; // Same as Send(), toAddress is insignificant
597 Ptr<Packet> Recv(uint32_t maxSize,
598 uint32_t flags) override; // Return a packet to be forwarded to app
599 Ptr<Packet> RecvFrom(uint32_t maxSize, uint32_t flags, Address& fromAddress)
600 override; // ... and write the remote address at fromAddress
601 uint32_t GetTxAvailable() const override; // Available Tx buffer size
603 const override; // Available-to-read data size, i.e. value of m_rxAvailable
604 int GetSockName(Address& address) const override; // Return local addr:port in address
605 int GetPeerName(Address& address) const override;
606 void BindToNetDevice(Ptr<NetDevice> netdevice) override; // NetDevice with my m_endPoint
607
615 typedef void (*TcpTxRxTracedCallback)(const Ptr<const Packet> packet,
616 const TcpHeader& header,
617 const Ptr<const TcpSocketBase> socket);
618
619 protected:
620 // Implementing ns3::TcpSocket -- Attribute get/set
621 // inherited, no need to doc
622
623 void SetSndBufSize(uint32_t size) override;
624 uint32_t GetSndBufSize() const override;
625 void SetRcvBufSize(uint32_t size) override;
626 uint32_t GetRcvBufSize() const override;
627 void SetSegSize(uint32_t size) override;
628 uint32_t GetSegSize() const override;
629 void SetInitialSSThresh(uint32_t threshold) override;
630 uint32_t GetInitialSSThresh() const override;
631 void SetInitialCwnd(uint32_t cwnd) override;
632 uint32_t GetInitialCwnd() const override;
633 void SetConnTimeout(Time timeout) override;
634 Time GetConnTimeout() const override;
635 void SetSynRetries(uint32_t count) override;
636 uint32_t GetSynRetries() const override;
637 void SetDataRetries(uint32_t retries) override;
638 uint32_t GetDataRetries() const override;
639 void SetDelAckTimeout(Time timeout) override;
640 Time GetDelAckTimeout() const override;
641 void SetDelAckMaxCount(uint32_t count) override;
642 uint32_t GetDelAckMaxCount() const override;
643 void SetTcpNoDelay(bool noDelay) override;
644 bool GetTcpNoDelay() const override;
645 void SetPersistTimeout(Time timeout) override;
646 Time GetPersistTimeout() const override;
647 bool SetAllowBroadcast(bool allowBroadcast) override;
648 bool GetAllowBroadcast() const override;
649
650 // Helper functions: Connection set up
651
657 int SetupCallback();
658
664 int DoConnect();
665
669 void ConnectionSucceeded();
670
677 int SetupEndpoint();
678
685 int SetupEndpoint6();
686
699 virtual void CompleteFork(Ptr<Packet> p,
700 const TcpHeader& tcpHeader,
701 const Address& fromAddress,
702 const Address& toAddress);
703
704 // Helper functions: Transfer operation
705
714 bool IsValidTcpSegment(const SequenceNumber32 seq,
715 const uint32_t tcpHeaderSize,
716 const uint32_t tcpPayloadSize);
717
726 void ForwardUp(Ptr<Packet> packet,
727 Ipv4Header header,
728 uint16_t port,
729 Ptr<Ipv4Interface> incomingInterface);
730
739 void ForwardUp6(Ptr<Packet> packet,
740 Ipv6Header header,
741 uint16_t port,
742 Ptr<Ipv6Interface> incomingInterface);
743
756 virtual void DoForwardUp(Ptr<Packet> packet,
757 const Address& fromAddress,
758 const Address& toAddress);
759
769 void ForwardIcmp(Ipv4Address icmpSource,
770 uint8_t icmpTtl,
771 uint8_t icmpType,
772 uint8_t icmpCode,
773 uint32_t icmpInfo);
774
784 void ForwardIcmp6(Ipv6Address icmpSource,
785 uint8_t icmpTtl,
786 uint8_t icmpType,
787 uint8_t icmpCode,
788 uint32_t icmpInfo);
789
798 uint32_t SendPendingData(bool withAck = false);
799
809 virtual uint32_t SendDataPacket(SequenceNumber32 seq, uint32_t maxSize, bool withAck);
810
816 virtual void SendEmptyPacket(uint8_t flags);
817
821 void SendRST();
822
830 bool OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const;
831
832 // Helper functions: Connection close
833
839 int DoClose();
840
844 void CloseAndNotify();
845
852 void Destroy();
853
860 void Destroy6();
861
865 void DeallocateEndPoint();
866
873 void PeerClose(Ptr<Packet> p, const TcpHeader& tcpHeader);
874
878 void DoPeerClose();
879
883 void CancelAllTimers();
884
888 void TimeWait();
889
890 // State transition functions
891
901 const TcpHeader& tcpHeader); // Received a packet upon ESTABLISHED state
902
911 void ProcessListen(Ptr<Packet> packet,
912 const TcpHeader& tcpHeader,
913 const Address& fromAddress,
914 const Address& toAddress);
915
922 void ProcessSynSent(Ptr<Packet> packet, const TcpHeader& tcpHeader);
923
932 void ProcessSynRcvd(Ptr<Packet> packet,
933 const TcpHeader& tcpHeader,
934 const Address& fromAddress,
935 const Address& toAddress);
936
943 void ProcessWait(Ptr<Packet> packet, const TcpHeader& tcpHeader);
944
951 void ProcessClosing(Ptr<Packet> packet, const TcpHeader& tcpHeader);
952
959 void ProcessLastAck(Ptr<Packet> packet, const TcpHeader& tcpHeader);
960
961 // Window management
962
970 virtual uint32_t UnAckDataCount() const;
971
979 virtual uint32_t BytesInFlight() const;
980
985 virtual uint32_t Window() const;
986
991 virtual uint32_t AvailableWindow() const;
992
999 virtual uint16_t AdvertisedWindowSize(bool scale = true) const;
1000
1013 void UpdateWindowSize(const TcpHeader& header);
1014
1015 // Manage data tx/rx
1016
1021 virtual Ptr<TcpSocketBase> Fork();
1022
1028 virtual void ReceivedAck(Ptr<Packet> packet, const TcpHeader& tcpHeader);
1029
1038 virtual void ProcessAck(const SequenceNumber32& ackNumber,
1039 bool scoreboardUpdated,
1040 uint32_t currentDelivered,
1041 const SequenceNumber32& oldHeadSequence);
1042
1048 virtual void ReceivedData(Ptr<Packet> packet, const TcpHeader& tcpHeader);
1049
1054 virtual void EstimateRtt(const TcpHeader& tcpHeader);
1055
1064 virtual void UpdateRttHistory(const SequenceNumber32& seq, uint32_t sz, bool isRetransmission);
1065
1071 virtual void NewAck(const SequenceNumber32& seq, bool resetRTO);
1072
1078 void DupAck(uint32_t currentDelivered);
1079
1085 void EnterCwr(uint32_t currentDelivered);
1086
1092 void EnterRecovery(uint32_t currentDelivered);
1093
1097 virtual void ReTxTimeout();
1098
1102 virtual void DelAckTimeout();
1103
1107 virtual void LastAckTimeout();
1108
1112 virtual void PersistTimeout();
1113
1118 void DoRetransmit();
1119
1127 void AddOptions(TcpHeader& tcpHeader);
1128
1137 void ReadOptions(const TcpHeader& tcpHeader, uint32_t* bytesSacked);
1138
1145 bool IsTcpOptionEnabled(uint8_t kind) const;
1146
1155 void ProcessOptionWScale(const Ptr<const TcpOption> option);
1164 void AddOptionWScale(TcpHeader& header);
1165
1173 uint8_t CalculateWScale() const;
1174
1184
1192
1198 void AddOptionSackPermitted(TcpHeader& header);
1199
1205 void AddOptionSack(TcpHeader& header);
1206
1217 void ProcessOptionTimestamp(const Ptr<const TcpOption> option, const SequenceNumber32& seq);
1226 void AddOptionTimestamp(TcpHeader& header);
1227
1238
1242 void NotifyPacingPerformed();
1243
1248 bool IsPacingEnabled() const;
1249
1253 void UpdatePacingRate();
1254
1259 void AddSocketTags(const Ptr<Packet>& p) const;
1260
1266 uint32_t GetRWnd() const;
1267
1274
1275 protected:
1276 // Counters and events
1282
1283 // ACK management
1287
1288 // Nagle algorithm
1289 bool m_noDelay{false};
1290
1291 // Retries
1296
1297 // Timeouts
1304
1305 // History of RTT
1306 std::deque<RttHistory> m_history;
1307
1308 // Connections to other layers of TCP/IP
1317
1319
1320 // Tx buffer management
1322
1323 // State-related attributes
1325
1326 mutable enum SocketErrno m_errno
1327 {
1329 };
1330
1331 bool m_closeNotified{false};
1332 bool m_closeOnEmpty{false};
1333 bool m_shutdownSend{false};
1334 bool m_shutdownRecv{false};
1335 bool m_connected{false};
1336 double m_msl{0.0};
1337
1338 // Window management
1339 uint16_t m_maxWinSize{0};
1346
1347 // Options
1348 bool m_sackEnabled{true};
1350 uint8_t m_rcvWindShift{0};
1351 uint8_t m_sndWindShift{0};
1354
1356
1357 // Fast Retransmit and Recovery
1359 0};
1360 bool m_recoverActive{false};
1364 bool m_limitedTx{true};
1365
1366 // Transmission Control Block
1371
1372 // Guesses over the other connection end
1374
1375 // The following two traces pass a packet with a TCP header
1377 const TcpHeader&,
1380
1382 const TcpHeader&,
1385
1386 // Pacing related variable
1388
1389 // Parameters related to Explicit Congestion Notification
1391 0};
1393 0};
1395};
1396
1405 const TcpSocketState::TcpCongState_t newValue);
1406
1415 const TcpSocketState::EcnState_t newValue);
1416
1417} // namespace ns3
1418
1419#endif /* TCP_SOCKET_BASE_H */
a polymophic address class
Definition: address.h:92
Callback template class.
Definition: callback.h:443
Class for representing data rates.
Definition: data-rate.h:90
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
A representation of an internet endpoint/connection.
Packet header for IPv4.
Definition: ipv4-header.h:34
Describes an IPv6 address.
Definition: ipv6-address.h:50
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:36
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:172
SocketType
Enumeration of the possible socket types.
Definition: socket.h:107
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
@ ERROR_NOTERROR
Definition: socket.h:85
General infrastructure for TCP testing.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
A base class for implementation of a stream socket using TCP.
void AddOptionSack(TcpHeader &header)
Add the SACK option to the header.
int GetSockName(Address &address) const override
Get socket address.
Time m_persistTimeout
Time between sending 1-byte probes.
void UpdateCwndInfl(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState inflated congestion window.
uint16_t m_maxWinSize
Maximum window size to advertise.
uint8_t m_rcvWindShift
Window shift to apply to outgoing segments.
void SetPaceInitialWindow(bool paceWindow)
Enable or disable pacing of the initial window.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
void TimeWait()
Move from CLOSING or FIN_WAIT_2 to TIME_WAIT state.
bool CheckEcnEct1(uint8_t tos) const
Checks for ECT(1) codepoint.
Ptr< TcpCongestionOps > m_congestionControl
Congestion control.
Ptr< TcpTxBuffer > GetTxBuffer() const
Get a pointer to the Tx buffer.
enum SocketErrno GetErrno() const override
Get last error number.
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.
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.
enum SocketType GetSocketType() const override
void CancelAllTimers()
Cancel all timer when endpoint is deleted.
Time GetDelAckTimeout() const override
Get the time to delay an ACK.
Ptr< TcpRecoveryOps > m_recoveryOps
Recovery Algorithm.
TracedCallback< uint32_t, uint32_t > m_bytesInFlightTrace
Callback pointer for bytesInFlight trace chaining.
uint32_t GetInitialSSThresh() const override
Get the initial Slow Start Threshold.
void NotifyPacingPerformed()
Notify Pacing.
void UpdatePacingRateTrace(DataRate oldValue, DataRate newValue)
Callback function to hook to TcpSocketState pacing rate.
void SetDelAckTimeout(Time timeout) override
Set the time to delay an ACK.
void CloseAndNotify()
Peacefully close the socket by notifying the upper layer and deallocate end point.
uint8_t MarkEcnEct1(uint8_t tos) const
Mark ECT(1) codepoint.
Ptr< TcpRateOps > m_rateOps
Rate operations.
void PeerClose(Ptr< Packet > p, const TcpHeader &tcpHeader)
Received a FIN from peer, notify rx buffer.
int Close() override
Close a socket.
bool m_shutdownSend
Send no longer allowed.
bool IsPacingEnabled() const
Return true if packets in the current window should be paced.
void ProcessOptionWScale(const Ptr< const TcpOption > option)
Read and parse the Window scale option.
bool m_closeOnEmpty
Close socket upon tx buffer emptied.
virtual void ReTxTimeout()
An RTO event happened.
void AddOptionSackPermitted(TcpHeader &header)
Add the SACK PERMITTED option to the header.
TracedValue< Time > m_rto
Retransmit timeout.
uint32_t GetSndBufSize() const override
Get the send buffer size.
virtual void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Recv of a data, put into buffer, call L7 to get it if necessary.
EventId m_timewaitEvent
TIME_WAIT expiration event: Move this socket to CLOSED state.
Ptr< TcpTxBuffer > m_txBuffer
Tx buffer.
void UpdateHighTxMark(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Callback function to hook to TcpSocketState high tx mark.
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.
EventId m_delAckEvent
Delayed ACK timeout event.
TracedCallback< Time, Time > m_lastRttTrace
Callback pointer for RTT trace chaining.
bool GetTcpNoDelay() const override
Check if Nagle's algorithm is enabled or not.
virtual void SetRtt(Ptr< RttEstimator > rtt)
Set the associated RTT estimator.
TracedCallback< uint32_t, uint32_t > m_cWndTrace
Callback pointer for cWnd trace chaining.
void SetDataRetries(uint32_t retries) override
Set the number of data transmission retries before giving up.
void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
TracedCallback< TcpSocketState::EcnState_t, TcpSocketState::EcnState_t > m_ecnStateTrace
Callback pointer for ECN state trace chaining.
void SetSynRetries(uint32_t count) override
Set the number of connection retries before giving up.
void ProcessWait(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSE_WAIT, FIN_WAIT_1, FIN_WAIT_2.
SequenceNumber32 m_highTxAck
Highest ack sent.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
bool m_timestampEnabled
Timestamp option enabled.
virtual void PersistTimeout()
Send 1 byte probe to get an updated window size.
TracedValue< TcpStates_t > m_state
TCP state.
int SetupCallback()
Common part of the two Bind(), i.e.
void UpdateEcnState(TcpSocketState::EcnState_t oldValue, TcpSocketState::EcnState_t newValue)
Callback function to hook to EcnState state.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
uint8_t MarkEcnEct0(uint8_t tos) const
Mark ECT(0) codepoint.
Timer m_pacingTimer
Pacing Event.
EventId m_retxEvent
Retransmission event.
uint32_t m_bytesAckedNotProcessed
Bytes acked, but not processed.
void AddOptionTimestamp(TcpHeader &header)
Add the timestamp option to the header.
virtual uint32_t BytesInFlight() const
Return total bytes in flight.
uint32_t GetSegSize() const override
Get the segment size.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
uint32_t m_dataRetries
Number of data retransmission attempts.
double m_msl
Max segment lifetime.
void ProcessLastAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon LAST_ACK.
bool m_limitedTx
perform limited transmit
virtual uint32_t SendDataPacket(SequenceNumber32 seq, uint32_t maxSize, bool withAck)
Extract at most maxSize bytes from the TxBuffer at sequence seq, add the TCP header,...
TracedCallback< TcpSocketState::TcpCongState_t, TcpSocketState::TcpCongState_t > m_congStateTrace
Callback pointer for congestion state trace chaining.
void ProcessSynRcvd(Ptr< Packet > packet, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Received a packet upon SYN_RCVD.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
int ShutdownSend() override
TracedValue< SequenceNumber32 > m_ecnCWRSeq
Sequence number of the last sent CWR.
Time GetPersistTimeout() const override
Get the timeout for persistent connection.
uint32_t m_delAckCount
Delayed ACK counter.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
static uint32_t SafeSubtraction(uint32_t a, uint32_t b)
Performs a safe subtraction between a and b (a-b)
virtual void DelAckTimeout()
Action upon delay ACK timeout, i.e.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
Time m_cnTimeout
Timeout for connection retry.
Time GetClockGranularity() const
Get the Clock Granularity (used in RTO calcs).
bool m_winScalingEnabled
Window Scale option enabled (RFC 7323)
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 UpdateRtt(Time oldValue, Time newValue)
Callback function to hook to TcpSocketState rtt.
void UpdateCongState(TcpSocketState::TcpCongState_t oldValue, TcpSocketState::TcpCongState_t newValue)
Callback function to hook to TcpSocketState congestion state.
void Destroy6()
Kill this socket by zeroing its attributes (IPv6)
uint8_t MarkEcnCe(uint8_t tos) const
Mark CE codepoint.
TracedValue< SequenceNumber32 > m_ecnCESeq
Sequence number of the last received Congestion Experienced.
void SetClockGranularity(Time clockGranularity)
Sets the Clock Granularity (used in RTO calcs).
bool IsValidTcpSegment(const SequenceNumber32 seq, const uint32_t tcpHeaderSize, const uint32_t tcpPayloadSize)
Checks whether the given TCP segment is valid or not.
Time m_clockGranularity
Clock Granularity used in RTO calcs.
void DupAck(uint32_t currentDelivered)
Dupack management.
bool m_shutdownRecv
Receive no longer allowed.
virtual uint32_t Window() const
Return the max possible number of unacked bytes.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
std::deque< RttHistory > m_history
List of sent packet.
void(* TcpTxRxTracedCallback)(const Ptr< const Packet > packet, const TcpHeader &header, const Ptr< const TcpSocketBase > socket)
TracedCallback signature for tcp packet transmission or reception events.
void ProcessOptionSackPermitted(const Ptr< const TcpOption > option)
Read the SACK PERMITTED option.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
virtual uint32_t AvailableWindow() const
Return unfilled portion of window.
TracedValue< SequenceNumber32 > m_highRxMark
Highest seqno received.
uint8_t ClearEcnBits(uint8_t tos) const
Clears ECN bits from TOS.
void ReadOptions(const TcpHeader &tcpHeader, uint32_t *bytesSacked)
Read TCP options before Ack processing.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
void UpdateSsThresh(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState slow start threshold.
bool m_connected
Connection established.
TracedValue< SequenceNumber32 > m_highRxAckMark
Highest ack received.
void AddOptionWScale(TcpHeader &header)
Add the window scale option to the header.
virtual void SendEmptyPacket(uint8_t flags)
Send a empty packet that carries a flag, e.g., ACK.
void UpdateWindowSize(const TcpHeader &header)
Update the receiver window (RWND) based on the value of the window field in the header.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
uint32_t GetDataRetries() const override
Get the number of data transmission retries before giving up.
int SetupEndpoint6()
Configure the endpoint v6 to a local address.
uint32_t GetRetxThresh() const
Get the retransmission threshold (dup ack threshold for a fast retransmit)
void DeallocateEndPoint()
Deallocate m_endPoint and m_endPoint6.
void Destroy()
Kill this socket by zeroing its attributes (IPv4)
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.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
void ProcessClosing(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received a packet upon CLOSING.
bool CheckEcnCe(uint8_t tos) const
Checks for CE codepoint.
TracedCallback< SequenceNumber32, SequenceNumber32 > m_highTxMarkTrace
Callback pointer for high tx mark chaining.
int Connect(const Address &address) override
Initiate a connection to a remote host.
Ptr< Node > m_node
the associated node
void SetSegSize(uint32_t size) override
Set the segment size.
TypeId GetInstanceTypeId() const override
Get the instance TypeId.
uint32_t m_synRetries
Number of connection attempts.
void SetConnTimeout(Time timeout) override
Set the connection timeout.
void SetDelAckMaxCount(uint32_t count) override
Set the number of packet to fire an ACK before delay timeout.
EventId m_lastAckEvent
Last ACK timeout event.
bool IsTcpOptionEnabled(uint8_t kind) const
Return true if the specified option is enabled.
void UpdatePacingRate()
Dynamically update the pacing rate.
EventId m_persistEvent
Persist event: Send 1 byte to probe for a non-zero Rx window.
void SetPacingStatus(bool pacing)
Enable or disable pacing.
void 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.
Ptr< TcpRxBuffer > GetRxBuffer() const
Get a pointer to the Rx buffer.
void SetPersistTimeout(Time timeout) override
Set the timeout for persistent connection.
void ConnectionSucceeded()
Schedule-friendly wrapper for Socket::NotifyConnectionSucceeded()
bool m_noDelay
Set to true to disable Nagle's algorithm.
uint32_t GetDelAckMaxCount() const override
Get the number of packet to fire an ACK before delay timeout.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
virtual void ProcessAck(const SequenceNumber32 &ackNumber, bool scoreboardUpdated, uint32_t currentDelivered, const SequenceNumber32 &oldHeadSequence)
Process a received ack.
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
virtual void DoForwardUp(Ptr< Packet > packet, const Address &fromAddress, const Address &toAddress)
Called by TcpSocketBase::ForwardUp{,6}().
bool m_isFirstPartialAck
First partial ACK during RECOVERY.
uint8_t MarkEcnCodePoint(const uint8_t tos, const TcpSocketState::EcnCodePoint_t codePoint) const
mark ECN code point
Time m_delAckTimeout
Time to delay an ACK.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
void SetInitialCwnd(uint32_t cwnd) override
Set the initial Congestion Window.
void UpdateNextTxSequence(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Callback function to hook to TcpSocketState next tx sequence.
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.
void UpdateBytesInFlight(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState bytes inflight.
int DoConnect()
Perform the real connection tasks: Send SYN if allowed, RST if invalid.
uint32_t GetSynRetries() const override
Get the number of connection retries before giving up.
void DoPeerClose()
FIN is in sequence, notify app and respond with a FIN.
void SendRST()
Send reset and tear down this socket.
bool OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const
Check if a sequence number range is within the rx window.
TracedValue< SequenceNumber32 > m_ecnEchoSeq
Sequence number of the last received ECN Echo.
uint32_t m_retxThresh
Fast Retransmit threshold.
uint32_t GetRWnd() const
Get the current value of the receiver's offered window (RCV.WND)
SequenceNumber32 GetHighRxAck() const
Get the current value of the receiver's highest (in-sequence) sequence number acked.
void BindToNetDevice(Ptr< NetDevice > netdevice) override
Bind a socket to specific device.
void EnterCwr(uint32_t currentDelivered)
Enter CA_CWR state upon receipt of an ECN Echo.
virtual void EstimateRtt(const TcpHeader &tcpHeader)
Take into account the packet for RTT estimation.
uint32_t GetInitialCwnd() const override
Get the initial Congestion Window.
TracedValue< uint32_t > m_rWnd
Receiver window (RCV.WND in RFC793)
void UpdateCwnd(uint32_t oldValue, uint32_t newValue)
Callback function to hook to TcpSocketState congestion window.
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 SetMinRto(Time minRto)
Sets the Minimum RTO.
Time GetConnTimeout() const override
Get the connection timeout.
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
uint32_t ProcessOptionSack(const Ptr< const TcpOption > option)
Read the SACK option.
void SetRecoveryAlgorithm(Ptr< TcpRecoveryOps > recovery)
Install a recovery algorithm on this socket.
int DoClose()
Close a socket by sending RST, FIN, or FIN+ACK, depend on the current state.
void AddSocketTags(const Ptr< Packet > &p) const
Add Tags for the Socket.
TracedCallback< uint32_t, uint32_t > m_cWndInflTrace
Callback pointer for cWndInfl trace chaining.
uint32_t GetRcvBufSize() const override
Get the receive buffer size.
(abstract) base class of all TcpSockets
Definition: tcp-socket.h:48
EcnCodePoint_t
ECN code points.
UseEcn_t
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn.
TcpCongState_t
Definition of the Congestion state machine.
EcnState_t
Definition of the Ecn state machine.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:296
A simple virtual Timer class.
Definition: timer.h:74
@ CANCEL_ON_DESTROY
This policy cancels the event from the destructor of the Timer or from Suspend().
Definition: timer.h:93
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
uint16_t port
Definition: dsdv-manet.cc:45
void(* EcnStatesTracedValueCallback)(const TcpSocketState::EcnState_t oldValue, const TcpSocketState::EcnState_t newValue)
TracedValue Callback signature for ECN state trace.
void(* TcpCongStatesTracedValueCallback)(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
TracedValue Callback signature for TcpCongState_t.
@ CLOSED
Socket is finished
Definition: tcp-socket.h:67
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Time timeout