TCP and IP Fundamentals – Part 2 (New)
TCP and IP Fundamentals – Part 2 (New)
1
TCP Header
2
Window Size
Definition:
• The Window Size is a 16-bit field in the TCP header.
• It is a crucial part of TCP's flow control mechanism.
Purpose:
• Indicates the amount of data (in bytes) that the receiver is
willing to accept at a given time.
• Prevents the sender from overwhelming the receiver by
controlling the data flow.
3
Window Size
Buffer Management:
• The receiver allocates a buffer to store incoming data.
• The size of this buffer determines the "Window Size."
• The receiver updates the sender about the available space using this field.
Dynamic Adjustments:
• As the receiver processes data, it adjusts the Window Size to reflect new
buffer availability.
• This dynamic adjustment ensures efficient data flow without data loss.
Scaling:
• For high-speed networks, the Window Scale Option is used to increase the
effective window size beyond 65,535 bytes.
4
Window Size
Example:
Initial Buffer Setup:
• Receiver’s buffer size: 2000 bytes.
• Initially, all 2000 bytes are available => Window Size = 2000.
Data Received:
• 1500 bytes are received by the buffer.
• Remaining space = 2000 - 1500 = 500 bytes => Window Size = 500.
Buffer Consumption:
• The receiver processes 800 bytes.
• New buffer availability = 500 + 800 = 1300 bytes => Window Size = 1300.
5
Checksum
Definition:
• The Checksum is a 16-bit field in the TCP header.
• It is used to ensure data integrity by detecting errors in
transmitted segments.
Purpose:
• Ensures that the transmitted data has not been altered during
transit.
• Helps the receiver verify that the received segment matches the
original.
6
Checksum
How it Works:
Checksum Calculation:
• The sender calculates the checksum value based on the segment's
content.
• The checksum is included in the TCP header before transmission.
Verification:
• The receiver recalculates the checksum for the received data.
• If the calculated checksum matches the transmitted checksum, the data is
considered error-free.
Error Handling:
• If a mismatch occurs, the segment is discarded, and the sender may
retransmit the data.
7
Noise, Interference or Transmission Issues
Detects corruption caused by noise, interference, or
transmission issues.
Noise: Unwanted electrical or electromagnetic energy that
disrupts the transmitted signal.
Types
• Thermal Noise: Caused by random motion of electrons in conductors,
Present in all communication channels.
• Impulse Noise: Sudden, high-energy bursts, Often caused by lightning,
power lines, or switching equipment.
• Crosstalk: Leakage of signals between adjacent communication
channels.
8
Interference
Interference: Occurs when external signals disrupt the
communication between sender and receiver.
Types:
• Electromagnetic Interference (EMI): From nearby electronic
devices (e.g., motors, fluorescent lights, or wireless devices).
• Radio Frequency Interference (RFI): Caused by overlapping
radio frequencies in wireless communication.
9
Transmission Issues
Transmission Issues: Problems that occur during the physical
transmission of data.
Common Issues:
• Signal Attenuation:
• Loss of signal strength over distance.
• Common in copper wires and fiber optics.
• Latency:
• Delays in data transmission due to network congestion or long distances.
• Packet Loss:
• Data packets fail to reach the receiver due to errors or congestion
10
Transmission Issues
Impact
• Reduced network efficiency and reliability.
• Requires error control mechanisms like retransmissions.
Example:
• Video buffering caused by high latency or dropped packets
11
Mitigation Techniques
Error Detection and Correction: Use checksums, cyclic redundancy
checks (CRC), or forward error correction (FEC) to identify and fix errors.
Shielding and Grounding: Protect cables from electromagnetic
interference.
Signal Amplification: Boost weak signals using repeaters or amplifiers.
Frequency Management: Avoid overlapping frequencies in wireless
communication.
12
Calculate a TCP checksum
Scenario:
We are given a segment of data: 11110000 10101010 00001111 01010101
This data consists of 4 bytes (32 bits) and will be divided into two 16-bit words.
Step 1: Divide the Data into 16-bit Words
• Split the 32-bit data into two 16-bit words:
• Word 1: 11110000 10101010
• Word 2: 00001111 01010101
Step 2: Add the Two 16-Bit Words
13
Calculate a TCP checksum
Step 3: Take the 1's Complement
• Invert all bits (flip 0s to 1s and 1s to 0s):
• 11111111 11111111 => 00000000 00000000
• Checksum = 00000000 00000000
Final Checksum:
The checksum for the given data is 00000000 00000000
14
Checksum, CRC, and FEC
15
Urgent Pointer
• The Urgent Pointer is a 16-bit field in the TCP header.
• It is used to mark urgent data that needs immediate attention by
the receiving application.
• This field is valid only if the URG (Urgent) flag in the TCP
header is set.
Purpose:
• Indicates the end of urgent data in the segment.
• Helps prioritize certain data over the rest of the transmission.
16
Urgent Pointer
Example:
• Sequence Number: 2000
• Urgent Pointer: 258
• Bytes 2000 to 2258 are urgent data:
• The urgent data spans 258 bytes, starting at byte 2000 and ending
at byte 2258.
Applications: URG Flag and Urgent Pointer are used in scenarios
requiring immediate attention, such as:
• Breaking a connection (e.g., CTRL+C in telnet or SSH).
• Sending interrupt signals in interactive sessions.
17
TCP Timers
TCP uses several timers to handle various aspects of communication,
ensuring reliability and proper connection management.
As timers rely on certain fields in the TCP header to manage the flow,
reliability, and termination of data transmission.
18
Retransmission Timer
Handles retransmission of segments if acknowledgments (ACKs) are not
received in time.
How It Works:
• Starts when a segment is sent.
• If the ACK is not received before the timer expires, the segment is
retransmitted.
• The retransmission time is typically twice the Round Trip Time (RTT).
Example:
If RTT = 200ms,
Retransmission Timeout (RTO) is set to 2×200=400ms
19
Retransmission Timer
20
Round Trip Time (RTT)
RTT is the time it takes for a data packet to travel from a sender to a
receiver and back to the sender as an acknowledgment.
21
Round Trip Time (RTT)
Components of RTT
RTT consists of the following components:
• Propagation Delay:
• Time for the signal to travel over the physical medium from sender to
receiver.
• Processing Delay:
• Time taken by the receiver to process the packet and generate an
acknowledgment.
• Return Path Delay:
• Time for the acknowledgment to travel back to the sender.
22
Formula for RTT Estimation
Where:
• α: Weighting factor
• EstimatedRTT: The smoothed (averaged) estimate of the round-trip
time.
• SampleRTT: The measured round-trip time for a segment
23
Formula for RTT Estimation
Example:
Initial EstimatedRTT = 0.028624 sec
SampleRTT for the new segment = 0.028628 sec
𝛼=0.125
24
RTT Calculation Table
𝛼=0.125
25
Estimated RTT Calculation
26
Applications of RTT
27
Factors Influencing Round Trip Time (RTT)
Network Congestion
When the network is overloaded with traffic, packets are
delayed in queues at routers or switches.
Impact:
• Queuing delays add to the total RTT.
• Congestion can also lead to packet loss, causing
retransmissions, further increasing RTT.
Example:
• A video call experiencing lag due to too many
simultaneous users on the network.
28
Factors Influencing Round Trip Time (RTT)
Physical Distance
The time taken by a signal to travel between the sender and
receiver, proportional to their geographical separation.
Impact:
• Longer distances mean higher propagation delays.
• The speed of signals is limited to the speed of light in fiber
or copper cables.
29
Factors Influencing Round Trip Time (RTT)
Bandwidth
The maximum rate at which data can be transmitted over a
network link.
Impact:
• Low bandwidth increases RTT because packets take longer to be
transmitted and processed.
• Bandwidth bottlenecks (e.g., at a slow link) can delay packets,
increasing RTT.
Example:
• A 1 Mbps connection will have higher RTT compared to a 100 Mbps
connection during heavy data transfers.
30
Factors Influencing Round Trip Time (RTT)
Routing
The path taken by packets through the network to reach the
destination.
• Impact:
• Suboptimal routing increases RTT as packets may travel through
unnecessary intermediate nodes.
• Dynamic routing changes due to link failures or congestion can
temporarily increase RTT.
• Example:
• A packet traveling through an inefficient route because of a
misconfigured router.
31
Factors Influencing Round Trip Time (RTT)
32
Persistence Timer
Prevents a deadlock situation when the receiver advertises a
zero window size.
How It Works:
• When the sender receives a "zero window size" from the receiver, it
pauses data transmission.
34
Keepalive Timer
Ensures that idle connections are still active.
How It Works:
• After a connection remains idle for a long period, the sender
sends keepalive probes to check if the receiver is still
connected.
• If no response is received after multiple probes, the
connection is terminated.
36
TIME-WAIT Timer
Ensures proper closure of a TCP connection by preventing
interference from delayed packets.
How It Works:
• After a connection is closed (via the FIN-ACK handshake), TCP waits
for 2 × Maximum Segment Lifetime (MSL) before fully closing the
connection.
• This ensures that all duplicate packets are discarded.
38
Comparison
39
Options and Padding in TCP
Options in TCP
The Options field in the TCP header is used for additional
features or extensions beyond the standard header fields.
This field is optional and its length can vary.
Purpose of TCP Options:
• Extend the functionality of the TCP protocol.
• Enable advanced features like timestamps, scaling, and
selective acknowledgments.
40
Options in TCP
Maximum Segment Size (MSS):
• Specifies the maximum amount of data (in bytes) that can be
sent in a single segment.
• Advertised during connection setup (SYN packets).
Purpose of MSS
• To prevent fragmentation at the IP layer by ensuring that TCP
segments fit within the Maximum Transmission Unit (MTU)
of the network path.
• Ensures efficient transmission by reducing overhead and
avoiding unnecessary fragmentation and retransmissions.
41
Options in TCP
Maximum Transmission Unit (MTU)
• MTU (Maximum Transmission Unit) is the largest size (in
bytes) of a packet that can be sent over a network link
without being fragmented.
• MTU includes both the header and payload of the packet.
42
Options in TCP
Example
MTU Calculation:
• Suppose the network MTU is 1500 bytes
• The TCP and IP headers are each 20 bytes
• MSS = 1500−20−20=1460 bytes
Handshake:
• Sender advertises MSS = 1460 bytes
• Receiver advertises MSS = 1400 bytes
• Effective MSS = 1400 bytes (smaller value).
Data Transmission:
• The sender will not send segments larger than 1400 bytes of data to avoid
fragmentation.
43
Options in TCP
Timestamps
• Used to measure Round Trip Time (RTT) accurately.
• Helps in PAWS (Protection Against Wrapped Sequence
numbers) to handle high-speed data transfers.
• PAWS - It is a mechanism in TCP to prevent sequence number reuse in
high-speed networks where sequence numbers might "wrap around" due
to the rapid transmission of data.
Use Cases:
• Improves RTT estimation for better retransmission timeout (RTO)
calculation.
• Enables efficient high-speed network operations.
44
Options in TCP
Window Scaling
Extends the Window Size field from 16 bits to 32 bits to handle large
amounts of data in high-speed, high-latency networks.
The effective window size is calculated as:
Use Cases:
• Essential for networks with high bandwidth-delay products (e.g., satellite
links).
• Prevents TCP from underutilizing the available bandwidth
45
Options in TCP
Selective Acknowledgments (SACK)
Allows the receiver to inform the sender about specific missing
segments, improving retransmission efficiency.
Use Cases:
• Improves performance in lossy networks (e.g., wireless or long-
distance connections).
• Reduces retransmission overhead.
46
Padding in TCP
The Padding field is used to ensure that the total length of the
TCP header (including options) is a multiple of 32 bits (4
bytes).
Why It’s Needed
• The TCP header length is expressed in 4-byte words
(HLEN).
• To align the header properly, padding bytes (all set to
zero) are added if necessary.
47
Propagation Delays
Propagation delay is the time it takes for a signal (data
packet) to travel from the sender to the receiver over a
transmission medium.
48
Propagation Delays
Key Factors Influencing Propagation Delay
Transmission Medium:
Different mediums have different signal speeds:
• Fiber Optics: Speed is approximately 200,000 km/s (about 2/3 the
speed of light in a vacuum).
• Copper Cables: Speed is slower, depending on the cable quality and
technology.
• Wireless: Speeds approach that of light in air, but obstacles can
affect delay. (approximately 300,000 kilometres per second)
Signal Speed:
Depends on the refractive index of the medium, which
determines how fast the signal propagates compared to the
speed of light.
49
Propagation Delays
50