Lab 9
Get started now
## Overview You will be building a simple service that functions as Domain Name System (DNS). A DNS is a translator between a domain name and the corresponding IP (Internet Protocol) address. For example, if the domain name "www.msoe.edu" is supplied to the system, the IP address "155.92.194.118" would be returned. A second function should be the ability to add a new IP address for a domain name (i.e. create a new domain/IP mapping), update a mapping or remove a mapping. ## Assignment You will need to create the following classes: * **`Simulator`** &mdash; Contains the GUI and `main` method * **`DomainName`** &mdash; Represents a domain name * **`IPAddress`** &mdash; Represents an IP address * **`DNS`** &mdash; The Domain Name System The user will interact with your program via a GUI similar to the mockup below: <figure>[![User Interface](dnsGUI.png)](dnsGUI.png)<figcaption>Figure 1: User Interface</figcaption></figure> When the program starts, only the <kbd>Start</kbd> and <kbd>Exit</kbd> buttons should be enabled. Once started, the other buttons should be enabled and the <kbd>Start</kbd> button should be disabled. The text fields should only be enabled when the <kbd>Start</kbd> button is disabled. If the user hits enter while in the domain name entry text field, the program should look up the IP address for the domain and display it in the IP Address field (or display "NOT FOUND" if the domain name was not found on the server. Pressing enter in the IP Address text field should not do anything. ### Domain Names The user interface allows the user to lookup a name using a single text line dialogue box that can take up to 253 characters. The format of the text should be that the string must start with an alphanumeric character followed by a sequence of legal characters. In addition to alphanumeric characters, periods <kbd>.</kbd> and dashes <kbd>-</kbd> are considered to be a legal characters; however, a domain name must not begin with a period or dash, and two periods must not be placed in series. The following are all legal names: * `google.com` * `localhost` * `ww4.google.com` * `t-a-y-l-o-r.com` * `msoe.edu` Domain names are case _insensitive_. At a minimum, your `DomainName` class must have the following interface: * **`DomainName(String domain)`** &mdash; Creates a new `DomainName` instance. If the domain passed to the constructor is invalid, a `IllegalArgumentException` must be thrown. * **`toString()`** &mdash; Returns a string representing the DomainName. * **`equals(Object domain)`** &mdash; Returns true if and only if `domain` is equivalent to this object (recall domain names are case insensitive). ### IP Addresses A valid IP 4 address must be of the form of four segments separated by periods: `[0-255].[0-255].[0-255].[0-255]` with no other characters permitted. The following are legal IP addresses: * `145.0.0.5` * `192.168.0.0` * `127.0.0.0` * `254.106.106.106` The following are illegal addresses: * `14a.0.0.5` * `a.b.c.d` * `301.456.789.124` At a minimum, your `IPAddress` class must have the following interface: * **`IPAddress(String newAddress)`** &mdash; Creates a new `IPAddress` instance. If the new address passed to the constructor represents an invalid ip address, a `IllegalArgumentException` must be thrown. * **`toString()`** &mdash; Returns a string representing the IP address. * **`equals(Object address)`** &mdash; Returns true if and only if `address` has the same four address subfields. ### The DNS The domain name system should use a class that implements the `Map` interface as an attribute when implementing the domain name system. The DNS should be a class and have the following interface: * **`DNS(String filename)`** &mdash; Constructor that sets the filename to be used to store the DNS entries. * **`start()`** &mdash; Starts the DNS by reading in the names and initializing the map (see Initialization below). Returns true if it was already started or if it was started successfully. * **`stop()`** &mdash; Terminates the server. However, it can be restarted (so don't exit the whole program). The DNS table should be written to the DNS file (specified in the constructor). Returns true if it was already stopped or if it was stopped successfully. * **`lookup(DomainName domain)`** &mdash; Returns the IP address for the specified domain. If the domain name is not found, it returns `null`. Note: if the server is currently not started, this method should return `null` regardless of what is passed to it. * **`update(String command)`** &mdash; See Update description below. When reading from a file, if a line contains an invalid domain name or IP address, an error message must be sent to `System.err` and the line in the file is ignored. When interacting with the GUI, if an invalid domain name or IP address is entered, an error dialog must be displayed indicating the error and the command should not be processed. #### Initialization When `start()` is called, your DNS instance must initialize and populate the map by reading in the file. Here is a sample file to use: [dnsentries.txt](dnsentries.txt). As we noted before, we can have multiple domain names map to single IP address, so it is alright if we have duplicate domain name to IP address mappings, just not the other way around. #### Update Note: if the server is not started, this method should just return `null`. We can receive a series of updates to the DNS. We will use a single file called [updates.txt](updates.txt) that contains multiple lines, each with a command (`ADD` or `DEL`), IP address, and domain name that is used to update our map. Each line of the file must be processed with a separate call to `update()`. There are two types of updates: <pre> ADD IPAddress DomainName DEL IPAddress DomainName </pre> If the command is not <kbd>ADD</kbd> or <kbd>DEL</kbd>, the domain name is invalid, or the IPAddress is invalid, the `update()` method must throw an `IllegalArgumentException`. For the `ADD` command, if the domain name exists, the IP address is updated and the previous IP address is returned. If no entry for the domain name was found, it is added and `null` is returned. For the `DEL` command, if the domain name/IPAddress mapping is found, the entry is removed and the IP address is returned. If the domain name does not exist, the command is ignored and the method returns `null`. If the domain name exists but the IPAddress does not match, a `InputMismatchException` must be thrown. Here is a sample update.txt file: <pre> ADD 178.56.67.89 google.com ADD 178.56.67.112 google.com DEL 104.40.211.35 microsoft.com </pre> To manually change an entry, enter the name of the domain and the corresponding IP address in the dialog box and click the <kbd>Add</kbd> or <kbd>Delete</kbd> button to add, update, or delete the entry. #### The Simulator Our DNS will be driven by a simple GUI simulator. The main program should present a simple GUI as shown above. When it starts, it should perform the creation of a new DNS server object, but not actually start it. When the <kbd>Start</kbd> button is clicked, it starts the service as described above. If <kbd>Stop</kbd> is clicked, the service is stopped if the service was running and the dialog waits for another start. If <kbd>Update</kbd> is clicked, the update (from update.txt) is performed as described above if and only if the service is running. If the service is running and <kbd>Start</kbd> is clicked, the action is ignored. If <kbd>Exit</kbd> is clicked, the simulation ends (the entire program stops running). ## Undo/Redo (potentially optional) Based on your knowledge of stacks and queues, you may wish to add <kbd>Undo</kbd> and/or <kbd>Redo</kbd> buttons. These would allow the user to undo/redo Add and Delete commands (generated by the Add and Delete buttons, not the update file). Ideally, the buttons would only be enabled when there is a command to be undone or redone. Check with your instructor to see if this functionality is required or optional. ## Benchmarking (potentially optional) You may wish to benchmark the performance when using a `TreeMap` and compare it to the performance when using a `HashMap`. You may need to make use of a larger dnsentries.txt file in order to see significant differences. Check with your instructor to see if this functionality is required or optional. ## Lab Deliverables > See your professor's instructions for details on submission guidelines and due dates. > * Dr. Taylor's students: See below > * All other students should refer to Blackboard > >If you have any questions, consult your instructor. ## Acknowledgements This assignment was written by Prof. Jon Hopkins and [Dr. Chris Taylor](/taylor/).

Thursday, 11-May-2017 17:33:30 EDT