A Discrete-Event Network Simulator
API
tcp-general-test.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
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  */
19 #ifndef TCPGENERALTEST_H
20 #define TCPGENERALTEST_H
21 
22 #include "ns3/simple-net-device.h"
23 #include "ns3/error-model.h"
24 #include "ns3/tcp-socket-base.h"
25 #include "ns3/tcp-congestion-ops.h"
26 #include "ns3/test.h"
27 
28 namespace ns3 {
29 
47 {
48 public:
49  static TypeId GetTypeId (void);
50 
52  {
53  }
54 
56  {
57  m_rcvAckCb = other.m_rcvAckCb;
60  m_forkCb = other.m_forkCb;
61  }
62 
68  uint32_t, bool> UpdateRttCallback;
69 
76  void SetRcvAckCb (AckManagementCb cb);
77 
84  void SetProcessedAckCb (AckManagementCb cb);
85 
91  void SetRetransmitCb (RetrCb cb);
92 
97  void SetForkCb (Callback<void, Ptr<TcpSocketMsgBase> > cb);
98 
104  void SetUpdateRttHistoryCb (UpdateRttCallback cb);
105 
106 protected:
107  virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
108  virtual void Retransmit (void);
109  virtual Ptr<TcpSocketBase> Fork (void);
110  virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader,
111  const Address& fromAddress, const Address& toAddress);
112  virtual void UpdateRttHistory (const SequenceNumber32 &seq, uint32_t sz,
113  bool isRetransmission);
114 
115 private:
116  AckManagementCb m_rcvAckCb;
117  AckManagementCb m_processedAckCb;
120  UpdateRttCallback m_updateRttCb;
121 };
122 
123 
139 {
140 public:
141  static TypeId GetTypeId (void);
142 
144  : TcpSocketMsgBase (),
145  m_bytesToAck (125),
147  m_lastAckedSeq (1)
148  {
149  }
150 
152  : TcpSocketMsgBase (other),
153  m_bytesToAck (other.m_bytesToAck),
156  {
157  }
158 
159  void SetBytesToAck (uint32_t bytes)
160  {
161  m_bytesToAck = bytes;
162  }
163 
164 protected:
165  virtual void SendEmptyPacket (uint8_t flags);
166  Ptr<TcpSocketBase> Fork (void);
167 
168  uint32_t m_bytesToAck;
171 };
172 
211 class TcpGeneralTest : public TestCase
212 {
213 public:
222  TcpGeneralTest (const std::string &desc);
223  ~TcpGeneralTest ();
224 
230  {
233  };
234 
235 protected:
242 
249 
256 
263 
270 
278  virtual Ptr<TcpSocketMsgBase> CreateSocket (Ptr<Node> node, TypeId socketType,
279  TypeId congControl);
280 
286  {
287  return m_senderSocket;
288  }
289 
295  {
296  return m_receiverSocket;
297  }
298 
315  virtual void DoRun (void);
316 
320  virtual void ConfigureEnvironment (void);
321 
325  virtual void ConfigureProperties (void);
326 
330  virtual void DoTeardown (void);
331 
335  void DoConnect ();
336 
343  virtual void ReceivePacket (Ptr<Socket> socket);
344 
353  void SendPacket (Ptr<Socket> socket, uint32_t pktSize,
354  uint32_t pktCount, Time pktInterval);
355 
363  uint32_t GetSegSize (SocketWho who);
364 
373 
379  uint32_t GetReTxThreshold (SocketWho who);
380 
385  uint32_t GetInitialSsThresh (SocketWho who);
386 
391  uint32_t GetInitialCwnd (SocketWho who);
392 
398  uint32_t GetDupAckCount (SocketWho who);
399 
405  uint32_t GetDelAckCount (SocketWho who);
406 
413 
420  Time GetRto (SocketWho who);
421 
428  Time GetMinRto (SocketWho who);
429 
437 
445 
453 
461 
469 
477 
484  uint32_t GetRWnd (SocketWho who);
485 
493 
501 
508  void SetRcvBufSize (SocketWho who, uint32_t size);
509 
516  void SetSegmentSize (SocketWho who, uint32_t segmentSize);
517 
524  void SetInitialCwnd (SocketWho who, uint32_t initialCwnd);
525 
532  void SetInitialSsThresh (SocketWho who, uint32_t initialSsThresh);
533 
541  void SetAppPktSize (uint32_t pktSize) { m_pktSize = pktSize; }
542 
550  void SetAppPktCount (uint32_t pktCount) { m_pktCount = pktCount; }
551 
557  void SetAppPktInterval (Time pktInterval) { m_interPacketInterval = pktInterval; }
558 
564  void SetPropagationDelay (Time propDelay) { m_propagationDelay = propDelay; }
565 
572 
578  void SetCongestionControl (TypeId congControl) { m_congControlTypeId = congControl; }
579 
585  void SetMTU (uint32_t mtu) { m_mtu = mtu; }
586 
592  virtual void CongStateTrace (const TcpSocketState::TcpCongState_t oldValue,
593  const TcpSocketState::TcpCongState_t newValue)
594  {
595  }
596 
603  virtual void CWndTrace (uint32_t oldValue, uint32_t newValue)
604  {
605  }
606 
615  virtual void RttTrace (Time oldTime, Time newTime)
616  {
617  }
618 
628  virtual void SsThreshTrace (uint32_t oldValue, uint32_t newValue)
629  {
630  }
631 
640  virtual void BytesInFlightTrace (uint32_t oldValue, uint32_t newValue)
641  {
642  }
643 
648  virtual void NormalClose (SocketWho who)
649  {
650  }
651 
657  virtual void ErrorClose (SocketWho who)
658  {
660  }
661 
666  virtual void QueueDrop (SocketWho who)
667  {
668  }
669 
674  virtual void PhyDrop (SocketWho who)
675  {
676  }
677 
687  virtual void RcvAck (const Ptr<const TcpSocketState> tcb,
688  const TcpHeader& h, SocketWho who)
689  {
690  }
691 
701  virtual void ProcessedAck (const Ptr<const TcpSocketState> tcb,
702  const TcpHeader& h, SocketWho who)
703  {
704  }
705 
713  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
714 
722  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
723 
730  virtual void RTOExpired (const Ptr<const TcpSocketState> tcb, SocketWho who)
731  {
732  }
733 
741  virtual void UpdatedRttHistory (const SequenceNumber32 & seq, uint32_t sz,
742  bool isRetransmission, SocketWho who)
743  {
744  }
745 
752  virtual void DataSent (uint32_t size, SocketWho who)
753  {
754  }
755 
760  virtual void FinalChecks ()
761  {
762  }
763 
769  {
770  return m_propagationDelay;
771  }
772 
778  {
779  return m_startTime;
780  }
781 
786  uint32_t GetMtu () const
787  {
788  return m_mtu;
789  }
790 
795  uint32_t GetPktSize () const
796  {
797  return m_pktSize;
798  }
799 
804  uint32_t GetPktCount () const
805  {
806  return m_pktCount;
807  }
808 
815  {
816  return m_interPacketInterval;
817  }
818 
820 
821 private:
822  // Member variables, accessible through getters
823  // giving write access to subclass can be dangerous
825 
827  uint32_t m_mtu;
828 
829  uint32_t m_pktSize;
830  uint32_t m_pktCount;
832  // down to tcp socket
833 
836 
837 private:
838  // De-multiplexing callbacks.
839  void NormalCloseCb (Ptr<Socket> socket);
840  void ErrorCloseCb (Ptr<Socket> socket);
841  void QueueDropCb (std::string context, Ptr<const Packet> p);
842  void PhyDropCb (std::string context, Ptr<const Packet> p);
843  void RcvAckCb (Ptr<const Packet> p, const TcpHeader& h,
845  void ProcessedAckCb (Ptr<const Packet> p, const TcpHeader& h,
847  void TxPacketCb (const Ptr<const Packet> p, const TcpHeader& h,
848  const Ptr<const TcpSocketBase> tcp);
849  void RxPacketCb (const Ptr<const Packet> p, const TcpHeader& h,
850  const Ptr<const TcpSocketBase> tcp);
851  void RtoExpiredCb (const Ptr<const TcpSocketState> tcb,
852  const Ptr<const TcpSocketBase> tcp);
854  uint32_t sz, bool isRetransmission);
855  void DataSentCb (Ptr<Socket> socket, uint32_t size);
856  void ForkCb (Ptr<TcpSocketMsgBase> tcp);
857  void HandleAccept (Ptr<Socket> socket, const Address& from);
858 
860 };
861 
868 static inline TcpSocketState::TcpCongState_t
870 {
871  return tcb->m_congState.Get ();
872 }
873 
874 } // namespace ns3
875 
876 #endif // TCPGENERALTEST_H
877 
virtual void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Processed ack.
Time GetMinRto(SocketWho who)
Get the minimun RTO attribute.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void DoTeardown(void)
Teardown the TCP test.
Time GetPersistentTimeout(SocketWho who)
Get the persistent timeout of the selected socket.
an Inet address class
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void SendEmptyPacket(uint8_t flags)
Send empty packet, copied/pasted from TcpSocketBase.
uint32_t GetPktSize() const
Get the application packet size.
Ptr< TcpSocketMsgBase > m_senderSocket
Pointer to sender socket.
void PhyDropCb(std::string context, Ptr< const Packet > p)
Time m_propagationDelay
Propagation delay of the channel.
uint32_t GetDelAckCount(SocketWho who)
Get the number of delayed ack (if present)
Callback template class.
Definition: callback.h:1176
void DataSentCb(Ptr< Socket > socket, uint32_t size)
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Class for inserting callbacks special points of the flow of TCP sockets.
TcpGeneralTest(const std::string &desc)
TcpGeneralTest constructor.
AckManagementCb m_rcvAckCb
Ptr< TcpSocketMsgBase > GetSenderSocket()
Get the pointer to a previously created sender socket.
void SetForkCb(Callback< void, Ptr< TcpSocketMsgBase > > cb)
Set the callback invoked after the forking.
void SetCongestionControl(TypeId congControl)
Congestion control of the sender socket.
virtual void DoRun(void)
Execute the tcp test.
void NormalCloseCb(Ptr< Socket > socket)
virtual void PhyDrop(SocketWho who)
Link drop.
virtual void DataSent(uint32_t size, SocketWho who)
Notifying application for sent data.
void QueueDropCb(std::string context, Ptr< const Packet > p)
virtual void ErrorClose(SocketWho who)
Socket closed with an error.
Callback< void, Ptr< const TcpSocketState >, Ptr< const TcpSocketBase > > RetrCb
void SetBytesToAck(uint32_t bytes)
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
void DoConnect()
Scheduled at 0.0, SENDER starts the connection to RECEIVER.
void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Send packets to other endpoint.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
virtual void SsThreshTrace(uint32_t oldValue, uint32_t newValue)
Slow start threshold changes.
void SetRcvAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received (at the beginning of the processing) ...
encapsulates test code
Definition: test.h:1147
static TcpSocketState::TcpCongState_t GetCongStateFrom(Ptr< const TcpSocketState > tcb)
Convenience function to retrieve the ACK state from a TCB.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
virtual Ptr< ErrorModel > CreateSenderErrorModel()
Create and return the error model to install in the sender node.
a polymophic address class
Definition: address.h:90
uint32_t GetRWnd(SocketWho who)
Get the rWnd of the selected socket.
virtual void ReceivePacket(Ptr< Socket > socket)
Packet received.
Time GetDelAckTimeout(SocketWho who)
Get the timeout of delayed ack (if present)
SequenceNumber32 GetHighestTxMark(SocketWho who)
Get the highest tx mark of the node specified.
void ErrorCloseCb(Ptr< Socket > socket)
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
TcpSocketMsgBase(const TcpSocketMsgBase &other)
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
double startTime
uint32_t m_pktCount
Count of the application packet.
Time m_interPacketInterval
Time between sending application packet.
void SetRetransmitCb(RetrCb cb)
Set the callback invoked after the processing of a retransmit timeout.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
Time GetConnTimeout(SocketWho who)
Get the retransmission time for the SYN segments.
A base class for implementation of a stream socket using TCP.
void ProcessedAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual void RcvAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Received ack.
TcpCongState_t
Definition of the Congestion state machine.
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
uint32_t GetInitialCwnd(SocketWho who)
Get the initial congestion window.
AckManagementCb m_processedAckCb
uint32_t GetMtu() const
Get the MTU of the environment.
Ptr< TcpSocketMsgBase > m_receiverSocket
Pointer to receiver socket.
Time GetRto(SocketWho who)
Get the retransmission time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void QueueDrop(SocketWho who)
Drop on the queue.
TracedValue< TcpCongState_t > m_congState
State in the Congestion state machine.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
TcpSocketSmallAcks(const TcpSocketSmallAcks &other)
uint32_t GetReTxThreshold(SocketWho who)
Get the retransmission threshold.
static TypeId GetTypeId(void)
void ForkCb(Ptr< TcpSocketMsgBase > tcp)
Time GetClockGranularity(SocketWho who)
Get the clock granularity attribute.
virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssth.
Time GetPktInterval() const
Get the interval to wait for each packet sent down from application to TCP.
void UpdateRttHistoryCb(Ptr< const TcpSocketBase > tcp, const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
UpdateRttCallback m_updateRttCb
TcpStates_t
Names of the 11 TCP states.
Definition: tcp-socket.h:65
virtual void NormalClose(SocketWho who)
Socket closed normally.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
General infrastructure for TCP testing.
An identifier for simulation events.
Definition: event-id.h:53
virtual void ConfigureEnvironment(void)
Change the configuration of the evironment.
void SetUpdateRttHistoryCb(UpdateRttCallback cb)
Set the callback invoked when we update rtt history.
Time GetStartTime() const
Get the data start time.
static TypeId GetTypeId(void)
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver socket.
virtual Ptr< SimpleChannel > CreateChannel()
Create and return the channel installed between the two socket.
void TxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
uint32_t GetPktCount() const
Get the number of application packets.
virtual void BytesInFlightTrace(uint32_t oldValue, uint32_t newValue)
Bytes in flight changes.
void RtoExpiredCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
uint32_t m_mtu
MTU of the environment.
Callback< void, Ptr< TcpSocketMsgBase > > m_forkCb
virtual void UpdatedRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission, SocketWho who)
Updated the Rtt history.
Time GetPropagationDelay() const
Get the channel Propagation Delay.
A TCP socket which sends ACKs smaller than the segment received.
virtual void RttTrace(Time oldTime, Time newTime)
Rtt changes.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
SequenceNumber32 m_lastAckedSeq
InetSocketAddress m_remoteAddr
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
virtual void RTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
void SetProcessedAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing) ...
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
Callback< void, Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > AckManagementCb
a unique identifier for an interface.
Definition: type-id.h:58
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Congestion window changes.
uint32_t m_pktSize
Size of the application packet.
TcpSocket::TcpStates_t GetTcpState(SocketWho who)
Get the state of the TCP state machine.
Time m_startTime
Data transmission time.
void HandleAccept(Ptr< Socket > socket, const Address &from)
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
TypeId m_congControlTypeId
Congestion control.
Callback< void, Ptr< const TcpSocketBase >, const SequenceNumber32 &, uint32_t, bool > UpdateRttCallback