CS 4514

Assignment 1

C-Term 1997

Due date: Thursday, January 30

1. Overview

In this assignment you will write a program to simulate some of the functionality of a data link layer. In the ISO OSI Model, the data link layer communicates with the network layer and the physical layer. The data link layer accepts a stream of data bits from the network layer, breaks the bit stream into discrete frames, computes a checksum for each frame, and passes the frames on to the physical layer. In the reverse direction, the data link layer accepts frames from the physical layer, verifies that the checksum is correct (or reports an error), and passes the resulting bit stream to the network layer.

In order to avoid the complexities of dealing with a physical network (for now), your simulated data link layer will read from files instead of receiving data from the other layers, and will write to files instead of passing data to the other layers. You will not have to deal with acknowledgments and re-transmissions, issues that are usually handled by the data link layer.

2. Program requirements

Please be sure to use the precise file names specified in the assignment so your work will be graded accurately.

Your program should accept command line arguments in the following form:

executable -source filename

where source can take the value n if the data is to be treated as coming from the network layer, and p if the data is to be treated as coming from the physical layer, and filename is the name of the input file to be used. Your program will write two output files, to be named filename.output and filename.error.

2.1. Processing when reading data from the upper layers

Your program will write series of frames to the output file. Each frame will consist of the start flag (DLE STX), a sequence number, 64 bytes of data from the input file (plus any bytes for character stuffing), the checksum, and the end flag (DLE ETX).

The ASCII codes for the start and end flags are: DLE 0x10; STX 0x02; ETX 0x03.

The sequence number will start at 0 and increment by one for each frame you output.

Character stuffing is described on page 180 of Tanenbaum.

Use a one-byte parity check as the checksum. To calculate this checksum, add all the bytes of the data modulo 2 (use the bit-wise exclusive or operator, ^ ) and place the result as the last byte of the frame, before the DLE ETX. For extra credit, use the CRC-16 checksum as described in Section 3.2.2 of Tanenbaum.

2.2. Processing when reading data from the physical layer

You should read one frame at a time from the input file; each frame will begin with DLE STX and end with DLE ETX. Verify that the sequence number is correct. The sequence numbers will start at zero for each input file; possible errors are missing sequence numbers and repeated sequence numbers. Remove any character stuffing, and then verify that the checksum is correct. If there are no errors, write the data to the output file; if there is an error, write an error message to the error file, and do not write anything to the output file.

The first bytes in the file, and the bytes immediately following DLE ETX should be DLE STX; otherwise, there is "start flag missing" error. If you reach the end of the input file without finding DLE STX, that is an "end flag missing" error.

There are five possible errors:

  1. start flag missing
  2. end flag missing
  3. missing sequence number
  4. repeated sequence number
  5. checksum error.

You should report any of these in the error file (a text file) in the following format:

frame_number error_number error_message <end-of-line>

where frame_number is a count from the beginning of the input file (not necessarily the same as the sequence number), and error_number and error_message are from the list above.

What to do when an error occurs: In a real data link layer, if an error is encountered when reading from the physical layer, the sender is asked to re-transmit the frame that was in error. Since we are reading from a static file, that option is not available. If there is a repeated sequence number, discard the frame containing the repeated sequence number, and continue processing the input file. For any other error, stop processing the input file.

3. Grading

There are four functions the program should perform:

  1. adding and detecting start and end flags
  2. adding and detecting sequence numbers
  3. character stuffing and unstuffing
  4. checksums

Your grade will be based on how many of these functionalities you correctly implement. If you implement them all, you will receive an A. If you implement fewer of them , your grade will be lower. It is expected that your program will use good program design, programming style, and will be properly commented. Egregious deviations from these expectations will result in a lowering of your grade.

4. What to turn in

Use the program turnin to turn in your work. You should turn in the following:

Do not turn in any executable files.