Chapter
Computer Communication & Networks 05
Transport Layer
(TCP/UDP)
Where are we in protocol stack?
application
end-to-end } today’s topic
IP
data link
physical
} Until now
we have been discussing
the issues related to
lower three layer
2
Transport Layer Protocols
3
User’s Perspective
Users demand connectivity, reliability, functionality
They don’t concern of underlying technology
Our IP network is an unreliable network
IP provides the Best Effort Service
Packets may be discarded, duplicated, receive with error,
etc.
Users want the reliable communication between
end applications
Connectivity between end host applications is
called End-to-End connectivity
4
Scope of different layers
Data Link Layer:
Communicate between directly-connected nodes Within a single
network only
IP Layer:
Communicate between hosts residing anywhere in the world Across
multiple networks
Taking end host as a single entity
Transport Layer:
We have multi-tasking computers
For users, each application is different entity
Communicate among different applications on individual hosts across
multiple networks
5
Transport Layer
For communication among applications:
We need another level of addressing
That uniquely distinguish different applications on host
Port numbers are used for this level of addressing
These are logical port numbers, in contrast to physical
ports
Port number is a 16-bits positive integer value Theoretically
it means, a computer can support thousands of
simultaneous connections! Enough
Transport layer protocols e.g. TCP, UDP, SCTP provide
separate pool of port numbers
6
Logical Port Numbers
Well-Known Ports:
Permanently assigned to servers listening for requests
Assigned by IANA
Ranging from 0 to 1023
Registered Ports:
Not permanently assigned But registered with IANA
e.g. WINS uses port-1512
Ephemeral Ports:
Temporarily assigned to clients by the OS
Can change for client applications in each session
Can range from 1024 to 65535
7
Well-Known Ports
For TCP:
Port-21 = FTP (File Transfer Protocol)
Port-25 = SMTP (Simple Mail Transfer Protocol)
Port-53 = DNS (Domain Name System)
Port-80 = HTTP (Hyper Text Transfer Protocol)
For UDP:
Port-53 = DNS (Domain Name System)
Port-69 = TFTP (Trivial FTP)
Port-123 = NTP (Network Time Protocol)
Port-161 = SNMP (Simple Network Management Protocol)
Port-520 = RIP (Routing Information Protocol)
8
Example Port 21 & Port 80
9
Transport Layer Services
Other than application multiplexing, there are two
other types of end-to-end services at transport
layer:
Connectionless Service (UDP)
Connection-Oriented Service (TCP)
10
Connectionless Service
Connectionless:
Unreliable
No Acknowledgments
No Control over out-of-order delivery
No Flow Control
No Congestion Control Protocol = UDP
Helpful for applications that don’t need guaranteed
delivery
e.g. interactive multimedia, delay-sensitive applications
Request/response transactions
11
Connection-Oriented Service
Connection-Oriented: Reliable Acknowledgments
In-Order Delivery Flow Control Congestion Control
Protocol = TCP
Helpful for applications that need each & every byte of
the message to be properly delivered
Used for bulk data transfer
e.g. HTTP, file transfer (FTP), emails (SMTP/MIME)
12
Transport Layer Protocols
Many transport layer protocols are supported over
the Internet
User Datagram Protocol (UDP) Transmission
Control Protocol (TCP) Stream Control Transmission
Protocol (SCTP) Datagram Congestion Control
Protocol (DCCP)
13
UDP
UDP = User Datagram Protocol Defined in
IETF RFC-768 in 1980 There is no notion of
connection You have the data, you send it
without checking whether destination is alive or
not
There
case ofiserror,
no acknowledgment of sent data In
there is no retransmissions
14
UDP Header
15
UDP Header Fields
Source Port:
Port number of sending application
Destination Port:
Port number of receiving application
Length:
Length of entire UDP packet including header & data
Checksum:
Optional, if not used then set equal to zero
16
UDP Datagram
17
TCP
Transmission Control Protocol (TCP) Defined in
IETF RFC-793 in 1981 For sending data:
First, establishes connection
Then, transfers data
In the end, terminates connection
Provides reliable byte-stream for applications
18
TCP:
-Byte Streaming
Continuous receiving data from Application and make
segments.
-Connection Oriented
Three way hand shake
-Full Duplex
Sender and receiver both can send data simultaneously
-Piggybacking
With Ack., data can also be send
In Sliding window use GBN(Go back N) and SR(Selective Repeat)
-Error Control
-Flow Control
-Congestion Control
Also take care of network along with receiver
-Header can be of 20 byte to 60 byte
Services of Transport layer
1. End-to-End delivery (Port-to-port)
2. Reliability
3. In-order delivery (without loss of data)
4. Error Control (Checksum)
5. Congestion Control (AIMD)
(Additive Increase Multiplicative Decrease )
6. Flow Control (Sliding Window)
7. Multiplexing / Demultiplexing
A1 B1
Flow Control at Transport layer (by TCP)
. Protocols
Noiseless Channels
Noisy Channels
Stop-and-wait Sliding Window
Stop-and-wait-ARQ
Go-back-N-ARQ
Selective Repeat ARQ
Flow Control at Transport layer (by TCP)
stop-and-wait –ARQ
Sliding Window
Flow Control at Transport layer (by TCP)
. Go-back-N-ARQ
Sliding Window
Selective Repeat ARQ
TCP Header
24
TCP Header Fields
Source Port:
Port number of sending application
Destination Port:
Port number of receiving application
Sequence Number:
Sequence number (byte count) of first byte of TCP segment
Used for in-order delivery (e.g if bytes start from Seq. No. 100 to
149 the Ack. No. will be 150)
Acknowledgment Number:
Sequence number of next byte expected by the receiver
Used for reliability & flow control
25
TCP Header Fields: cont…
Data Offset:
Number of 32-bit words in the header (header length)
Reserved:
Reserved for future use
TCP Header Flags:
FIN: Finish, set in connection close message
SYN: Synchronize, set in connection-request message
RST: Reset connection
PSH: Push data from TCP send buffer
ACK: Acknowledgment field is significant URG: urgent
pointer field is significant
ECE: ECN (Explicit Congestion Notification) indication
CWR: Congestion Window Reduced indication (*RFC-3168)
26
TCP Header Fields: cont…
Window:
Indicate number of bytes that receiver can receive
Used for flow control
Checksum:
Same as IP & UDP checksum, for error detection
Urgent Pointer:
Indicate to receiver that some urgent data is included
Options + Padding:
Optional information if any
e.g. negotiation of maximum segment size
27
TCP Connection
Two applications talking to each other over TCP
establish a TCP-connection between each other
For this connection, TCP at each host reserves
some resources
This is an agreement between end hosts only Network is
unaware of any such connection Network doesn’t know
any thing above IP layer
This is in contrast to Circuit-Switched connection
Where network reserves resources for end nodes
28
TCP Connection Identification
Over the Internet, each application is identified
through 2-parameters
Port Number of application & IP Address of host over
which that application is being executed
(port number, IP address)
Each TCP connection between two applications is
identified through 4-parameters
Two from source application, two from destination
application
(source port, source IP, destination port, destination IP)
29
TCP Connection Setup
A single TCP connection is full-duplex
Both, client & server can send/receive simultaneously
Connection is established through a three step
process
3-way handshake
1. Client sends request (syn segment)
2. Server acknowledges it and also sends its own syn
segment
3. Client acknowledges server’s syn
Recall the flags in TCP header
SYN, FIN, RESET, PUSH, URG, ACK
30
TCP Connection Setup: cont…
3-way Handshake
J and K are (different) sequence numbers for messages
Sequence numbers need not start at zero
Initial Sequence Number (ISN) is selected randomly
SYN J
Active SYN K Passive
participant participant
ACK J+1
(client) (server)
ACK K+1
31
TCP Syn Segment
32
TCP Syn-Ack Segment
33
TCP Ack Segment
34
Data Transfer over TCP
After establishment of connection, in terms of
communication, there is no discrimination between
client & server
They both are now sender & receiver
(NOTE: we are talking in terms of communication, not in
terms of services)
Sender sends with byte sequence number
Receiver replies with acknowledgment number &
advertised window size
35
Data Transfer over TCP: cont…
Reliability & Flow control
SequenceNum, ACK, AdvertisedWindow
Data(SequenceNum)
Sender Receiver
Acknowledgment
AdvertisedWindow+
36
TCP Connection Termination
Either client or server can initiate connection termination
TCP connection teardown in 4 steps
active close FIN J
passive close
ACK J+1
closes connection
client FIN K server
ACK K+1
37
TCP Connection: (concept)
I am
Talk to
yahoo.com:
yahoo.com: yahoo.com
my-machine port b
port b
I accept
connections
client server
Resulting TCP connection identified by
I will talk to
(my-machine:a, yahoo.com:b)
my-machine:
port a
34
TCP Connection: (implementation)
I am
Talk to
yahoo.com:
yahoo.com: yahoo.com
my-machine port b
port b 1. socket()
2. bind()
4. socket()
5. connect()
I accept
connections
client server 3. listen()
7. send() / sendto()
8. recv() / recvfrom()
6. accept() I will talk to
9. close() / shutdown()
my-machine:
port a
35
Questions ??
36
References
1. http://en.wikipedia.org/wiki/Transmission_Control_
Protocol
37