User Datagram Protocol ( udp )

31
USER DATAGRAM PROTOCOL (UDP) Prof. Crista Lopes

description

User Datagram Protocol ( udp ).  Prof. Crista Lopes. What is UDP ?. an unreliable transport protocol that can be used in the Internet. an alternative to the Transmission Control Protocol(TCP). UDP uses the Internet Protocol to get a data unit (datagram) from one computer to another. - PowerPoint PPT Presentation

Transcript of User Datagram Protocol ( udp )

Page 1: User Datagram Protocol ( udp )

USER DATAGRAM PROTOCOL (UDP)

 Prof. Crista Lopes

Page 2: User Datagram Protocol ( udp )

What is UDP?

an unreliable transport protocol that can be used in the Internet.

an alternative to the Transmission Control Protocol(TCP).

UDP uses the Internet Protocol to get a data unit (datagram) from one computer to another.

a connectionless transport layer protocol in the TCP/IP protocol stack.

Page 3: User Datagram Protocol ( udp )

Position of UDP in the OSI model

Page 4: User Datagram Protocol ( udp )

UDP(cont’d)

UDP does not provide: flow or error control connection management guaranteed in-order packet delivery

UDP is almost a “null” transport layer. UDP is often used for time-sensitive

applications where missing data is preferred to late-arriving data.(i.e. Domain Name Server (DNS))

Page 5: User Datagram Protocol ( udp )

Why UDP?

No connection needs to be set up. Throughput may be higher because UDP

packets are easier to process, especially at the source.

The user doesn’t care if the data is transmitted reliably.

Example:Real-time video and audio streaming protocols are designed to handle occasional lost packets, so only slight degradation in quality occurs, rather than large delays if lost packets were retransmitted. 

Page 6: User Datagram Protocol ( udp )

TCP and UDP Functional Comparison

Function TCP UDP

Ordered data transfer This involves a continuous stream of ordered data.

Does not reorder received data.

Multiplexing using ports Receiving hosts decide the correct application for which the data is destined, based on the port number.

Same as TCP.

Reliable transfer Acknowledgment of data uses the Sequence and Acknowledgment fields in the TCP header.

This is not a feature of UDP.

Flow control This process is used to protect buffer space and routing devices.

This is not a feature of UDP.

Connections This process is used to initialize port numbers and other TCP header fields.

UDP is connectionless.

Page 7: User Datagram Protocol ( udp )

IP addresses versus port numbers

Page 8: User Datagram Protocol ( udp )

UDP header format

Page 9: User Datagram Protocol ( udp )

UDP header format

Source port :This field identifies the sending port.

Destination port: This field identifies the destination port and is required.

Length :16-bit field that specifies the length in bytes of the entire datagram: header and data. 

Checksum: The 16-bit checksum field is used for error-checking of the header and data

Page 10: User Datagram Protocol ( udp )

Checksum calculation

Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.

Page 11: User Datagram Protocol ( udp )

IPv4 PSEUDO-HEADER

Page 12: User Datagram Protocol ( udp )

Checksum calculation

Page 13: User Datagram Protocol ( udp )

Encapsulation and decapsulation

Page 14: User Datagram Protocol ( udp )

Notes

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

UDP length = IP length − IP header’s length Port numbers obtained by Internet Assigned Numbers

Authority (IANA):

Page 15: User Datagram Protocol ( udp )

Some well-known ports used with UDP

Port Protocol Description

7 Echo Echoes a received datagram back to sender

9 Discard Discards diagrams that are received

13 Daytime Returns date and time

17 Quote of the Day Server returns a short arbitrary message to the client

23 Message Send Protocol used to send a short message between nodes on a network.

53 Domain Name System translates a host name into an IP address .

68 Bootstrap Protocol (BOOTP) Client

used by a network client to obtain an IP address from a configuration server (DHCP).

69 Trivial File Transfer Protocol  a very basic form of File Transfer Protocol (FTP)

Page 16: User Datagram Protocol ( udp )

Domain Name System(DNS)

IP addresses are tough for humans to remember.

IP addresses are impossible to guess. The domain name system is usually used

to translate a host name into an IP address .

Domain names comprise a hierarchy so that names are unique, yet easy to remember.

Page 17: User Datagram Protocol ( udp )

DNS and UDP

DNS primarily uses User Datagram Protocol (UDP) on port number 53 to serve requests.

Single UDP request from the client followed by a single UDP reply from the server.

In Domain Name System (DNS), queries must be fast and only consist of a single request followed by a single reply packet

Page 18: User Datagram Protocol ( udp )

Domain Name

The domain name for a host is the sequence of labels that lead from the host (leaf node in the naming tree) to the top of the worldwide naming tree.

A domain is a subtree of the worldwide naming tree.

Top Level Domains : edu, gov, com, net, org

Countries each have a top level domain (2 letter domain name).

Page 19: User Datagram Protocol ( udp )

Host name structure

Each host name is made up of a sequence of labels separated by periods. Each label can be up to 63 characters The total name can be at most 255

characters. Examples:

whitehouse.gov isr.ics.uci.edu

Page 20: User Datagram Protocol ( udp )

DNS Organization

Distributed Database The organization that owns a domain name

is responsible for running a DNS server that can provide the mapping between hostnames within the domain to IP addresses.

some machine run by UCI is responsible for everything within the uci.edu domain.

Page 21: User Datagram Protocol ( udp )

DNS Distributed Database

There is one primary server for a domain, and typically a number of secondary servers containing replicated databases. uci.edu DNS

server

rpi.eduDNS DB

rpi.eduDNS DB

uci.eduDNS DB

uci.eduDNS DB

ReplicasAuthoritative

Page 22: User Datagram Protocol ( udp )

UDP or TCP

Both UDP and TCP are used in DNS: Generally UDP is used to serve requests. If the response data size exceeds 512

bytes, requestor resubmits request using TCP( i.e. zone transfers) .

Page 23: User Datagram Protocol ( udp )

DNS Clients

A DNS client is called a resolver. A call to gethostbyname()is handled by a

resolver (typically part of the client). Most Unix workstations have the file /etc/resolv.conf that contains the local domain and the addresses of DNS servers for that domain.

Page 24: User Datagram Protocol ( udp )

/etc/resolv.conf

domain ics.uci.edu

128.195.1.48

Page 25: User Datagram Protocol ( udp )

The Root DNS Server

the official DNS root is administered by the Internet Corporation for Assigned Names and Numbers (ICANN). 

The root server needs to know the address of 1st (and many 2nd) level domain nameservers.

ics

edu com org jp

ucsduci

eng

Page 26: User Datagram Protocol ( udp )

DNS Servers

Servers handle requests for their domain directly.

If a server has no clue about where to find the address for a hostname, asks the root server. The root server will tell you what nameserver to contact.

A request may get forwarded a few times. Servers cache external mappings(since root

servers are bottleneck for trillions of queries placed every day)

Page 27: User Datagram Protocol ( udp )

Address resolution mechanism

1-the root server address is often stored in a file of root hints, which are updated periodically by an administrator from a reliable source.

2-ask the root server to find the server authoritative for the top-level domain.

3-ask the obtained Top Level Domain DNS server for the second-level domain.

4-Repeating the previous step

Page 28: User Datagram Protocol ( udp )

UDP Client and Server Example in Java

The server continuously receives datagram packets over a datagram socket.

Each datagram packet received by the server indicates a client request for a quotation.

When the server receives a datagram, it replies by sending a datagram packet that contains a one-line "quote of the moment" back to the client.

Two classes implement the server application: QuoteServer and QuoteServerThread. A single class implements the client application: QuoteClient.

Page 29: User Datagram Protocol ( udp )

QuoteServer Class

import java.io.*;public class QuoteServer {

public static void main(String[] args) throws IOException { new QuoteServerThread().start(); }

}

Page 30: User Datagram Protocol ( udp )

The QuoteServerThread Classpublic class QuoteServerThread extends Thread {

...

super(name);

socket = new DatagramSocket(4445);

public void run() {

while (moreQuotes) {

try { byte[] buf = new byte[256];

// receive request

DatagramPacket packet = new DatagramPacket(buf, buf.length);

socket.receive(packet);

// figure out response

String dString = null;

dString = getNextQuote();

buf = dString.getBytes();

// send the response to the client at "address" and "port“

InetAddress address = packet.getAddress();

int port = packet.getPort();

packet = new DatagramPacket(buf, buf.length, address, port);

socket.send(packet);

}...}}

Page 31: User Datagram Protocol ( udp )

The QuoteClient Class

public class QuoteClient { public static void main(String[] args) throws IOException {

if (args.length != 1) { System.out.println("Usage: java QuoteClient <hostname>");return; }

// get a datagram socket DatagramSocket socket = new DatagramSocket();

// send request byte[] buf = new byte[256]; InetAddress address = InetAddress.getByName(args[0]); DatagramPacket packet = new DatagramPacket(buf, buf.length,

address, 4445); socket.send(packet);

// get responsepacket = new DatagramPacket(buf, buf.length);

socket.receive(packet); // display response

String received = new String(packet.getData(), 0, packet.getLength()); System.out.println("Quote of the Moment: " + received); socket.close();

}}