Unit 3_Transport Layer
Unit 3_Transport Layer
UNIT-3
TRANSPORT LAYER
✓
Syllabus
Loopi
ng Transport Layer: Introduction and transport
layer services, Multiplexing and
Demultiplexing, Connectionless transport
(UDP), Principles of reliable data transfer,
Connection-oriented transport (TCP),
Congestion control, TCP congestion control
2
✓ Loop
Outline
ing
hosts.
🞆 A transport protocols run in end
systems.
○ Sender side: It breaks application
messages into segments, then
passes to network layer. applicatio
East Side
Hosts(End Systems) = Houses
Processes = Cousins
Multiplexing at sender:
To handle data from multiple Demultiplexing at receiver:
sockets, add transport Use header information to
header (later used for deliver received segments to
demultiplexing) correct socket
application
DatagramSocket serverSocket =
DatagramSocket mySocket2 = new DatagramSocket(6428); DatagramSocket mySocket1 =
new DatagramSocket(9157); new DatagramSocket(5775);
applicati
application on application
P3 P1 P4
transpo
transport rt transport
networ
network k lin network
link k
physic link
physical al physical
UDP
● No connection establishment
application
data (which can add delay)
(payload) ● Simple: no connection state at
sender and receiver
● Small header size
● No congestion control: UDP can
blast away as fast as desired
UDP segment format
UDP - CHECKSUM
🞆 Checksum is used to detect errors in transmitted segment.
Sender:
🞆 Treat segment contents, including header fields, as sequence of
16-bit integers.
🞆 Checksum: addition (one ’ s complement pf sum)
of segment
contents.
🞆 Sender puts checksum value into UDP checksum field.
Receiver:
🞆 Compute checksum of received segment.
🞆 Check if computed checksum equals checksum field value:
✔ NO - error detected
CHECKSUM - EXAMPLE
🞆 Add two 16-bit integers word
Sender Receiver
1110011001100110 1110011001100110
1101010101010101 1101010101010101
wraparound 1 1011101110111011 1 1011101110111
+ 1 0 1 1+ 1
sum 1011101110111100 1011101110111100
checksum 0100010001000011 0100010001000011
1111111111111111
If one of the bits is a 0, then we can
say that error introduced into
packet
Note: when adding numbers, a carryout from
the most significant bit needs to be added to the result
CHECKSUM CALCULATION OF A SIMPLE UDP
USER DATAGRAM
Here are the ASCII values for each letter in the word
"TESTING":
T: 84 E: 69 S: 83 T: 84 I: 73 N: 78 G: 71
PRINCIPLES OF RELIABLE
DATA TRANSFER
PRINCIPLES OF RELIABLE DATA TRANSFER
sender receiver
side side
sender receiver
RDT 2.0 – CHANNEL WITH BIT ERRORS
🞆 There is no packet loss
🞆 Underlying channel may flip bits in packet.
⚫ Checksum to detect bit errors.
🞆 Question: How do we recover from errors?
⚫ Acknowledgements (ACKs): receiverexplicitly tells
sender that packet received OK.
⚫ Negative acknowledgements (NAKs): receiver explicitly tells sender
that packet had errors.
⚫ Sender retransmits packet on receipt of NAK.
🞆 New mechanisms in rdt 2.0 (beyond rdt 1.0):
⚫ Error detection
⚫ Feedback: control messages(ACK,NAK) from receiverto
sender
⚫ Retransmission: Error in received packet,
retransmitted by the sender
🞆 It is known as stop-and-wait protocol.
RDT2.0 HAS A FATAL FLAW!
What happens if ACK/NAK
corrupted?
🞆 Sender doesn’t know what
happened at receiver!
🞆 Can’t just retransmit: possible
duplicate
Handling duplicates:
🞆 Sender retransmits current pkt if
ACK/NAK corrupted
🞆 Sender adds sequence
stop and wait number to each pkt
sender sends one packet, 🞆 Receiver discards (doesn’t deliver
then waits for receiver up) duplicate pkt
response
RDT 2.0 – WITH NO ERROR
rdt_send(data)
Receiver
RDT 2.0 – WITH ERROR
rdt_send(data)
snkpkt = make_pkt(data, checksum) Receiver
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
Wait for Wait for isNAK(rcvpkt)
rdt_rcv(rcvpkt) &&
call from ACK udt_send(sndpkt)
above or corrupt(rcvpkt)
NAK udt_send(NAK)
#42
udt_send(data)
“wait for Ack/Nack”
udt_send(data) udt_send(NACK)
...
udt_send(data) udt_send(NACK)
udt_send(data) udt_send(ACK)
“wait for call”
Handling duplicates:
🞆 Sender adds sequence number to each packet
🞆 Sender retransmits current packet if ACK/NACK garbled
receiver discards (doesn’t deliver up) duplicate packet
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
RDT2.2: A NACK-FREE PROTOCOL
● Same functionality as rdt2.1,
using ACKs only sende
rFSM
● Instead of NACK, receiver
sends ACK for last pkt
received OK
○ receiver must explicitly
include seq # of pkt
being ACKed
● Duplicate ACK at sender
results in same action as !
NACK: retransmit current
pkt
RDT 2.2 – SENDER AND RECEIVER
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt) rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
Wait for Wait for
ACK isACK(rcvpkt,1) )
call 0 from
above 0 udt_send(sndpkt)
sender FSM
fragment rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && && isACK(rcvpkt,0)
(corrupt(rcvpkt) || Λ
has_seq1(rcvpkt)) Wait for receiver FSM
0 from
udt_send(sndpkt) below fragment
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK,1, chksum)
udt_send(sndpkt)
RDT 2.2 IN ACTION
sender receiver send receiv
er er
pkt0 pkt0
send send
pkt0 rcv pkt0 pkt0 rcv pkt0
ACK0 ACK
send send
rcv rcv ACK0 0
pkt1 ACK0 ACK0
ACK0 send
send rcv pkt1 pkt1 X (corrupterdcv)
send
pkt1 ACK send
pkt1
ACK1 pkt1
0 ACK0
rcv rcv
send
ACK1 ACK resend
ACK0
pkt0 rcv pkt0 pkt1 pkt1 rcv pkt1
1 send send
ACK
ACK0 1 ACK1
pkt0
a) operation with no b) packet
corruptionACK corrupted
0
RDT 2.2 IN ACTION (CONT)
sender receiver
pkt
send
0
pkt0 rcv
ACK0 send
(corrupted)pkt0
rcv X ACK0
resend pkt0
ACK0
pkt0 rcv
ACK send
pkt0
0 ACK0
rcv
send
ACK0
pkt1 pkt1 rcv pkt1
send
ACK
1 ACK1
c) ACK
corrupted
RDT 3.0: CHANNEL WITH ERROR AND LOSS
🞆 Underlying channel can also lose packets
(data, ACKs).
⚫Even checksum, sequence #, ACKs,
retransmissions will not enough help.
🞆 Sender waits “reasonable” amount of time for ACK.
🞆 It retransmits if no ACK received in this time.
🞆 If packet(or ACK) just delayed (not lost):
⚫Retransmission will be duplicate, but sequence #’s already
handled it.
🞆 Receiver must specify sequence # of packet
being ACKed.
🞆 It requires countdown timer.
CHANNEL UC 3.0
🞆 FIFO:
⚫Data packets and Ack packets are delivered in order.
🞆 Errors and Loss:
⚫Data and ACK packets might get corrupt or lost
🞆 No duplication: but can handle it!
🞆 Liveness:
⚫If continuously sending packets, eventually, an
uncorrupted packet received.
RDT3.0: CHANNELS WITH ERRORS AND
LOSS
New assumption: underlying Approach: sender waits
channel can also lose packets “reasonable” amount of
(data or ACKs) time for ACK
⚫ checksum, seq. #, 🞆 retransmits if no ACK
ACKs, retransmissions received in this time
will be of help, but not
enough 🞆 if pkt (or ACK) just delayed
(not lost):
Q: how to deal with
⚫ retransmission will be
loss?
duplicate, but use of seq.
⚫ sender waits until
#’s already handles this
certain data or ACK
lost, then retransmits ⚫ receiver must specify seq #
⚫ feasible? of pkt being ACKed
🞆 requires countdown timer
RDT 3.0: ALTERNATING-BIT PROTOCOL
(b) packet
loss
RDT 3.0 – CONT…
sender receiv
receiver send er
sender pkt0
pkt0
pkt0 rcv pkt0
send pkt0 ack0 send
rcv pkt0
send rcv
ack0 ack0 ack0
rcv ack0
send rcv pkt1
ack0 pkt1 pkt1
send rcv pkt1 send
pkt1
ack1 ack1
pkt1 send ack1
X
los ack1 timeout
s pkt1
timeout resend rcv
resend pkt1 pkt1 pkt0 (detect
pkt1
rcv pkt1 send ack1
duplicate
pkt1 ack1
ack1 (detect rcv
duplicate) ack0 rcv pkt0
rcv ack1
pkt0 send ack1 pkt0 send ack0
ack1 send
rcv pkt0 rcv pkt0
send ack0 send pkt0 ack0
(detect
pkt0 ack0 rcv duplicate
ack1 send ack0
(c) ACK (d) premature
send timeout/ delayed
loss ACK pkt0
SLIDING WINDOW CONCEPT
Core Concepts of Sliding Window:
🞆 Window Size:
⚫ A sliding window represents the range of sequence
numbers that are allowed to be sent (for the sender) or
received (for the receiver) without waiting for an
acknowledgment.
⚫ The window size determines the number of
unacknowledged packets that the sender can transmit
before it must stop and wait for ACKs.
⚫ Both sender and receiver maintain their own sliding
windows.
🞆 Send Window:
⚫ This is the range of sequence numbers that the sender is
allowed to transmit.
⚫ Once packets are acknowledged, the window "slides"
forward, allowing the sender to transmit more packets.
🞆 Receive Window:
⚫ This is the range of sequence numbers that the receiver is
willing to accept at any point in time.
⚫ It ensures that the receiver doesn’t get overwhelmed by
too many packets too quickly.
🞆 ACKs and Cumulative ACKs:
⚫ For each packet received without errors, the receiver sends
an acknowledgment (ACK).
⚫ In cumulative acknowledgment, the receiver
acknowledges the highest in-sequence packet number
received correctly.
⚫ This implies that all packets up to the acknowledged one
have been received without issues.
🞆 Sliding the Window:
⚫ Once a packet is acknowledged, both the sender and
receiver slide their respective windows forward to allow
for new transmissions.
🞆 Types of Sliding Window Protocols:
1) Go-Back-N:
■ The sender can send several packets specified by the
window size, but if a packet is lost or an error occurs,
the receiver ignores all subsequent packets and sends a
NAK for the lost packet.
■ The sender, upon receiving the NAK, goes back and
retransmits the lost packet and all subsequent packets,
even if they were received correctly by the receiver.
2) Selective Repeat:
■ Instead of retransmitting all subsequent packets after a
lost one (like in Go-Back-N), only the lost packet is
retransmitted.
■ The receiver buffers the correctly received packets
until the lost one is received, after which it delivers
them in sequence to the application layer.
■ This improves efficiency, especially in networks with a
high error rate.
🞆 Sliding Window Key Parameters:
⚫ Window Size: The number of unacknowledged packets
that can be sent.
⚫ Sequence Numbers: The range of numbers used to
identify each packet.
⚫ Acknowledgment Number: The sequence number of the
next expected packet.
⚫ Timeout: If the sender doesn’t receive an
acknowledgment within a certain time, it retransmits the
packet.
Example of How Sliding Window Works:
Scenario:
🞆 Window Size = 4
🞆 Packets to send: P1, P2, P3, P4, P5, P6, P7, P8
🞆 Sender Side:
⚫ The sender transmits P1, P2, P3, P4 (as allowed by the
window size of 4).
⚫ The receiver successfully receives P1, P2, but P3 is lost,
and P4 is received.
⚫ The receiver sends an ACK for P2 (cumulative
acknowledgment), meaning packets up to P2 have been
received correctly.
⚫ The sender receives this ACK and slides its window to
allow for sending P5 and P6 but retransmits P3 due to the
missing acknowledgment.
🞆 Receiver Side:
⚫ The receiver gets P1, P2, but P3 is lost. It stores P4 in its
buffer and waits for P3 to be retransmitted.
⚫ Once P3 is retransmitted, it delivers the packets in order
(P3, then P4) to the application layer.
⚫ It then sends an ACK for P4 to the sender.
Advantages of Sliding Window:
🞆 Higher Efficiency: The sender doesn't need to stop and wait
after sending each packet. Multiple packets can be sent before
needing an ACK.
🞆 Error Handling: If an error occurs, retransmissions are
controlled by either retransmitting all subsequent packets (Go-
Back-N) or only the erroneous packets (Selective Repeat).
🞆 Flow Control: It prevents the sender from overwhelming the
receiver with more packets than it can handle.
Sliding window
PIPELINED PROTOCOL:
Go-back-N Protocol &
Selective Repeat Protocol
PIPELINED PROTOCOL
🞆 It's a technique in which multiple requests are written out to a
single socket without waiting for the corresponding responses
(acknowledged).
⚫No. of Packets(request) must be increased.
⚫Data or Packet should be buffered at sender and/or receiver.
● A SYN segment cannot carry data, but it consumes one sequence number.
● A SYN + ACK segment cannot carry data, but does consume one sequence
number.
● An ACK segment, if carrying no data, consumes no sequence number.
DATA TRANSFER
CONNECTION TERMINATION USING THREE-WAY
HANDSHAKING
🞆 The FIN segment consumes one sequence number if it does not carry data.
🞆 The FIN + ACK segment consumes one sequence number if it does not
carry data.
TCP SEGMENT FORMAT
🞆 Delay Increase
⚫If Delay Increases, retransmission occurs, making
situation worse.
🞆 Performance Decrease
CONGESTION CONTROL – CONT…
Host B
CAUSES/COSTS OF CONGESTION:
SCENARIO 2
🞆 One router, finite buffers
🞆 Sender retransmission of timed-out packet
▪ application-layer input = application-layer output: λ in= λout
Host A
Host A
no buffer space!
Host B
🞆 Realistic: duplicate packets
🞆 Packets can be lost, dropped at router due to full buffers
🞆 Sender times out prematurely, sending two copies, both of
which are delivered
λ
in
cop
timeo λout
ut
y
λ'in
Host B
APPROACHES TOWARDS CONGESTION
CONTROL
🞆 Two broad approaches towards congestion control
1. End to End congestion control
🞆 No explicit feedback from network
🞆 Congestion inferred from end-system observed loss,
delay
🞆 Approach taken by TCP
2. Network-assisted congestion control
🞆 Routers provide feedback to end systems
🞆 Single bit indicating congestion (SNA, DECbit,
TCP/IP ECN, ATM)
🞆 Explicit rate for sender to send
TCP SLOW START
🞆 An algorithm which balances
the speed of a network
connection.
🞆 TCP slow start is one of the
first steps in the congestion
control process.
🞆 It balances the amount of data a
sender can transmit (known as
the congestion window) with the
amount of data the receiver can
accept (known as receiver
window).
TCP SLOW START – CONT…
🞆 Slow start gradually increases the amount of data transmitted
until it finds the network’s maximum carrying capacity.
🞆 A sender communicate to a receiver. Initial packet contains a
small congestion window, which is determined based on the
sender’s maximum window.
🞆 A receiver acknowledges the packet and responds with its
own window size.
🞆 If the receiver fails to respond, the sender knows not to
continue sending data.
🞆 After receiving the acknowledgement, the sender
increases the next packet’s window size.
🞆 The window size gradually increases until the receiver can no
longer acknowledge each packet, or until either the sender or
the receiver’s window limit is reached.
Thank you……
107