Chapter 11
User Datagram Protocol (UDP)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Outline
o Process-to-process communication o User datagram o Checksum o UDP operation o Use of UDP o UDP packet
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-1 Position of UDP in the TCP/IP Protocol Suite
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Introduction
o A transport layer protocol usually has two responsibilities n Create a process-to-process communications
n Provide control mechanism at the transport layer o UDP does this task at a very minimal level o It only provides error control to some extent
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Introduction (Cont.)
o Thus, UDP is a connectionless, unreliable transport protocol n Only add process-to-process to the IP n And perform very limited error checking
o Advantages n UDP is very simple protocol using a minimum of overhead
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.1.1 PROCESS TO PROCESS COMMUNICATION
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Process-to-Process Communication
o Host-to-host communication n Network layer protocol: IP n Deliver the message only to the destination computer o Process-to-process communication n Transport layer protocol: UDP and TCP n Deliver the message to the appropriate process
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-2
UDP Versus IP
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Port Numbers
o Used to define the process o 0~65535 o Well-known port numbers n Some serves needs to be assign a universal port number o However, client’s port number can be defined randomly n Ephemeral port number
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-3
Port Numbers
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-4
IP Addresses Versus Port Numbers
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com IANA Ranges
o The IANA divides the port numbers into three ranges n Well-known: assigned and controlled by IANA o 0~1,023 n Registered: not assigned or controlled by IANA o 1,024~49,151 o Can only be registered with IANA to prevent duplication n Dynamic (or private): neither controlled nor registered o 49152~65535 o Ephemeral ports and can by used by any process
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-5
IANA Ranges
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Well-Known Ports for 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 Return the data and the time 17 Quote Returns a quote of a day 19 Chargen Return 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
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Well-Known Ports for UDP (Cont.)
Port Protocol Description 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)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Socket Addresses
o UDP needs two identifiers n The IP address n The port number
o Socket address n The combination of an IP address and a port number
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-6
Socket Addresses
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.2.2 USER DATAGRAM
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com User Datagram
o UDP packets: called user datagrams n Have a fixed-size header of 8 bytes o The fields are n Source port number: 16-bits: 0~65535 o Usually chosen by the UDP software n Destination port number: 16-bits: 0~65535 n Length: 16 bits: o Total length (header plus data) of the user datagram o Minimum length must be 8 bytes (contains only header) n Checksum: 16 bits o Detect errors over the entire user datagram (header plus data)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-7
User Datagram Format
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com User Datagram (Cont.)
o However, the UDP length can also be derived from the IP header n UDP length = IP length – IP header’s length o Thus, theoretically, the length field in a UDP datagram is not necessary n However, it is more efficient to derive the length of a UDP packet by the UDP package itself o Ask the IP layer is time consuming
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com UDUDPP lelennggtthh == IIPP lelennggtthh -- IIPP hheeadaderer’’ss lelennggthth
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.3.3
CHECKSUM
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Checksum
o UDP checksum calculation is different from the one for IP and ICMP o The checksum includes three sections n The Pseudoheader o However, it will not appear in the UDP datagram n The UDP header n The data coming from the application layer
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Pseudoheader
o Some part of the header of the IP packet n With some fields are filled with 0s o Fields n Source and destination IP address o To prevent that UDP datagram is correct but IP header is corrupted and be delivered to the wrong host n Protocol o To prevent the packet to deliver to the TCP o UDP has the value of 17
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com PseudoheaderAdded to the UDP Datagram
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Checksum Calculation at Sender
o Add the pseudoheaderto the UDP datagram o Fill the checksum field with zeros o Divide the total bits into 16-bits words o If the total number of bytes is not even n Add 1 byte of padding (all 0s) o Add all 16-bit section using one’s complement arithmetic o Complement the result and insert it in the checksum field o Drop the pesudoheaderand any added padding o Deliver the UDP datagram to the IP software
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Checksum Calculation at Receiver
o Add the pseudoheaderto the UDP user datagram o Add padding if needed o Divide the total bits into 16-bit sections o Add all 16-bit sections using one’s complement arithmetic o Complement the result o If the result is all 0s n Drop the pseudoheaderand any added padding n Accept the user datagram o Otherwise n Discard the user datagram
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-9 Checksum Calculation of a Simple UDP User Datagram
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Optional Use of the Checksum
o The calculation of the checksum in UDP is optional
o If the checksum is not calculated n The field is filled with 0s
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.4.4 UDP OPERATION
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com UDP Operation
o Connectionless Services
o Flow and Error Control
o Encapsulation and Decapsulation
o Queuing
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Connectionless Services
o Each user datagram is an independent datagram n Even coming from the same source process o The user datagram is not numbered
o No connection establishment and no connection termination
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Flow and Error Control
o No flow control n The receiver may overflow with incoming messages
o No error control except for the checksum n The sender does not know if a message has been lost or duplicated
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-10
Encapsulation and Decapsulation
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-11
Queues in UDP
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-12
Multiplexing and Demultiplexing
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.5.5 USE OF UDP
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Uses of UDP
o For a process that require simple request-response communication with little concern for flow and error control o For a process with internal flow and error-control n TFTP (Trivial File Transfer Protocol) o For muticastingand broadcasting n Embedded in UDP but not in the TCP software o For some management processes o For some route updating protocol n RIP (Routing Information Protocol)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com 1111.6.6 UDP PACKAGE
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com UDP Package
o Five components n A control-block table n Input queues n A control-block module n An input module n An output module
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Figure 11-13 UDP Package
The McGraw-Hill Companies, Inc., 2000 PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Control-Block Table
o Keep track of the open ports
o Eachentry has a minimum of four fields n State: FREE or IN-USE n Process ID n Port number n Corresponding queue number
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Input Queues
o A set of input queues n One for each process
o In the book’s design n They do not use output queues
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Control-Block Module
o Manage the control-block table o Pseudo code n Receive: a process ID and a port number n Search the control block table for a FREE entry o If (not found) n Delete an entry using a predefined strategy o Create a new entry with the state IN-USE o Enter the process ID and the port number n Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Input Module
o Receive: a user datagram from IP o Look for the corresponding entry in the control- block table n If (found) o Check the queue field to see if a queue is allocated o If (no) n Allocate a queue o Enqueuethe data in the corresponding queue n If (not found) o Ask the ICMP module to send an “unreachable port” message o Discard the user datagram o Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Output Module
o Receive: data and information from a process o Create a UDP data datagram o Send the user datagram o Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Example: Control-Block Table at the Beginning
State Process ID Port Number Queue Number ------IN-USE2,34552,01034 IN-USE3,42252,011 FREE IN-USE4,65252,01238 FREE
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com EExaxammpplele 11
o The first activity is the arrival of a user datagram with destination port number 52,012 o The input module searches for this port number and finds it o Queue number 38 has been assigned to this port n The port has been previously used o The input module sends the data to queue 38 o The control-block table does not change
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com EExaxammpplele 22
o After a few seconds, a process starts o It asks the operating system for a port number and is granted port number 52,014 o Now the process sends its ID (4,978) and the port number to the control-block module to create an entry in the table o The module does not allocate a queue at this moment n because no user datagram have arrived for this destination
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Modified Table After Example 2
State Process ID Port Number Queue Number ------IN-USE2,34552,01034 IN-USE3,42252,011 IN-USE4,97852,014 IN-USE4,65252,01238 FREE
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com EExaxammpplele 33
o A user datagram now arrives for port 52,011 o The input module checks the table and finds that no queue has been allocated for this destination n This is the first time a user datagram has arrived for this destination o The module creates a queue and gives it a number (43)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com Modified Table After Example 3
State Process ID Port Number Queue Number ------IN-USE2,34552,01034 IN-USE3,42252,01143 IN-USE4,97852,014 IN-USE4,65252,01238 FREE
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com EExaxammpplele 44
o After a few seconds, a user datagram arrives for port 52,222 o The input module checks the table n Cannot find the entry for this destination o The user datagram is dropped o A request is made to ICMP to send an “unreachable port” message to the source
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com EExaxammpplele 55
o After a few seconds, a process needs to send a user datagram n It delivers the data to the output module which adds the UDP header and sends it
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com