CSCI-4220 Network Programming

Spring 2000

Project 1 - Layered System
Due Date: January 25th (received by midnight)

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. I've already done this, you can test your code using the layer 0 subroutines and the main program provided here. This code uses pipes to communicate between a parent and child process.

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. If l0_read() returns a 1, the character *buf will contain the value 0 or 1 (this is the bit that was read). NOTE: The value of *buf will be 0 or 1, not '0' or '1'.

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 by the other end of the communication (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!).

int l1_read(int cid, char *buff);

int l1_write(int cid, char c);

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

Layer 1 is unreliable, so having l1_write return a 1 means that the data was sent (using layer 0) and we have no idea if the other end actually got the data.


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!).

int l2_read(int cid, char *buff);

int 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. I'm not looking for timers and retransmissions, just make sure these functions work when everything goes smoothly...


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!).

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

int 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 brief (one or two paragraph) description of your implementation of 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 in a single file named layers.c. Feel free to include any test code you develop, but make sure that the file layers.c contains only your layer 1,2 and 3 code. Submission instructions will be posted on the course web site when ready. Your code must also include a file named README that includes the following:

Computer Accounts

You can use any machines you want, your RCS account is fine for this project. I am requesting CS (Computer Science) accounts for everyone that is officially on the course roster on Friday, 1/14/00, they will hopefully be ready within a few days. You should receive email from labstaff@cs.rpi.edu when you account is ready, including some brief instructions on how to log in. If you have any problems getting started with your CS account, send email to netprog@cs.rpi.edu.

The lecture on 1/13 includes a description of the homework and a demonstration of the test code provided, if you slept through the lecture you can always rent the video tape or wade through the video stream available via the course home page...

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

HTML>