Presentation 6: Workflow of TCP in NS3 Presented By : 1705033 1705034 1705037 1705048 TcpSocketBase TcpSocketBase ● ● ● A base class for implementation of a stream socket using TCP. This class contains the essential components of TCP. Does Congestion Control together with TcpSocketState Class. TcpSocketBase Member Functions Related to Congestion Control SetCongestionControlAlgorithm() ● Install a congestion control algorithm on this socket. TcpL4Protocol::CreateSocket() SetInitialCwnd() ● Set the initial Congestion Window. SetInitialSSThresh() ● Set the initial Slow Start Threshold. Other Setter Functions ● ● ● ● ● SetMinRTO() SetRtt() SetRcvBufSize() SetSegSize() SetConnTimeout() etc etc Most of the Setter functions have getter and update functions too!! TcpSocketState TcpSocketState ● ● Data Structure that records Congestion State of a connection. Has lots of public attributes that keeps the information of a congestion state. TcpSocketState Public Attributes Public Attributes ● ● ● ● ● ● ● ● m_cWnd: Congestion Window Size m_initialCWnd: Initial Congestion Window size m_initialSSThresh : Initial Slow Start Threshold Value m_lastRtt : Last Rtt Sample Collected m_minRtt: Minimum Rtt Observed Throughout the Connection m_segmentSize: Segment Size m_ssThresh: Slow Start Threshold etc etc…. If we want to get any value of a congestion control related parameter, most of the time we will get them through these attributes of an object of TcpSocketState Class Code Examples Set value to the attributes: Constructor of tcpSocketBase() Keep these values up-to-date: Constructor of tcpSocketBase() TcpSocketState Member Functions GetCwndInSegments() ● Get Congestion Window in Segments rather than bytes. TcpCubic: GetSsThresh() GetSsThreshInSegments() ● ● Get Slow Start Threshold in Segments rather than bytes. Similiar to GetCwndInSegments() TcpCongestionOps TcpCongestionOps ● ● ● ● The congestion control is split from the main socket code, and it is a pluggable component. It is an abstract class Variables are maintained in the TcpSocketState class Subclasses of TcpCongestionOps operate over an instance of that class. TcpCongestionOps Member Functions IncreaseWindow() ● ● ● Congestion avoidance algorithm implementation. New segments have been ACKed, and the congestion control duty is to update the window. This function is allowed to change directly cWnd and/or ssThresh. IncreaseWindow() ● Reimplemented in TcpNewReno : ns-3.35/src/internet/model/tcp-congestion-ops.cc : line 214 IncreaseWindow() ● Reimplemented in TcpVegas : ./ns-3.35/src/internet/model/tcp-vegas.cc:156: PktsAcked() ● ● ● The function is called every time an ACK is received and contains timing information. It is optional (congestion controls need not implement it) The default implementation does nothing. PktsAcked() ● Reimplemented in TcpVegas : ns-3.35/src/internet/model/tcp-vegas.cc :100 Usage of IncreaseWindow and PktsAcked ns-3.35/src/internet/test/tcp-vegas-test.cc : 118 CongControl() ● Called when packets are delivered to update cwnd and pacing rate. Reimplemented in TcpBbr : ./ns-3.35/src/internet/model/tcp-bbr.cc:689: CongestionStateSet() ● Trigger events/calculations specific to a congestion state. CongestionStateSet() Reimplemented in TcpVegas : ./ns-3.35/src/internet/model/tcp-vegas.cc:141: CongestionStateSet() Reimplemented in TcpBbr : …} ./ns-3.35/src/internet/model/tcp-bbr.cc:701: CongestionStateSet() Usage : ./ns-3.35/src/internet/test/tcp-bbr-test.cc:77: CwndEvent() ● Trigger events/calculations on occurrence of congestion window event. CwndEvent() Reimplemented in TcpBbr : … … ./ns-3.35/src/internet/model/tcp-bbr.cc:744: TcpRecoveryOps TcpRecoveryOps ● ● ● Inspired by the TcpCongestionOps class The fast recovery is split from the main socket code, and it is a pluggable component. Subclasses of TcpRecoveryOps modifies TcpSocketState variables TcpRecoveryOps Member Functions EnterRecovery() ● ● ● Called when the first loss is guessed Performs variable initialization at the start of recovery. The function is called when the TcpSocketState is changed to CA_RECOVERY. DoRecovery() ● ● ● ● Called each time a duplicate ACK is received Performs recovery based on the recovery algorithm. The function is called on arrival of every ack when TcpSocketState is set to CA_RECOVERY. It performs the necessary cwnd changes as per the recovery algorithm. ExitRecovery() ● ● ● Called when the sequence transmitted when the socket entered the Recovery phase is ACKed, therefore ending phase Performs cwnd adjustments at the end of recovery. The function is called when the TcpSocketState is changed from CA_RECOVERY. Declaration ./ns-3.35/build/ns3/tcp-recovery-ops.h:115: Implementation ./ns-3.35/src/internet/model/tcp-recovery-ops.cc:108: Usage ./ns-3.35/src/internet/test/tcp-classic-recovery-test.cc:80: Using CongestionOps and RecoveryOps in Socket ./ns-3.35/src/internet/model/tcp-socket-base.h:1327: Using CongestionOps and RecoveryOps in Socket ● The fork method from both CongestionOps and RecoveryOps class is used to copy the congestion control algorithm and recovery algorithm across socket. … } ./ns-3.35/src/internet/model/tcp-socket-base.cc:386: Tcp Vegas TCP VEGAS ● ● TCP Vegas is a TCP congestion avoidance algorithm that emphasizes packet delay, rather than packet loss, as a signal to help determine the rate at which to send packets. TCP Vegas is a pure delay-based congestion control algorithm TCP Vegas Inheritance Diagram Tcp Vegas Set Attributes for Major Phases AddAttribute ● AddAttribute() method associates a given string with a strongly typed value in the class ./ns-3.35/src/internet/model/tcp-vegas.cc:37 AddAttribute ● The key point is that now the value of the variables like m_alpha and its default value are accessible in the attribute namespace, which is based on string such as "Alpha" ./ns-3.35/src/internet/test/tcp-vegas-test.cc:158 Constructor ● Attribute initialization in the constructor of tcp-vegas.cc ./ns-3.35/src/internet/model/tcp-vegas.cc:60 Diff Calculation ● Vegas continuously samples the RTT and computes the actual throughput a connection achieves and compares it with the expected throughput. ./ns-3.35/src/internet/test/tcp-vegas-test.cc:146 Diff Calculation ● The difference between these two sending rates reflects the amount of extra packets being queued at the bottleneck. ./ns-3.35/src/internet/test/tcp-vegas-test.cc:154 Alpha ● Alpha is the lower bound of packets in the network ./ns-3.35/src/internet/model/tcp-vegas.cc:44 Beta ● Beta is the upper bound of packets in the network ./ns-3.35/src/internet/model/tcp-vegas.cc:48 Gamma ● Gamma is the limit on increase ./ns-3.35/src/internet/model/tcp-vegas.cc:52 Tcp Vegas Slow Start Phase Slow Start Phase ● Vegas calls TcpNewReno::SlowStart when congestion window is less than slow start threshold and diff is less than gamma. ./ns-3.35/src/internet/model/tcp-vegas.cc:233 TCP NewReno Slow Start Phase ./ns-3.35/src/internet/model/tcp-congestion-ops.cc:165 Tcp Vegas Congestion Avoidance Phase Congestion Avoidance Phase ● Vegas starts congestion avoidance phase when congestion window is less than slow start threshold but diff is greater than gamma. ./ns-3.35/src/internet/model/tcp-vegas.cc:163 Congestion Avoidance Phase ● Vegas linearly decreases congestion window if diff is greater than beta. ./ns-3.35/src/internet/test/tcp-vegas-test.cc:179 Congestion Avoidance Phase ● Vegas linearly increases congestion window if diff is greater than beta. ./ns-3.35/src/internet/test/tcp-vegas-test.cc:184 Congestion Avoidance Phase ● Vegas does nothing if diff is in between the predefined threshold value ./ns-3.35/src/internet/test/tcp-vegas-test.cc:184 Implementation ./ns-3.35/src/internet/test/tcp-vegas.cc:155 Fast Retransmission and Recovery Fast Retransmission And Recovery (FRR) ● Without FRR, the TCP uses a timer that requires a retransmission timeout if a packet is lost. ● No new or duplicate packets can be sent during the timeout period. ● With FRR, if a receiver receives a data segment that is out of order, it immediately sends a duplicate acknowledgement to the sender. ● If the sender receives three duplicate acknowledgements, it assumes that the data segment is lost and immediately retransmits the lost segment. Fast Retransmission and Recovery In NS3 ● Implemented inside tcp-socket-base.cc in processAck() function. ● It first checks if : ○ The incoming ACK is a duplicate acknowledgment ○ And the TCP is not currently in loss recovery ./ns-3.35/src/internet/model/tcp-socket-base.cc:1922: Then it calls DupAck() functidfdsf Inside DupAck() ● Here it checks if ‘DupAcks >= DupThresh’ ● DupThresh is set to 3 by default ● If true, then it calls ‘EnterRecovery()’ ./ns-3.35/src/internet/model/tcp-socket-base.cc:1721: Inside EnterRecovery() ● Recovery point is set to the highest seq number. ● Recovery state is activated. ./ns-3.35/src/internet/model/tcp-socket-base.cc:1626: Inside EnterRecovery() ● ssThresh is reduced. ● DoRetransmit() is called. ./ns-3.35/src/internet/model/tcp-socket-base.cc:1635: Inside DoRetransmit() ● Finds the first lost segment ● Updates the trace ● Retransmit the segment by calling SendDataPacket() ./ns-3.35/src/internet/model/tcp-socket-base.cc:3859: ./ns-3.35/src/internet/model/tcp-socket-base.cc:3873: Thank You