Network Applications: DNS; Socket Programming

Slides:



Advertisements
Similar presentations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
Advertisements

2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r Sockets are explicitly created, used, released by applications.
Client-Server Paradigm and Performance L. Grewe. 2 Review: Basic Client-Server Request/Reply Paradigm Typical Internet app has two pieces: client and.
Network Programming and Java Sockets
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Application Layer – Lecture.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
9/23/2003-9/25/2003 Sockets & DNS September 23-25, 2003.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming February 8, 2005 Arthur Goldberg Computer Science Department.
2: Application Layer1 Chapter 2 (continued) Application Layer – part 2 Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
1 Network Layers Application Transport Network Data-Link Physical bits.
Protocols Rules for communicating between two entities (e.g., a client and a server) “A protocol definition specifies how distributed system elements interact.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
2: Application Layer 1 Socket Programming TCP and UDP.
Network Applications: UDP and TCP Socket Programming Y. Richard Yang 9/17/2013.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
1 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 2 nd edition. Jim Kurose, Keith Ross.
Network Applications: DNS, UDP Socket Y. Richard Yang 9/12/2013.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Java Socket programming. Socket programming with TCP.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
NETWORK PROGRAMMING.
Socket-Programming.  Establish contact (connection).  Exchange information (bi-directional).  Terminate contact.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Network Applications: DNS, UDP Socket 1/24/ Outline  Recap r DNS r Network application programming: UDP.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
Network Applications: DNS Details; UDP Network App Programming
Network Applications: Network App Programming: TCP FTP Y. Richard Yang 2/8/2016.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
1 All rights reserved to Chun-Chuan Yang Upon completion you will be able to: The OSI Model and the TCP/IP Protocol Suite Understand the architecture of.
2: Application Layer1 Network applications: some jargon Process: program running within a host. r within same host, two processes communicate using interprocess.
16-1 Last time □ Reliable Data Transfer with packet loss ♦ rdt3.0 □ Pipelining ♦ Problems with stop-and-wait ♦ Go-Back-N ♦ Selective-Repeat.
Socket Programming Socket Programming Overview
Transport layer (last part) Application layer
DNS: Domain Name System
Socket programming with TCP
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
Java Socket Programming
Socket Programming 2: Application Layer.
DNS: Domain Name System
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
DNS: Domain Name System
DNS: Domain Name System
Socket Programming with UDP
Presentation transcript:

Network Applications: DNS; Socket Programming Y. Richard Yang http://zoo.cs.yale.edu/classes/cs433/ 9/20/2018

Admin Assignment Two to be linked on the Schedule page Pace slow down?

Recap: Domain-based Message Authentication, Reporting, and Conformance (DMARC) [RFC7489]

Recap: Domain Name System (DNS) Function map between (domain name, service) to value, e.g., (www.cs.yale.edu, Addr) -> 128.36.229.30 (cs.yale.edu, Email) -> netra.cs.yale.edu clients DNS Hostname, Service Address routers Why name: easy to remember, one-level of indirection servers

Summary: DNS Design Features Hierarchical name space and hierarchical delegation avoids administrative bottleneck/ central control, improving manageability and scalability Multiple domain servers improve scalability/robustness Native caching (control) reduces workload and improves robustness Flexible recursive and iterative query allows structure such as local resolver to simplify client and enable caching Using UDP to reduce overhead but also support TCP using the same format Same query and response format can make simplify basically servers Domain name encoding compression reduces query/response overhead Proactive answers of anticipated queries (server push) reduce # queries on server and latency on client More naming designs Grapevine: Xerox PARC early 1980’s, Birrell, Levin, Needham, Schroeder CACM 25(1) 1982 two-level naming hierarchy e.g. name@registry birrell@pa primarily for email, but also gave primitive authentication and access control ( check password as attribute of user, check ACL ) any Grapevine server would take any request from a GV user agent Clearinghouse, Xeroc PARC, Oppen and Dalal 1983 ISO standard based on an extension of Grapevine three-level hierarchy GNS Global Name Service, DEC SRC, Lampson et al. 1986 - see below full hierarchical naming support for namespace restructuring support for namespace restructuring X.500 and LDAP, see below N ii ame services in Middleware CORBA: naming and (interface) trading services, Java JNDI, Web W3C: UDDI Allow registration of names/interfaces of externally invocable components with interface references and attributes such as location 12 references and attributes such as location May offer separate services for: name –> object-reference, object-reference –> location Today: approximately 1.3 million authoritative name servers listed in the .COM, .NET and .ORG zone files. Grown from a few thousand entries to over 100 million entries. – That's scaling!

Many Other Uses of DNS DNSBL (black list) or RBL (realtime) Spec: https://tools.ietf.org/html/rfc5782 See changes: https://www.spamhaus.org/sbl/latest/ Query dig <reverse>.zen.spamhaus.org https://www.spamhaus.org/zen/ Valuable tool or censorship? https://blog.returnpath.com/blacklist-basics-the-top-email-blacklists-you-need-to-know-v2/

Problems/Remaining Issues of DNS Security of DNS itself Limited extensibility limited query model Mixed, limited query cmd and query type See https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 Largely a read data store, although theoretically you can update the values of the records, it is rarely enabled Each local domain needs servers, but an ad hoc domain may not have a DNS server

Outline Admin and recap DNS Interface Architecture design Message design Extensions/alternatives service discovery

Context What do we need to extend standard DNS to support service discovery, say to implement Bonjour-type service discovery (discover local printers, local appletv, file-share…)?

DNS-Service Discovery Component: Multicast DNS [RFC6762] Utilize IP multicast (broadcast medium) link-local addressing send to multicast address: 224.0.0.251 (address as a group name, and any host can specify that it joins the group) Implication: each node (host) can become a responder each node (host) can use multicast to announce (write) its values Printer Network 169.254.1.219 169.254.4.51 169.254.10.29

DNS-Service Discovery Component: DNS-based Service Discovery [RFC6763] Avoid continuous adding to DNS Resource Record Type, use ptr as as the only type introduce an extensible service naming convention (service in name) Example: dig _http._tcp.dns-sd.org. ptr "My Test" _printer._tcp dns-sd.org. Name of instance providing service <type_service>. <transport> domain (. means default, which is local

DNS-SD Local Service Discovery Use the dns-sd command on Mac as example Advertise (register) an LPR printer on port 515 dns-sd -R "My Test" _printer._tcp . 515 pdl=application/postscript Capture packets using wireshark port Name of instance providing the service domain (. means default, which is local <type_service>. <transport> Txt for additional data

Exercise Use the dns-sd command on Mac as example Browse web pages on local machines dns-sd -B _http._tcp Advertise (register) a web page on local machine dns-sd -R "My Test" _http._tcp . 80 path=/path-to-page.html Kill the command

Network Service Discovery in Android Based on DNS-SD/mDNS Foundation for peer-to-peer/Wi-Fi Direct in Android See https://developer.android.com/training/connect-devices-wirelessly/nsd.html for programming using nsd

General Service/Naming Discovery Paradigm: Linda “Distributed workspace” by David Gelernter in the 80’s at Yale Very influential in naming and resource discovery Key issues How to name services/resources How to write/update into name space How to resolve names                                                                                        

The Linda Paradigm Naming scheme: arbitrary tuples (heterogeneous-type vectors) Name resolution: Nodes write into shared memory Nodes read matching tuples from shared memory exact matching is required for extraction                                                                                        

Linda: Core API evaluates a tuple on the server out(): writes tuples to shared space example: out("abc", 1.5, 12). result: insert (“abc”, 1.5, 12) into space read(): retrieves tuple copy matching arg list (blocking) example: read(“abc”, ? A, ? B) result: finds (“abc”, 1.5, 12) and sets local variables A = 1.5, B = 12. Tuple (“abc”, 1.5, 12) is still resident in space. in(): retrieves and deletes matching tuple from space (blocking) example: same as above except (“abc”, 1.5, 12) is deleted eval(expression): similar to out except that the tuple argument to eval is evaluated example: eval("ab",-6,abs(-6)) creates tuple (“ab”, -6, 6)                                                                                         eval() evaluates a tuple on the server

Linda Extension: JavaSpaces Industry took Linda principles and made modifications add transactions, leases, events store Java objects instead of tuples a very comprehensive service discovery system Definitive book, “JavaSpaces Principles, Patterns, and Practice” 2 of 3 authors got Ph.D.’s from Yale

Additional Pointers Grapevine: Xerox PARC early 1980’s Birrell, Levin, Needham, Schroeder CACM 25(1) The MAIN name system, an exercise in centralized computing, Deegan, Crowcroft and Warfield, ACM SIGCOMM 35(5), Oct 2005

Outline Admin and recap DNS Implementation/programming: UDP programming

Socket Programming Socket API introduced in BSD4.1 UNIX, 1981 Two types of sockets connectionless (UDP) connection-oriented (TCP) an interface (a “door”) into which one application process can both send and receive messages to/from another (remote or local) application process socket

Services Provided by Transport User data protocol (UDP) multiplexing/demultiplexing Transmission control protocol (TCP) multiplexing/demultiplexing reliable data transfer rate control: flow control and congestion control Host A Host B Hello I am ready DATA ACK

Big Picture: Socket buffers, states buffers, states

Outline Admin and recap DNS Basic network application programming Overview UDP (Datagram Socket)

Discussion What might the UDP API look like if you were to design it?

DatagramSocket(Java) (Basic) constructs a datagram socket and binds it to any available port on the local host DatagramSocket(int lport) constructs a datagram socket and binds it to the specified port on the local host machine.  // more methods on multiplexing control: bind, connect; see demos DatagramPacket(byte[] buf, int length) constructs a DatagramPacket for receiving packets of length length. DatagramPacket(byte[] buf, int length, InetAddress address, int port) constructs a datagram packet for sending packets of length length to the specified port number on the specified host. receive(DatagramPacket p) receives a datagram packet from this socket.  send(DatagramPacket p) sends a datagram packet from this socket. // socket state control close() closes this datagram socket. https://docs.oracle.com/javase/9/docs/api/java/net/DatagramSocket.html

Connectionless UDP: Big Picture (Java version) Server (running on serv) Client create socket, port=x, for incoming request: create socket, clientSocket = DatagramSocket() serverSocket = DatagramSocket( x ) Create datagram using (serv, x) as (dest addr. port), send request using clientSocket read request from serverSocket generate reply, create datagram using client host address, port number write reply to serverSocket read reply from clientSocket close clientSocket

Example: UDPServer.java A simple UDP server which changes any received sentence to upper case.

Java Server (UDP): Create Socket import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); Create datagram socket bind at port 9876 Check socket state: %netstat –a –p udp –n

local address why shown as “*”? System State after the Call server 128.36.232.5 128.36.230.2 UDP socket space “*” indicates that the socket binds to all IP addresses of the machine: % ifconfig -a address: {*:9876} snd/recv buf: local port local address why shown as “*”? address: {128.36.232.5:53} snd/recv buf:

Binding to Specific IP Addresses server Public address: 128.36.59.2 Local address: 127.0.0.1 InetAddress sIP1 = InetAddress.getByName(“localhost”); DatagramSocket ssock1 = new DatagramSocket(9876, sIP1); InetAddress sIP2 = InetAddress.getByName(“128.36.59.2”); DatagramSocket ssock2 = new DatagramSocket(9876,sIP2); DatagramSocket serverSocket = new DatagramSocket(6789); UDP socket space address: {127.0.0.1:9876} snd/recv buf: address: {128.36.59.2:9876} address: {*:6789} snd/recv buf: address: {128.36.232.5:53} snd/recv buf:

Exercise: UDPPortScanner Try to test all UDP bindings [sudo] lsof -i4UDP –n –P

Exercise: UDP Demultiplexing client on server server SP: x DP: 9876 S-IP: A D-IP: 127.0.0.1 Public address: 128.36.59.2 Local address: 127.0.0.1 UDP socket space address: {127.0.0.1:9876} snd/recv buf: address: {128.36.59.2:9876} client IP: A P2 client IP: B SP: y DP: 9876 S-IP: B D-IP: 128.36.59.2 address: {128.36.232.5:53} snd/recv buf: UDP demutiplexing is based on matching state

Exercise: UDP Demultiplexing Client on server server SP: x DP: 9876 S-IP: A D-IP: 127.0.0.1 Public address: 128.36.59.2 Local address: 127.0.0.1 UDP socket space address: {127.0.0.1:9876} snd/recv buf: address: {128.36.59.2:9876} client IP: A P3 client IP: C address: {*:9876 snd/recv buf: SP: y DP: 9876 S-IP: C D-IP: 128.36.59.2 address: {128.36.232.5:53} snd/recv buf: UDP demutiplexing is based on matching state

Per Socket State Each Datagram socket has a set of states: local address send buffer size receive buffer size timeout traffic class See http://download.java.net/jdk7/archive/b123/docs/api/java/net/DatagramSocket.html Example: socket state after clients sent msgs to the server

Exercise: UDPClient Send messages to UDPServer from local, from a zoo machine Use wireshark to capture traffic

Java Server (UDP): Receiving import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = null; while(true) DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create space for received datagram Receive datagram

DatagramPacket Receiving Sending DatagramPacket(byte[] buf, int length) constructs a DatagramPacket for receiving packets of length length. DatagramPacket(byte[] buf, int offset, int length) constructs a DatagramPacket for receiving packets starting at offset, length length. Sending DatagramPacket(byte[] buf, int length, InetAddress address, int port) constructs a datagram packet for sending packets of length length to the specified port number on the specified host. DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port)

Java Server (UDP): Processing import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { … // process data String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); getData() returns a pointer to an underlying buffer array NOTE the missing of type during conversion new String(), should add “US-ASCII”); getLength() returns how much data is valid.

Java Server (UDP): Response Java DatagramPacket: getAddress()/getPort() returns the source address/port

Java server (UDP): Reply InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Create datagram to send to client Write out datagram to socket End of while loop, loop back and wait for another datagram

Example: UDPClient.java A simple UDP client which reads input from keyboard, sends the input to server, and reads the reply back from the server.

Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); String sentence = inFromUser.readLine(); byte[] sendData = sentence.getBytes(); DatagramSocket clientSocket = new DatagramSocket(); InetAddress sIPAddress = InetAddress.getByName(“servname"); Create input stream Create client socket Translate hostname to IP address using DNS

Example: Java client (UDP), cont. Create datagram with data-to-send, length, IP addr, port DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, sIPAddress, 9876); clientSocket.send(sendPacket); byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Send datagram to server Read datagram from server

Java Server (UDP): Processing A simple upper-case UDP echo service is among the simplest network service. Are there any problems with the processing? class UDPServer { public static void main(String args[]) throws Exception { … DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); // process String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); // send DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket);

Data Encoding/Decoding Rule: ALWAYS pay attention to encoding/decoding of data if not careful, query sent != query received (how?) client server query result encoding decoding byte array

Example: Endianness of Numbers int var = 0x0A0B0C0D sent != received: take an int on a big-endian machine and send a little-endian machine ARM, Power PC, Motorola 68k, IA-64 Intel x86

Example: String and Chars Will we always get back the same string? client server String String (UTF-16) (UTF-16) byte array String.getBytes() String(rcvPkt, 0, rcvPkt.getLength()); Depends on default local platform char set : java.nio.charset.Charset.defaultCharset()

Example: Charset Troubles Try java EncodingDecoding US-ASCII UTF-8 System.out.println(clientSocket.getLocalAddress()); System.out.println(clientSocket.getLocalPort()); System.out.println(clientSocket.getReceiveBufferSize()); System.out.println(clientSocket.getSendBufferSize()); System.out.println(clientSocket.getSoTimeout()); System.out.println( java.nio.charset.Charset.defaultCharset() );

Encoding/Decoding as a Common Source of Errors Please read chapter 2 (Streams) of Java Network Programming for more details Java stream, reader/writer can always be confusing, but it is good to finally understand Common mistake even in many (textbook) examples: http://www.java2s.com/Code/Java/Network-Protocol/UseDatagramSockettosendoutandreceiveDatagramPacket.htm System.out.println(clientSocket.getLocalAddress()); System.out.println(clientSocket.getLocalPort()); System.out.println(clientSocket.getReceiveBufferSize()); System.out.println(clientSocket.getSendBufferSize()); System.out.println(clientSocket.getSoTimeout()); System.out.println( java.nio.charset.Charset.defaultCharset() );

Offline Exercise: UDP/DNS Server Pseudocode Modify the example UDP server code to implement a local DNS server. root name server 2 3 4 7 1 8 6 5 local name server 130.132.1.9 TLD name server authoritative name server dns.cs.umass.edu requesting host cyndra.cs.yale.edu gaia.cs.umass.edu