USER DATAGRAM PROTOCOL UDP Prof Crista Lopes What

  • Slides: 31
Download presentation
USER DATAGRAM PROTOCOL (UDP) Prof. Crista Lopes

USER DATAGRAM PROTOCOL (UDP) Prof. Crista Lopes

What is UDP? an unreliable transport protocol that can be used in the Internet.

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.

Position of UDP in the OSI model

Position of UDP in the OSI model

UDP(cont’d) UDP does not provide: flow or error control connection management guaranteed in-order packet

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

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

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.

TCP and UDP Functional Comparison Function TCP UDP Ordered data transfer This involves a

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 Same as TCP. correct application for which the data is destined, based on the port number. 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 UDP is connectionless. port numbers and other TCP header fields.

IP addresses versus port numbers

IP addresses versus port numbers

UDP header format

UDP header format

UDP header format Source port : This field identifies the sending port. Destination port:

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

Checksum calculation Checksum is the 16 -bit one's complement of the one's complement sum

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.

IPv 4 PSEUDO-HEADER

IPv 4 PSEUDO-HEADER

Checksum calculation

Checksum calculation

Encapsulation and decapsulation

Encapsulation and decapsulation

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

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

Some well-known ports used with UDP Port Protocol Description 7 Echoes a received datagram

Some well-known ports used with UDP Port Protocol Description 7 Echoes a received datagram back to sender 9 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)

Domain Name System(DNS) IP addresses are tough for humans to remember. IP addresses are

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.

DNS and UDP DNS primarily uses User Datagram Protocol (UDP) on port number 53

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

Domain Name The domain name for a host is the sequence of labels that

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

Host name structure Each host name is made up of a sequence of labels

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

DNS Organization Distributed Database The organization that owns a domain name is responsible for

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.

DNS Distributed Database There is one primary server for a domain, and typically a

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 uci. edu DNS DB Authoritative uci. edu rpi. edu DNS DB Replicas

UDP or TCP Both UDP and TCP are used in DNS: Generally UDP is

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

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

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.

/etc/resolv. conf domain ics. uci. edu 128. 195. 1. 48

/etc/resolv. conf domain ics. uci. edu 128. 195. 1. 48

The Root DNS Server the official DNS root is administered by the Internet Corporation

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 1 st (and many 2 nd) level domain nameservers. edu uci ucsd ics eng com org jp

DNS Servers handle requests for their domain directly. If a server has no clue

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

Address resolution mechanism 1 -the root server address is often stored in a file

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 toplevel domain. 3 -ask the obtained Top Level Domain DNS server for the secondlevel domain. 4 -Repeating the previous step

UDP Client and Server Example in Java The server continuously receives datagram packets over

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 oneline "quote of the moment" back to the client. Two classes implement the server application: Quote. Server and Quote. Server. Thread. A single class implements the client application: Quote. Client.

Quote. Server Class import java. io. *; public class Quote. Server { public static

Quote. Server Class import java. io. *; public class Quote. Server { public static void main(String[] args) throws IOException { new Quote. Server. Thread(). start(); } }

The Quote. Server. Thread Class public class Quote. Server. Thread extends Thread { .

The Quote. Server. Thread Class public class Quote. Server. Thread extends Thread { . . . super(name); socket = new Datagram. Socket(4445); public void run() { while (more. Quotes) { try { byte[] buf = new byte[256]; // receive request Datagram. Packet packet = new Datagram. Packet(buf, buf. length); socket. receive(packet); // figure out response String d. String = null; d. String = get. Next. Quote(); … buf = d. String. get. Bytes(); // send the response to the client at "address" and "port“ Inet. Address address = packet. get. Address(); int port = packet. get. Port(); packet = new Datagram. Packet(buf, buf. length, address, port); socket. send(packet); }. . . }}

The Quote. Client Class public class Quote. Client { public static void main(String[] args)

The Quote. Client Class public class Quote. Client { public static void main(String[] args) throws IOException { if (args. length != 1) { System. out. println("Usage: java Quote. Client <hostname>"); return; } // get a datagram socket Datagram. Socket socket = new Datagram. Socket(); // send request byte[] buf = new byte[256]; Inet. Address address = Inet. Address. get. By. Name(args[0]); Datagram. Packet packet = new Datagram. Packet(buf, buf. length, address, 4445); socket. send(packet); // get response packet = new Datagram. Packet(buf, buf. length); socket. receive(packet); // display response String received = new String(packet. get. Data(), 0, packet. get. Length()); System. out. println("Quote of the Moment: " + received); socket. close(); }