Network Programming代写:CS456 File Transfer Application

代写一个UDP协议的文件传输程序。

Requirement

The goal of this assignment is to become familiar with socket programming. You must implement an unreliable, UDP-based file transfer application. You need to document aspects of your design and report simple performance experiment results. You can implement your programs in any of the following programming languages: C, C++, Java, Python, Scheme. However, do not use any libraries that substantially alter and/or enhance the basic socket interface as discussed in class. If in doubt, consult with the instructor.

Details

Sender Program

You must implement a sender program with the following command-line interface:

sender <host> <port> <payload size> <file name>

host

This is the name or IP address of the destination host to which the file is transferred.

port

This is the port number at which the receiver process, running on the destination host, has opened a socket.

payload size

This is the maximum payload size (data portion) of the UDP messages in bytes (see Messages below).

file name

This is the name of the file that is being transmitted, at the sender host.
Special Case: If this parameter is given as an integer number, the number is taken as the virtual file size in bytes. In this case, the sender application does not transmit the contents of an actual file, but empty messages equivalent to the virtual file size. This is used for performance experiments. See System Calls below for a method to determine the type of this parameter.

Example:

sender ubuntu1604 38548 500 testfile

The sender creates a UDP socket and then sends all data to the receiver’s socket at the specific destination host and port number, assuming that the receiver is already up and running. If the (virtual) file size exceeds the <payload size> parameter, the sender must transmit multiple messages. After sending all data, the sender closes its socket and terminates after reporting two numbers on a single line: number of messages sent, number of bytes sent.

Receiver Program

receiver <file name> <timeout>

file name

This is the name of the file that is being stored at the destination host.

timeout

This parameter specifies a timeout in milliseconds that starts at the arrival of the first message. If the file transfer is not completed after this amount of time, the receiver program terminates.

Example:

receiver testfile 10000

The receiver creates a UDP socket at an OS-assigned port. It should print out the assigned post number, which is used when starting the sender. The receiver then waits for incoming data and stores it in a file with the given name. After it has received the last message or the timeout expires, the receiver terminates after reporting two numbers on a single line: number of messages received, number of bytes received. The receiver must terminate immediately after receiving the last message (i.e., must not wait for the timeout in this case). Also, if the receiver terminates via timeout, it must still report the number of messages and bytes received.

Messages

Define and document a simple message format that can satisfy the requirements of this assignment. Because UDP is a an unreliable transport protocol, messages might be lost or reordered. For this assignment, it is not necessary to correct this behaviour. However, sender and receiver program must exchange control information regarding the length or end of the file transfer, so that the receiver can terminate immediately after receiving the last message.

System Calls

In a POSIX environment, such as Linux, the following system calls provide necessary functionality for this assignment. These are not the only system call interfaces available for this purpose. See the respective man-pages for details. Programming languages other than C/C++ typically provide corresponding interfaces.

strtol

This call can be used to convert a string (command-line argument) to an integer numbers. It is also possible to detect whether the string is a proper integer number.

getsockname

After a socket is implicitly or explicitly bound to a local port, the local addressing information can be obtained with this call.

ualarm

This call starts an OS-controlled timer that delivers a SIGALRM signal when it expires. Note that the timer is measured in microseconds, whereas the command-line argument for the receiver program is specified in millisceonds.

sigaction

This call can be used to install a signal handler.

Experiments

  1. Use your programs to transmit files of different sizes (ranging from 100 bytes to 10 MB) with various message sizes (try at least 128, 512, and 2048 bytes). Report whether you observe any losses.
  2. Devise and document two test runs that demonstrate that your receiver program satisfies the requirements of a) immediately terminating after receiving the last message, and b) terminating after the timeout expires, if the file transfer is not completed.
  3. Devise and document a sequence of tests runs that study the file transfer performance for different file and message sizes. Use the time command to measure the sender’s run time for each parameter configuration. Focus on the reported ‘sys’ time values as the total sender overhead of each file transfer. Find parameter combinations that report a ‘sys’ time of at least 0.050s. You should be able to identify two trends. Describe the trends and draw conclusions.

Notes:

  • Verify that the reported ‘user’ time is significantly smaller than the ‘sys’ time value. If not, this might indicate that your program has a performance flaw.
  • Use the virtual file size parameter setting for the sender program to avoid large test files at the sender.
  • Choose /dev/zero as output file name for the receiver program to avoid large test files at the receiver.
  • You are free to enhance the functionality of your programs to simplify running a sequence of tests. If you do, clearly document those enhancements.

Example:

time ./sender ubuntu1604-006 57321 16 1000000

Output from time:

real    0m0.135sone
user    0m0.003s
sys        0m0.123s

Overhead: 0.123 seconds

Additional Note

In addition to printing out the port number on the terminal, the receiver should also create a file named ‘port’ in the current directory and store the port number in that file. This makes it easier to automatically run tests. This can be done, for example, with the following C++ code snippet:

1
2
3
4
// assume port number is store in variable 'portnum'
ofstream portfile("port");
portfile << portnum << endl;
portfile.close();

Procedures

What to hand in

  • Hand in source code files, including appropriate comments. All files must be stored in the same directory. There should be no directory hierarchy or package definitions. Your assignment must come with a Makefile. The targets in the Makefile must include:
    • ‘clean’ to remove all object files, as well as all log and temporary files; and
    • ‘all’ to build all object and executable files.
      Make sure to execute ‘make clean’ before submitting your assignment!
  • After executing ‘make all’, two executables (or start scripts) sender and receiver must exist in the current directory and function according to the specifications provided in this assignment.
  • ‘README’ file (in plain ASCII text): Report which machines your program was built and tested on. Also, document which parts of the assignment have or have not been completed. Finally, provide the results of the experiments along with your conclusions. This file does not need to be long, but should succinctly provide all the requested information.

Evaluation

The assignment is to be done individually. Your program must work in the linux.student.cs environment. Your program must not silently terminate under any circumstances. At the very least, all errors should lead to an error message indicating the location in the source code where the error is detected, before termination. Marks will be assigned as follows:

  • Functionality: 75%
  • Code Quality: 5%
  • Experiments: 20%

Submission Instructions

After you have completed testing your code, hand it in using the dropbox feature of the Learn environemnt. Combine all files into a zip/tar/gzip/bzip2 archive with the following corresponding names: a1.{zip,tgz,tbz}. Make sure to execute ‘make clean’ before creating the file archive and do not include temporary or object files. Late submissions are permitted with a time-based penalty as described in the course outline.