0% found this document useful (0 votes)
76 views

Lecture_07_CN214 Transport Layer UDP

Uploaded by

hashimalmusalam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Lecture_07_CN214 Transport Layer UDP

Uploaded by

hashimalmusalam
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

CN214 Ch.

Transport Layer: UDP


Lecture 7
M.M. Hafizur Rahman

Office: 1186, CCSIT, KFU


Email: [email protected]
Computer Networking: A Top-
Down Approach

Computer Networks and the


Internet
Application Layer
Transport Layer
Network Layer
Data Link Layer
Physical Layer

CCSIT/KFU Transport Layer 2


Transport Layer Goals
Understand principles behind transport layer
services:
Multiplexing (MUX) & Demultiplexing (DEMUX)
Reliable Data Transfer
Transport Layer Protocols
UDP: Connectionless unreliable transport
TCP: Connection-oriented reliable transport
 Flow Control
 Congestion Control
CCSIT/KFU Transport Layer 3
Outline
Transport-layer services
Multiplexing and demultiplexing
Connectionless Transport: UDP
Principles of Reliable Data Transfer (RDT)
Connection-oriented Transport: TCP
Principles of congestion control
TCP congestion control

CCSIT/KFU Transport Layer 4


Transport Layer Services
The transport layer is located between the network layer and the
application layer. It receives services from the network layer. It is
responsible for providing services to the application layer.
Network layer is the logical communication between hosts, whereas
transport layer provides logical communication between processes.
Relies on, enhances, the network layer services

CCSIT/KFU Transport Layer 5


Transport Layer Services
Provide logical communication application
transport
network
between application processes mobile network
data link
physical
national or global ISP
running on different hosts

log
Transport protocols actions in

ica
end systems:

le
n d-
Sender: breaks application

e nd
local or
messages into segments,

tra
regional ISP

nsp
passes to network layer

ort
home network content
Receiver: reassembles provider
network datacenter
segments into messages, application
transport
network

passes to application layer network


data link
physical
Two Transport protocols
enterprise
available to Internet network
applications
UDP & TCP
CCSIT/KFU Transport Layer 6
Transport Layer Action

Sender:
Sender:
application  is passed an application- app. msg
application
layer message
TThtranspor
app. msg
transport  determines segment h

header fields values t


network
network (IP)  creates segment
(IP)
link
link  passes segment to IP
physical physical

CCSIT/KFU Transport Layer 7


Transport Layer Action
Receiver:
Receiver:
application  receives segment from IP application
 checks header values
app. msg
transport  extracts application-layer transport
message
network (IP)  demultiplexes message up network
to application via socket (IP)
link
link
physical physical
Th app. msg

CCSIT/KFU Transport Layer 8


Transport Layer vs. Network Layer

Al Hasa Riyad

Postal-service
Ahmed mail carrier Mohammed
 Ahmed & Mohammed - responsible
for mail collection, distribution, and  Postal service – carries the mails from
communicating with postal service house to house
9
CCSIT/KFU Transport Layer 9
Transport Layer vs. Network Layer

hosts (also called end systems) = ?


processes = ?
application messages = ?
network layer protocol = ?
transport layer protocol = ?

10
CCSIT/KFU Transport Layer 10
Transport Layer vs. Network Layer
Their services are constrained by the possible
services that the postal service provides
•T
hosts (also called end systems) = houses
processes = cousins
application messages = letters in envelope
transport layer protocol = Ahmed & Mohammed
network layer protocol = postal service (including mail
persons)
It may so happen that their uncles
could get sick, and so other people
may take over – analogously, the
computer network may provide
multiple transport protocols
Transport Layer
11
CCSIT/KFU 11
Two Transport Layer Protocol
 TCP: Transmission Control application
transport
network
mobile network
Protocol data link
physical
national or global ISP
• Reliable, in-order delivery

log
• Congestion control

ica
le
• Flow control

n d-
e nd
• Connection setup local or

tra
regional ISP
 UDP: User Datagram Protocol

nsp
ort
• Unreliable, unordered delivery home network content
provider
• No-frills extension of “best- network
application
datacenter
network
transport
effort” IP network
data link

 Services not available: physical

enterprise
• Delay guarantees network

• Bandwidth guarantees
CCSIT/KFU Transport Layer 12
Transport Protocol Services
TCP Services
Reliable transport between sending and receiving process
Connection-oriented: setup required between client and server
processes
Flow control: sender won’t overwhelm receiver
Congestion control: throttle sender when network overloaded
Does not provide timing, minimum throughput guarantee,
security
UDP Services
Unreliable data transfer between sending and receiving process
Does not provide reliability, flow control, congestion control,
timing, throughput guarantee, security, or connection setup
It is a faster and connectionless protocol
CCSIT/KFU Transport Layer 13
HTTP server
client
application application
HTTP
msg
transport

transport network transport


network link network
link physical link
physical physical
HTTP server
client
application application
HTTP
msg
Ht HTTP
transport
msg
transport network transport
network link network
link physical link
physical physical
HTTP server
client
application application
HTTP
msg
Ht HTTP
transport
msg
Hnetwork
n Ht HTTP
transport transport
msg
network link network
link physical link
physical physical
HTTP server
client
application application

transport

transport network transport


network link network
link physical link
physical physical

Hn Ht HTTP
msg
User Datagram Protocol (UDP)
“No frills,” “bare bones” Internet transport
protocol
“Best effort” service, UDP segments may be:
Lost
Delivered out-of-order to application
Connectionless:
No handshaking between UDP sender & receiver
Each UDP segment handled independently of others

CCSIT/KFU Transport Layer 18


Why is there a UDP?
No connection establishment (which can add
RTT delay)
Simple: No connection state at sender &
receiver
Small header size (TCP: 20 B & UDP: 8 B)
No congestion control
UDP can blast away as fast as desired!
Can function in the face of congestion

CCSIT/KFU Transport Layer 19


UDP
UDP use:
Streaming multimedia apps (loss tolerant, rate sensitive)
DNS
SNMP
HTTP/3
If reliable transfer needed over UDP (e.g.,
HTTP/3):
Add needed reliability at application layer
Add congestion control at application layer
CCSIT/KFU Transport Layer 20
UDP: Transport Layer Action

SNMP client SNMP server

application application

transport transport
(UDP) (UDP)

network (IP) network


(IP)
link
link
physical physical

CCSIT/KFU Transport Layer 21


UDP: Transport Layer Action

UDP sender actions: SNMP server


SNMP client  is passed an application-
application layer message SNMP msg
application
 determines UDP transpor
transport UDP
UDPh h SNMP msg

(UDP)
segment header fields t
values (UDP)
network
network (IP)
link
 creates UDP segment (IP)
link
 passes segment to IP physical
physical

CCSIT/KFU Transport Layer 22


UDP: Transport Layer Action

UDP receiver actions:


SNMP client  receives segment from IP SNMP server

application  checks UDP checksum application


header value transpor
transport
SNMP msg
(UDP)  extracts application-layer t
message (UDP)
network
UDP h SNMP (IP)
network msg
 demultiplexes message up (IP)
link
link
to application via socket physical
physical

CCSIT/KFU Transport Layer 23


UDP Segment Header
32 bits Source Port #: 2 B
Dest. Port #: 2 B
source port # dest port # Length: 2 B
length checksum Checksum: 2B
Header Length: 8 B

application
length, in bytes of
data
UDP segment,
(payload) including header

data to/from
UDP segment format application layer

CCSIT/KFU Transport Layer 24


UDP Checksum
Goal: detect errors (i.e., flipped bits) in transmitted
segment
1st number 2nd number sum

Transmitted: 5 6 11

Received: 4 6 11

receiver-computed
checksum
= sender-computed
checksum (as received)

CCSIT/KFU Transport Layer 25


UDP Checksum
Goal: detect errors (i.e., flipped bits) in transmitted
segment
Sender
Treat contents of UDP segment (including UDP header fields and IP
addresses) as sequence of 16-bit integers
Checksum: addition (one’s complement sum) of segment content
Checksum value put into UDP checksum field
Receiver
Compute checksum of received segment
Check if computed checksum equals checksum field value:
Not equal - error detected
Equal - no error detected. But maybe errors, nonetheless? More
later ….
CCSIT/KFU Transport Layer 26
An Example of Checksum
Example: Add two 16-bit integers
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1

sum 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1

Note: when adding numbers, a carryout from the most


significant bit needs to be added to the result

CCSIT/KFU Transport Layer 27


Checksum: Weak Protection

Example: Add two 16-bit integers


0 1
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1

sum 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
Even though
numbers have
changed (bit
flips), no change
in checksum!
CCSIT/KFU Transport Layer 28
Checksum: Example
Suppose our data is a list of five 4-bit numbers that we want to
send to a destination. In addition to sending these numbers, we
send the sum of the numbers. For example, if the set of numbers is
(7, 11, 12, 0, 6), we send (7 , 11 , 1 2 , 0 , 6 , 3 6 ) , where 36 is the
sum of the original numbers. The receiver adds the five numbers
and compares the result with the sum. If the two are the same, the
receiver assumes no error, accepts the five numbers, and discards
the sum. Otherwise, there is an error somewhere and the data are
not accepted.
We can make the job of the receiver easier if we send the
negative (complement) of the sum, called the checksum. In
this case, we send (7, 11, 12, 0, 6, −36). The receiver can add
all the numbers received (including the checksum). If the
result is 0, it assumes no error;
CCSIT/KFU otherwise,
Transport Layer there is an error. 29
Example (1’s Complement)
Q1: How can we represent the number 21 in one’s
complement arithmetic using only four bits?
Solution: The number 21 in binary is 10101 (it needs five bits).
We can wrap the leftmost bit and add it to the four rightmost
bits. We have (0101 + 1) = 0110 or 6.
Q2: How can we represent the number −6 in one’s
complement arithmetic using only four bits?
Solution: In one’s complement arithmetic, the negative or
complement of a number is found by inverting all bits. Positive
6 is 0110; negative 6 is 1001. If we consider only unsigned
numbers, this is 9. In other words, the complement of 6 is 9.
Another way to find the complement of a number in one’s
complement arithmetic is to subtract the number from 2n − 1
(16 − 1 in this case).
CCSIT/KFU Transport Layer 30
Example
Let us redo Exercise 10.19 using one’s complement
arithmetic. Figure 10.24 shows the process at the sender
and at the receiver. The sender initializes the checksum to
0 and adds all data items and the checksum (the checksum
is considered as one data item and is shown in color). The
result is 36. However, 36 cannot be expressed in 4 bits.
The extra two bits are wrapped and added with the sum to
create the wrapped sum value 6. In the figure, we have
shown the details in binary. The sum is then
complemented, resulting in the checksum value 9 (15 − 6
= 9). The sender now sends six data items to the receiver
including the checksum 9.
CCSIT/KFU Transport Layer 31
Example (Cont’d)
The receiver follows the same procedure as the sender. It
adds all data items (including the checksum); the result is
45. The sum is wrapped and becomes 15. The wrapped
sum is complemented and becomes 0. Since the value of
the checksum is 0, this means that the data is not
corrupted. The receiver drops the checksum and keeps the
other data items. If the checksum is not zero, the entire
packet is dropped.

CCSIT/KFU Transport Layer 32


Example

CCSIT/KFU Transport Layer 33


Note

Sender site: Receiver site:


1. The message is divided into 1. The message (including
16-bit words. checksum) is divided into 16-
2. The value of the checksum bit words.
word is set to 0. 2. All words are added using
3. All words including the one’s complement addition.
checksum are added using 3. The sum is complemented
one’s complement addition. and becomes the new
4. The sum is complemented checksum.
and becomes the checksum. 4. If the value of checksum is
5. The checksum is sent with 0, the message is accepted;
the data. otherwise, it is rejected.

CCSIT/KFU Transport Layer 34


… a Series of Numbers …
Q1: Calculate the checksum for a series of 6
Numbers. AB2379)h

Q2:Calculate the checksum for a series of


binary Numbers ………………

CCSIT/KFU Transport Layer 35


CCSIT/KFU Transport Layer 36
Example
Let us calculate the checksum for a text of 8 characters
(“Forouzan”). The text needs to be divided into 2-byte (16-
bit) words. We use ASCII (see Appendix A) to change each
byte to a 2-digit hexadecimal number. For example, F is
represented as and o is represented as . Figure 10.25 shows
how the checksum is calculated at the sender and receiver
sites. In part a of the figure, the value of partial sum for the
first column is 0x36. We keep the rightmost digit (6) and
insert the leftmost digit (3) as the carry in the second
column. The process is repeated for each column. Note that
if there is any corruption, the checksum recalculated by the
receiver is not all 0s. We leave this an exercise.

CCSIT/KFU Transport Layer 37


Example

CCSIT/KFU Transport Layer 38


CCSITKFU

CCSIT/KFU Transport Layer 39


Summary: UDP
“No frills” protocol:
Segments may be lost, delivered out of order
Best effort service: send and hope for the best

UDP has its plusses:


No setup/handshaking needed (no RTT incurred)
Can function when network service is compromised
Helps with reliability (checksum)

Build additional functionality on top of UDP in


application layer (e.g., HTTP/3)

CCSIT/KFU Transport Layer 40


MUX & DEMUX

CCSIT/KFU Transport Layer 41


HTTP server
client1 client2
P-client1 P-client2 application
application

transport

transport network transport


network link network
link physical link
physical physical
MUX & DEMUX
multiplexing at sender: demultiplexing at receiver:
handle data from multiple use header info to deliver
sockets, add transport header received segments to correct
(later used for demultiplexing) socket

application

application P1 P2 application socket


P3 transport P4
process
transport network transport
network link network
link physical link
physical physical

CCSIT/KFU Transport Layer 43


How DEMUX Works?
Host receives IP datagrams
Each datagram has source IP 32 bits
address, destination IP address source port # dest port #
Each datagram carries one
transport-layer segment other header fields
Each segment has source,
destination port number application
Host uses IP addresses & data
(payload)
port numbers to direct
segment to appropriate TCP/UDP segment format
socket
CCSIT/KFU Transport Layer 44
Connectionless DEMUX
Recall: when receiving host receives
 when creating socket, must UDP segment:
• checks destination port # in
specify host-local port #: segment
DatagramSocket mySocket1 • directs UDP segment to socket
= new DatagramSocket(12534);
with that port #

 when creating datagram to send


into UDP socket, must specify
• destination IP address
• destination port # IP/UDP datagrams with same dest. port
#, but different source IP addresses
and/or source port numbers will be
directed to same socket at receiving
host
CCSIT/KFU Transport Layer 45
Example: Connectionless Demux
DatagramSocket
serverSocket = new
DatagramSocket DatagramSocket DatagramSocket
mySocket2 = new (6428); mySocket1 = new
DatagramSocket DatagramSocket
(9157); (5775);
application
application P1 application
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical

source port: 6428 source port: ?


dest port: 9157 dest port: ?

source port: 9157 source port: ?


dest port: 6428 dest port: ?

CCSIT/KFU Transport Layer 46


Connection Oriented DEMUX
TCP socket identified by 4-tuple:
Source IP address
Source port number
Destination IP address
Destination port number
DEMUX: receiver uses all four values (4-tuple) to
direct segment to appropriate socket
Server may support many simultaneous TCP sockets:
Each socket identified by its own 4-tuple
Each socket associated with a different connecting client
CCSIT/KFU Transport Layer 47
Ex. of Connection Oriented DEMUX
application
application P4 P5 P6 application
P1 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: physical
IP
address
B
host: IP source IP,port: B,80 host: IP
address dest IP,port: A,9157 source IP,port: C,5775 address
A dest IP,port: B,80 C
source IP,port: A,9157
dest IP, port: B,80
source IP,port: C,9157
dest IP,port: B,80
Three segments, all destined to IP address: B,
dest port: 80 are demultiplexed to different sockets
CCSIT/KFU Transport Layer 48
Summary
Multiplexing, demultiplexing: based on
segment, datagram header field values
UDP: Demultiplexing using destination port
number (only)
TCP: Demultiplexing using 4-tuple: source and
destination IP addresses, and port numbers
Multiplexing/demultiplexing happen at all
layers

CCSIT/KFU Transport Layer 49

You might also like