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 22.214.171.124. 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 126.96.36.199 amazon.com 241.23.18.44 netflix.com 188.8.131.52
Example input file named DNScommands.txt:
L + apple.com 184.108.40.206 + toyota.com 220.127.116.11 + netflix.com 18.104.22.168 L + cs.uky.edu 22.214.171.124 L - netflix.com + whitehouse.gov 126.96.36.199 ? apple.com ? yahoo.com ? 188.8.131.52 ? 184.108.40.206 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 220.127.116.11 amazon.com 241.23.18.44 netflix.com 18.104.22.168 ------------------------------ Command + apple.com 22.214.171.124 Addition successful Command + toyota.com 126.96.36.199 Addition successful Command + netflix.com 188.8.131.52 Addition successful Command L Domain Name IP Number ------------------------------ google.com 184.108.40.206 amazon.com 241.23.18.44 netflix.com 220.127.116.11 apple.com 18.104.22.168 toyota.com 22.214.171.124 ------------------------------ Command + cs.uky.edu 126.96.36.199 Addition successful Command L Domain Name IP Number ------------------------------ google.com 188.8.131.52 amazon.com 241.23.18.44 netflix.com 184.108.40.206 apple.com 220.127.116.11 toyota.com 18.104.22.168 cs.uky.edu 22.214.171.124 ------------------------------ Command - netflix.com Removal successful netflix.com Command + whitehouse.gov 126.96.36.199 Addition successful Command ? apple.com Found apple.com 188.8.131.52 Command ? yahoo.com Search for yahoo.com failed Command ? 184.108.40.206 Found google.com 220.127.116.11 Command ? 18.104.22.168 Search for 22.214.171.124 failed Command S A Data sorted ascending Command L Domain Name IP Number ------------------------------ amazon.com 241.23.18.44 apple.com 126.96.36.199 cs.uky.edu 188.8.131.52 google.com 184.108.40.206 toyota.com 220.127.116.11 whitehouse.gov 18.104.22.168 ------------------------------ 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 22.214.171.124 cs.uky.edu 126.96.36.199 google.com 188.8.131.52 toyota.com 184.108.40.206 whitehouse.gov 220.127.116.11
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.
they should have the 3 P's for each function pre (parameters), purpose, post (return value or output) if they have extra parameters or fewer - with no justification for the change, take points and some pseudocode for each function or at least mention the control structures they will use. yes, they should say something about what's in the body and indent that loops and ifs should be described in the functions where they are used, at least to say there IS a loop or an if in there and something about why it's there.
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.
NOTE: in this function, you do not have to consider that the IP number provided may already be in the table. You only have to handle the DOMAIN NAME either being in the table or not in the table.
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.
The load function
domain name IP number domain name IP number domain name IP number etc.
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:
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.