CS 436 Winter 2010 - Assignment 2

(Version: Mar 1 23:46:57)

Due Date: Wednesday, Mar 3, 2010, 22:00

In this assignment, you are provided with a channel emulator for an unreliable channel. You must implement the selective repeat versions of reliable pipelined data transfer and a simple file transfer application. The reliable transfer protocol must be able to handle network errors such as packet loss, duplication, and reordering. For simplicity, the protocol only needs to be unidirectional, i.e. data flows in one direction only (from sender to receiver) and acknowledgements (ACKs) in the opposite direction. To implement this protocol, you need to write two programs: a sender and a receiver with the specifications given below. Communication to and from the channel emulator uses UDP. You can implement your solution in any programming language. The overall setup is shown in the schematic diagram below

Sender S UDP B Channel Emulator C UDP E Receiver

and uses the following addressing scheme (see Addressing for further information):

S: address/port learned automatically by channel emulator using 'recvfrom'
B: address/port written into 'channelInfo' by channel emulator, read by sender
C: address/port learned automatically by receiver using 'recvfrom'
E: address/port written in 'recvInfo' by receiver, read by channel emulator

When the sender needs to send packets to the receiver, it sends them to the channel emulator at 'B' instead of sending them directly to the receiver. The channel emulator then forwards the received packets to the receiver at 'E'. However, it may randomly discard or delay packets. The receiver sends ACKs to the sender via the channel at 'C', which may also randomly discard or delay ACKs.

Details

Packet Format

All packets exchanged between the sender and the receiver must adhere to the following format:
FieldType
Packet Type32 bit unsigned integer, big endian
Sequence Number32 bit unsigned integer, big endian
Packet Length32 bit unsigned integer, big endian
Payloadbyte sequence, maximum 500 bytes

The Packet Type field indicates the type of the packet. It is set to

For data packets, the Sequence Number is the modulo 32 sequence number of the packet, i.e. the sequence number range is [0,31]. For ACK packets, Sequence Number is the sequence number of the packet being acknowledged.

The Packet Length field specifies the total length of the packet in bytes, including the packet header. For ACK and EOT packets, the size of the packet is just the size of the header.

Sender Program

You must implement a sender program that takes two arguments: the value of a timeout in milliseconds and a filename. The sender then transfers the file reliably to the receiver program. The timeout is used as the timeout period for the reliable data transfer. During the transfer, the sender program should create packets as big as possible, i.e. containing 500 bytes payload, if enough data is available. After all contents of the file have been transmitted successfully to the receiver and the corresponding ACKs have been received, the sender should send an EOT packet to the receiver. The sender can close its connection and exit, after the receiver has responded with an EOT packet. You can assume that EOT packets are never lost. The sender must be robust in the presence of a faulty receiver. For example, when receiving unsolicited ACKs or EOT, the sender must report this as error to standard error, but otherwise continue.

Receiver Program

You must implement a receiver program. The receiver program takes one argument: the filename to which the transferred file is written. When the receiver program receives the EOT packet, it sends an EOT packet back and exits. The receiver must be robust in the presence of a faulty sender. For example, when receiving data packets out of range or an EOT while packets are still missing, the receiver must report this as error, but otherwise continue.

Output

For both testing and marking purposes, your sender and receiver program must print log messages to standard output - a line for each data packet being sent and received (including duplicates) in the following format:

PKT <SEND|RECV> {DAT,ACK,EOT} <sequence number> <total length>
For example:
PKT SEND DAT 17 512
PKT RECV ACK 17 12
You must follow this format to avoid problems during testing and marking.

Further, whenever your program executes a potentially blocking function call (read, recv, select, sleep, etc.), it must print a message to standard output, describing the call that is being made. The format of this message is not important, but it should not contain the string "PKT". If the program ever hangs, this output will help to determine why.

Selective Repeat

In the Selective Repeat variant, if there's data available for sending, the sender sends more data according to the current status of its send window. The send window size should be set to a fixed value of 10 packets. ACKs are not cumulative and only acknowledge the sequence number in the ACK packet. Follow the description of Selective Repeat as discussed in class.

Channel Emulator

The channel emulator is started with the following syntax:
channel <max delay> <discard probability> <random seed> <verbose>

Addressing

In order to avoid global addressing settings, but enable quick testing, the following addressing scheme is used. The receiver program is started first and must write its 'E' address information (hostname and port number) into a file recvInfo that is read by the emulator. The channel emulator is started next and uses this information to send packets towards the receiver. The corresponding sending address 'C' of the emulator must be learned automatically by the receiver (see man recvfrom) upon reception of the first packet and used for sending all acknowledgements. The same mechanism is used between the sender and the emulator, i.e. the emulator writes its 'B' addressing information into a file channelInfo which is then read by the sender. The sending address 'S' of the sender is learned automatically by the channel. All files are read and written in the current directory. The contents of each file are the hostname and port number, separated by space. Example:

cpu06.student.cs 38548

Additional Comments/Hints

  1. Since UDP is used for data transmission, delivery to and from the channel emulator is not guaranteed. This should not matter for data or ACK packets. You can ignore the residual probability that this could result in a loss of an EOT packet.
  2. Be aware that the channel emulator only forwards two EOT packets (one in each direction) and then exits!
  3. To implement the operating system timer using C/C++, you need to use either 'select' or 'ualarm' . Read the respective man pages to learn about these mechanisms.
  4. In general, carefully read the man pages of all system calls that you are using.

Download

Procedures

What to hand in

Evaluation

The assignment is to be done individually. Your program will be evaluated in the student.cs undergraduate computing environment. Your program should not silently crash under any circumstances. At the very least, all fatal errors should lead to an error message indicating the location in the source code before termination. Marks will be assigned as follows:

Submission Instructions

After you have completed testing your code, hand it in using the submit command. Combine all files as a zip/tar/gzip/bzip2 archive with any of the following corresponding names: a2.{zip,tgz,tbz}. Make sure to execute 'make clean' before submitting and do not submit temporary or object files.