1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept....

39
1 Chapter 11 Chapter 11 User Datagram User Datagram Protocol Protocol (UDP) (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering [email protected]

Transcript of 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept....

Page 1: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

11

Chapter 11Chapter 11 User Datagram Protocol User Datagram Protocol (UDP) (UDP)

Mi-Jung Choi

Dept. of Computer Science and Engineering

[email protected]

Page 2: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

22

11.1 PROCESS-TO-PROCESS COMMUNICATION

11.2 USER DATAGRAM

11.3 CHECKSUM

11.4 UDP OPERATION

11.5 USE OF UDP

11.6 UDP PACKAGE

Contents Contents

Page 3: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

33

Objectives Objectives

Be able to explain process-to-process communication

Know the format of a UDP user datagram

Be able to calculate a UDP checksum

Understand the operation of UDP

Know when it is appropriate to use UDP

Understand the modules in a UDP package

Page 4: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

44

Position of UDP in TCP/IP Position of UDP in TCP/IP

Page 5: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

55

UDP protocol dutiesUDP protocol duties

To create a process-to-process communication: UDP port number

Error control to some extent

If UDP detects an error in the received packet, it silently drops it

No flow control and no acknowledgement for received data

Connectionless, unreliable transport protocol

A very simple protocol using minimum overhead

The disadvantages come some advantages

Sending a small messages b/w UDP

Page 6: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

66

11.1 PROCESS-TO-PROCESS COMMUNICATION11.1 PROCESS-TO-PROCESS COMMUNICATION

Before we examine UDP, we must first understand host-to-host Before we examine UDP, we must first understand host-to-host

communication and process-to-process communication and the communication and process-to-process communication and the

difference between them.difference between them.

The topics discussed in this section include:The topics discussed in this section include:

Port NumbersPort Numbers

Socket AddressesSocket Addresses

Page 7: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

77

11.1 PROCESS-TO-PROCESS COMMUNICATION11.1 PROCESS-TO-PROCESS COMMUNICATION

Page 8: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

88

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

Prot Number

Process-to-process communication: client-server paradigm

Both process (client and server) have the same name Daytime client process / daytime server

Today OS supports multi-user and multi-processors A remote computer can run several server programs at same time A local computer can run several client programs at same time

For communication, we must define the

local host

local process

remote host

remote process

Page 9: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

99

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

Port number for process communication

Local host and remote host: IP address

Process: port number

Range of port number : integer b/w 0 ~ 65,535 well-known port number (1 ~ 1023) registered port (1,024 ~ 49,151) ephemeral port number(49,152 ~ 65,535)

Page 10: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1010

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

IP address vs. port number

Page 11: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1111

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

IANA(Internet Assigned Numbers Authority) range

Well-known port: 0 ~ 1,023

Registered port: 1,024 ~ 49,151

Ephemeral port number(dynamic port): 49,152 ~ 65,535

Page 12: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1212

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

Well-known port in UDP

Port Protocol Description

7 Echo Echoes a received datagram back to the sender

9 Discard Discards any datagram that is received

11 Users Active users

13 Daytime Returns the date and the time

17 Quote Returns a quote of the day

19 Chargen Returns a string of characters

53 Nameserver Domain Name Service

67 Bootps Server port to download bootstrap information

68 Bootpc Client port to download bootstrap information

69 TFTP Trivial File transfer Protocol

111 RPC Remote Procedure Call

123 NTP Network Time Protocol

161 SNMP Simple Network Management Protocol

162 SNMP Simple Network Management Protocol (trap)

Page 13: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1313

In UNIX, the well-known ports are stored in a file called /etc/services. Each line in this file gives the name of the server and the well-known port number. We can use the grep utility to extract the line corresponding to the desired application. The following shows the port for TFTP. Note TFTP can use port 69 on either UDP or TCP.

See Next Slide

$ grep tftp /etc/services tftp 69/tcp tftp 69/udp

Example 1Example 1

Page 14: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1414

SNMP uses two port numbers (161 and 162), each for a different purpose, as we will see in Chapter 21

$ grep snmp /etc/services snmp 161/tcp #Simple Net Mgmt Proto snmp 161/udp #Simple Net Mgmt Proto snmptrap 162/udp #Traps for SNMP

Example 1 Example 1 (cont.)(cont.)

Page 15: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1515

11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)11.1 PROCESS-TO-PROCESS COMMUNICATION (cont.)

Socket Address

Combination of IP address and port number

Page 16: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1616

11.2 USER DATAGRAM11.2 USER DATAGRAM

UDP packets are called user datagrams and have a fixed-size header of UDP packets are called user datagrams and have a fixed-size header of 8 8

bytesbytes..

UDP length = IP length − IP header’s length

Page 17: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1717

11.2 USER DATAGRAM11.2 USER DATAGRAM Format

source port number

destination port number

length : header + data (0~65,535)

checksum : to detect error for entire user datagram (Pseudoheader + header + data)

Page 18: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1818

UDP checksum calculation is different from the one for IP and ICMP. UDP checksum calculation is different from the one for IP and ICMP. Here the checksum includes three sections: a pseudoheader, the UDHere the checksum includes three sections: a pseudoheader, the UDP header, and the data coming from the application layer.P header, and the data coming from the application layer.

The topics discussed in this section include:The topics discussed in this section include:

Checksum Calculation at SenderChecksum Calculation at SenderChecksum Calculation at ReceiverChecksum Calculation at ReceiverOptional Use of the ChecksumOptional Use of the Checksum

11.3 CHECKSUM11.3 CHECKSUM

Page 19: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

1919

11.3 Checksum (cont.)11.3 Checksum (cont.)

Pseudoheader added to UDP header

Page 20: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2020

11.3 Checksum (cont.)11.3 Checksum (cont.)

Checksum calculation at receiver

Add the peudoheader to UDP user datagram

Fill the checksum field with 0s

Divide the total bits into 16-bit (2 bytes) sections

If the total number of bytes is not even, add 1 byte of padding (all 0s). The padding is only for the purpose of calculating the checksum and will be discarded afterwards.

Add all 16-bit sections using one’s complement arithmetic

Complement the result, which is a 16-bit number, and insert in the checksum field

Drop the peudoheader and any added padding

Deliver the user datagram to the IP layer for encapsulation

Page 21: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2121

11.3 Checksum (cont.)11.3 Checksum (cont.)

Checksum calculation of a UDP user datagram

Page 22: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2222

11.3 Checksum (cont.)11.3 Checksum (cont.)

Checksum calculation at receiver

Add the peudoheader to UDP user datagram

Add padding if needed

Divide the total bits into 16-bit (2 bytes) sections

Add all 16-bit sections using one’s complement arithmetic

Complement the result

If the result is all 0s, drop the peudoheader and any added padding and accept the user datagram. If the result anything else, discard the user datagram

Page 23: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2323

UDP uses concepts common to the transport layer. These concepts UDP uses concepts common to the transport layer. These concepts will be discussed here briefly, and then expanded in the next will be discussed here briefly, and then expanded in the next chapter on the TCP protocol.chapter on the TCP protocol.

The topics discussed in this section include:The topics discussed in this section include:

Connectionless ServicesConnectionless ServicesFlow and Error ControlFlow and Error ControlEncapsulation and DecapsulationEncapsulation and DecapsulationQueuingQueuingMultiplexing and DemultiplexingMultiplexing and Demultiplexing

11.4 UDP OPERATION11.4 UDP OPERATION

Page 24: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2424

11.4 UDP OPERATION11.4 UDP OPERATION

Connectionless services

No flow control and a simple error check

Encapsulation and Decapsulation

Page 25: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2525

11.4 UDP OPERATION (cont.)11.4 UDP OPERATION (cont.)

Queuing of UDP

A client site, when a process starts, some implements create both an incoming and outgoing queue associated with each process identified by ephemeral port number.

When process terminates, the queues are destroyed.

If an outgoing queue is overflow, the OS ask the client process to wait before sending any more messages.

When message arrived for a client, UDP checks to have been created an incoming queue for the port number of arrived user datagram. If there is no such incoming queue, UDP discard the user datagram, ask the ICMP to send a port unreachable message to the server.

Page 26: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2626

11.4 UDP OPERATION (cont.)11.4 UDP OPERATION (cont.)

Queues in UDP

Page 27: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2727

UDP vs. TCP communicationUDP vs. TCP communication

응용 응용 응용 응용

TCP송신버퍼

TCP수신버퍼

segmentsegment segmentsegment

응용 응용 응용 응용

UDP역다중화

datagramdatagram dtatgramdatagram

UDP다중화

Page 28: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2828

11.4 UDP OPERATION (cont.)11.4 UDP OPERATION (cont.)

Multiplexing and Demultiplexing

Page 29: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

2929

11.5 USE OF UDP11.5 USE OF UDP

A simple request-response communication with little concern for

flow and error control (not to send bulk data: ftp…)

A process with internal flow and error control mechanism.

Transport protocol for multicasting and broadcasting.

For management process such as SNMP

For some route updating protocols such as RIP (Routing Information

Protocol)

Page 30: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3030

11.6 UDP PACKAGE11.6 UDP PACKAGE

To show how UDP handles the sending and receiving of UDP packets, we To show how UDP handles the sending and receiving of UDP packets, we

present a simple version of the UDP package. The UDP package involves five present a simple version of the UDP package. The UDP package involves five

components: a control-block table, input queues, a control-block module, an input components: a control-block table, input queues, a control-block module, an input

module, and an output module.module, and an output module.

The topics discussed in this section include:The topics discussed in this section include:

Control-Block Table

Input queue

Control-block module

Input module

Output module

Page 31: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3131

11.6 UDP PACKAGE (cont.)11.6 UDP PACKAGE (cont.)

UDP design

Page 32: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3232

11.6 UDP PACKAGE (cont.)11.6 UDP PACKAGE (cont.)

StateState Process IDProcess ID Port NumberPort Number Queue NumberQueue Number

---------------- ------------------------ ---------------------------- ------------------------------------

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Control Block Table

Table to keep track of open ports

Table entries (state, process ID, port number, queue number)

Input Queue

One for each process

Page 33: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3333

11.6 UDP PACKAGE (cont.)11.6 UDP PACKAGE (cont.)

Control-Block Module

Management of the control block table

When process starts, it asks for a port number from the OS

OS assigns well-know port numbers to server and ephemeral port numbers to client

The process passes the process ID and port number to the control block module to create an entry in the table for the process

Algorithm

Receive: a process ID and a port number.

1. Search the control block table for a FREE entry.

1. If (not found)

1. Delete an entry using a predefined strategy.

2. Create a new entry with the state IN-USE.

3. Enter the process ID and the port number.

2. Return

Page 34: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3434

11.6 UDP PACKAGE (cont.)11.6 UDP PACKAGE (cont.) Input Module

It receives a user datagram from IP layer

It searches the control block table to find same port number as this user datagram If the entry is found, the module uses the information in the entry to enqueue the data in

the corresponding queue If the entry is not found, it generates an ICMP message

Algorithm

Receive: a user datagram from IP1. Look for the corresponding entry in the control-block table.

1. If (found)

1. Check the queue field to see if a queue is allocated.

1. If (no)

1. Allocate a queue.

2. Enqueue the data in the corresponding queue.

2. If (not found)

1. Ask the ICMP module to send an “unreachable port” message.

2. Discard the user datagram.

2. Return

Page 35: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3535

11.6 UDP PACKAGE (cont.)11.6 UDP PACKAGE (cont.)

Output module

Responsible for creating and sending user datagram

AlgorithmReceive: data and information from a process

1. Create a UDP user datagram.

2. Send the user datagram.

3. Return.

Page 36: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3636

Control-block table at the beginning

Example 2

The first activity is the arrival of a user datagram with destination port number 52,012. The input module searches for this port number and finds it. Queue number 38 has been assigned to this port, which means that the port has been previously used. The input module sends the data to queue 38. The control-block table does not change.

Example 2Example 2

StateState Process IDProcess ID Port NumberPort Number Queue NumberQueue Number

---------------- ------------------------ ---------------------------- ------------------------------------

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Page 37: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3737

Example 3Example 3

After a few seconds, a process starts. It asks the operating system for a port nu

mber and is granted port number 52,014. Now the process sends its ID (4,978)

and the port number to the control-block module to create an entry in the ta

ble. The module does not allocate a queue at this moment because no user

datagrams have arrived for this destination

StateState Process IDProcess ID Port NumberPort Number Queue NumberQueue Number

---------------- ------------------------ ---------------------------- ------------------------------------

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

IN-USE 4,978 52,014

IN-USE 4,652 52,012 38

FREE

Page 38: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3838

Example 4Example 4

A user datagram now arrives for port 52,011. The input module checks the

table and finds that no queue has been allocated for this destination since

this is the first time a user datagram has arrived for this destination. The

module creates a queue and gives it a number (43).

StateState Process IDProcess ID Port NumberPort Number Queue NumberQueue Number

---------------- ------------------------ ---------------------------- ------------------------------------

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011 43

IN-USE 4,978 52,014

IN-USE 4,652 52,012 38

FREE

Page 39: 1 Chapter 11 User Datagram Protocol (UDP) Chapter 11 User Datagram Protocol (UDP) Mi-Jung Choi Dept. of Computer Science and Engineering mjchoi@postech.ac.kr.

3939

Examples 5 & 6 Examples 5 & 6

Example 5: After a few seconds, a user datagram arrives for port 52,222.

The input module checks the table and cannot find the entry for this

destination. The user datagram is dropped and a request is made to

ICMP to send an “unreachable port” message to the source.

Example 6: After a few seconds, a process needs to send a user

datagram. It delivers the data to the output module which adds the UDP

header and sends it.