Académique Documents
Professionnel Documents
Culture Documents
TRANSPORT
LAYER
Position of Transport layer
17/02/09 2
Process-to-process delivery
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 ,
)
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
Time ACK
DATA
DATA
DR
DATA
DR
CLICK
CLICK
Transport layer MUX &
DeMUX
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
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
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
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
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:
Direction of transmission
17/02/09 47
Flow control (cnt’d)
• 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
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