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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7#ifndef TCPGENERALTEST_H
8#define TCPGENERALTEST_H
9
10#include "ns3/error-model.h"
11#include "ns3/simple-net-device.h"
12#include "ns3/tcp-congestion-ops.h"
13#include "ns3/tcp-rate-ops.h"
14#include "ns3/tcp-recovery-ops.h"
15#include "ns3/tcp-socket-base.h"
16#include "ns3/test.h"
17
18namespace ns3
19{
20
21/**
22 * \ingroup internet-test
23 *
24 * \brief Class for inserting callbacks special points of the flow of TCP sockets
25 *
26 * This subclass is born to extend TcpSocketBase, inserting callbacks in certain
27 * points of the flow, to be used in testing to check certain values or flow
28 * directions.
29 *
30 * There isn't the necessity to fill TcpSocketBase of TracedCallbacks; the rationale
31 * is to maintain the base class as clean as possible.
32 *
33 * To be fair with testing, this class should NOT modify the behavior of TcpSocketBase.
34 *
35 * \see SetRcvAckCb
36 * \see SetProcessedAckCb
37 * \see SetAfterRetransmitCb
38 * \see SetBeforeRetransmitCb
39 */
41{
42 public:
43 /**
44 * \brief Get the type ID.
45 * \return the object TypeId
46 */
47 static TypeId GetTypeId();
48
51 {
52 }
53
54 /**
55 * \brief Constructor.
56 * \param other The object to copy from.
57 */
68
69 /// Callback for the ACK management.
72 /// Callback for the packet retransmission management.
74 /// Callback for the RTT update management.
77
78 /**
79 * \brief Set the callback invoked when an ACK is received (at the beginning
80 * of the processing)
81 *
82 * \param cb callback
83 */
85
86 /**
87 * \brief Set the callback invoked when an ACK is received and processed
88 * (at the end of the processing)
89 *
90 * \param cb callback
91 */
93
94 /**
95 * \brief Set the callback invoked after the processing of a retransmit timeout
96 *
97 * \param cb callback
98 */
100
101 /**
102 * \brief Set the callback invoked before the processing of a retransmit timeout
103 *
104 * \param cb callback
105 */
107
108 /**
109 * \brief Set the callback invoked after the forking
110 * \param cb callback
111 */
113
114 /**
115 * \brief Set the callback invoked when we update rtt history
116 *
117 * \param cb callback
118 */
120
121 protected:
122 void ReceivedAck(Ptr<Packet> packet, const TcpHeader& tcpHeader) override;
123 void ReTxTimeout() override;
124 Ptr<TcpSocketBase> Fork() override;
126 const TcpHeader& tcpHeader,
127 const Address& fromAddress,
128 const Address& toAddress) override;
129 void UpdateRttHistory(const SequenceNumber32& seq, uint32_t sz, bool isRetransmission) override;
130
131 private:
132 AckManagementCb m_rcvAckCb; //!< Receive ACK callback.
133 AckManagementCb m_processedAckCb; //!< Processed ACK callback.
134 RetrCb m_beforeRetrCallback; //!< Before retransmission callback.
135 RetrCb m_afterRetrCallback; //!< After retransmission callback.
137 UpdateRttCallback m_updateRttCb; //!< Update RTT callback.
138};
139
140/**
141 * \ingroup internet-test
142 *
143 * \brief A TCP socket which sends ACKs smaller than the segment received.
144 *
145 * Usually, a TCP socket which receives the sequence number "x" replies with
146 * an ACK to "x+1". What happen if a malicious socket sends smaller ACKs
147 * (e.g. two ACKs, one for "x/2", and the other for "x+1") ? A TCP implementation
148 * should avoid to artificially increase the congestion window, thinking of
149 * having ACKed 2 segments instead of 1.
150 *
151 * Set the number of bytes that should be acked in each ACK packet with
152 * SetBytesToAck.
153 *
154 * \see TcpSlowStartAttackerTest
155 */
157{
158 public:
159 /**
160 * \brief Get the type ID.
161 * \return the object TypeId
162 */
163 static TypeId GetTypeId();
164
172
173 /**
174 * \brief Constructor.
175 * \param other The object to copy from.
176 */
184
185 /**
186 * \brief Set the bytes to be ACKed.
187 * \param bytes The number of bytes.
188 */
190 {
191 m_bytesToAck = bytes;
192 }
193
194 protected:
195 void SendEmptyPacket(uint8_t flags) override;
196 Ptr<TcpSocketBase> Fork() override;
197
198 uint32_t m_bytesToAck; //!< Number of bytes to be ACKed.
199 uint32_t m_bytesLeftToBeAcked; //!< Number of bytes to be ACKed left.
200 SequenceNumber32 m_lastAckedSeq; //!< Last sequence number ACKed.
201};
202
203/**
204 * \ingroup internet-test
205 *
206 * \brief General infrastructure for TCP testing
207 *
208 * The class provides a simple setup for a connection testing. Implement
209 * or modify the virtual methods in order to install a specified
210 * channel, a specified socket and a specified error model on this simulation.
211 * Default values are a null error model, and as a channel a SimpleChannel with
212 * the propagation delay set through the constructor.
213 *
214 * Check DoRun documentation for more information on the environment setup.
215 *
216 * Apart from setting up the environment for testing, subclassing permits also
217 * to track and check what is happening inside the two connected sockets. Thanks
218 * to TcpSocketMsgBase, there are many information provided to children:
219 *
220 * - Tracing of states inside the state machines (TCP and ACK ones, through
221 * functions CongStateTrace and TcpStateTrace)
222 * - cWnd tracing (through CWndTrace)
223 * - Socket closing: error state, or normal state (NormalClose and ErrorClose)
224 * - Packet drop, inside queue or over the link (QueueDrop, PhyDrop)
225 * - Ack received (RcvAck) and Ack processed (ProcessedAck). The first is used to
226 * signal that an ACK has been received; after the processing of it, the Second
227 * is called
228 * - A packet is transmitted to IP layer or received from IP layer (Tx and Rx)
229 * - The RTO expires (RTOExpired)
230 *
231 * The default version of such methods is empty; implement their behavior differently,
232 * based on what you want to test. Default is empty to avoid the need to implement
233 * useless pure virtual function.
234 *
235 * If you need values from TcpSocketBase, thanks to the friend relationship between
236 * this class and TcpSocketBase itself you can get it. Remember that friendship
237 * isn't passed by inheritance, so the way to go is to write a Getters (like
238 * GetSegSize) and call it in the subclass.
239 *
240 * \see DoRun
241 * \see TcpSocketMsgBase
242 */
244{
245 public:
246 /**
247 * \brief TcpGeneralTest constructor
248 *
249 * Please use the method ConfigureEnvironment () to configure other
250 * parameters than the test description.
251 *
252 * \param desc description of the test
253 */
254 TcpGeneralTest(const std::string& desc);
255 ~TcpGeneralTest() override;
256
257 /**
258 * \brief Used as parameter of methods, specifies on what node
259 * the caller is interested (e.g. GetSegSize).
260 */
262 {
263 SENDER, //!< Sender node
264 RECEIVER //!< Receiver node
265 };
266
267 protected:
268 /**
269 * \brief Create and return the channel installed between the two socket
270 *
271 * \return A SimpleChannel subclass
272 */
274
275 /**
276 * \brief Create and return the error model to install in the sender node
277 *
278 * \return sender error model
279 */
281
282 /**
283 * \brief Create and return the error model to install in the receiver node
284 *
285 * \return receiver error model
286 */
288
289 /**
290 * \brief Create and install the socket to install on the receiver
291 * \param node receiver node pointer
292 * \return the socket to be installed in the receiver
293 */
295
296 /**
297 * \brief Create and install the socket to install on the sender
298 * \param node sender node pointer
299 * \return the socket to be installed in the sender
300 */
302
303 /**
304 * \brief Create a socket
305 *
306 * \param node associated node
307 * \param socketType Type of the TCP socket
308 * \param congControl congestion control
309 * \return a pointer to the newer created socket
310 */
312 TypeId socketType,
313 TypeId congControl);
314
315 /**
316 * \brief Create a socket
317 *
318 * \param node associated node
319 * \param socketType Type of the TCP socket
320 * \param congControl congestion control
321 * \param recoveryAlgorithm recovery algorithm
322 * \return a pointer to the newer created socket
323 */
325 TypeId socketType,
326 TypeId congControl,
327 TypeId recoveryAlgorithm);
328
329 /**
330 * \brief Get the pointer to a previously created sender socket
331 * \return ptr to sender socket or 0
332 */
337
338 /**
339 * \brief Get the pointer to a previously created receiver socket
340 * \return ptr to receiver socket or 0
341 */
346
347 /**
348 * \brief Execute the tcp test
349 *
350 * As environment, two socket are connected through a SimpleChannel. Each device
351 * has an MTU of 1500 bytes, and the application starts to send packet at
352 * 10s of simulated time, through SendPacket.
353 *
354 * If you need to change parameters of the environment, please inherit an
355 * implement the method ConfigureEnvironment (); that will be called at the
356 * beginning of this method. To configure Socket parameters (i.e. parameters
357 * that should be applied after socket have been created) use ConfigureProperties.
358 *
359 * Please do not use any Config:: statements.
360 *
361 * \see ConfigureEnvironment
362 */
363 void DoRun() override;
364
365 /**
366 * \brief Change the configuration of the environment
367 */
368 virtual void ConfigureEnvironment();
369
370 /**
371 * \brief Change the configuration of the socket properties
372 */
373 virtual void ConfigureProperties();
374
375 /**
376 * \brief Teardown the TCP test
377 */
378 void DoTeardown() override;
379
380 /**
381 * \brief Scheduled at 0.0, SENDER starts the connection to RECEIVER
382 */
383 void DoConnect();
384
385 /**
386 * \brief Packet received
387 *
388 * The method processes the packet (application-layer)
389 * \param socket socket which has received the packet
390 */
391 virtual void ReceivePacket(Ptr<Socket> socket);
392
393 /**
394 * \brief Send packets to other endpoint
395 *
396 * \param socket Socket
397 * \param pktSize size of the packet
398 * \param pktCount number of packets to send
399 * \param pktInterval interval between packet (application-level)
400 */
401 void SendPacket(Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval);
402
403 /**
404 * \brief Get the segment size of the node specified
405 *
406 * \param who node to get the parameter from
407 *
408 * \return segment size of the specified node
409 */
411
412 /**
413 * \brief Get the highest tx mark of the node specified
414 *
415 * \param who node to get the parameter from
416 *
417 * \return mark of the specified node
418 */
420
421 /**
422 * \brief Get the retransmission threshold
423 * \param who node to get the parameter from
424 * \return retransmission threshold
425 */
427
428 /**
429 * \brief Get the initial slow start threshold
430 * \param who node to get the parameter from
431 * \return initial slow start threshold
432 */
434
435 /**
436 * \brief Get the initial congestion window
437 * \param who node to get the parameter from
438 * \return initial cwnd
439 */
441
442 /**
443 * \brief Get the number of dupack received
444 * \param who node to get the parameter from
445 * \return number of dupack
446 */
448
449 /**
450 * \brief Get the number of delayed ack (if present)
451 * \param who node to get the parameter from
452 * \return number of ack we will wait before sending an ACK
453 */
455
456 /**
457 * \brief Get the timeout of delayed ack (if present)
458 * \param who node to get the parameter from
459 * \return time we will wait before sending an ACK
460 */
462
463 /**
464 * \brief Get the retransmission time
465 *
466 * \param who node to get the parameter from
467 * \return calculated RTO time
468 */
469 Time GetRto(SocketWho who);
470
471 /**
472 * \brief Get the minimum RTO attribute
473 *
474 * \param who node to get the parameter from
475 * \return minimum RTO time
476 */
478
479 /**
480 * \brief Get the retransmission time for the SYN segments
481 *
482 * \param who node to get the parameter from
483 * \return SYN segments RTO time
484 */
486
487 /**
488 * \brief Get the Rtt estimator of the socket
489 *
490 * \param who node to get the parameter from
491 * \return Rtt estimator
492 */
494
495 /**
496 * \brief Get the clock granularity attribute
497 *
498 * \param who node to get the parameter from
499 * \return clock granularity
500 */
502
503 /**
504 * \brief Get the state of the TCP state machine
505 *
506 * \param who socket where check the parameter
507 * \return the state of the socket
508 */
510
511 /**
512 * \brief Get the TCB from selected socket
513 *
514 * \param who socket where get the TCB
515 * \return the transmission control block
516 */
518
519 /**
520 * \brief Get the Rx buffer from selected socket
521 *
522 * \param who socket where get the TCB
523 * \return the rx buffer
524 */
526
527 /**
528 * \brief Get the Tx buffer from selected socket
529 *
530 * \param who socket where get the TCB
531 * \return the tx buffer
532 */
534
535 /**
536 * \brief Get the rWnd of the selected socket
537 *
538 * \param who socket where check the parameter
539 * \return the received advertised window
540 */
542
543 /**
544 * \brief Get the persistent event of the selected socket
545 *
546 * \param who socket where check the parameter
547 * \return the persistent event in the selected socket
548 */
550
551 /**
552 * \brief Get the persistent timeout of the selected socket
553 *
554 * \param who socket where check the parameter
555 * \return the persistent timeout in the selected socket
556 */
558
559 /**
560 * \brief Forcefully set a defined size for rx buffer
561 *
562 * \param who socket to force
563 * \param size size of the rx buffer
564 */
565 void SetRcvBufSize(SocketWho who, uint32_t size);
566
567 /**
568 * \brief Forcefully set the segment size
569 *
570 * \param who socket to force
571 * \param segmentSize segmentSize
572 */
574
575 /**
576 * \brief Forcefully set the initial cwnd
577 *
578 * \param who socket to force
579 * \param initialCwnd size of the initial cwnd (segments)
580 */
581 void SetInitialCwnd(SocketWho who, uint32_t initialCwnd);
582
583 /**
584 * \brief Forcefully set the delayed acknowledgement count
585 *
586 * \param who socket to force
587 * \param count value of delayed ACKs
588 */
589 void SetDelAckMaxCount(SocketWho who, uint32_t count);
590
591 /**
592 * \brief Forcefully set the ECN mode of use
593 *
594 * \param who socket to force
595 * \param useEcn Value representing the mode of ECN usage requested
596 */
598
599 /**
600 * \brief Enable or disable pacing in the TCP socket
601 *
602 * \param who socket
603 * \param pacing Boolean to enable or disable pacing
604 */
605 void SetPacingStatus(SocketWho who, bool pacing);
606
607 /**
608 * \brief Enable or disable pacing of the initial window
609 *
610 * \param who socket
611 * \param paceWindow Boolean to enable or disable pacing of initial window
612 */
613 void SetPaceInitialWindow(SocketWho who, bool paceWindow);
614
615 /**
616 * \brief Forcefully set the initial ssthresh
617 *
618 * \param who socket to force
619 * \param initialSsThresh Initial slow start threshold (bytes)
620 */
621 void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh);
622
623 /**
624 * \brief Set app packet size
625 *
626 * The application will generate packet of this size.
627 *
628 * \param pktSize size of the packet
629 */
634
635 /**
636 * \brief Set app packet count
637 *
638 * The application will generate this count of packets.
639 *
640 * \param pktCount count of packets to generate
641 */
643 {
644 m_pktCount = pktCount;
645 }
646
647 /**
648 * \brief Interval between app-generated packet
649 *
650 * \param pktInterval interval
651 */
652 void SetAppPktInterval(Time pktInterval)
653 {
654 m_interPacketInterval = pktInterval;
655 }
656
657 /**
658 * \brief Propagation delay of the bottleneck link
659 *
660 * \param propDelay propagation delay
661 */
662 void SetPropagationDelay(Time propDelay)
663 {
664 m_propagationDelay = propDelay;
665 }
666
667 /**
668 * \brief Set the initial time at which the application sends the first data packet
669 *
670 * \param startTime start time
671 */
672 void SetTransmitStart(Time startTime)
673 {
674 m_startTime = startTime;
675 }
676
677 /**
678 * \brief Congestion control of the sender socket
679 *
680 * \param congControl typeid of the congestion control algorithm
681 */
682 void SetCongestionControl(TypeId congControl)
683 {
684 m_congControlTypeId = congControl;
685 }
686
687 /**
688 * \brief recovery algorithm of the sender socket
689 *
690 * \param recovery typeid of the recovery algorithm
691 */
693 {
694 m_recoveryTypeId = recovery;
695 }
696
697 /**
698 * \brief MTU of the bottleneck link
699 *
700 * \param mtu MTU
701 */
702 void SetMTU(uint32_t mtu)
703 {
704 m_mtu = mtu;
705 }
706
707 /**
708 * \brief State on Ack state machine changes
709 * \param oldValue old value
710 * \param newValue new value
711 */
712 virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue [[maybe_unused]],
713 const TcpSocketState::TcpCongState_t newValue [[maybe_unused]])
714 {
715 }
716
717 /**
718 * \brief Tracks the congestion window changes
719 *
720 * \param oldValue old value
721 * \param newValue new value
722 */
723 virtual void CWndTrace(uint32_t oldValue [[maybe_unused]], uint32_t newValue [[maybe_unused]])
724 {
725 }
726
727 /**
728 * \brief Tracks the inflated congestion window changes
729 *
730 * \param oldValue old value
731 * \param newValue new value
732 */
733 virtual void CWndInflTrace(uint32_t oldValue [[maybe_unused]],
734 uint32_t newValue [[maybe_unused]])
735 {
736 }
737
738 /**
739 * \brief Rtt changes
740 *
741 * This applies only for sender socket.
742 *
743 * \param oldTime old value
744 * \param newTime new value
745 */
746 virtual void RttTrace(Time oldTime [[maybe_unused]], Time newTime [[maybe_unused]])
747 {
748 }
749
750 /**
751 * \brief Slow start threshold changes
752 *
753 * This applies only for sender socket.
754 *
755 * \param oldValue old value
756 * \param newValue new value
757 */
758 virtual void SsThreshTrace(uint32_t oldValue [[maybe_unused]],
759 uint32_t newValue [[maybe_unused]])
760 {
761 }
762
763 /**
764 * \brief Bytes in flight changes
765 *
766 * This applies only for sender socket.
767 *
768 * \param oldValue old value
769 * \param newValue new value
770 */
771 virtual void BytesInFlightTrace(uint32_t oldValue [[maybe_unused]],
772 uint32_t newValue [[maybe_unused]])
773 {
774 }
775
776 /**
777 * \brief RTO changes
778 *
779 * This applies only for sender socket.
780 *
781 * \param oldValue old value
782 * \param newValue new value
783 */
784 virtual void RtoTrace(Time oldValue [[maybe_unused]], Time newValue [[maybe_unused]])
785 {
786 }
787
788 /**
789 * \brief Next tx seq changes
790 *
791 * This applies only for sender socket.
792 *
793 * \param oldValue old value
794 * \param newValue new value
795 */
796 virtual void NextTxSeqTrace(SequenceNumber32 oldValue [[maybe_unused]],
797 SequenceNumber32 newValue [[maybe_unused]])
798 {
799 }
800
801 /**
802 * \brief Highest tx seq changes
803 *
804 * This applies only for sender socket.
805 *
806 * \param oldValue old value
807 * \param newValue new value
808 */
809 virtual void HighestTxSeqTrace(SequenceNumber32 oldValue [[maybe_unused]],
810 SequenceNumber32 newValue [[maybe_unused]])
811 {
812 }
813
814 /**
815 * \brief Track the rate value of TcpRateLinux.
816 * \param rate updated value of TcpRate.
817 */
818 virtual void RateUpdatedTrace(const TcpRateLinux::TcpRateConnection& rate [[maybe_unused]])
819 {
820 }
821
822 /**
823 * \brief Track the rate sample value of TcpRateLinux.
824 * \param sample updated value of TcpRateSample.
825 */
826 virtual void RateSampleUpdatedTrace(const TcpRateLinux::TcpRateSample& sample [[maybe_unused]])
827 {
828 }
829
830 /**
831 * \brief Socket closed normally
832 * \param who the socket closed (SENDER or RECEIVER)
833 */
834 virtual void NormalClose(SocketWho who [[maybe_unused]])
835 {
836 }
837
838 /**
839 * \brief Socket closed with an error
840 *
841 * \param who the socket closed (SENDER or RECEIVER)
842 */
843 virtual void ErrorClose(SocketWho who [[maybe_unused]])
844 {
845 /** \todo indicate the error */
846 }
847
848 /**
849 * \brief Drop on the queue
850 * \param who where the drop occurred (SENDER or RECEIVER)
851 */
852 virtual void QueueDrop(SocketWho who [[maybe_unused]])
853 {
854 }
855
856 /**
857 * \brief Link drop
858 * \param who where the drop occurred (SENDER or RECEIVER)
859 */
860 virtual void PhyDrop(SocketWho who [[maybe_unused]])
861 {
862 }
863
864 /**
865 * \brief Received ack
866 *
867 * Invoked when an ACK is received (no processing is done yet)
868 *
869 * \param tcb Transmission Control Block
870 * \param h the header of segment
871 * \param who the socket which has received the ACK (SENDER or RECEIVER)
872 */
873 virtual void RcvAck(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
874 const TcpHeader& h [[maybe_unused]],
875 SocketWho who [[maybe_unused]])
876 {
877 }
878
879 /**
880 * \brief Processed ack
881 *
882 * Invoked after the processing of the ACK
883 *
884 * \param tcb Transmission Control Block
885 * \param h the header of segment
886 * \param who the socket which has processed the ACK (SENDER or RECEIVER)
887 */
888 virtual void ProcessedAck(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
889 const TcpHeader& h [[maybe_unused]],
890 SocketWho who [[maybe_unused]])
891 {
892 }
893
894 /**
895 * \brief Packet transmitted down to IP layer
896 *
897 * \param p packet
898 * \param h header
899 * \param who the socket which has received the packet (SENDER or RECEIVER)
900 */
901 virtual void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who);
902
903 /**
904 * \brief Packet received from IP layer
905 *
906 * \param p packet
907 * \param h header
908 * \param who the socket which has received the packet (SENDER or RECEIVER)
909 */
910 virtual void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who);
911
912 /**
913 * \brief Rto has expired
914 *
915 * \param tcb Transmission control block
916 * \param who where the RTO has expired (SENDER or RECEIVER)
917 */
918 virtual void AfterRTOExpired(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
919 SocketWho who [[maybe_unused]])
920 {
921 }
922
923 /**
924 * \brief Rto has expired
925 *
926 * \param tcb Transmission control block
927 * \param who where the RTO has expired (SENDER or RECEIVER)
928 */
929 virtual void BeforeRTOExpired(const Ptr<const TcpSocketState> tcb [[maybe_unused]],
930 SocketWho who [[maybe_unused]])
931 {
932 }
933
934 /**
935 * \brief Updated the Rtt history
936 * \param seq Sequence inserted
937 * \param sz size
938 * \param isRetransmission self-explanatory
939 * \param who where the rtt history was updated
940 */
941 virtual void UpdatedRttHistory(const SequenceNumber32& seq [[maybe_unused]],
942 uint32_t sz [[maybe_unused]],
943 bool isRetransmission [[maybe_unused]],
944 SocketWho who [[maybe_unused]])
945 {
946 }
947
948 /**
949 * \brief Notifying application for sent data
950 *
951 * \param size the amount of bytes transmitted
952 * \param who where the RTO has expired (SENDER or RECEIVER)
953 */
954 virtual void DataSent(uint32_t size [[maybe_unused]], SocketWho who [[maybe_unused]])
955 {
956 }
957
958 /**
959 * \brief Performs the (eventual) final checks through test asserts
960 */
961 virtual void FinalChecks()
962 {
963 }
964
965 /**
966 * \brief Get the channel Propagation Delay
967 * \return propagation delay of the channel
968 */
970 {
971 return m_propagationDelay;
972 }
973
974 /**
975 * \brief Get the data start time
976 * \return start time of data packets
977 */
979 {
980 return m_startTime;
981 }
982
983 /**
984 * \brief Get the MTU of the environment
985 * \return MTU of the environment
986 */
988 {
989 return m_mtu;
990 }
991
992 /**
993 * \brief Get the application packet size
994 * \return application packet size
995 */
997 {
998 return m_pktSize;
999 }
1000
1001 /**
1002 * \brief Get the number of application packets
1003 * \return count of application packets to be generated
1004 */
1006 {
1007 return m_pktCount;
1008 }
1009
1010 /**
1011 * \brief Get the interval to wait for each packet sent down from application
1012 * to TCP
1013 * \return interval between packet
1014 */
1016 {
1017 return m_interPacketInterval;
1018 }
1019
1020 TypeId m_congControlTypeId; //!< Congestion control
1022
1023 private:
1024 // Member variables, accessible through getters
1025 // giving write access to subclass can be dangerous
1026 Time m_propagationDelay; //!< Propagation delay of the channel
1027
1028 Time m_startTime; //!< Data transmission time
1029 uint32_t m_mtu; //!< MTU of the environment
1030
1031 uint32_t m_pktSize; //!< Size of the application packet
1032 uint32_t m_pktCount; //!< Count of the application packet
1033 Time m_interPacketInterval; //!< Time between sending application packet down to tcp socket
1034
1035 Ptr<TcpSocketMsgBase> m_senderSocket; //!< Pointer to sender socket
1036 Ptr<TcpSocketMsgBase> m_receiverSocket; //!< Pointer to receiver socket
1037
1038 private:
1039 // De-multiplexing callbacks.
1040
1041 /**
1042 * \brief Normal Close Callback.
1043 * \param socket The socket.
1044 */
1045 void NormalCloseCb(Ptr<Socket> socket);
1046 /**
1047 * \brief Error Close Callback.
1048 * \param socket The socket.
1049 */
1050 void ErrorCloseCb(Ptr<Socket> socket);
1051 /**
1052 * \brief Queue Drop Callback.
1053 * \param context The context.
1054 * \param p The packet.
1055 */
1056 void QueueDropCb(std::string context, Ptr<const Packet> p);
1057 /**
1058 * \brief Drop at Phy layer Callback.
1059 * \param context The context.
1060 * \param p The packet.
1061 */
1062 void PhyDropCb(std::string context, Ptr<const Packet> p);
1063 /**
1064 * \brief Receive ACK Callback.
1065 * \param p The packet.
1066 * \param h TCP header.
1067 * \param tcp The TCP socket.
1068 */
1070 /**
1071 * \brief ACK processed Callback.
1072 * \param p The packet.
1073 * \param h TCP header.
1074 * \param tcp The TCP socket.
1075 */
1077 /**
1078 * \brief Tx packet Callback.
1079 * \param p The packet.
1080 * \param h TCP header.
1081 * \param tcp The TCP socket.
1082 */
1083 void TxPacketCb(const Ptr<const Packet> p,
1084 const TcpHeader& h,
1085 const Ptr<const TcpSocketBase> tcp);
1086 /**
1087 * \brief Rx packet Callback.
1088 * \param p The packet.
1089 * \param h TCP header.
1090 * \param tcp The TCP socket.
1091 */
1092 void RxPacketCb(const Ptr<const Packet> p,
1093 const TcpHeader& h,
1094 const Ptr<const TcpSocketBase> tcp);
1095 /**
1096 * \brief RTO expired Callback.
1097 * \param tcb Transmission control block.
1098 * \param tcp The TCP socket.
1099 */
1101 /**
1102 * \brief Update RTT with new data.
1103 * \param tcp The TCP socket.
1104 * \param seq The sequence number.
1105 * \param sz The segment size.
1106 * \param isRetransmission True if packet is a retransmission.
1107 */
1109 const SequenceNumber32& seq,
1110 uint32_t sz,
1111 bool isRetransmission);
1112
1113 /**
1114 * \brief Invoked after a retransmit event.
1115 * \param tcb Transmission control block.
1116 * \param tcp The TCP socket.
1117 */
1119
1120 /**
1121 * \brief Invoked before a retransmit event.
1122 * \param tcb Transmission control block.
1123 * \param tcp The TCP socket.
1124 */
1126 const Ptr<const TcpSocketBase> tcp);
1127
1128 /**
1129 * \brief Data sent Callback.
1130 * \param socket The socket.
1131 * \param size The data size.
1132 */
1133 void DataSentCb(Ptr<Socket> socket, uint32_t size);
1134 /**
1135 * \brief Fork Callback.
1136 * \param tcp The TCP socket.
1137 */
1138 void ForkCb(Ptr<TcpSocketMsgBase> tcp);
1139 /**
1140 * \brief Handle an accept connection.
1141 * \param socket The socket.
1142 * \param from The sender.
1143 */
1144 void HandleAccept(Ptr<Socket> socket, const Address& from);
1145
1146 InetSocketAddress m_remoteAddr; //!< Remote peer address.
1147};
1148
1149} // namespace ns3
1150
1151#endif // TCPGENERALTEST_H
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
An identifier for simulation events.
Definition event-id.h:45
an Inet address class
Smart pointer class similar to boost::intrusive_ptr.
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.
TcpGeneralTest(const std::string &desc)
TcpGeneralTest constructor.
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:36
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:1050
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
uint32_t segmentSize
TcpStates_t
Names of the 11 TCP states.
Definition tcp-socket.h:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Information about the connection rate.
Rate Sample structure.
uint32_t pktSize
packet size used for the simulation (in bytes)