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