CS 115 Program 3 DNS Server Simulation Fall 2018



Design Due: November 28, Wednesday midnight
Source Code Due: December 5, Wednesday midnight
The Source Code may be turned in December 6 or 7 with a late penalty. It will NOT be accepted after Friday December 7, midnight!!

Use the Canvas link for both the design and the source code.

Assignment total points = 175 points = Design (45 points) + Testing (35 points) + Code (95 points)

The educational goals of this program are to:

Every machine on the Internet is identified by a unique string of numbers called an IP number. It has 4 parts separated by periods, like 128.32.48.9. Each part can be between 0 and 255. Each IP number is associated with a domain name, a string of characters that usually spells some English word or name, separated by periods also, like www.cs.uky.edu. The last part of the domain name is called the Top-Level Domain. At one time, there were only a few TLDs, like .gov, .com, .edu, .net, .org. Now many more are being added to the system, like .biz.

Note: this paragraph is getting out-of-date because there is a new version of the IP protocol which describes these numbers. The new version (IPv6) looks a fair bit different from the old style (IPv4). See bonus below.

When you click on a link or use an email address or transfer a file, the software doing the work has to know what the IP number of the destination machine is. It would be impossible for every software package to keep track of all IP numbers. Instead, a system of Domain Name Servers (DNS) is set up all over the world. These machines reside at ISPs and Net backbone sites. They have databases that associate domain names with IP numbers. When provided with an IP number, a DNS responds with a domain name, if one is associated with that number. If given a domain name, it replies with an IP number, again if there is one for it. And the DNS takes orders to put new information in its database and take information out as domain names expire.

This is what you are going to program. Your program will open a file and process all the instructions in it. The instructions will be of several types, indicated by different characters at the start of each line.

Example input file named DNSdata.txt:

google.com  
23.194.28.29
amazon.com
241.23.18.44
netflix.com
14.88.254.99

Example input file named DNScommands.txt:

L
+ apple.com   17.142.160.59
+ toyota.com     72.246.45.58
+ netflix.com 54.243.253.96
L
+ cs.uky.edu  128.163.146.21
L
- netflix.com
+ whitehouse.gov 23.218.197.212
? apple.com
? yahoo.com
? 23.194.28.29
? 111.123.44.9
S A
L
X
Q

The result of running your program on this input would be:

Domain Name System Simulator

Give me a filename for domain name/IP number data: dnsdata.txt
Enter filename of simulator commands: dnscommands.txt

Command L

Domain Name             IP Number
------------------------------
google.com               23.194.28.29
amazon.com               241.23.18.44
netflix.com              14.88.254.99
------------------------------


Command + apple.com   17.142.160.59
Addition successful

Command + toyota.com     72.246.45.58
Addition successful

Command + netflix.com 54.243.253.96
Addition successful

Command L

Domain Name             IP Number
------------------------------
google.com               23.194.28.29
amazon.com               241.23.18.44
netflix.com              54.243.253.96
apple.com                17.142.160.59
toyota.com               72.246.45.58
------------------------------


Command + cs.uky.edu  128.163.146.21
Addition successful

Command L

Domain Name             IP Number
------------------------------
google.com               23.194.28.29
amazon.com               241.23.18.44
netflix.com              54.243.253.96
apple.com                17.142.160.59
toyota.com               72.246.45.58
cs.uky.edu               128.163.146.21
------------------------------


Command - netflix.com
Removal successful netflix.com

Command + whitehouse.gov 23.218.197.212
Addition successful

Command ? apple.com
Found apple.com 17.142.160.59

Command ? yahoo.com
Search for yahoo.com failed

Command ? 23.194.28.29
Found google.com 23.194.28.29

Command ? 111.123.44.9
Search for 111.123.44.9 failed

Command S A
Data sorted ascending

Command L

Domain Name             IP Number
------------------------------
amazon.com               241.23.18.44
apple.com                17.142.160.59
cs.uky.edu               128.163.146.21
google.com               23.194.28.29
toyota.com               72.246.45.58
whitehouse.gov           23.218.197.212
------------------------------


Command X
Invalid command

Command Q
Invalid command

17 commands processed.
2 invalid commands seen

Give me a filename to save data in: newdata.txt

And the newdata.txt file would contain:

amazon.com
241.23.18.44
apple.com
17.142.160.59
cs.uky.edu
128.163.146.21
google.com
23.194.28.29
toyota.com
72.246.45.58
whitehouse.gov
23.218.197.212

NOTE: an 'invalid command' is one that is not on the list of commands that are known. If a command is processed and it has to report failure (like a search or removal), that is NOT invalid. The command executed fine. An invalid command would be like X or Q.

(25 points) Step 1: Testing

The assignment gives an example of a normal run. There are many other test cases possible. Reading about how to test programs with files.

A scaffolding for your program. It will be used for running test cases on your program. You can see why it is very important for you to use the function names specified in this assignment. If you like, you can run your program with it yourself - a good idea! Just comment out the call to the main function, and paste this code at the bottom of your py file. Then you can choose which test or tests to run by just commenting out the appropriate statements. If a boolean is set to True, the tests will run for it; if it's False, they won't.

This code does not replace the tests run in the sample run above. The scaffolding tests each function in an 'ideal' environment with the correct arguments given to it. The dnscommands.txt file checks the main function to make sure it calls the right functions and gives them the correct arguments. Both need to be done to test your program well.

If you have trouble generating an empty file to use for input, you can use the save function tests in the scaffolding. There is an empty list saved and it generates a zero-byte file.

(45 points) Step 2: Design

Make a list of steps and put it in Python form in comment statements. Save this Python file as "design3.py". You need to do design for each of the specified functions.

Data Structures

Your program will use one two-dimensional list to store the domain names and the IP numbers. It should look like [[domain name, IP number], [domain name, IP number], etc.] and can possibly be empty.

Concerning the data in the file:
There may be ANY amount of data in the file. You can assume that the domain names and IP numbers will not contain spaces in them. There may be any number of whitespace characters between the instruction characters and domains and IP numbers.

Note that all functions should work properly if given an EMPTY table. No search will succeed, removals will fail, listing will give an empty list with just a header, etc. You shouldn't need extra code to have this happen.

(100 points) Step 3: Implementation

Write a Python program to implement your design. Make sure you eliminate the syntax and semantics errors. Start with a copy of the design file that you wrote. Write your code between the commented lines of the design. Run your code many times with unit testing and test cases!


Functions that you must design and write and use:

Note that none of these functions gets any input from the keyboard OR from an input file. Only the display_table function does output to the screen. All the other outputs are from the main function.


Two more functions that you must design and write and use:

The load function

The save function

A reminder: you do not want to use any global variables! The penalty is 40 points! Your import statement(s) (if any) should be the only global statement(s). You definitely do not want to break the rules of structured programming, which means no "break" or "continue" or "pass" statements at all and only ONE return statement (at most) at the bottom of each function. Function definitions must not be nested inside each other. Loops should not be deliberately infinite, "while True:" or "while 1:". There is ALWAYS a better way to solve problems than that!! They should also not be accidentally infinite! Note that your functions can call each other. That is a GOOD thing. More than one function needs the search function's ability.

Constructs you are NOT allowed to use in this program:

Bonus (10 points)

Research the difference between IPv4 and IPv6 IP numbers. The ones used in this program are IPv4. Add some code to handle IPv6 numbers in addition to IPv4.

The program must be turned in on time to be eligible for bonus points. So don't wait to turn in your program to finish the bonus until it is late!

Please read the documentation standard on the class web page. We will be looking to see how you meet these standards. Interleave your design as comments in your code. Don't forget to note any side effects a function has in its postconditions. Specifically, if the function receives a table as a parameter, note whether it does or may change it. Remember a table (list) as a parameter is passed by reference so any function CAN change it.