You are on page 1of 56

UNIT II

TRANSPORT
LAYER
Position of Transport layer

17/02/09 2
Process-to-process delivery

• Several processes (application programs) can run on both
the source and the destination host
• Two communicating processes are in client-server
relationship
– Client – a process on the local host
– Server – a process at the remote host

17/02/09 3
Analogy
• Two houses, each with a dozen of kids, are located in
Hadapsar and Kothrud
• All kids in different houses are relatives (cousins)
• Each kid weekly writes a letter to every other kid in another
house
– 144 letters/week in total (huge cost)
• kids would probably use e-mail (low cost)
• In each household there is one kid (Ajay & Vijay,
respectively) responsible for mail collection and mail
distribution
– each week they give all the letters to a postal-service mail
carrier who makes daily visits to the house.

• Application message =
letters in the envelope
• Processes =
cousins
• Hosts (end systems) =
houses
• Transport-layer protocol =
Ajay & Vijay
• Network-layer protocol =
17/02/09 4
postal service (including
Connection Request Connection Primitive
TPDU received IDLE executed

Passive Active
Establishme Establishme
nt nt Pending
Pending
Connection Primitive Connection accepted
executed TPDU received
ESTABLISH
ED
Disconnecti Disconnecti
on TPDU on Primitive
Passive executed Active
received
Disconnect Disconnect
Pending Pending

Disconnecti Disconnection
on Primitive request TPDU
executed IDLE received
BERKELEY Sockets
Primitive Meaning
SOCKET Create new communication end point
BIND Attach a local address to socket
LISTEN Announce willingness to accept
connection
ACCEPT Block the caller until a connection attempt
arrives
CONNECT Actively attempt to establish a connection
SEND Send some data over the connection
RECEIVE Receive some data from the connection
CLOSE Release the connection
Elements of Transport
Protocols
• Addressing
• Connection Establishment
• Connection Release
• Flow control & Buffering
• Multiplexing
• Crash Recovery

Addressing
Data link =
MAC address
• Network =
IP address
• Transport =
port number
– needed to chose among multiple processes running on the destination host
– The Internet model: 16 bit integer 0 – 65 535
• Client mostly chooses ephemeral port number
• Server mostly uses well-known (permanent) port numbers

ephemeral well-known
port number port number

17/02/09 11
IP addressing versus port

addressing
destination IP defines the host
• after the host has been selected:
the port number defines one of the processes on this
host

17/02/09 12
Socket address
• Process-to-process delivery needs 2 identifiers:
– IP number
– port number

17/02/09 13
CLICK
• PROBLEMS
Three - Way Hand - Shake
Host Host
1 2
CR (seq=x
Time )

C K ( s e q =y,
A
ACK=x)

DATA (
se
ACK=y q=x ,
)

Establishing a connection using a three way
handshaking
-CR denotes CONNECTION REQUEST
Three - Way Hand - Shake
Old duplicate CONNECTION REQUEST appearing..
Host Host
1 2
CR (seq=x
)
Time

C K ( s e q =y,
A
ACK=x)

REJECT
(ACK=
y)

CLICK
Connection Release
• Asymmetric e.g. Telephone system
• Symmetric
Asymmetric Connection
Release
Host Host
1 2
Time CR

ACK

DATA

No data are delivered
after a disconnect
request
Symmetric Connection Release
Host Host
1 2
CR

Time ACK
DATA

DATA
DR

DATA
DR
CLICK
CLICK
Transport layer MUX &
DeMUX

• Extending host-to-host delivery to process-to-process
delivery
• Transport layer de/multiplexes several processes on the
transport layer protocol (TCP, UDP)

17/02/09 23
Transport layer MUX & DeMUX (cnt’d)

CLICK

17/02/09 24
CLICK
User Datagram Protocol
(UDP)
• UDP – unreliable connectionless transport protocol
• Application:
– simple request-response communication with little concern
about flow & error control
– in processes with internal flow & error control
• Trivial File Transport Protocol
– Multicasting
– in conjunction with Real Time Transport Protocol (RTP)
for real-time data

17/02/09 26
UDP
• A process (application program)
sends a chunk of bytes to UDP for
delivery
• UDP adds its own header to this
chunk of data (user datagram) and
delivers it to IP
• UDP treats each chunk
independently

17/02/09 27
User datagram format
8
bytes
Heade Data
r

Source Port Destination
(16 bits) Port
(16 bits)
UDP Length UDP
(16 bits) Checksum
(16 bits)

17/02/09 28
UDP Header
Fields
• Source Port – from 0 – 65535
• Destination Port - from 0- 65535
• UDP length- total Length of the user
datagram (header + data)
• Checksum- detect errors over the entire
datagram
S
RTP Header format
Transmission Control Protocol
(TCP)
• Some Assigned Port numbers

Port Protocol Description
20 FTP, Data File Transfer Protocol (data connection)
21 FTP, Control File Transfer Protocol (control connection)
23 TELNET Terminal Network
25 SMTP Simple Mail Transfer Protocol
53 DNS Domain Name Server
67 BOOTP Bootstrap Protocol
79 Finger Look up information about the user
80 HTTP Hypertext Transfer Protocol
111 RPC Remote Procedure Call
119 NNTP USENET news

17/02/09 33
Transmission Control
Protocol
• Byte-stream connection-oriented & reliable
transport protocol

17/02/09 34
TCP - buffers
• Sending & receiving buffers
– Processes do not consume data at the same speed
• Sending site:
– White section: empty locations to be filled by sending
process
– Blue section: bytes sent but not yet acknowledged
– Red section: bytes to be sent by sending TCP
• Receiving site:
– White section: empty locations to be filled by bytes from the
networks
– Red section: received bytes to be consumed by the
receiving process

35
TCP – bytes & segments
• TCP at the sending site gathers bytes into a packet
called a segment
• TCP adds a header to each segment and delivers it to IP
for transmission
• Segments can arrive out of order
• Size of the segment varies

17/02/09 36
TCP segment format

17/02/09 37
TCP Header fields
• Fixed format, 20 byte header.
• May or may not be followed by 20 byte optional field
• Data up to 65535- 40=65495
• Source & Destination port-identify the local end points of the connection.
• Sequence no. & Ack. No.-
• TCP Header Length- How may 32 bit words contained in header?
• Next 6 bit field that is not used
• Six 1 bit flags-
1) URG- Urgent data if set to 1.
2) ACK- if 1 then acknowledgement no is valid otherwise this field is ignored
3) PSH- PUSHed data
4) RST- reset connection, reject invalid segment or refuse to open a connection
5) SYN- to establish the connection
6) FIN- To release the connection
TCP - connections
• Connection
establishment
– Three-way handshake
Why is two-way
handshake not enough?

• Connection termination
– Four steps

17/02/09 39
Connection Establishment

Active participant Passive participant
(client) (server)
SYN,
Sequ
enceN
um =
x
u m = y,
en ceN 1
equ x+
+A CK, S en t =
SYN owl e dgm
Ackn
ACK,
Ackno
wledg
m ent =
y +1

CS 640 41
Connection Termination
Active participant Passive participant
(server) (client)
FIN, S
eque
nceN
u m=
x

1
e nt =x+
le dgm
Ackn
o w
u m = y
N
e q u ence
S
FIN,

Ackno
wledg
m ent = y +
1

CS 640 42
State Transition Diagram
CLOSED
Active open/SYN
Passive open Close
Close

LISTEN

SYN/SYN + ACK Send/SYN
SYN/SYN + ACK
SYN_RCVD SYN_SENT
ACK SYN + ACK/ACK

Close/FIN ESTABLISHED

Close/FIN FIN/ACK
FIN_WAIT_1 CLOSE_WAIT
AC FIN/ACK
ACK K Close/FIN
+
FI
FIN_WAIT_2 N
/A CLOSING LAST_ACK
CK
ACK Timeout after two ACK
segment lifetimes
FIN/ACK
TIME_WAIT CLOSED

CS 640 43
TCP – numbering bytes
Numbering is used for flow & error control
Segments are not numbered, only bytes
Full-duplex connection – numbering is
independent in each direction
Numbers generated randomly from 0 to 232-
1

• Sequence number
– The number of the first byte carried in the
segment
• Acknowledgement number
– To confirm received bytes
– Defines the number of the next byte the
party expects to receive
– Cumulative
17/02/09 44
TCP numbering – an
example
Imagine a TCP connection is transferring a file of 6000
bytes.
The first byte is numbered 10010.
What are the sequence numbers for each segment if
data are sent in five segments with the first four
segments carrying 1000 bytes and the last segment
carrying 2000 bytes?
The following shows the sequence number for each segment:

Segment 1 ==> sequence number: 10 010 (range: 10,010 to
11,009)
Segment 2 ==> sequence number: 11 010 (range: 11,010 to
12,009)
Segment 3 ==> sequence number: 12 010 (range: 12,010 to
13,009)
Segment 4 ==> sequence number: 13 010 (range: 13,010 to
14,009)
17/02/09 45
Flow control

• The amount of data a source can
send before receiving an ACK from
the destination
• Whether to send 1 byte of data and
wait for ACK or send all bytes and
wait for the ACK for the complete
message?
• TCP gives a solution in between
• Sliding window protocol
– byte oriented
17/02/09 46
Flow control (cnt’d)
sender buffer

Direction of transmission

• If no window, a sender can send all bytes without
regarding the condition of the receiver
– if data are consumed too slowly then receiver buffer
becomes full -> drop the packet (retransmit)
– the sender must adjust itself to the number of the free
locations in the receiver buffer

17/02/09 47
Flow control (cnt’d)
• Receiver window

M

N N-M = receiver window

• Sender window

17/02/09 48
Flow control (cnt’d)
Direction of window shift

•sliding widow
•ACK is
received for Direction of transmission
bytes 200-
202
• the sender
can send
bytes 205-
209
• expanding the
sender widow

• shrinking the
sender widow

17/02/09 49
Silly window syndrome
• When either a sending application sends
data slowly or a receiving application
consumes data slowly
– Example: when 1 byte sent, 40 bytes
overhead – not efficient
• Syndrome created by the sender
– Nagle’s algorithm
• to prevent TCP from sending data byte by byte
– send the 1st byte
– wait for either the received ACK or the maximum-size
segment full
– repeat step 2
• Syndrome created by the receiver
– Clark’s solution
• send ACK asa data arrive, but advertise 0 size
window
– Delayed ACK
17/02/09 50
TCP timers

17/02/09 51
Retransmission timer
1. if an ACK is received before the timer
goes off – destroy the timer
2. if the timer goes off before ACK arrives
– retransmit the segment & reset the
timer
• Retransmission time = 2* RTT
– not fixed since paths that IP packets take
may differ
– if too short – retransmissions -> waste of
bandwidth
– if too large – delay for the application
program

RTT = α* previous RTT + (1- α)*current
RTT, α usually 90 %
17/02/09 52
• Karn’s algorithm:
RTT samples and estimates

Copyright © 2005 Pearson Addison-Wesley. All
rights reserved.

17/02/09 53
Persistence timer
• To deal with the zero-size windows
• What if the receiver advertises that the
window size is ≠ 0 (by sending ACK) and
this ACK is lost?
– ACK are not acknowledged in TCP
• Start persistence timer
– when this goes off send a probe (1 byte of
data)
– it is set to the retransmission time &
doubled every time a response is not
17/02/09
received (until 60s, then sent every 60s) 54
Keep alive timer
• to prevent a long idle connection
between a client and a server
– either client or server crash
• usually set to 2h

17/02/09 55
Time-Waited Timer
• used during connection termination
to allow duplicate FIN segments to be
discarded at the destination
• usually 2 times the expected lifetime
of a segment

17/02/09 56