Upload
lamtruc
View
228
Download
0
Embed Size (px)
Citation preview
Chapter 11
User Datagram Protocol (UDP)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Outlineo Process-to-process communicationo User datagramo Checksumo UDP operationo Use of UDPo 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
Introductiono A transport layer protocol usually has two
responsibilitiesn Create a process-to-process communications
n Provide control mechanism at the transport layero UDP does this task at a very minimal levelo 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 protocoln Only add process-to-process to the IPn And perform very limited error checking
o Advantagesn UDP is very simple protocol using a minimum of
overhead
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
PROCESS TO
PROCESSCOMMUNICATION
11.111.1
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Process-to-Process Communicationo Host-to-host communicationn Network layer protocol: IPn Deliver the message only to the destination
computero Process-to-process communicationn Transport layer protocol: UDP and TCPn 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 Numberso Used to define the processo 0~65535o Well-known port numbersn Some serves needs to be assign a universal port
numbero However, client’s port number can be defined
randomlyn 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 Rangeso The IANA divides the port numbers into three ranges
n Well-known: assigned and controlled by IANAo 0~1,023
n Registered: not assigned or controlled by IANAo 1,024~49,151o Can only be registered with IANA to prevent duplication
n Dynamic (or private): neither controlled nor registeredo 49152~65535o 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
Server port to download bootstrap informationBootps67Domain Name ServiceNameserver53
Client port to download bootstrap informationBootpc68
Return a string of charactersChargen19Returns a quote of a dayQuote 17Return the data and the timeDaytime13Active usersUsers11Discards any datagram that is receivedDiscard9Echoes a received datagram back to the senderEcho7DescriptionProtocolPort
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Well-Known Ports for UDP (Cont.)
Simple Network Management Protocol (trap)SNMP162Simple Network Management ProtocolSNMP161Network Time ProtocolNTP 123Remote Procedure CallRPC111Trivial File Transfer ProtocolTFTP69DescriptionProtocolPort
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Socket Addresseso UDP needs two identifiersn The IP addressn The port number
o Socket addressn 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
USER DATAGRAM
11.211.2
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
User Datagramo UDP packets: called user datagrams
n Have a fixed-size header of 8 byteso The fields are
n Source port number: 16-bits: 0~65535o Usually chosen by the UDP software
n Destination port number: 16-bits: 0~65535n Length: 16 bits:
o Total length (header plus data) of the user datagramo Minimum length must be 8 bytes (contains only header)
n Checksum: 16 bitso 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 headern UDP length = IP length – IP header’s length
o Thus, theoretically, the length field in a UDP datagram is not necessaryn However, it is more efficient to derive the length
of a UDP packet by the UDP package itselfo Ask the IP layer is time consuming
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
UDP length UDP length ==IP length IP length −− IP headerIP header’’s lengths length
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
CHECKSUM
11.311.3
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Checksumo UDP checksum calculation is different from
the one for IP and ICMPo The checksum includes three sectionsn The Pseudoheader
o However, it will not appear in the UDP datagramn The UDP headern The data coming from the application layer
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Pseudoheadero Some part of the header of the IP packet n With some fields are filled with 0s
o Fieldsn 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 Protocolo To prevent the packet to deliver to the TCPo UDP has the value of 17
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Pseudoheader Added to the UDP Datagram
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Checksum Calculation at Sendero Add the pseudoheader to the UDP datagramo Fill the checksum field with zeroso Divide the total bits into 16-bits wordso 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 arithmetico Complement the result and insert it in the checksum fieldo Drop the pesudoheader and any added paddingo Deliver the UDP datagram to the IP software
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Checksum Calculation at Receivero Add the pseudoheader to the UDP user datagramo Add padding if neededo Divide the total bits into 16-bit sectionso Add all 16-bit sections using one’s complement
arithmetico Complement the resulto If the result is all 0s
n Drop the pseudoheader and any added paddingn Accept the user datagram
o Otherwisen 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 Checksumo The calculation of the checksum in UDP is
optional
o If the checksum is not calculatedn The field is filled with 0s
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
UDP OPERATION
11.411.4
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
UDP Operationo 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 Serviceso Each user datagram is an independent
datagramn 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 Controlo No flow controln The receiver may overflow with incoming
messages
o No error control except for the checksumn 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
USE OF UDP
11.511.5
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Uses of UDPo 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 muticasting and broadcastingn Embedded in UDP but not in the TCP software
o For some management processeso For some route updating protocol
n RIP (Routing Information Protocol)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
UDPPACKAGE
11.611.6
The McGraw-Hill Companies, Inc., 2000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
UDP Packageo Five componentsn A control-block tablen Input queuesn A control-block modulen An input modulen 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 Tableo Keep track of the open ports
o Each entry has a minimum of four fieldsn State: FREE or IN-USEn Process IDn Port numbern Corresponding queue number
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Input Queueso A set of input queuesn One for each process
o In the book’s designn They do not use output queues
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Control-Block Moduleo Manage the control-block tableo Pseudo coden Receive: a process ID and a port numbern 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-USEo Enter the process ID and the port number
n Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Input Moduleo Receive: a user datagram from IPo Look for the corresponding entry in the control-
block tablen If (found)
o Check the queue field to see if a queue is allocatedo If (no)
n Allocate a queueo Enqueue the data in the corresponding queue
n If (not found)o Ask the ICMP module to send an “unreachable port” messageo Discard the user datagram
o Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Output Moduleo Receive: data and information from a processo Create a UDP data datagramo Send the user datagramo Return
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Example: Control-Block Table at the Beginning
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
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
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 portn The port has been previously used
o The input module sends the data to queue 38o The control-block table does not change
Example 1Example 1
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
o After a few seconds, a process startso It asks the operating system for a port number and is
granted port number 52,014o 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 momentn because no user datagram have arrived for this destination
Example 2Example 2
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Modified Table After Example 2StateState 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
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
o A user datagram now arrives for port 52,011o The input module checks the table and finds
that no queue has been allocated for this destinationn This is the first time a user datagram has arrived
for this destinationo The module creates a queue and gives it a
number (43)
Example 3Example 3
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
Modified Table After Example 3StateState 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
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
o After a few seconds, a user datagram arrives for port 52,222
o The input module checks the tablen Cannot find the entry for this destination
o The user datagram is droppedo A request is made to ICMP to send an
“unreachable port” message to the source
Example 4Example 4
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
o After a few seconds, a process needs to send a user datagramn It delivers the data to the output module which
adds the UDP header and sends it
Example 5Example 5
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com