You are on page 1of 29

Lecture

Data Communication & Networks 13


Transport Layer
(TCP/UDP)

Muhammad Yousaf
Where we are in protocol stack:

application

end-to-end } today’s topic

}
IP
Until now
we have been discussing
data link
the issues related to
lower three layer
physical

myousaf@ymail.com 2
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

myousaf@ymail.com 3
Scope of different layer:
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
Take end host as a single entity
Transport Layer:
We possess multi-tasking computers
For users, each application is different entity
Communicate among different applications on individual hosts across
multiple networks

myousaf@ymail.com 4
Transport Layer:
For communication among applications:
we need another level of addressing
that uniquely distinguish different applications on host
Port numbers are used to achieve this level of
addressing
These are logical port numbers, in contrast to physical
ports
Port number is a 16-bit positive integer value
Theoretically it means, a computer can support
thousands of simultaneous connections! Enough
Transport layer protocols e.g. TCP & UDP provide port
numbers
myousaf@ymail.com 5
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
Can change for client applications in each session
Can range from 1024 to 65536
myousaf@ymail.com 6
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), [www]
For UDP:
Port-69 = TFTP (Trivial FTP)
Port-123 = NTP (Network Time Protocol)
Port-161 = SNMP (Simple Network Management Protocol)
Port-520 = RIP (Routing Information Protocol)

myousaf@ymail.com 7
Transport Layer Services:
Other than application multiplexing, there are two
other types of end-to-end services at transport
layer:
Connectionless Service
Connection-Oriented Service

myousaf@ymail.com 8
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. multimedia, delay-sensitive applications

myousaf@ymail.com 9
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
e.g. file transfer (FTP), emails (SMTP/MIME), HTTP

myousaf@ymail.com 10
Transport Layer Protocols:
Many transport layer protocols are supported by
Internet
User Datagram Protocol (UDP)
Transmission Control Protocol (TCP)
Stream Control Transmission Protocol (SCTP)
Datagram Congestion Control Protocol (DCCP)

myousaf@ymail.com 11
UDP:
UDP = User Datagram Protocol
Defined in RFC-768
There is no notion of connection
You have the data, you send it without checking
whether destination is alive or not
Also, there is no acknowledgment of sent data
In case of error there is no retransmissions

myousaf@ymail.com 12
UDP header:

myousaf@ymail.com 13
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

myousaf@ymail.com 14
TCP:
Transmission Control Protocol
Defined in RFC-793
For sending data:
First establishes connection
Then transfer data
In the end, terminates connection
Provides reliable byte-stream for end-users

myousaf@ymail.com 15
TCP header:

myousaf@ymail.com 16
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
Acknowledgment Number:
Sequence number of next byte expected by the receiver
Used for reliability & flow control
myousaf@ymail.com 17
TCP header fields: cont…
Data Offset:
Number of 32-bit words in the header (header length)
Reserved:
Reserved for future use
TCP Header Flags:
CWR: Congestion Window Reduced indication (*RFC-3168)
ECE: ECN (Explicit Congestion Notification) indication
URG: urgent pointer field is significant
ACK: Acknowledgment field is significant
PSH: Push data from TCP send buffer
RST: Reset connection
SYN: Synchronize, set in connection-request message
FIN: Finish, set in connection close message

myousaf@ymail.com 18
TCP header fields: cont…
Window:
Indicate number of bytes that receiver can receive
Used for flow control
Checksum:
Same as IP & UDP checksum
Urgent Pointer:
Indicate to receiver that some urgent data is coming
Options + Padding:
Optional information if any
e.g. negotiation of maximum segment size

myousaf@ymail.com 19
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 for this connection
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

myousaf@ymail.com 20
TCP connection: cont…
Over Internet each application is identified through
2-parameters
Port Number of application & IP Address over which that
application is being executed
(port number, IP address)
And 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)

myousaf@ymail.com 21
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
Client sends request (syn segment)
Server acknowledges it and also send its own syn
segment
Client acknowledges server’s syn
Recall the flags in TCP header
SYN, FIN, RESET, PUSH, URG, ACK

myousaf@ymail.com 22
TCP connection setup: cont…
3-way Handshake
J and K are (different) sequence numbers for messages
Sequence numbers need not start at zero

SYN J

Active Passive
SYN K
participant participant
ACK J+1 (server)
(client)
ACK K+1

myousaf@ymail.com 23
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

myousaf@ymail.com 24
Data transfer over TCP: cont…
Reliability & Flow control
SequenceNum, ACK, AdvertisedWindow

Data(SequenceNum)

Sender Receiver

Acknowledgment +
AdvertisedWindow

myousaf@ymail.com 25
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

myousaf@ymail.com 26
TCP connection: (concept)

I am
Talk to
mail.yahoo.com,
mail.yahoo.com, mail.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, mail.yahoo.com:b)
my-machine,
port a
myousaf@ymail.com 27
TCP connection: (implementation)

I am
Talk to
mail.yahoo.com,
mail.yahoo.com, mail.yahoo.com
my-machine port b
port b
1. socket()
4. socket() 2. bind()
5. connect()
I accept
connections
client server 3. listen()
7. send() / sendto()
8. recv() / recvfrom() I will talk to
6. accept()
9. close() / shutdown() my-machine,
port a
myousaf@ymail.com 28
To be continued…

myousaf@ymail.com 29

You might also like