Due: Tuesday May 2nd, 2016
You are to write an emulation program to mimic the behavior of transmitting data through an unreliable medium. You will implement a basic version of stop-and-go protocol, a.k.a., 1-bit sliding window protocol. Your program consists of two parts, a server and a client. The client sends a file of arbitrary length to the server, along with computed CRC. The server receives the data and checks for the integrity of the data by computing CRC using the same generating function as the client does. If the remainder is zero, the data is correct; otherwise the data is incorrect. Depending on the correctness of the data, the server sends an ack or a nack to the client. If a nack is received, the client will resend the data to the server.
In network software such as TCP/IP suite many implementation details have to be considered. In our project, we simplify the use cases to focus on some essential aspects. In particular, you are asked to provide a general API for the client of the format:
int send_data(char *host, char *data, int len)
int send_data(char *host, int port, char *data, int len)
and an API for the server
int recv_data(char *host, char *data, int len)
int recv_data(char *host, int port, char *data, int len)
where the host is a symbolic name of the receiver such as dana213-lnx-4, port is the port number, data is the buffer for the data, and len is the length of the buffer in bytes. The behavior of the two functions is very similar to that of read()/write() pair or sendto()/recvfrom().
The functions of send_data() and recv_data() can use UDP to send and receive data. If the size of the data to be sent is larger than the limit of UDP, the send_data() function is responsible for breaking the data into smaller segments and sending each to the receiver. For each data segment sent, the sender will wait for an acknowledgment from the receiver before next segment is sent. The function send_data() will not return to the caller until all segments of data are sent successfully. If a segment of data contains any error, the receiver sends a negative acknowledgment (nack) so that the sender can re-send the data segment.
If a piece of data is split into multiple segments, the receiver is responsible for reassembling the segments back to its original form using the sequence numbers that are sent with the data segments.
You are asked to define a packet format, similar to that of UDP, which at minimum should include the following pieces of information.
The data types used in this definition such as
uint8_t are defined in the including file
stdint.h. You need to include this file to access these data types. The meaning of these types are self-explanatory. For example,
uint8_t is an 8-bit unsigned integer. The fields in
struct pkthdr are explained below.
Test your programs using small data files first, that is, files that don't have to be split into multiple segments. Test also the cases where a data segment is corrupted, i.e., altering a byte before sending to the receiver but after computing its CRC. Once these cases work fine, try your programs on larger files. In particular, try to send the file bode.pgm which is a static image (photo). After the receiver receives and reassembles the data, compare the two files to see if they are identical.
Lastly when everything is working, add a timer to your client (the sender) so that when the timer expires before an ack is received, the sender will resend the packet. Note that the receiver also needs to be revised so that if the same packet ((id, seq) pair are the same) is received, the later ones are dropped.
Demonstrate your program works by sending a small file such as Lincoln's Gettysburg Address and a large file such as the photo bode.pgm You can use the Linux diff command to compare the file sent and the file received by
diff file1 file2
Copy and paste the result into a text file answer.txt. Also in answer.txt please provide any instructions how to compile and run the programs and any thoughts you have for the project.
Once everything is finished, clean up the directory, and send everything to Gitlab.
Congratulations! You are done with the projects in this course!