資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies...

30
資 資 Lee <Lesson 8-1> Lesson 8 User Datagram Protocol (UDP)

Transcript of 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies...

Page 1: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-1>

Lesson 8

User Datagram Protocol (UDP)

Page 2: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-2>

UDP

TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP

ICMP

IP

TCP UDP

IGMP

SMTP FTP TFTP DNS SNMP BOOTPApplicationlayer

Transportlayer

Networklayer

Data linklayer

Physicallayer

Underlying LAN or WANtechnology

RARPARP

Page 3: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-3>

InternetInternet

Process(Running application program)

Process(Running application program)

Domain of IP protocol

Domain of UDP protocol

Port Numbers are integers between 0 and 65,535

Page 4: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-4>

IP header

193.14.26.7

13

13

UDP header

Port numberselects the process

Processes

193.14.26.7

0 1,023

1,024 49,151

49,152 65,535

Well-known

Registered

Dynamic

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 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 downlaod 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)

193.14.26.7

13Socket address

Page 5: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-5>

UDP packet-User Datagram

Source port number (16 bits)

Destination port number (16 bits)

Total length16 bits

Checksum16 bits

Header Data

UDP datagram format

Source port, Dest. Port: range from 0 to 65,535.Length: total length of the user datagram(UDP), header plus data.Why this field exist?Checksum: contains three sections, a pseudoheader, the UDP header, and the data.

Page 6: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-6>

Checksum field in UDP packet

32-bit source IP address

32-bit destination IP address

All 0s 8-bit protocol (17)

16-bit UDP total length

Source port address (16 bits)

Dest. port address (16 bits)

UDP total length (16 bits)

Checksum (16 bits)

Data(padding must be added to make

the data a multiple of 16 bits)TE: 5 4 4 5ST: 5 3 5 4IN: 4 9 4 EG0: 4 7 0 0

pseu

doh

ead

er

153.18.8.105

171.2.14.10

All 0s 17 15

1087 13

15 All 0s

T E S T

I N G All 0s

Only used in the checksum Calculation

Optional use of the Checksum: If the checksum is not calculated, the field is filled with 0s.

Page 7: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-7>

UDP Operation

Message from process

UDPheader UDP data

IPheader IP data

Frameheader Frame data

Process

a. Encapsulation

b. Decapsulation

Message from process

UDPheader UDP data

IPheader IP data

Frameheader Frame data

Process

UDP is:◎ connectionless services, this means that each user datagram sent by UDP is an independent datagram. So a process that uses UDP cannot send a streamOf data to UDP and expect UDP to chop them into different related user datagrams.Instead each request must be small enough to fit into one user datagram.◎ No flow control means the receive may overflow with incoming messages.◎ No error control in UDP except for the checksum. This means that the sender does notKnow if a message has been lost or duplicated. When the receiver detects an error usingThe checksum, the user datagram is silently discarded.

Process which uses UDP must provide for these mechanisms.

Page 8: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-8>

UDP Operation

UDP

Daytimeclient

Port 52000

Incomingqueue

Outgoingqueue

UDP

Daytimeserver

Port 13

Incomingqueue

Outgoingqueue

Use of UDP• UDP is suitable for a process that requires simple request-response communication and with little concern for flow and error control. Not usually for a protocol that needs to send bulk data, such as FTP.•UDP is suitable for a process with internal flow and error-control mechanisms. For example,the Trivial File Transfer Protocol(TFTP).•UDP is a suitable transport protocol for multicasting and broadcasting.•UDP is used for management processes such as SNMP.•UDP is used for some route updating protocols such as RIP.

Page 9: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-9>

UDP Design

Input module

Process

Queues

Output module

Five components: (two data-structures plus three modules)Control-block table: keep tracks of the open ports. Four fields: the state, the Process ID, the port number, and the corresponding queue number.Input Queues: s set of input queues, one for each process.

Process Process

Control-blockmodule

… …

Control-block table

DataProcesses(when started)

UDP User datagram

UDP User datagram IP

UDP

Page 10: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-10>

Control-Block Module operationReceive: a process ID and a port number 1. Search the control block table for a FREE entry

1) If (not found), 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.

Input Module operationReceive: a user datagram from IP 1. Look for the corresponding entry in the control-block table.

1) If (found), check the queue field to see if a queue is allocated.

If (no) , allocate a queue, then enqueue the data.2) if (not found) ask the ICMP module to send an “unreachable port” message.

discard the user datagram. 2. Return.

Output Module operationReceive: data and information from a process 1. Create a UDP user datagram. 2. Send the user datagram. 3. Return.

Page 11: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-11>

Examples

State Process ID Port Number Queue Number

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Example 1: arrival of a user datagram with destination port number 52,012.Ans:

Example 2: After a few seconds, a process starts. Get port number 52,014 from OS.

The control-block table at the beginning of examples

State Process ID Port Number Queue Number

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Page 12: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-12>

State Process ID Port Number Queue Number

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Example 3: A user datagram now arrives for port 52,011.

Example 4: A user datagram now arrives for port 52,223.

Example 5: A process needs to send a user datagram:

State Process ID Port Number Queue Number

IN-USE 2,345 52,010 34

IN-USE 3,422 52,011

FREE

IN-USE 4,652 52,012 38

FREE

Page 13: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-13>

Practice set If the outgoing queue of a UDP client overflows,

a. the user data grams are discarded and a port unreachable message is sent.b. the operating system asks the server to wait before any more messages are sentc. new queues are initiatedd. the operating system asks the client process to wait before any more messages are sent.

If the incoming queue of a UDP client overflows, If the incoming queue of a UDP server overflows, Which component in our UDP package allocates the queus?

a. control-block moduleb. . control-block tablec. input moduled. output module

Which component in our UDP package communicates with the ICMP software? The following is a dump of a UDP header in hexadecimal format.

06 32 00 0D 00 1C E2 17a. what is the source port number?b. what is the destination port number?c. what is the total length of the user datagram?d. what is the length of data?e. is the packet directed from a client to a server or vice versa?

Page 14: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-14>

UDP Application – Trivial File Transfer protocol

(TFTP)There are occasions when we need to simply copy a file without the need for all of the functions of the FTP protocol.

Page 15: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-15>

TFTP, a protocol quickly copies(writes) the files. used in bootstrap or DHCP.

Operation:◦ Reading: copy a file from the server site to the client. ◦ Writing: copy a file from the client site to the server site.

TFTP uses the services of UDP on the well-known port 69.

Five types of message, RRQ, WRQ, DATA, ACK, and ERROR

Page 16: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-16>

RRQ- read request message

OPcode=1 File name All 0s Mode All 0s

2 bytes Variable 1 byte 1 byteVariable(netascii, (ASCII )or octet (binary file)

RRQ message format (the client establish a connection for reading data from the server.)

OPcode=2 File name All 0s Mode All 0s

2 bytes Variable 1 byte 1 byteVariable(netascii, (ASCII )or octet (binary file)

WRQ message format (the client establish a connection for writing data to the server.)

Page 17: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-17>

OPcode=3

Blocknumber Data

2 bytes

DATA message format (Server or client send blocks of data)

2 bytes 0~512 bytes

Block number. The sender of the data (server or client) uses this field for sequencing. the block number is necessary for acknowledgement.Data: this block must be exactly 512 bytes in all DATA messages except the last block which must be between 0 and 511 bytes.

OPcode=4

Blocknumber

2 bytes

ACK message format

2 bytes

Page 18: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-18>

OPcode=5

Errornumber Data All 0s

2 bytes

ERROR message format

Variable2 bytes 1 byte

Number Meaning

0 Not defined

1 File not found

2 Access violation

3 Disk full or quota on disk exceeded

4 Illegal operation

5 Unknown port number

6 File already exists

7 No such user

ERROR message format: is used when a connection can not be established or when there is a problem during data transmission. It can e sent as a negative response to PRQ or WRQ. ItCan also be used if the next block can not be transferred during the actual data transfer phase.

Page 19: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-19> 資 管

ConnectionTFTP uses UDP services. There is no provision for connection establishment and termination in UDP. In TFTP, we may transfer blocks of data as they all belong to the same file. TFTP uses RRQ, WRQ, ACK and ERROR messages To establish connection. It uses the DATA message with a block of data fewer than 512 bytes (0~511) to terminate connection.

READING: TFTP client sends the RRQ message to server. 1) RRQ include the file and the transmission mode. if permits, the server responds positively with a DATA message containing the first block of data. Others, the server responds negatively by sending an ERROR message.

WRITING: TFTP client sends the WRQ message to server. 1) RRQ include the file and the transmission mode. if permits, the server responds positively with a ACK message. Others, the server responds negatively by sending an ERROR message.

Connection Termination: termination is accomplished by sending the last block of data, which should be fewer than 512 bytes.

Page 20: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-20> 資 管

Connection

ascii file1 1

3 1 First block of data

5 Error data

ERROR

OR

ServerClient

ascii file1 2

4 1

5 Error data

ERROR

ServerClient

RRQ

DATA

WRQ

ACK

OR

Connection for reading Connection for writing

Connection Termination: termination is accomplished by sending the last block of data, which should be fewer than 512 bytes.

Page 21: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-21>

examplesAssume a client claim a file of 1356 bytes from

the servers. (assume: the file name size is 20 bytes)

1. How many data messages is required?

2. List the IP datagram sizes for each data message?

3. (assume no error exists): list all the messages for both client and server operation and the IP datagram sizes for each messages?

Page 22: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-22>

Data Transfer Data Transfer phase occurs between connection.

◦ The file is divided into blocks of data, in which each block except the last one is exactly 512 bytes.

◦ TFTP has to creates a flow-and error-control mechanism to transfer a file.

TFTP sends a block of data using the DATA message and waits for an ACK message. If the sender receives an acknowledge before

the time-out, it sends the next block. Thus, flow control is achieved by numbering the data blocks and waiting for an ACK before the next data block is send.

Flow Control

Both the sender and the receiver use time-outs. The sender uses a time-out for data messages; the receives uses a time-out for acknowledge messages. If a data message is lost, the sender retransmits it after time-out expiration. So is the same as the receiver.

Error Control

Page 23: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-23>

Error Control is needed in four situations: damaged message, lost message, lost ack, orDuplicated message.

Damaged message: Receiver: If a block of data is damaged, it will detected by the receiver and theBlock is discarded. The checksum field in the UDP provide the damaged check for the message.

Sender waits for the ACK and does not receive it within the time-out period.

Lost message: If a block is lost, it never reaches the receiver and no ACK is sent. The sender resends the block after the time-out.

Lost ACK: Two situations can happen. If the timer of the receiver matures before the timer of the sender, the receiver retransmits the ACK; otherwise, the sender retransmits the data.

Duplicate message: Duplication of blocks can be detected by the receiver through block number. If a block is duplicated, it is simply discarded by the receiver.

Page 24: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-24>

Sorcerer’s Apprentice Bug(魔法師學徒蟲 )

ServerClient

Block 5

ack 5 Block 5

ack 5

Block 6

Block 6

ack 5

ack 6ack 6

Block 7

Block 7

Situation occurs when the ACK message for a message is not lost, but delayed.

In this figure, ack 5 is delayed. After the time-out, the sender retransmits the fifth block, which will be acknowledged by the receiver again. The sender receives the two ack 5, which triggers it to send the sixth block twice.

Page 25: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-25>

UDP ports

Server69Client

Passive open

Server69Client 50032

Activeopen

Server69

Client 50032

a. Passive open by server

62001

b. Active open by client

a. Rest of Communication

Page 26: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-26>

TFTP Example

ascii file1 1

3 1 Block 1: 512 bytes

ServerClient

RRQ

1 4

3 2 Block 2: 512 bytes

Lost

3 2 Block 2: 512 bytes

2 4

2 4

Damaged

3 3 Block 3: 312 bytes

3 4

The client wants to retrieve the content of a 1336-byte file called file1. Step 1: the client sends an RRQ message. Step 2:The server sends the first block with 512 byte.Step 3: ACKStep 4: lost DATA of block 2Step 5: time-out then resend DATA of block 2.Step 6: ACK to block 2 {damaged}Step 7: time-out , resend the ACK…

Page 27: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-27>

Security

Client Server

TELNETclient

TFTPserver

TFTPclient

TELNETserver

Security in TFTP must combined with other protocol such as TELNET.The user must first access TELNET. TELNET checks whether the user Has the right to access the system and the corresponding file. It then calls The TFTP client and passes the file name to the client.The client then makes the TFTP connection to TFTP server at the user site.

Page 28: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-28>

Applications

Client Server

TFTPclient

BOOTPclient

BOOTPserver

TFTPserver

1

2

4

5

3

TFTP is very useful for basic file transfer where security is not a big issue.It can be used to initialize devices such as bridges or routers. Its main applicationIs I conjunction with the BOOTP or DHCP protocols.It can easily be configured into ROM. When the station is powered on, TFTP will be Connected to a server and can download the config. Files from there.BOOTP { get the config. File}TFTP { get the content of the config. File}

Page 29: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-29>

Practice set The ERROR message can follow a ? Message.

a. PRQ b. WRQ c. DATA d. all The flow-control mechanism in TFTP is called.

a. stop-and-wait b. sliding window c. is nonexist d. depends on the TFTP

Describe the connection establishment in TFTP? Describe the connection termination in TFTP? Describe the flow control in TFTP? Describe the error control in TFTP?

Page 30: 資 管 Lee Lesson 8 User Datagram Protocol (UDP). 資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP TCP.

資 管 Lee <Lesson 8-30>

Port

TCP UDP Description Status

0 TCP UDP Reserved Official1 TCP UDP TCP Port Service Multiplexer Official2 TCP UDP Management Utility Official3 TCP UDP Compression Process Official4 TCP UDP Unassigned Official5 TCP UDP Remote Job Entry Official6 TCP UDP Unassigned Official7 TCP UDP Echo Official8 TCP UDP Unassigned Official9 TCP UDP Discard Official10 TCP UDP Unassigned Official11 TCP UDP Active Users Official12 TCP UDP Unassigned Official13 TCP UDP DAYTIME – (RFC 867) Official14 TCP UDP Unassigned Official16 TCP UDP Unassigned Official17 TCP UDP Quote of the Day Official18 TCP UDP Message Send Protocol Official19 TCP UDP Character Generator Official20 TCP FTP – data Official21 TCP FTP – control (command) Official

22 TCP UDPSecure Shell (SSH)—used for secure logins, file transfers (scp, sftp) and port forwarding

Official

23 TCPTelnet protocol—unencrypted text communications

Official USA only

24 TCP UDP Priv-mail : any private mail system. Official

25 TCPSimple Mail Transfer Protocol (SMTP)—used for e-mail routing between mail servers

Official

34 TCP UDPRemote File (RF)—used to transfer files between machines

Unofficial

35 TCP UDP Any private printer server protocol Official37 TCP UDP TIME protocol Official

39 TCP UDP

Resource Location Protocol[2] (RLP)—used for determining the location of higher level services from hosts on a network

Official

41 TCP UDP Graphics Official

42 TCP UDPnameserver, ARPA Host Name Server Protocol

Official

42 TCP UDP WINS Unofficial43 TCP WHOIS protocol Official47 TCP GRE protocol Official49 TCP UDP TACACS Login Host protocol Official50 TCP UDP Encapsulating Security Payload (ESP) Official51 TCP UDP Authentication Header (AH) Official

52 TCP UDPXNS (Xerox Network Systems) Time Protocol

Official

53 TCP UDP Domain Name System (DNS) Official

54 TCP UDPXNS (Xerox Network Systems) Clearinghouse

Official

55 TCP UDP ISI Graphics Language (ISI-GL) Unofficial

56 TCP UDPXNS (Xerox Network Systems) Authentication

Official

56 TCP UDP Route Access Protocol (RAP)[3] Unofficial57 TCP Mail Transfer Protocol (MTP) Unofficial58 TCP UDP XNS (Xerox Network Systems) Mail Official

67 UDP

Bootstrap Protocol (BOOTP) Server; also used by Dynamic Host Configuration Protocol (DHCP)

Official

68 UDP

Bootstrap Protocol (BOOTP) Client; also used by Dynamic Host Configuration Protocol (DHCP)

Official

69 UDP Trivial File Transfer Protocol (TFTP) Official70 TCP Gopher protocol Official79 TCP Finger protocol Official80 TCP UDP Hypertext Transfer Protocol (HTTP) Official81 TCP Torpark—Onion routing Unofficial82 UDP Torpark—Control Unofficial83 TCP MIT ML Device Official