Unit 2
Unit 2
Networks
Unit-2
Transport Layer
lo
gi
ca
le
systems.
nd
-e
▪ Sender side: It breaks application
nd
tra
ns
messages into segments, then
po
rt
passes to network layer.
application
▪ Receiver side: It reassembles transport
network
data link
segments into messages, then physical
East Side
Hosts(End Systems) = Houses
Processes = Cousins
sender receiver
side side
state state
1 event
2
actions
rdt 1.0
▪ Reliable transfer over a reliable channel
▪ Underlying channel perfectly reliable channel
✔ no bit errors
✔ no loss of packets
▪ Separate FSMs for sender & receiver:
✔ Sender sends data into underlying channel
✔ Receiver reads data from underlying channel
sender receiver
RDT 2.0 – STOP & WAIT PROTOCOL
rdt 2.0 – channel with bit errors
▪ Underlying channel may flip bits in packet.
✔ checksum to detect bit errors.
▪ To recover from errors:
✔ acknowledgements (ACKs): receiver explicitly 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 receiver to sender
✔ Retransmission: Error in received packet, retransmitted by the sender
▪ It is known as stop-and-wait protocol.
rdt 2.0 – with no error
rdt_send(data)
snkpkt = make_pkt(data, checksum) receiver
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for Wait for rdt_rcv(rcvpkt) &&
call from ACK or udt_send(sndpkt) corrupt(rcvpkt)
above NAK
udt_send(NAK)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
RDT 2.2 & RDT 3.0
rdt 2.2
▪ Use same functionality as rdt2.1, using ACKs only
▪ Instead of NAK, receiver sends ACK for last packet received OK
▪ Receiver must explicitly include sequence # of packet being ACKed
▪ Duplicate ACK at sender results in same action as NAK: retransmit
current packet.
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 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.
Rdt 3.0: Alternating-bit protocol
sender receiver sender receiver
send pkt0 pkt0 send pkt0 pkt0
rcv pkt0 rcv pkt0
ack0 send ack0 ack0 send ack0
rcv ack0 rcv ack0
send pkt1 pkt1 send pkt1 pkt1
rcv pkt1 X
ack1 send ack1 loss
rcv ack1
send pkt0 pkt0
rcv pkt0 timeout
ack0 send ack0 resend pkt1 pkt1
rcv pkt1
ack1 send ack1
rcv ack1
send pkt0 pkt0
(a) no loss rcv pkt0
ack0 send ack0
▪ 1. Speed: UDP is faster than TCP because it does not have the overhead of establishing a connection and ensuring
reliable data delivery.
▪ 2. Lower latency: Since there is no connection establishment, there is lower latency and faster response time.
▪ 3. Simplicity: UDP has a simpler protocol design than TCP, making it easier to implement and manage.
▪ 4. Broadcast support: UDP supports broadcasting to multiple recipients, making it useful for applications such as
video streaming and online gaming.
▪ 5. Smaller packet size: UDP uses smaller packet sizes than TCP, which can reduce network congestion and improve
overall network performance.
Disadvantages of UDP:
▪ 1. No reliability
▪ 2. No congestion control
▪ 3. No flow control
▪ 4. Vulnerable to attacks
▪ 5. Limited use cases: UDP is not suitable for applications that require reliable data delivery, such as email or file
transfers, and is better suited for applications that can tolerate some data loss, such as video streaming or online
gaming.
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 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
✔ YES - no error detected
Checksum - Example
▪ Add two 16-bit integers word
Sender Receiver
1 1110011001100110 1 1110011001100110
1 1101010101010101 1 1101010101010101
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1011101110111011
+ +
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1011101110111100
sum
checksum 0100010001000011 1 0100010001000011
1111111111111111
If one of the bits is a 0, then we can
say that error introduced into packet
▪ Threshold
▪ = Maximum number of TCP segments that receiver window can
accommodate / 2
▪ = (Receiver window size / Maximum Segment Size) / 2
Congestion Avoidance Phase
▪ Additive increment: This phase starts after the threshold value also
denoted as ssthresh. The size of cwnd(congestion window) increases
additive. After each RTT cwnd = cwnd + 1.
▪ Initially cwnd = i
▪ After 1 RTT, cwnd = i+1
▪ 2 RTT, cwnd = i+2
▪ 3 RTT, cwnd = i+3
Congestion Detection Phase
▪ Multiplicative decrement: If congestion occurs, the congestion window size is decreased.
▪ The only way a sender can guess that congestion has happened is the need to retransmit a
segment.
▪ Retransmission is needed to recover a missing packet that is assumed to have been dropped by
a router due to congestion.
▪ Retransmission can occur in one of two cases: when the RTO timer times out or when three
duplicate ACKs are received.
▪ Case 1: Retransmission due to Timeout – In this case, the congestion possibility is high.
▪ (a) ssthresh is reduced to half of the current window size.
▪ (b) set cwnd = 1
▪ (c) start with the slow start phase again.