MODULE-4
Transport Layer
Lochan Gowda M
Asst. Professor
Dept. of Cse
SJBIT
Dept. of CSE 1
Dept. of CSE 2
Introduction and Transport-
Layer Services
• logical communication
• segments
• datagram
• Internet has two protocols—TCP and UDP
3
Dept. of CSE
Overview of the Transport
Layer in the Internet
• IP service model is a best-effort delivery service
• IP is said to be an unreliable service
• Extending host-to-host delivery to process-to-process delivery is called transport-layer
multiplexing and demultiplexing.
• two minimal transport-layer services
• A. process-to-process data delivery and
• B. error checking
• several additional services :
• reliable data transfer - Using flow control, sequence numbers, acknowledgments, and timers
• congestion control
4
Dept. of CSE
Multiplexing and
Demultiplexing
• service is needed for all computer networks
• host-to-host delivery service provided by the network layer to a process-
to-process delivery service for applications running on the hosts
• job of delivering the data in a transport-layer segment to the correct
socket is called demultiplexing
• multiplexing-encapsulating each data chunk.
• transport-layer multiplexing requires : 1) sockets have unique identifiers
2) segment have special fields
• Figure 3.3
A socket is a communication endpoint in a network, functioning as SOCKET an address for
two-way data transmission between two pro-grams, often on different machines.
5
Dept. of CSE
6
Dept. of CSE
Connectionless Multiplexing
and Demultiplexing
• clientSocket = socket(socket.AF_INET,
socket.SOCK_DGRAM)
• [Link]((‘’, 19157))
7
Dept. of CSE
Connection-Oriented Multiplexing
and Demultiplexing
• TCP socket is identified by a four-tuple: (source IP
address, source port number, destination IP address,
destination port number)
• Connection establishment
• clientSocket = socket(AF_INET, SOCK_STREAM)
[Link]((serverName,12000))
• Server :connectionSocket, addr = [Link]()
• Figure 3.5
8
Dept. of CSE
9
Dept. of CSE
Connectionless Transport:
UDP
• DNS is an example of an application-layer protocol
• Uses UDP
• application process, attaches source and destination port
number fields for the multiplexing/demultiplexing service
10
Dept. of CSE
many applications are better suited
for UDP for the following reasons:
• Finer application-level control over what data is sent, and
when
• No connection establishment
• No connection state
• Small packet header overhead- tcp 20bytes header
overhead , UDP - 8bytes.
• Figure 3.6
11
Dept. of CSE
12
Dept. of CSE
UDP Segment Structure
• defined in RFC 768
• Figure 3.7
13
Dept. of CSE
UDP Checksum
• Calculation of checksum
14
Dept. of CSE
Note that this last addition had overflow, which was wrapped
around.
The 1s complement is obtained by converting all the Os to
1s and converting all the 1s to Os.
Thus the 1s complement of the sum 0100101011000010 is
1011010100111101, which becomes the checksum.
At the receiver, all four 16-bit words are added, including
the checksum.
If no errors are introduced into the packet, then clearly
the sum at the receiver will be 1111111111111111.
If one of the bits is a 0, then we know that errors have
been introduced into the packet.
15
Dept. of CSE
Principles of Reliable Data
Transfer
• Figure 3.8 illustrates the framework for our study of
reliable data transfer.
• no transferred data bits are corrupted or lost.
• all packets are delivered in the order in which they were
sent.
• TCP is a reliable data transfer protocol that is implemented
on top of an unreliable (IP).
16
Dept. of CSE
17
Dept. of CSE
Cont....
• unidirectional data transfer
• The case of reliable bidirectional (that is, full-duplex) data
transfer.
• rdt_rcv()
• deliver_data()
• udt_send()
18
Dept. of CSE
Building a Reliable Data
Transfer Protocol
• through a series of protocols
19
Dept. of CSE
Reliable Data Transfer over a
Perfectly Reliable Channel: rdt1.0
• simplest case
• finite-state machine (FSM) definitions for the rdt1.0 sender
and receiver
• no difference between a unit of data and a packet
• receiver is able to receive data as fast as the sender
happens to send data.
• no need for the receiver side to provide any feedback.
20
Dept. of CSE
21
Dept. of CSE
Reliable Data Transfer over a
Channel with Bit Errors: rdt2.0
• bits in a packet may be corrupted
• Such bit errors typically occur in the physical components.
• scenario : positive acknowledgments (“OK”) and negative
acknowledgments (“Please repeat that.”)
• reliable data transfer protocols based on such
retransmission are known as ARQ (Automatic Repeat
reQuest) protocols.
22
Dept. of CSE
23
Dept. of CSE
ARQ (Automatic Repeat
reQuest) protocols
• sender is in the wait-for-ACK-or-NAK state, it cannot get
more data from the upper layer
• stop-and-wait protocols
• if an ACK or NAK is corrupted???
24
Dept. of CSE
Three additional protocol capabilities are
required in ARQ protocols to handle the
presence of bit errors:
• Error detection
• Receiver feedback
• Retransmission
• Figure 3.10 shows the FSM representation of rdt2.0
25
Dept. of CSE
Consider three possibilities for
handling corrupted ACKs or NAKs:
• The receiver, having no idea whether the garbled sen-
tence was part of the dictation- heading down a difficult
path.
• A second alternative is to add enough checksum bits -
corrupt pkt not lose.
• A third approach is for the sender simply to resend the
current data packet when it receives a garbled ACK or
NAK packet.
26
Dept. of CSE
Cont
• solution- seq num field
• Figures 3.11 and 3.12 show the FSM description for rdt2.1
• A sender that receives two ACKs for the same packet (that
is, receives duplicate ACKs)
• NAK-free reliable data transfer protocol for a channel with
bit errors is rdt2.2
• Figures 3.13 and 3.14
27
Dept. of CSE
28
Dept. of CSE
29
Dept. of CSE
30
Dept. of CSE
31
Dept. of CSE
Reliable Data Transfer over a Lossy
Channel with Bit Errors: rdt3.0
• Two additional concerns must now be addressed by the
protocol: how to detect packet loss and what to do when
packet loss occurs
• The use of checksumming, sequence numbers, ACK packets,
and retransmissions—the techniques already developed
• new protocol mechanism - dealing with packet loss
• countdown timer - The sender will thus need to be able to (1)
start the timer each time a packet (either a first-time packet or
a retransmission) is sent, (2) respond to a timer interrupt
(taking appropriate actions), and (3) stop the timer.
32
Dept. of CSE
33
Dept. of CSE
Figure 3.15 shows the
sender FSM for rdt3.0
• packet sequence numbers alternate between 0 and 1,
protocol rdt3.0 is some times known as the alternating-
bit protocol.
34
Dept. of CSE
35
Dept. of CSE
Pipelined Reliable Data Transfer
Protocols
• rdt3.0’s performance problem is the fact that it is a stop-and-wait protocol.
• as shown in Figure 3.17
• round-trip propagation delay between these two end systems —
approximately 30 milliseconds
36
Dept. of CSE
Cont
• last bit of the packet emerging at the receiver at t = RTT/2 + L/R = 15.008 msec
• t = RTT + L/R = 30.008 msec
• stop-and-wait—performance problem
• Figure 3.17(b)
• Figure 3.18(b)
• many in-transit sender-to-receiver packets can be visualized as filling a
pipeline, this technique is known as pipelining
37
Dept. of CSE
38
Dept. of CSE
consequences for reliable
data transfer protocols:
• sequence numbers
• buffer
• Range of sequence numbers needed and the buffering
requirements will depend on the manner in which a data
transfer protocol responds to lost, corrupted, and overly
delayed packets.
• Two basic approaches toward pipelined error recovery can
be identified: Go-Back-N and selective repeat
39
Dept. of CSE
Go-Back-N (GBN)
• Figure 3.19
• base to be the sequence number of the oldest unacknowledged packet
• nextseqnum to be the smallest unused sequence number.
40
Dept. of CSE
four intervals in the range of
sequence numbers can be identified
• Sequence numbers in the interval [0,base-1]— pkt
transmitted and acknowledged
• [base,nextseqnum-1] pkts that have been sent but not yet
acknowledged
• [nextseqnum,base+N-1] —packets that can be sent
immediately should data arrive from the upper layer
• greater than or equal to base+N cannot be used until an
unacknowledged packet currently in the pipeline has been
acknowledged.
41
Dept. of CSE
Cont...
• N is often referred to as the window size
• GBN protocol itself as a sliding-window protocol
• k is the number of bits in the packet sequence number field
• the range of sequence numbers is thus [0,2^k – 1]
• TCP has a 32-bit sequence number field
• Figures 3.20 and 3.21 give an extended FSM description of
the sender and receiver sides of an ACK-based, NAK-free,
GBN protocol.
42
Dept. of CSE
43
Dept. of CSE
Cont
• extended FSM because we have added variables for base
and nextseqnum, and added operations on these variables
and conditional actions involving these variables.
• receiver discards out-of-order packets
• advantage—receiver need not buffer any out-of-order
packets
• disadvantage—The subsequent retransmission of that
packet might be lost or garbled—more retransmissions
would be required.
44
Dept. of CSE
45
Dept. of CSE
46
Dept. of CSE
Cont...
• Figure 3.22 shows the operation of the GBN protocol.
• techniques include the use of sequence numbers,
cumulative acknowledgments, checksums, and a
timeout/retransmit operation.
47
Dept. of CSE
48
Dept. of CSE
The GBN sender must respond
to three types of events:
• Invocation from above - check for window is full
• Receipt of an ACK- cumulative acknowledgement
• A timeout event- timer
49
Dept. of CSE
Selective Repeat(SR)
• single packet error can thus cause GBN to retransmit a
large number of packets
• sender retransmit only those packets that it suspects - SR
• a window size that is 1 less than the size of the sequence
number space won’t work.
• Lack of synchronisation
50
Dept. of CSE
51
Dept. of CSE
52
Dept. of CSE
SR sender events and actions
1. Data received from above.
2. Timeout
3. ACK received.
SR receiver events and actions
1. Packet with sequence number in [rcv_base, rcv_base+N-1] is correctly received.
2. Packet with sequence number in [rcv_base-N, rcv_base-1] is correctly received.
Packet that the receiver has previously acknowledged.
3. Otherwise. Ignore the packet.
53
Dept. of CSE
a window size that is 1 less than the size of
the sequence number space won’t work.
54
Dept. of CSE
55
Dept. of CSE
TCP Connection
Management
• SYN flood attack
• establishing a TCP connection client to server
• Step1: SYN=1, client_isn,special segment- no data
• Step2: TCP SYN segment arrives at the server host, the server extracts
the TCP SYN segment from the datagram, allocates the TCP buffers
and variables to the connection, and sends a connection-granted
segment to the client TCP, SYN bit is set to 1,ACK=client_isn+1, Seq =
server_isn, The connection- granted segment is referred to as a
SYNACK segment.
• Step 3 : receiving the SYNACK segment, allocate Buffer & variables
to the connection, server_isn+1, SYN=0, client-to-server data.
56
Dept. of CSE
Three-way handshake
• Figure 3.39
• Figure 3.40
• Figure 3.41 illustrates a typical sequence of TCP states
that are visited by the client TCP
57
Dept. of CSE
three-way handshake
• Figure 3.39
58
Dept. of CSE
• Figure 3.40
59
Dept. of CSE
• Figure 3.41 illustrates a typical sequence of TCP states that
are visited by the client TCP
60
Dept. of CSE
61
Dept. of CSE