This documentation is not the Latest Release.
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/test.h"
26 
27 namespace ns3 {
28 
46 {
47 public:
48  static TypeId GetTypeId (void);
49 
51  {
52  }
53 
55  {
56  m_rcvAckCb = other.m_rcvAckCb;
59  m_forkCb = other.m_forkCb;
60  }
61 
66 
73  void SetRcvAckCb (AckManagementCallback cb);
74 
81  void SetProcessedAckCb (AckManagementCallback cb);
82 
88  void SetRetransmitCb (RetrCallback cb);
89 
94  void SetForkCb (Callback<void, Ptr<TcpSocketMsgBase> > cb);
95 
96 protected:
97  virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
98  virtual void Retransmit (void);
99  virtual Ptr<TcpSocketBase> Fork (void);
100  virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader,
101  const Address& fromAddress, const Address& toAddress);
102 
103 private:
104  AckManagementCallback m_rcvAckCb;
105  AckManagementCallback m_processedAckCb;
106  RetrCallback m_retrCallback;
108 };
109 
110 
126 {
127 public:
128  static TypeId GetTypeId (void);
129 
131  : TcpSocketMsgBase (),
132  m_bytesToAck (125),
134  m_lastAckedSeq (1)
135  {
136  }
137 
139  m_bytesToAck (other.m_bytesToAck),
142  {
143  }
144 
145  void SetBytesToAck (uint32_t bytes)
146  {
147  m_bytesToAck = bytes;
148  }
149 
150 protected:
151  virtual void SendEmptyPacket (uint8_t flags);
152  Ptr<TcpSocketBase> Fork (void);
153 
154  uint32_t m_bytesToAck;
157 };
158 
197 class TcpGeneralTest : public TestCase
198 {
199 public:
211  TcpGeneralTest (const std::string &desc,
212  uint32_t pktSize = 500,
213  uint32_t pktCount = 10,
214  const Time& pktInterval = Seconds (0.01),
215  const Time& propagationDelay = Seconds (0.5),
216  const Time& startTime = Seconds (10),
217  uint32_t initialSlowStartThresh = 0xffff,
218  uint32_t initialCwnd = 1,
219  uint32_t segmentSize = 500,
220  TypeId congestionControl = TcpNewReno::GetTypeId (),
221  uint32_t mtu = 1500);
222  ~TcpGeneralTest ();
223 
229  {
232  };
233 
234 protected:
241 
248 
255 
262 
269 
277  virtual Ptr<TcpSocketMsgBase> CreateSocket (Ptr<Node> node, TypeId socketType,
278  TypeId congControl);
279 
285  {
286  return m_senderSocket;
287  }
288 
294  {
295  return m_receiverSocket;
296  }
297 
305  virtual void DoRun (void);
306 
310  virtual void DoTeardown (void);
311 
315  void DoConnect ();
316 
323  virtual void ReceivePacket (Ptr<Socket> socket);
324 
333  void SendPacket (Ptr<Socket> socket, uint32_t pktSize,
334  uint32_t pktCount, Time pktInterval);
335 
343  uint32_t GetSegSize (SocketWho who);
344 
350  uint32_t GetReTxThreshold (SocketWho who);
351 
357  uint32_t GetDupAckCount (SocketWho who);
358 
364  uint32_t GetDelAckCount (SocketWho who);
365 
372 
379  Time GetRto (SocketWho who);
380 
387  Time GetMinRto (SocketWho who);
388 
396 
404 
412 
420 
428 
435  uint32_t GetRWnd (SocketWho who);
436 
444 
452 
459  void SetRcvBufSize (SocketWho who, uint32_t size);
460 
466  virtual void CongStateTrace (const TcpSocketState::TcpCongState_t oldValue,
467  const TcpSocketState::TcpCongState_t newValue)
468  {
469  }
470 
477  virtual void CWndTrace (uint32_t oldValue, uint32_t newValue)
478  {
479  }
480 
485  virtual void NormalClose (SocketWho who)
486  {
487  }
488 
494  virtual void ErrorClose (SocketWho who)
495  {
497  }
498 
503  virtual void QueueDrop (SocketWho who)
504  {
505  }
506 
511  virtual void PhyDrop (SocketWho who)
512  {
513  }
514 
524  virtual void RcvAck (const Ptr<const TcpSocketState> tcb,
525  const TcpHeader& h, SocketWho who)
526  {
527  }
528 
538  virtual void ProcessedAck (const Ptr<const TcpSocketState> tcb,
539  const TcpHeader& h, SocketWho who)
540  {
541  }
542 
550  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
551 
559  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
560 
567  virtual void RTOExpired (const Ptr<const TcpSocketState> tcb, SocketWho who)
568  {
569  }
570 
575  virtual void FinalChecks ()
576  {
577  }
578 
584  {
585  return m_propagationDelay;
586  }
587 
593  {
594  return m_startTime;
595  }
596 
601  uint32_t GetMtu () const
602  {
603  return m_mtu;
604  }
605 
610  uint32_t GetPktSize () const
611  {
612  return m_pktSize;
613  }
614 
619  uint32_t GetPktCount () const
620  {
621  return m_pktCount;
622  }
623 
630  {
631  return m_interPacketInterval;
632  }
633 
638  uint32_t GetInitialSsThresh () const
639  {
641  }
642 
647  uint32_t GetInitialCwnd () const
648  {
649  return m_initialCwnd;
650  }
651 
652 
654 
655 private:
656  // Member variables, accessible through getters
657  // giving write access to subclass can be dangerous
659 
661  uint32_t m_mtu;
662 
663  uint32_t m_pktSize;
664  uint32_t m_pktCount;
666  // down to tcp socket
668  uint32_t m_initialCwnd;
669  uint32_t m_segmentSize;
670 
673 
674 private:
675  // De-multiplexing callbacks.
676  void NormalCloseCb (Ptr<Socket> socket);
677  void ErrorCloseCb (Ptr<Socket> socket);
678  void QueueDropCb (std::string context, Ptr<const Packet> p);
679  void PhyDropCb (std::string context, Ptr<const Packet> p);
680  void RcvAckCb (Ptr<const Packet> p, const TcpHeader& h,
682  void ProcessedAckCb (Ptr<const Packet> p, const TcpHeader& h,
684  void TxPacketCb (const Ptr<const Packet> p, const TcpHeader& h,
685  const Ptr<const TcpSocketBase> tcp);
686  void RxPacketCb (const Ptr<const Packet> p, const TcpHeader& h,
687  const Ptr<const TcpSocketBase> tcp);
688  void RtoExpiredCb (const Ptr<const TcpSocketState> tcb,
689  const Ptr<const TcpSocketBase> tcp);
690  void ForkCb (Ptr<TcpSocketMsgBase> tcp);
691  void HandleAccept (Ptr<Socket> socket, const Address& from);
692 
694 };
695 
702 static inline TcpSocketState::TcpCongState_t
704 {
705  return tcb->m_congState.Get ();
706 }
707 
708 } // namespace ns3
709 
710 #endif // TCPGENERALTEST_H
711 
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:1164
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.
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.
virtual void DoRun(void)
Execute the tcp test.
void NormalCloseCb(Ptr< Socket > socket)
virtual void PhyDrop(SocketWho who)
Link drop.
void QueueDropCb(std::string context, Ptr< const Packet > p)
virtual void ErrorClose(SocketWho who)
Socket closed with an error.
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.
Callback< void, Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > AckManagementCallback
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.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
AckManagementCallback m_rcvAckCb
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
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:217
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.
uint32_t m_initialCwnd
Initial congestion window.
a polymophic address class
Definition: address.h:90
void SetRcvAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received (at the beginning of the processing) ...
TcpGeneralTest(const std::string &desc, uint32_t pktSize=500, uint32_t pktCount=10, const Time &pktInterval=Seconds(0.01), const Time &propagationDelay=Seconds(0.5), const Time &startTime=Seconds(10), uint32_t initialSlowStartThresh=0xffff, uint32_t initialCwnd=1, uint32_t segmentSize=500, TypeId congestionControl=TcpNewReno::GetTypeId(), uint32_t mtu=1500)
TcpGeneralTest constructor.
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)
static TypeId GetTypeId(void)
Get the type ID.
void ErrorCloseCb(Ptr< Socket > socket)
Callback< void, Ptr< const TcpSocketState >, Ptr< const TcpSocketBase > > RetrCallback
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
TcpSocketMsgBase(const TcpSocketMsgBase &other)
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
double startTime
void SetRetransmitCb(RetrCallback cb)
Set the callback invoked after the processing of a retransmit timeout.
uint32_t m_pktCount
Count of the application packet.
Time m_interPacketInterval
Time between sending application packet.
uint32_t GetInitialCwnd() const
Get the initial congestion window.
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.
AckManagementCallback m_processedAckCb
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
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
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.
void SetProcessedAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing) ...
virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
Time GetPktInterval() const
Get the interval to wait for each packet sent down from application to TCP.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
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
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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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.
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
Time GetPropagationDelay() const
Get the channel Propagation Delay.
A TCP socket which sends ACKs smaller than the segment received.
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.
uint32_t m_initialSlowStartThresh
Initial slow start threshold.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
SequenceNumber32 m_lastAckedSeq
InetSocketAddress m_remoteAddr
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
TcpStates_t
Names of the 11 TCP states.
Definition: tcp-socket.h:64
uint32_t GetInitialSsThresh() const
Get the initial slow start threshold.
uint32_t m_segmentSize
Segment size.
virtual void RTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
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)
TypeId m_congControlTypeId
Congestion control.