A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-general-test.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18#ifndef TCPGENERALTEST_H
19#define TCPGENERALTEST_H
20
21#include "ns3/error-model.h"
22#include "ns3/simple-net-device.h"
23#include "ns3/tcp-congestion-ops.h"
24#include "ns3/tcp-rate-ops.h"
25#include "ns3/tcp-recovery-ops.h"
26#include "ns3/tcp-socket-base.h"
27#include "ns3/test.h"
28
29namespace ns3
30{
31
52{
53 public:
58 static TypeId GetTypeId();
59
62 {
63 }
64
70 : TcpSocketBase(other)
71 {
72 m_rcvAckCb = other.m_rcvAckCb;
76 m_forkCb = other.m_forkCb;
78 }
79
88
96
104
111
118
124
131
132 protected:
133 void ReceivedAck(Ptr<Packet> packet, const TcpHeader& tcpHeader) override;
134 void ReTxTimeout() override;
135 Ptr<TcpSocketBase> Fork() override;
137 const TcpHeader& tcpHeader,
138 const Address& fromAddress,
139 const Address& toAddress) override;
140 void UpdateRttHistory(const SequenceNumber32& seq, uint32_t sz, bool isRetransmission) override;
141
142 private:
149};
150
168{
169 public:
174 static TypeId GetTypeId();
175
178 m_bytesToAck(125),
181 {
182 }
183
189 : TcpSocketMsgBase(other),
193 {
194 }
195
201 {
202 m_bytesToAck = bytes;
203 }
204
205 protected:
206 void SendEmptyPacket(uint8_t flags) override;
207 Ptr<TcpSocketBase> Fork() override;
208
212};
213
255{
256 public:
265 TcpGeneralTest(const std::string& desc);
266 ~TcpGeneralTest() override;
267
273 {
275 RECEIVER
276 };
277
278 protected:
285
292
299
306
313
323 TypeId socketType,
324 TypeId congControl);
325
336 TypeId socketType,
337 TypeId congControl,
338 TypeId recoveryAlgorithm);
339
345 {
346 return m_senderSocket;
347 }
348
354 {
355 return m_receiverSocket;
356 }
357
374 void DoRun() override;
375
379 virtual void ConfigureEnvironment();
380
384 virtual void ConfigureProperties();
385
389 void DoTeardown() override;
390
394 void DoConnect();
395
402 virtual void ReceivePacket(Ptr<Socket> socket);
403
412 void SendPacket(Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval);
413
422
431
438
445
452
459
466
473
480 Time GetRto(SocketWho who);
481
489
497
505
513
521
529
537
545
553
561
569
576 void SetRcvBufSize(SocketWho who, uint32_t size);
577
585
592 void SetInitialCwnd(SocketWho who, uint32_t initialCwnd);
593
600 void SetDelAckMaxCount(SocketWho who, uint32_t count);
601
609
616 void SetPacingStatus(SocketWho who, bool pacing);
617
624 void SetPaceInitialWindow(SocketWho who, bool paceWindow);
625
632 void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh);
633
642 {
644 }
645
654 {
655 m_pktCount = pktCount;
656 }
657
663 void SetAppPktInterval(Time pktInterval)
664 {
665 m_interPacketInterval = pktInterval;
666 }
667
673 void SetPropagationDelay(Time propDelay)
674 {
675 m_propagationDelay = propDelay;
676 }
677
683 void SetTransmitStart(Time startTime)
684 {
685 m_startTime = startTime;
686 }
687
693 void SetCongestionControl(TypeId congControl)
694 {
695 m_congControlTypeId = congControl;
696 }
697
704 {
705 m_recoveryTypeId = recovery;
706 }
707
713 void SetMTU(uint32_t mtu)
714 {
715 m_mtu = mtu;
716 }
717
723 virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue [[maybe_unused]],
724 const TcpSocketState::TcpCongState_t newValue [[maybe_unused]])
725 {
726 }
727
734 virtual void CWndTrace(uint32_t oldValue [[maybe_unused]], uint32_t newValue [[maybe_unused]])
735 {
736 }
737
744 virtual void CWndInflTrace(uint32_t oldValue [[maybe_unused]],
745 uint32_t newValue [[maybe_unused]])
746 {
747 }
748
757 virtual void RttTrace(Time oldTime [[maybe_unused]], Time newTime [[maybe_unused]])
758 {
759 }
760
769 virtual void SsThreshTrace(uint32_t oldValue [[maybe_unused]],
770 uint32_t newValue [[maybe_unused]])
771 {
772 }
773
782 virtual void BytesInFlightTrace(uint32_t oldValue [[maybe_unused]],
783 uint32_t newValue [[maybe_unused]])
784 {
785 }
786
795 virtual void RtoTrace(Time oldValue [[maybe_unused]], Time newValue [[maybe_unused]])
796 {
797 }
798
807 virtual void NextTxSeqTrace(SequenceNumber32 oldValue [[maybe_unused]],
808 SequenceNumber32 newValue [[maybe_unused]])
809 {
810 }
811
820 virtual void HighestTxSeqTrace(SequenceNumber32 oldValue [[maybe_unused]],
821 SequenceNumber32 newValue [[maybe_unused]])
822 {
823 }
824
829 virtual void RateUpdatedTrace(const TcpRateLinux::TcpRateConnection& rate [[maybe_unused]])
830 {
831 }
832
837 virtual void RateSampleUpdatedTrace(const TcpRateLinux::TcpRateSample& sample [[maybe_unused]])
838 {
839 }
840
845 virtual void NormalClose(SocketWho who [[maybe_unused]])
846 {
847 }
848
854 virtual void ErrorClose(SocketWho who [[maybe_unused]])
855 {
857 }
858
863 virtual void QueueDrop(SocketWho who [[maybe_unused]])
864 {
865 }
866
871 virtual void PhyDrop(SocketWho who [[maybe_unused]])
872 {
873 }
874
884 virtual void RcvAck(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
885 const TcpHeader& h [[maybe_unused]],
886 SocketWho who [[maybe_unused]])
887 {
888 }
889
899 virtual void ProcessedAck(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
900 const TcpHeader& h [[maybe_unused]],
901 SocketWho who [[maybe_unused]])
902 {
903 }
904
912 virtual void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who);
913
921 virtual void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who);
922
929 virtual void AfterRTOExpired(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
930 SocketWho who [[maybe_unused]])
931 {
932 }
933
940 virtual void BeforeRTOExpired(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
941 SocketWho who [[maybe_unused]])
942 {
943 }
944
952 virtual void UpdatedRttHistory(const SequenceNumber32& seq [[maybe_unused]],
953 uint32_t sz [[maybe_unused]],
954 bool isRetransmission [[maybe_unused]],
955 SocketWho who [[maybe_unused]])
956 {
957 }
958
965 virtual void DataSent(uint32_t size [[maybe_unused]], SocketWho who [[maybe_unused]])
966 {
967 }
968
972 virtual void FinalChecks()
973 {
974 }
975
981 {
982 return m_propagationDelay;
983 }
984
990 {
991 return m_startTime;
992 }
993
999 {
1000 return m_mtu;
1001 }
1002
1008 {
1009 return m_pktSize;
1010 }
1011
1017 {
1018 return m_pktCount;
1019 }
1020
1027 {
1028 return m_interPacketInterval;
1029 }
1030
1033
1034 private:
1035 // Member variables, accessible through getters
1036 // giving write access to subclass can be dangerous
1038
1041
1045
1048
1049 private:
1050 // De-multiplexing callbacks.
1051
1056 void NormalCloseCb(Ptr<Socket> socket);
1061 void ErrorCloseCb(Ptr<Socket> socket);
1067 void QueueDropCb(std::string context, Ptr<const Packet> p);
1073 void PhyDropCb(std::string context, Ptr<const Packet> p);
1094 void TxPacketCb(const Ptr<const Packet> p,
1095 const TcpHeader& h,
1096 const Ptr<const TcpSocketBase> tcp);
1103 void RxPacketCb(const Ptr<const Packet> p,
1104 const TcpHeader& h,
1105 const Ptr<const TcpSocketBase> tcp);
1120 const SequenceNumber32& seq,
1121 uint32_t sz,
1122 bool isRetransmission);
1123
1130
1137 const Ptr<const TcpSocketBase> tcp);
1138
1144 void DataSentCb(Ptr<Socket> socket, uint32_t size);
1149 void ForkCb(Ptr<TcpSocketMsgBase> tcp);
1155 void HandleAccept(Ptr<Socket> socket, const Address& from);
1156
1158};
1159
1160} // namespace ns3
1161
1162#endif // TCPGENERALTEST_H
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
an Inet address class
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
General infrastructure for TCP testing.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
uint32_t GetPktCount() const
Get the number of application packets.
virtual void HighestTxSeqTrace(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Highest tx seq changes.
void ErrorCloseCb(Ptr< Socket > socket)
Error Close Callback.
TypeId m_recoveryTypeId
Recovery.
uint32_t GetDelAckCount(SocketWho who)
Get the number of delayed ack (if present)
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
virtual void DataSent(uint32_t size, SocketWho who)
Notifying application for sent data.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
void SetDelAckMaxCount(SocketWho who, uint32_t count)
Forcefully set the delayed acknowledgement count.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
void BeforeRetransmitCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
Invoked before a retransmit event.
Ptr< TcpTxBuffer > GetTxBuffer(SocketWho who)
Get the Tx buffer from selected socket.
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Tracks the congestion window changes.
void TxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Tx packet Callback.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
void SetCongestionControl(TypeId congControl)
Congestion control of the sender socket.
virtual void RateUpdatedTrace(const TcpRateLinux::TcpRateConnection &rate)
Track the rate value of TcpRateLinux.
virtual void NormalClose(SocketWho who)
Socket closed normally.
uint32_t m_mtu
MTU of the environment.
virtual void RcvAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Received ack.
virtual void NextTxSeqTrace(SequenceNumber32 oldValue, SequenceNumber32 newValue)
Next tx seq changes.
Time GetMinRto(SocketWho who)
Get the minimum RTO attribute.
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
Time m_interPacketInterval
Time between sending application packet down to tcp socket.
virtual void SsThreshTrace(uint32_t oldValue, uint32_t newValue)
Slow start threshold changes.
uint32_t m_pktSize
Size of the application packet.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
uint32_t m_pktCount
Count of the application packet.
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an accept connection.
virtual void BeforeRTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
void QueueDropCb(std::string context, Ptr< const Packet > p)
Queue Drop Callback.
virtual void BytesInFlightTrace(uint32_t oldValue, uint32_t newValue)
Bytes in flight changes.
void ForkCb(Ptr< TcpSocketMsgBase > tcp)
Fork Callback.
uint32_t GetReTxThreshold(SocketWho who)
Get the retransmission threshold.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Rx packet Callback.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
virtual void CWndInflTrace(uint32_t oldValue, uint32_t newValue)
Tracks the inflated congestion window changes.
Time GetPktInterval() const
Get the interval to wait for each packet sent down from application to TCP.
void SetPaceInitialWindow(SocketWho who, bool paceWindow)
Enable or disable pacing of the initial window.
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual void ErrorClose(SocketWho who)
Socket closed with an error.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
virtual void UpdatedRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission, SocketWho who)
Updated the Rtt history.
virtual void QueueDrop(SocketWho who)
Drop on the queue.
virtual Ptr< SimpleChannel > CreateChannel()
Create and return the channel installed between the two socket.
void DoRun() override
Execute the tcp test.
Time GetDelAckTimeout(SocketWho who)
Get the timeout of delayed ack (if present)
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
Time GetPropagationDelay() const
Get the channel Propagation Delay.
Time GetClockGranularity(SocketWho who)
Get the clock granularity attribute.
void SetUseEcn(SocketWho who, TcpSocketState::UseEcn_t useEcn)
Forcefully set the ECN mode of use.
Time m_startTime
Data transmission time.
Ptr< TcpSocketMsgBase > m_senderSocket
Pointer to sender socket.
void DoConnect()
Scheduled at 0.0, SENDER starts the connection to RECEIVER.
Time GetRto(SocketWho who)
Get the retransmission time.
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
Time GetConnTimeout(SocketWho who)
Get the retransmission time for the SYN segments.
void AfterRetransmitCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
Invoked after a retransmit event.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
uint32_t GetRWnd(SocketWho who)
Get the rWnd of the selected socket.
void PhyDropCb(std::string context, Ptr< const Packet > p)
Drop at Phy layer Callback.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
TypeId m_congControlTypeId
Congestion control.
virtual void ReceivePacket(Ptr< Socket > socket)
Packet received.
virtual void RateSampleUpdatedTrace(const TcpRateLinux::TcpRateSample &sample)
Track the rate sample value of TcpRateLinux.
virtual void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Processed ack.
void DataSentCb(Ptr< Socket > socket, uint32_t size)
Data sent Callback.
Time GetStartTime() const
Get the data start time.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Send packets to other endpoint.
virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
uint32_t GetMtu() const
Get the MTU of the environment.
void NormalCloseCb(Ptr< Socket > socket)
Normal Close Callback.
Time m_propagationDelay
Propagation delay of the channel.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
Receive ACK Callback.
virtual void AfterRTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
TcpSocket::TcpStates_t GetTcpState(SocketWho who)
Get the state of the TCP state machine.
virtual void PhyDrop(SocketWho who)
Link drop.
void RtoExpiredCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
RTO expired Callback.
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssthresh.
SequenceNumber32 GetHighestTxMark(SocketWho who)
Get the highest tx mark of the node specified.
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
Time GetPersistentTimeout(SocketWho who)
Get the persistent timeout of the selected socket.
void SetRecoveryAlgorithm(TypeId recovery)
recovery algorithm of the sender socket
virtual void RtoTrace(Time oldValue, Time newValue)
RTO changes.
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
void SetPacingStatus(SocketWho who, bool pacing)
Enable or disable pacing in the TCP socket.
Ptr< TcpSocketMsgBase > m_receiverSocket
Pointer to receiver socket.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
virtual Ptr< ErrorModel > CreateSenderErrorModel()
Create and return the error model to install in the sender node.
uint32_t GetInitialCwnd(SocketWho who)
Get the initial congestion window.
void UpdateRttHistoryCb(Ptr< const TcpSocketBase > tcp, const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update RTT with new data.
Ptr< TcpSocketMsgBase > GetSenderSocket()
Get the pointer to a previously created sender socket.
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver socket.
uint32_t GetPktSize() const
Get the application packet size.
virtual void RttTrace(Time oldTime, Time newTime)
Rtt changes.
void ProcessedAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
ACK processed Callback.
void DoTeardown() override
Teardown the TCP test.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
InetSocketAddress m_remoteAddr
Remote peer address.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
A base class for implementation of a stream socket using TCP.
Class for inserting callbacks special points of the flow of TCP sockets.
UpdateRttCallback m_updateRttCb
Update RTT callback.
AckManagementCb m_processedAckCb
Processed ACK callback.
void SetAfterRetransmitCb(RetrCb cb)
Set the callback invoked after the processing of a retransmit timeout.
Callback< void, Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > AckManagementCb
Callback for the ACK management.
void SetForkCb(Callback< void, Ptr< TcpSocketMsgBase > > cb)
Set the callback invoked after the forking.
Callback< void, Ptr< const TcpSocketState >, Ptr< const TcpSocketBase > > RetrCb
Callback for the packet retransmission management.
TcpSocketMsgBase(const TcpSocketMsgBase &other)
Constructor.
void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission) override
Update the RTT history, when we send TCP segments.
void SetRcvAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received (at the beginning of the processing)
AckManagementCb m_rcvAckCb
Receive ACK callback.
void SetProcessedAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing)
void SetBeforeRetransmitCb(RetrCb cb)
Set the callback invoked before the processing of a retransmit timeout.
void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress) override
Complete a connection by forking the socket.
Ptr< TcpSocketBase > Fork() override
Call CopyObject<> to clone me.
static TypeId GetTypeId()
Get the type ID.
Callback< void, Ptr< const TcpSocketBase >, const SequenceNumber32 &, uint32_t, bool > UpdateRttCallback
Callback for the RTT update management.
RetrCb m_beforeRetrCallback
Before retransmission callback.
Callback< void, Ptr< TcpSocketMsgBase > > m_forkCb
Fork callback.
void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader) override
Received an ACK packet.
RetrCb m_afterRetrCallback
After retransmission callback.
void ReTxTimeout() override
An RTO event happened.
void SetUpdateRttHistoryCb(UpdateRttCallback cb)
Set the callback invoked when we update rtt history.
A TCP socket which sends ACKs smaller than the segment received.
static TypeId GetTypeId()
Get the type ID.
SequenceNumber32 m_lastAckedSeq
Last sequence number ACKed.
uint32_t m_bytesToAck
Number of bytes to be ACKed.
void SendEmptyPacket(uint8_t flags) override
Send a empty packet that carries a flag, e.g., ACK.
TcpSocketSmallAcks(const TcpSocketSmallAcks &other)
Constructor.
uint32_t m_bytesLeftToBeAcked
Number of bytes to be ACKed left.
void SetBytesToAck(uint32_t bytes)
Set the bytes to be ACKed.
Ptr< TcpSocketBase > Fork() override
Call CopyObject<> to clone me.
UseEcn_t
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn.
TcpCongState_t
Definition of the Congestion state machine.
encapsulates test code
Definition: test.h:1061
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
uint32_t segmentSize
TcpStates_t
Names of the 11 TCP states.
Definition: tcp-socket.h:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Information about the connection rate.
Definition: tcp-rate-ops.h:174
Rate Sample structure.
Definition: tcp-rate-ops.h:140
uint32_t pktSize
packet size used for the simulation (in bytes)