CSCI-4220 Network Programming

Spring 1999

 

Project 1 - Layered System
Due Date: Jan 21

Submission Instructions


Layered System

This project involves the creation of code that provides functionality of 3 layers in a layered communication system. The functionality of each layer is described in detail later in this document, here is the general idea:

LayerService Provided
0 transfer of a single bit of data between 2 processes (you don't have to write this layer - it is provided)
1(unreliable) transfer of a single byte (8 bits) of data.
2 reliable transfer of a single byte (8 bits) of data.
3 supports the reliable transfer of a null terminated ASCII string.

For each layer you must provide subroutines (C functions) that provide the services needed by senders and the receivers. The API (Application Programming Interface) for these interfaces is listed below - you must provide functions that support this API! Each of your layers will be tested individually (with alternative implementation of the other layers) so you must support the API exactly!

Testing your code means that you need to come up with some kind of implementation for layer 0. You can use a pipe, FIFO or socket and pass the file/socket descriptor as the cid, and you might want to check the P1 FAQ - I will probably include some sample code for layer 0 and some code that calls layer3 with valid cid's ("communication id"s) that will work sample layer 0 code.


Layer 0 API

You don't need to write these functions - they are provided so you can call them (and described here so you know what to call). The cid parameter represents a "communication endpoint identifier", the exact nature of this endpoint is not important (you don't need to know anything about it other than that your layer 1,2 and 3 code needs to pass them along to lower layers).

int l0_read(int cid, char *buf);

l0_read() returns a 1 on success, and a negative number on error. You don't need to worry about the cause of the error, for this assignment you can simply note that an error occurred. l0_read() is a blocking function - it will not return until there is an error, or a character is received.

int l0_write(int cid, char c);

l0_write() returns 1 on success and a negative number on error. The valid values for the c parameter are 1 and 0 (not '1' and '0'), l0_write() will return an error if you give it anything other than a 1 or a 0. If l0_write returns without an error it only means that the bit of data was sent, not that it was received (l0_write is not reliable).


Layer 1 API

Layer 1: sends/receives 1 byte (8 bits). You need to write these (and they should use the layer 0 code to send bits!).

l1_read(int cid, char *buff);

l1_write(int cid, char c);

Return values should be 1 on success, -1 on any error.


Layer 2 API

Layer 2: sends/receives 1 byte (8 bits) reliably. You need to write these (and they should use the layer 1 code to send bytes!).

l2_read(int cid, char *buff);

l2_write(int cid, char c);

Return values should be 1 on success, -1 on any error. This is the only difficult layer - you need to create a service that ensures that the destination received the byte of data. There are many possible ways of providing this reliability - although in general you need to have the receiver acknowledge receipt of the data. You do NOT need to worry about data integrity for this assignment (making sure the right data was received - just that a byte was received is enough). You also don't need to worry about having the receiver know that it's acknowledgement was received.


Layer 3 API

Layer 3: sends/receives a NULL terminated ascii string reliably. You need to write these (and they should use the layer 2 code to send bytes reliably!).

l3_read(int cid, char *buff, int maxlen);

l3_write(int cid, char *s);

l3_read() needs to have the maxlen parameter so that l3_read() does not write past the end of the buffer passed in. l3_read() should return an error if it reads maxlen bytes without finding a terminating NULL. l3_read() must return a NULL terminated string (including the null!).

Both functions should return a negative number on error, and on success should return the number of bytes written/received on success.


Deliverables

You should submit a one page writeup describing how you would implement the 3 layers, specifically provide a detailed description of how layer 2 (reliable bytes) would work. You should also submit the source code for your implementation of the 3 layers. Feel free to include any test code you develop as well. Submission instructions are here. Your code must also include a file named README that includes the following:

Computer Accounts

You can use any machines you want, but you might as well get used to using the CS machines (later projects will be done only on the CS machines). Your code will be tested on the CS machines, so you need to make sure your code can be built and run on the CS machines.

All questions should be sent to "netprog@cs.rpi.edu".