DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT



Similar documents
cs2010: algorithms and data structures

dictionary find definition word definition book index find relevant pages term list of page numbers

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Binary Trees and Huffman Encoding Binary Search Trees

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Binary Search Trees (BST)

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

A Comparison of Dictionary Implementations

Binary Search Trees. basic implementations randomized BSTs deletion in BSTs

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Binary Search Trees 3/20/14

Binary Heap Algorithms

Binary Heaps. CSE 373 Data Structures

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Analysis of Binary Search algorithm and Selection Sort algorithm

Binary search algorithm

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Chapter 14 The Binary Search Tree

Binary Search Trees. Ric Glassey

DATABASE DESIGN - 1DL400

Ordered Lists and Binary Trees

Lecture 2 CS An example of a middleware service: DNS Domain Name System

Full and Complete Binary Trees

How To Create A Tree From A Tree In Runtime (For A Tree)

1. Domain Name System

Symbol Tables. Introduction

Network Layers. CSC358 - Introduction to Computer Networks

Zabin Visram Room CS115 CS126 Searching. Binary Search

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Big Data and Scripting. Part 4: Memory Hierarchies

Analysis of Algorithms I: Optimal Binary Search Trees

Sample Questions Csci 1112 A. Bellaachia

Data Structures and Algorithms

Application Layer. CMPT Application Layer 1. Required Reading: Chapter 2 of the text book. Outline of Chapter 2

Review of Hashing: Integer Keys

Chapter 13: Query Processing. Basic Steps in Query Processing

Internet Content Distribution

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Lecture Notes on Binary Search Trees

Algorithms and Data Structures Written Exam Proposed SOLUTION

From Last Time: Remove (Delete) Operation

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

The Domain Name System

Division of Informatics, University of Edinburgh

Hashing. hash functions collision resolution applications. References: Algorithms in Java, Chapter 14.

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Chapter Objectives. Chapter 9. Sequential Search. Search Algorithms. Search Algorithms. Binary Search

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Scalable Prefix Matching for Internet Packet Forwarding

Domain Name System. DNS is an example of a large scale client-server application. Copyright 2014 Jim Martin

Configuring DNS. Finding Feature Information

Raima Database Manager Version 14.0 In-memory Database Engine

Hash Tables. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited

DATA STRUCTURES USING C

Analysis of Algorithms I: Binary Search Trees

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

Optimal Binary Search Trees Meet Object Oriented Programming

Part 5 DNS Security. SAST01 An Introduction to Information Security Martin Hell Department of Electrical and Information Technology

Binary search tree with SIMD bandwidth optimization using SSE

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Keys and records. Binary Search Trees. Data structures for storing data. Example. Motivation. Binary Search Trees

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Domain Name Service (DNS) Training Division, NIC New Delhi

CS3600 SYSTEMS AND NETWORKS

Fast Sequential Summation Algorithms Using Augmented Data Structures

Converting a Number from Decimal to Binary

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Assignment 4 Solutions

Binary Search Tree Intro to Algorithms Recitation 03 February 9, 2011

03 Internet Addressing

CSE 473 Introduction to Computer Networks. Exam 2 Solutions. Your name: 10/31/2013

Persistent Binary Search Trees

Universal hashing. In other words, the probability of a collision for two different keys x and y given a hash function randomly chosen from H is 1/m.

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Motivation. Domain Name System (DNS) Flat Namespace. Hierarchical Namespace

CSE 326: Data Structures B-Trees and B+ Trees

ARP and DNS. ARP entries are cached by network devices to save time, these cached entries make up a table

(n)code Solutions CA A DIVISION OF GUJARAT NARMADA VALLEY FERTILIZERS COMPANY LIMITED P ROCEDURE F OR D OWNLOADING

Lecture 3: Scaling by Load Balancing 1. Comments on reviews i. 2. Topic 1: Scalability a. QUESTION: What are problems? i. These papers look at

Simple Solution for a Location Service. Naming vs. Locating Entities. Forwarding Pointers (2) Forwarding Pointers (1)

Using Peer to Peer Dynamic Querying in Grid Information Services

Configuring Nex-Gen Web Load Balancer

Lecture Notes on Binary Search Trees

Department of Computer Science Institute for System Architecture, Chair for Computer Networks. File Sharing

TREE BASIC TERMINOLOGIES

IMPROVING PERFORMANCE OF RANDOMIZED SIGNATURE SORT USING HASHING AND BITWISE OPERATORS

Merkle Hash Trees for Distributed Audit Logs

Application-layer protocols

The Survey Report on DNS Cache & Recursive Service in China Mainland

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

1. Comments on reviews a. Need to avoid just summarizing web page asks you for:

Enhancing the Search in MOLAP Sparse Data

Transcription:

DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT By GROUP Avadhut Gurjar Mohsin Patel Shraddha Pandhe Page 1

Contents 1. Introduction... 3 2. DNS Recursive Query Mechanism:...5 2.1. Client Side...5 2.2. DNS Server Side... 6 2.3. Root DNS Server Side... 7 3. Search Algorithms:...8 3.1. Binary Search using arrays... 8 3.1.1. Data Members:... 8 3.1.2. Search Function... 8 3.1.3. Insertion Function... 9 3.1.4. Binary Search using arrays Complexity... 9 3.2. Linear Search using Linked List...10 3.2.1. Data Members... 10 3.2.2. Search Function... 10 3.2.3. Insertion Function... 10 3.2.4. Linear Search using Linked List Complexity... 10 3.3. Hash Tables...11 Chained Hash Tables... 11 Open-addressed hash tables (Linear Probing)... 11 3.3.1. Data Members... 11 3.3.2. Search Function... 11 3.3.3. Insertion Function... 12 3.3.4. Linear Probing Hash Table Search Complexity...12 3.4. Binary Search Tree Algorithm... 13 3.4.1. Data Members... 13 3.4.2. Search for a place... 13 3.4.3. Inserting Domain names in BST... 14 3.4.4. Binary Search Tree Complexity... 15 4. Future Work... 16 5. References... 16 Page 2

1. Introduction Whenever a host requests for a web page, it sends a query to the DNS server, which resolves the hostname of the requested page, and returns the IP address of the server hosting that page. In our project, we have implemented this DNS lookup with 2 levels. When a host requests a page (www.google.com), DNS server (dns.isp) looks up for the entry in its database using a search algorithm. If found, it returns the IP address of the server. If the entry is not found, it queries the second level of DNS server (dns.com). This server has the entries of all the servers. Now, dns.com will return the IP to the ISP's dns server, which caches this new entry in its database and forwards it further to the host. Following diagram explains this architecture. Figure1. DNS Lookup System Page 3

In this project, we have implemented the DNS lookup using various search algorithms like: 1. Binary Search 2. Linked List 3. Hash Map 4. Binary Search Tree The number of entries that we are caching are of the order of 10 6. Examples are as follows: dns.com dns.edu www.google.com www.rutgers.edu dns.isp Page 4

2. DNS Recursive Query Mechanism: This mechanism is a classic example of Client-Server socket programming. The server listens for a connection. When a connection is established by a client, the client can send data. In this module, the client sends the message, which contains the Hostname. Server replies back with the IP address of the designated host. Finally the connection is ended and the server waits for another connection. The two programs run on different machines, in same subnet. Java Socket Programming is used for communicating between DNS and root servers with client. There are two types of java program that needs to be installed on the machine. DNS and root servers execute server program while client machine executes client program. DNS Server also runs client program when it forwards the query to the Root DNS. The server program listens for a connection which is established by a client. 2.1. Client Side An object of class Socket is created to connect to the DNS server. It takes DNS server s IP address and port number as its arguments. Port number 2004 is used for client-dns server communication. requestsocket = new Socket("172.31.101.242", 2004); Socket s output and input streams are instantiated and flushed to clear any random data if present. User s input (request - Hostname) is placed in socket s output stream and is sent to the DNS server. sendmessagetodnsserver(hostname); DNS Server s response (IP Address) is taken in the socket s input stream and is displayed to the user. message = (String)in.readObject(); IPAddress=message; When user wants to terminate the program, it sends Bye message to DNS server and terminates the program after receiving Bye message from the server. Page 5

2.2. DNS Server Side DNS Server waits for a connection request from the client. connection = providersocket.accept(); DNS Server receives a request (Hostname) from the client. Server first looks for the entry in its own database. This search takes place using any of the search algorithms mentioned. message = (String)in.readObject(); System.out.println("client>" + message); hostip=search.search(message); If the key (Hostname) is not found in the database, query is forwarded to the Root DNS Server. Now, this DNS Server acts as a Client (Requester) for Root DNS Server. if(hostip.equals("not Found")) { hostip=requester.run(message); // Query //forward write(message,hostip); // save to local cache An object of class Socket is created to connect to the Root server. It takes Root server s IP address and port number as its arguments. Port number 2005 is used for DNS server-root server communication. requestsocket = new Socket("172.31.99.171", 2005); Socket s output and input streams are instantiated and flushed to clear any random data if present. DNS server sends domain name as a request to the Root server and receives corresponding IP address. It then adds that key-value entry in its database and also returns the same to the client machine by sending it through 2004 socket port. The program remains open until user wants to terminate. After each request is processed, DNS and Root servers wait for next request. When user wants to terminate the program, it sends Bye message to DNS server. DNS server in turn sends same message to Root server and then DNS server closes both socket connections and the programs are terminated respectively. Page 6

2.3. Root DNS Server Side DNS LOOKUP SYSTEM An object of class Socket is created to connect to the DNS server. It takes DNS server s IP address and port number as its arguments. Port number 2005 is used for DNS server-root server communication. providersocket = new ServerSocket(2005, 10); connection = providersocket.accept(); Socket s output and input streams are instantiated and flushed to clear any random data if present. Root server waits for DNS server request. As soon as it receives the request, it uses the given domain name to call various search algorithms to fetch corresponding IP address value. hostip=search.search(message); When Root server has the requested record it returns the IP address to DNS server by sending reply message on socket s output stream. sendmessagetodnsserver(hostip); The program remains open until user wants to terminate. After each request is processed, DNS and Root servers wait for next request. When user wants to terminate the program, it sends Bye message to DNS server. DNS server in turn sends same message to Root server. After receiving Bye from Root server, DNS server closes both socket connections and the programs are terminated respectively. Page 7

3. Search Algorithms: 3.1. Binary Search using arrays 3.1.1. Data Members: private Val[] vals; private Key[] keys; private int N = 0; // symbol table values // symbol table keys // number of elements 3.1.2. Search Function // binary search in interval [left, right] private int bsearch(key key) { int left = 0, right = N-1; while (left <= right) { int mid = left + (right - left) / 2; int cmp = key.compareto(keys[mid]); if (cmp < 0) right = mid - 1; else if (cmp > 0) left = mid + 1; else return mid; return -1; // return value associated with given key, or null if no such key public Val get(key key) { int i = bsearch(key); if (i == -1) return null; return vals[i]; Page 8

3.1.3. Insertion Function // add key-value pair public void put(key key, Val val) { if (N >= vals.length) resize(2*n); // duplicate if (contains(key)) { int i = bsearch(key); vals[i] = val; return; // shift key-value pairs one position to right, and add new key-value pair int i = N; while ( (i > 0) && (key.compareto(keys[i-1]) < 0) ) { keys[i] = keys[i-1]; vals[i] = vals[i-1]; i--; vals[i] = val; keys[i] = key; N++; 3.1.4. Binary Search using arrays Complexity O(log n) time expected search, O(n) worst case O(log n) time expected insertion O(n) space Page 9

3.2. Linear Search using Linked List 3.2.1. Data Members private int N; private Node first; // number of key-value pairs // the linked list of key-value pairs // a helper linked list data type private class Node { Key key; Value value; Node next; 3.2.2. Search Function // return the value associated with the key, or null if the key is not present public Value get(key key) { for (Node x = first; x!= null; x = x.next) { if (key.equals(x.key)) return x.value; return null; // not found 3.2.3. Insertion Function // add a key-value pair, replacing old key-value pair if key is already present public void put(key key, Value value) { for (Node x = first; x!= null; x = x.next) if (key.equals(x.key)) { x.value = value; return; first = new Node(key, value, first); N++; 3.2.4. Linear Search using Linked List Complexity O(n) time expected search O(n) time expected insertion O(n) space Page 10

3.3. Hash Tables Hash tables support one of the most efficient types of searching: hashing. Fundamentally, a hash table consists of an array in which data is accessed via a special index called a key. The primary idea behind a hash table is to establish a mapping between the set of all possible keys and positions in the array using a hash function. A hash function accepts a key and returns its hash coding, or hash value. Keys vary in type, but hash codes are always integers. Since both computing a hash value and indexing into an array can be performed in constant time, the beauty of hashing is that we can use it to perform constant time searches. When a hash function can guarantee that no two keys will generate the same hash coding, the resulting hash table is said to be directly addressed. This is ideal, but direct addressing is rarely possible in practice. Typically, the number of entries in a hash table is small relative to the universe of possible keys. Consequently, most hash functions map some keys to the same position in the table. When two keys map to the same position, they collide. A good hash function minimizes collisions, but we must still be prepared to deal with them. There are two broad types of implementation of Hash Tables: Chained Hash Tables Hash tables that store data in buckets. Each bucket is a linked list that can grow as large as necessary to accommodate collisions. Open-addressed hash tables (Linear Probing) Hash tables that store data in the table itself instead of in buckets. Collisions are resolved using various methods of probing the table. We have used Linear Probing in our implementation. 3.3.1. Data Members private int key; private int value; 3.3.2. Search Function public int get(int key) { int hash = (key % TABLE_SIZE); // Generating hash key while (table[hash]!= null && table[hash].getkey()!= key) hash = (hash + 1) % TABLE_SIZE; // If key not found at the expected //position, check next possible //position if (table[hash] == null) return -1; else return table[hash].getvalue(); // return the value if key found Page 11

3.3.3. Insertion Function public void put(int key, int value) { int hash = (key % TABLE_SIZE); // Generate Hash Key while (table[hash]!= null && table[hash].getkey()!= key) // If that position is hash = (hash + 1) % TABLE_SIZE; //already filled, //compute next //position. Continue //until empty slot is //found table[hash] = new HashEntry(key, value); 3.3.4. Linear Probing Hash Table Search Complexity O(1) time expected search O(1) time expected insertion O(1) space Page 12

3.4. Binary Search Tree Algorithm 3.4.1. Data Members private Node root; // root of BST Node class members are as follows: private Key key; private Value val; private Node left, right; private int N; // sorted by key // associated data // left and right subtrees // number of nodes in subtree Adding a value to BST can be divided into two stages: Search for a place to put a new key-value pair by looking at keys; Insert the new key-value pair to this place. Let us see these stages in more detail. 3.4.2. Search for a place Figure2. Binary Search Tree At this stage an algorithm should follow binary search tree property. If a new key value is less than the current node's key value, go to the left subtree, else go to the right subtree. Following this simple rule, the algorithm reaches a node, which has no left or right subtree. By the moment a place for insertion is found, we can say for sure, that a new key-value pair has no duplicate in the tree. Initially, a new node has no children, so it is a leaf. Let us see it at the picture. Gray circles indicate possible places for a new node. Domain names are keys whereas IP addresses are corresponding values. Page 13

Search Function public Value get(key key) { return get(root, key); private Value get(node x, Key key) { if (x == null) return null; int cmp = key.compareto(x.key); if (cmp < 0) return get(x.left, key); else if (cmp > 0) return get(x.right, key); else return x.val; 3.4.3. Inserting Domain names in BST Figure3. Binary Search Tree Realization for Insertion Now, let's go down to algorithm itself. Here and in almost every operation on BST recursion is utilized. Starting from the root, 1. Check, whether first character value of key in current node and a new value are equal. If so, duplicate is found. 2. In this case repeat step 1 for second character in the key. However, if duplicate is not found, go to step 3. 3. If a new value is less than the node's value, there are two cases possible: If a current node has no left child, place for insertion has been found; Otherwise, handle the left child with the same algorithm. 4. If a new value is greater than the node's value, again two possible cases are as follows: If a current node has no right child, place for insertion has been found; Otherwise, handle the right child with the same algorithm. Just before code snippets, let us have a look on the example, demonstrating a case of insertion in the binary search tree. Page 14

For example, in BST shown above, let s insert the key-value pair passport.net 65.54.179.226 into the BST. Now according to the algorithm, look for the first character values in key fields and select left/right subtree accordingly for recursive traversal. Figure 4 indicates the possible place for inserting passport.net key. Insertion Function Figure4. Inserting key = passport.net in Binary Search Tree public void put(key key, Value val) { if (val == null) { delete(key); return; root = put(root, key, val); assert check(); private Node put(node x, Key key, Value val) { if (x == null) return new Node(key, val, 1); int cmp = key.compareto(x.key); if (cmp < 0) x.left = put(x.left, key, val); else if (cmp > 0) x.right = put(x.right, key, val); else x.val = val; x.n = 1 + size(x.left) + size(x.right); return x; 3.4.4. Binary Search Tree Complexity O(1.39 log n) time expected search, O(n) worst case O(1.39 log n) time expected insertion, O(n) worst case O(n) space Page 15

4. Future Work Number of client machines can be increased and many clients can simultaneously query IP addresses from the servers. Two tier system can be enhanced to multiple tiers to develop a huge system to handle multiple clients. We can assign different servers for each domain and further increase the scalability of the system. 5. References 1. Introduction to Algorithms second edition by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rives 2. Algorithms in C++, Parts 1 4: Fundamentals, Data Structure, Sorting, Searching, Third Edition by Robert Sedgewick - Princeton University 3. http://zerioh.tripod.com/ressources/sockets.html 4. http://www.algolist.net/data_structures/binary_search_tree Page 16