1 Chapter 6 Datagram Delivery by UDP Just as the Internet Protocol uses the services of subnetworks,...

25
1 Chapter 6 Datagram Delivery by U Just as the Internet Protocol uses the ser vices of subnetworks, transport protocols build upon the services of IP. They rely o n IP to deliver packets to the right place, and then they take over. Transport protocols have two major responsibilities. First, they must distinguish the traffic of different applications within a system. The second obligation facing a transport protocol is reliability. Recall that IP cannot guarantee delivery of packets. Nor does it typically ensure that the data within those packets arrives free from corruption. Transport protocols compensate for these problems, although different

Transcript of 1 Chapter 6 Datagram Delivery by UDP Just as the Internet Protocol uses the services of subnetworks,...

1

Chapter 6 Datagram Delivery by UDP

Just as the Internet Protocol uses the services of subnetworks, transport protocols build upon the services of IP. They rely on IP to deliver packets to the right place, and then they take over.

Transport protocols have two major responsibilities. First, they must distinguish the traffic of different applications within a system. The second obligation facing a transport protocol is reliability. Recall that IP cannot guarantee delivery of packets. Nor does it typically ensure that the data within those packets arrives free from corruption. Transport protocols compensate for these problems, although different transport protocols compensate in different ways, and to different degrees.

2

Chapter 6 Datagram Delivery by UDP

This chapter considers the simplest level of service--datagram delivery. Datagram delivery is not a guaranteed service, but it does protect against corruption

The specific transport protocol that provides TCP/IP’s datagram delivery service is the User Datagram protocol, or UDP.

3

Chapter 6 Datagram Delivery by UDPDistinguishing Applications

4

Chapter 6 Datagram Delivery by UDPDistinguishing Applications

5

Chapter 6 Datagram Delivery by UDPPorts

To identify different applications, TCP/IP protocols tag each packet with a number known as a port. Different applications use different values for port fields, and a transport protocol can use the port value to decide which application should receive a packet’s data.

In this way, the port value acts like the IP next header field. The next header value distinguishes different transport protocols for IP, and the port values distinguishes different application protocols for a transport protocol.

6

Chapter 6 Datagram Delivery by UDPPorts

Applications select a port in one of two ways. The two approaches correspond to the two roles that an application can play in a conversation. These roles correspond to a client and a server.

When a client application needs to make a request, it must know how to get that request to a server; it must know, in advance, which port value to use for the particular application. A server, on the other hand, doesn’t have to know the port value to use for its response. It can have the client designate a port as part of the initial request.

7

Chapter 6 Datagram Delivery by UDPPorts

Internet Protocol

Data

AP Protocol Header

TCP, UDP Header

IPheader

Ethernet header

Ethernet trailer

Encapsulation of data

16-bit port #

32-bit address

48-bit address

8

Chapter 6 Datagram Delivery by UDPPorts

Port values that are predefined for specific applications are well-known ports.

9

Chapter 6 Datagram Delivery by UDP

There are two ways for a process to have an Internet port assigned:•The process can request a specific port (from 5000 ~)•The process can let the system automatically assign a port

For Internet Protocol:1-1023: reserved ports 512-1023: ports assigned by resvport()1024-5000: ports automatically assigned by system5001-65535: used by user

Ports

10

Chapter 6 Datagram Delivery by UDPSockets

By themselves, ports merely define application protocols. They do not identify actual application programs running in real machines. By combining port value with a network address, however, just such a distinction is possible. The combination is known as a socket.

Different sockets can have the same values for both their port and network address.

11

Chapter 6 Datagram Delivery by UDPSockets

Same port, same IP address

12

Chapter 6 Datagram Delivery by UDPSockets

Socket Programming

iterative server concurrent serverconnection-oriented protocol infrequent (Daytime) typicalconnectionless protocol typical infrequent (TFTP)

Iterative vs. Concurrent Server

Socket system callsServer

create endpoint: socket()bind address: bind()specify queue: listen()wait for connection: accept()

Clientcreate endpoint: socket()bind address: bind()connect to server: connect()

Transfer data: read(), write(0, recv(), send(), recvfrom(), sendto()Terminate: close(), shutdown()

13

Chapter 6 Datagram Delivery by UDPSockets

Socket Programming

connection-oriented protocol

socket() bind() listen() accept() read() write()

socket() connect() write() read()

request reply

blocked until connection from client

Client:

connectionless protocolsocket() bind() recvfrom() sendto()

Client: socket() bind() sendto() recvfrom()

request reply

14

An Association

{protocol, local-addr, local-process, foreign-addr, foreign-process}

{udp, 203.64.100.101, 20, 203.64.80.11, 30}

Chapter 6 Datagram Delivery by UDPSockets

Socket Programming

protocol local-addr, foreign addr, local-process foreign-processconnection-oriented server socket() bind() listen(), accept()connection-oriented client socket() connect()connectionless server socket() bind() recvfrom()connectionless client socket() bind() sendto()

15

Chapter 6 Datagram Delivery by UDPSockets

Socket ProgrammingTypical scenario for a concurrent server (connection-oriented)

int sockfd,newsockfd;if ((sockfd=socket(...))<0) err_sys("socket error");if ((bind(sockfd,...)<0) err_sys("bind error");if (listen(sockfd,5)<0) err_sys("listen error");for (;;) { newsockfd=accept(sockfd,...); /* 5-tuple association determined by accept system call for newsockfd */ if (newsockfd<0) err_sys("accept error"); if (fork()==0) { close(sockfd); /*child process */ doit(newsockfd); /* process the request */ exit(0); } close(newsockfd); /* parent */ }

16

Chapter 6 Datagram Delivery by UDPDatagram Delivery

UDP provides a particular type of service to applications calleddatagram delivery. Datagram delivery is a connectionless service,which means:•each datagram exists entirely independently of all other datagrams, even datagrams between the same sockets

•there is no reference to tie multiple datagrams together•there is no mechanism that allows a receiver to acknowledge reception of a datagram

•there is no reference that can establish a relative ordering of different datagrams

17

In practice, this means that UDP provides a best effort delivery.

Chapter 6 Datagram Delivery by UDPDatagram Delivery

That is, it does its best to transfer datagrams for its applications, but UDP makes no guarantees. Datagrams may get reordered, even lost, in transit, and the applications must be prepared for such event.

UDP does provide one enhancement to the network service available from IP. It includes simple error-checking that can detect corrupted datagrams.

18

Chapter 6 Datagram Delivery by UDPDatagram Delivery

The application has to handle the lost of packet 2 by itself.

19

Chapter 6 Datagram Delivery by UDPDatagram Delivery

Datagrams experienced larger delay in Router B.

20

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

Why an application would use UDP instead of TCP. The answer lies in UDP’s simplicity. Since UDP has no connections, applications do not have to establish or clear them. When an application has data to send, it just sends them. This approach make things simpler for the application, and it can eliminate a substantial delay in communication.

UDP is also ideal for those systems that are so limited that they cannot afford to implement TCP.

21

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

UDP header+data

22

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

Pseudoheader

With IPv4, however, a sender could effectively omit the checksum by setting its value to zero. Receivers disregarded the checksum. Even though this omission is no longer legal in IPv6, IPv6 implementations must still be prepared to receive UDP datagrams from systems using IPv4.

23

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

Source IP Address

Destination IP Address

Zero protocol(17) UDP length

IPv4 UDP’s pseudo header for computing checksum

24

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

Constructing the UDP checksum

1. Prepend the pseudo header to the UDP datagram2. If the application data contains an odd number of bytes, append

a final byte of zero. (Do not increase the payload length or datagram length to include this byte.)

3. Set the checksum field to zero.4. Calculate the sum of the resulting series of 16-bit values, using

one’s complement arithmetic.5. Use the complement of the summation result as the checksum.

25

Chapter 6 Datagram Delivery by UDPUser Datagram Protocol

Validating the UDP checksum

1. If the checksum value is zero, assume it is correct and skip the remaining steps.

2. Prepend the pseudo header to the UDP datagram3. If the application data contains an odd number of bytes, append

a final byte of zero. (Do not increase the payload length or datagram length to include this byte.)

4. Calculate the sum of the resulting series of 16-bit values, using one’s complement arithmetic.

5. If the result of this summation is 0xFFFF, the checksum is valid; otherwise, the checksum is invalid.