CIS 410/510 Introduction to Networks
Fall 1998

Program A: Stop-and-Wait

Handed Out: 9 October 1998
Due: 6 November 1998 in class by 10am


Overview

You will write two file transfer protocols that are layered on top of a UDP socket interface. The first one, called plain will simply fragment the file into packets and send each packet without any reliability mechanism. The second one will be the reliable stop-and-wait protocol described in the textbook.

Most of your effort writing this program should focus on getting the protocols right, including the error checking.

Supplied Code

I will supply you with code for a client and a server, along with some supporting files, in the class directory in:
   /cs/classes/cis510networks/program1
Together, these will form a framework for this assignment. The files are:
Makefile Has the information needed to compile the programs. You should first type make depend to create dependencies (be sure mkdep has execute permission). This will allow you to recompile only the necessary modules when you change a file. To compile the programs, type make. To remove any object files, type make clean.
client.cc Implements the client. This does the argument parsing and then calls one of the file transfer protocols to send the file.
server.cc Implements the server. This also does argument parsing and then calls one of the file transfer protocols to receive the file.
sock.h Defines the UDP socket interface. This will create a UDP socket between the client and server, then allow you to send and receive data over this socket. The data transfer over this socket is unreliable. Because you will be using the socket over a single link, you may not see any packet loss. To allow you to test your protocols in a truly unreliable environment, the socket interface emulates unreliability.
packet.h Defines the format for packets exchanged by the client and server.
error.h Defines the error messages that are printed by the client and server.
plain.h Defines the plain file transfer protocol class (its data and methods). You should implement this class using plain.cc, which has templates for the methods you should write.
stop-and-wait.h Defines the stop-and-wait file transfer protocol class. You should implement this class using stop-and-wait.cc.

See the files for more details. Files are commented and marked with TBD to indicate where you should make changes.

UDP Socket Interface

The UDP socket interface is documented in sock.h. The client and server use different commands to create the socket. Once the socket is created on both ends, the client can start sending data and the server can start listening for data. The server can use the repl method to respond to a client.

Packet Formats

Packet formats are described in packet.h. The plain protocol should use only the data packet and does not need the three-way handshake. The stop-and-wait client should use the data packet and the server should respond with the ack packet. Once the client has reliably sent the entire file, it should do a three-way handshake to signal the end of the file to the server. The client executes the following: Meanwhile, the server executes the following: Note that packet loss can occur between any of these steps. The long timeout should be set so that the client has a chance to resend the close packet 5 times (so it should be more than 5 times the short timer the client uses). Use a short timer of 5000 microseconds and a long timer of 50000 microseconds. See the class home page for a diagram.

Error Checking

The following lists the packet errors you should check for. If one of these errors occurs, ignore the packet and print out an error message using the methods in error.h. The error must be printed using these methods for you to receive credit. Keep in mind that there may be multiple places where you need to check for these errors. You must also check for failure of every system call that you use and, if a failure occurs, use the perror() system call to report the error and immediately exit the program.

Extra Graduate Requirements

Graduates are also required to implement the Internet checksum algorithm for all packets transmitted in the stop-and-wait protocol. The checksum should be calculated and stored in each packet (zero the checksum before calculating) and then checked when it arrives. If the checksum is invalid, your program should discard the packet and print the corresponding error message.

Output

Your server program should print out the file being transferred, along with any error messages that occur. The client should only print out any error messages that occur. Grading will be based on exactly matching the output of a solution program that runs as described in this handout. You can find sample output in the class directory so you can test your program's abilities. Note that the server will not halt if it uses the plain protocol because in this case there is no three-way handshake. Just use control-c to stop it.

For testing purposes you can run both the server and the client on the same machine. You may also want to try running them on different machines.

Deliverables

Things you should turn in on paper:

You should turn in a printout of any source code files you change. You should put comments in your code so that I can understand what you have written. You should also turn in a printout of sample output using a battery of tests that you have designed to test all cases given above. Organize the printouts so that I understand what each piece of paper is demonstrating.

Things you should turn in online:

Submit all the source code (including the files I have supplied). Do not submit any object code. Use the submit program documented in the Assignments section of the class web page.

Grading

Grading will be based on a battery of tests based on the scenarios outlined above and judged on strict compliance to the output your program produces. Borderline grades can be pushed up or down a level by the quality of the documentation.