CPS 114 Introduction to Computer Networks: Labs

Lab 1: Reliable transport

Introduction

Your task is to implement a reliable sliding window transport layer on top of the user datagram protocol (UDP). You are NOT required to handle demultiplex traffic, but you should not rely on UDP's checksum to detect bit errors in packets.

In this assignment, you are provided with a library (rlib.h and rlib.c) and you have to implement some functions and data structures in reliable.c. rlib.[h|c] provides some useful helper functions. Your implementation should:

You will implement both the sender and receiver component of a transport layer. The sender will read a stream of data in, break it into fixed-sized packets suitable for UDP transport, prepend a control header to the data, and write this packet to the receiver. The receiver will read these packets, and write the corresponding data, in order, to a reliable stream.

Getting started

You should be able to finish your assignment on any machine in the department's linux cluster: linux.cs.duke.edu. If you prefer to finish your assignment on your own machine, you may download and install ubuntu. You may run Ubuntu a virtual machine such as the free VirtualBox. We do not support MAC or Windows. Sorry.

Download and untar the reliable.tar.gz.

xwy@linux21$ wget http://www.cs.duke.edu/courses/spring10/cps114/labs/lab1/reliable.tar.gz
xwy@linux21$ tar xzvf reliable.tar.gz

Copy reliable.c-dist to reliable.c. Your task will be filling in the functions in this file.

You should be able to run the command make to build the reliable program. An example of the working program is given here.

On machine linux21, run:

xwy@linux21$./reliable 6666 linux22:5555
[listening on UDP port 6666]

On machine linux22, run:

xwy@linux22$./reliable 5555 linux21:6666
[listening on UDP port 5555]

When you are done with the assignment, anything you type on linux21 will show up on linux22 and vice versa.

Understanding the code

Packet format

There are two kinds of packets, Data packets and Ack-only packets. You can tell the type of a packet by length. Data packets vary from 12 to 512 bytes, and Ack packets are 8 bytes. The packet format is defined in rlib.h:

        struct packet {
          uint16_t cksum; /* Ack and Data */
          uint16_t len;   /* Ack and Data */
          uint32_t ackno; /* Ack and Data */
          uint32_t seqno; /* Data only */
          char data[500]; /* Data only; Can be less than 500 bytes*/
        }; typedef struct packet packet_t;

Every Data packet contains a 32-bit sequence number and 0 or more bytes of payload. Both Data and Ack packets contain the following fields. The length, seqno, and ackno fields are always in big-endian order (use htonl/htons to write and ntohl/ntohs to read):

The following fields only exist in a data packet:

Requirements

Your transport layer must support the following:

Functions and data structures you need to implement

The reliable transport protocol connects the standard input and output of the sender and receiver processes together. You are provided with a library (rlib.[h|c]) and your task is to implement the following six functions: rel_create, rel_destroy, rel_recvpkt, rel_read, rel_output, rel_timer:

Testing and Debugging

For debugging purposes, you may find it useful to run ./reliable with the -d command-line option. This option will print all the packets your implementation sends and receives.

For testing purposes, you may wish to download the source code for our test and a reference implementation here. You may compile the reference implementation and the tester on any of the department's linux machined by typing "make" in the tester-src directory after you untar the source file. Your program ./reliable should be able to communicate with the reference implementation. The tester takes your program reliable as an input and runs it against the reference implementation. Run the command ./tester, and ./reference to see the list of options available. In particular, ./tester -L will list the set of tests we will run against your reliable program. The -v option will print out packet traces for you. You should NOT use the tester's -s option, and test for window sizes greater than 1.

Submitting

To submit the assignment, do the following:

Collaboration policy

You can discuss with anyone, but you must not look at each other's code, or copy code from others.

Acknowledgement

We thank the course staff of cs 144 at Stanford university for their support. This lab is adapted from one of their assignments.

Last updated: 01/2010