ì Computer Systems and Networks ECPE 170 – Jeff Shafer – University of the Pacific Networking: UDP & DNS
2 Lab Schedule Activities Assignments Due This Week Lab 9 ì ì Due by Apr 2 nd 5:00am DNS & UDP ì ì Lab 9 (DNS, UDP sockets) ì Next Week ì Start Assembly ì Programming (lecture for 1+ day) Computer Systems and Networks Spring 2019
3 ì User Datagram Protocol (UDP) Computer Systems and Networks Spring 2019
4 UDP versus TCP TCP UDP Reliable? Yes No (Via acknowledgements and retransmitting) Connection- Yes No oriented? (Server has one socket per (Server has one socket and all client) messages from all clients are received on it) Programming Stream Datagram model? (continuous flow of data – (data is sent in its entirety or not at may get a little bit at a time) all. Size of each datagram is small) Applications HTTP (Lab 8) DNS (Lab 9) Web, email, file transfer Streaming Audio/Video, Gaming Computer Systems and Networks Spring 2019
5 User Datagram Protocol (UDP) UDP: no “connection” ì between client and server application viewpoint No handshaking ì UDP provides unreliable transfer Sender explicitly ì of groups of bytes (“datagrams”) attaches IP address between client and server and port of destination to each message Receiver can extract IP ì address, port of sender from received datagram Computer Systems and Networks Spring 2019
6 User Datagram Protocol (UDP) ì Each UDP message is self-contained and complete ì Each time you read from a UDP socket, you get a complete message as sent by the sender That is, assuming it wasn’t lost in transit! ì ì Think of UDP sockets as putting a stamp on a letter and sticking it in the mail No need to establish a connection first ì Receiver has no idea “letter” is arriving until they ì look in the mailbox Computer Systems and Networks Spring 2019
7 Python UDP Programming ì Two new functions: sendto() and recvfrom() server_ip = 1.2.3.4 port = 5678 dest_addr = (server_ip, port) s = socket.socket(socket.AF_INET, socket. SOCK_DGRAM ) ... ... bytes_sent = s. sendto (raw_bytes, dest_addr ) ... ... max_bytes = 4096 (raw_bytes, src_addr ) = s. recvfrom (max_bytes) Computer Systems and Networks Spring 2019
8 ì Domain Name System (DNS) Computer Systems and Networks Spring 2019
9 IP Addresses ì IP version 4 addresses are 32 bits long ì IP version 6 address are 128 bits long ì Every network interface has at least one IP address A computer might have 2 or more IP addresses ì ì IPv4 addresses are usually displayed in dotted decimal notation Each byte represented by decimal value ì Bytes are separated by a period ì IP address 0x 8002C2F2 = 128 . 2 . 194 . 242 ì Computer Systems and Networks Spring 2019
10 Motivation ì IP addresses are hard to remember 198.16.253.143 ? Or was it .146 ? ì ì Human-friendly names are much better ì engineering.pacific.edu ì How can we translate between the two? Computer Systems and Networks Spring 2019
11 Early Days (prior to 1983) Each computer on the ARPAnet (early Internet) had a single file ì hosts.txt maps all known host names to IP address ì Master list maintained ì by SRI Network Information Center Email them if your ì mapping changes New list produced 1-2 ì times a week All hosts download the ì new list Problems with this approach? ì Computer Systems and Networks Spring 2019
12 Domain Name System (DNS) ì Distributed database implemented in hierarchy of many name servers ì Application-layer protocol Hosts, routers, and name servers communicate to ì resolve names (address/name translation) Core Internet function implemented as application- ì layer protocol Computer Systems and Networks Spring 2019
13 DNS is Decentralized ì No single point of failure ì No distant centralized database ì Easier maintenance Take one or a dozen servers offline without issue ì ì Support high traffic volume ì *** Scalability *** Computer Systems and Networks Spring 2019
14 How many DNS requests/second globally? Computer Systems and Networks Spring 2019
15 DNS: Scalability Challenging to find data on global DNS requests/sec ì No global internet “dashboard” ì Internet is a “network of networks” ì Would have to inquire with AT&T, Comcast, TimeWarner, Pacific, etc ì They would have to check stats on all of their local servers ì Google Public DNS ì 1+ trillion requests/day as of August 2018 ì https://security.googleblog.com/2018/08/google-public-dns-turns-8888-years-old.html ì OpenDNS ì 160 billion requests/day as of October 2018 ì http://system.opendns.com/ ì Computer Systems and Networks Spring 2019
16 What’s in a Name? ì engineering.pacific.edu .edu is top-level domain ì “pacific” belongs to .edu ì “engineering” belongs to “pacific” ì Hierarchical! Read from right to left ì Computer Systems and Networks Spring 2019
17 Distributed, Hierarchical Database Root DNS Servers org DNS servers edu DNS servers com DNS servers poly.edu umass.edu pbs.org yahoo.com amazon.com DNS servers DNS servers DNS servers DNS servers DNS servers ì Client wants IP for www.amazon.com Client queries a root server to find com DNS server 1. Client queries com DNS server to get amazon.com DNS 2. server Client queries amazon.com DNS server to get IP address 3. for www.amazon.com Computer Systems and Networks Spring 2019
18 DNS: Root Name Servers Contacted by local name server that can not resolve top-level domain ì Root name server: ì Contacts authoritative name server for TLD if name mapping not known ì Gets mapping ì Returns mapping to local name server ì 13 root name “servers” worldwide labeled a - m • Each “server” is really a cluster • Some clusters are geographically distributed • 504 total in Fall 2014 Computer Systems and Networks Spring 2019
19 DNS: Root Name Servers http://www.root-servers.org/ Computer Systems and Networks Spring 2019
20 DNS and UDP DNS uses UDP by default ì It can use TCP, but it’s rare ì Isn’t this unreliable? ì Why use UDP ì Reliability not needed ì ì DNS will just re-request if no response received (2-5 seconds) Faster (in three ways!) ì ì No need to establish a connection (RTT/latency overhead) ì Lower per-packet byte overhead in UDP header ì Less packet processing by hosts Computer Systems and Networks Spring 2019
21 ì Demonstrations Computer Systems and Networks Spring 2019
22 Demonstrations DNS Client: dns.py 1. Wireshark packet capture 2. Computer Systems and Networks Spring 2019
23 ì Programming Tips Computer Systems and Networks Spring 2019
24 Packet Construction ì HTTP requests are ASCII strings Easy to construct! J ì ì DNS requests are fixed-length byte fields How do we build this?!? L ì Computer Systems and Networks Spring 2019
25 Packet Construction ì Method 1 – Explicitly concatenate bytes together ì # Create array of bytes raw_bytes = bytearray() # Append values to array raw_bytes.append(0xfe) # Convert string to bytes & append raw_bytes+=bytes("www",'ascii’) ì It “works”, but computer code full of raw hex numbers is NOT HUMAN FRIENDLY L Computer Systems and Networks Spring 2019
26 The struct Module ì Method 2 – The struct module! ì The details of variables are hidden in Python For example, how many bytes is an integer? ì ì Need a method to deal with binary data for file I/O or network I/O: the struct module Module performs conversions between basic Python ì datatypes and arrays of bytes Computer Systems and Networks Spring 2019
27 The struct Module ì Two main functions in the struct module pack : convert a group of variables into an array of ì bytes unpack : convert an array of bytes into a group of ì variables ì Similar to C’s printf and scanf ì Each function requires a format string to describe how to pack or unpack the arguments Computer Systems and Networks Spring 2019
28 The struct Module Common format string options: ì See https://docs.python.org/3/library/struct.html ì Format Python Type Size (bytes) B Integer 1 H Integer 2 L Integer 4 Q Integer 8 raw_bytes = struct.pack("BH", val1, val2) ì (val1, val2) = struct.unpack("BH", raw_bytes) ì Computer Systems and Networks Spring 2019
29 The struct Module ì Endianness must be considered when doing file or network I/O with fields greater than one byte ì The first character of the format string determines the endianness Character Byte order Size Alignment @ Native Native Native = Native Standard None < Little Standard None > Big Standard None ! Network (Big) standard None Computer Systems and Networks Spring 2019
30 DNS Endianness ì What endianness is your computer? Little endian (x86) ì ì What endianness is the DNS protocol? (or most network protocols) Big endian ì ì What fields in the DNS header does this matter for? Two-byte integer fields ì (question count, answer count, etc…) Computer Systems and Networks Spring 2019
Recommend
More recommend