Homework 4
Due Wednesday, May 26

Make sure to combine all required files, for both problems, into one large .tar file. Remember that when a requirement is explicitly stated, it is required.

Problem I:

Write a pair of programs, a client Sender.c and a server Receiver.c, to do "Go Back N" flow control and error recovery.

The usage format of sender is

sender N receiver_hostname port_number

where N is the maximum window size. Usage for receiver is

receiver N port_number

A frame will consist of

In the context of our simple experiment here, you may or may not get "natural" errors, so you will simulate them: Program the receiver to NAK 10% of the frames, even if they are correct.

Have the receiver send an ACK or NAK for each frame. You will not simulate lost ACK/NAK messages from the receiver.

Feel free to have Receiver.c use separate sockets for receiving and sending if you wish, and similarly for Sender.c.

Use UDP, not TCP. Note that that means you need only one call to read()/recvfrom() for each call to write()/sendto().

Have Sender.c use malloc() and free() to store pending frames and discard ACKed ones.

This is meant to be a simple illustration of windowing and error control, nothing elaborate like calls to fork(), threading, signals etc. I merely want sender to send out N frames, receive (hopefully) N ACKs, send out N more frames, etc. If it gets an ACK, it will have to back up, but still it will send N frames from the point it was told to back up to.

Here is pseudocode for the heart of Sender.c:

I = 0
while (1)  {
   for L = I to I+N-1 mod N
      send frame L 
   for J = 1 to N  {
      receive ACK/NAK
      if NAK(K)  {
         I = K
         break
   }
}

Keep in mind that the frame numbers get reused. For instance, if there is no error, then your second frame 3 should be different from your first frame 3. So, for example, if there is no NAK in a batch of N frames, although the pseudocode shows that the variable I will not change, it will not be the case that we send out the same N frames again.

For its part, receiver will ignore the remaining frames it receives in an N-frame set after sending a NAK back to sender. Note, though, that it must read the frames anyway, so that they are not confused with the next batch.

To help illustrate the concepts, both programs will report what they are doing, printing out messages:

Note that this will also be used by the reader to test that your checksum is working properly.

Have your code process enough frames for a thorough test, say 30 frames or so.

Problem II:

In this problem you will investigate the error-catching abilities of CRC, and write up your findings in LaTeX. Here we will have m = 5 and c = 4. We will take our C to be 1011.

Assume each of the eight bits has probability p of being in error, with bit errors being independent. Thus for example the error pattern E = 00110100 has probability p3(1-p)5.

Find all eight-bit E patterns which that C will NOT detect. Note that this is easy, because they consist of all possible products C*Q, where Q ranges over all 31 nonzero five-bit strings. List all these strings, and the probability of occurrence for each (one probability for each string).

(Do the multiplication C*Q just like the division--mod 2, and bitwise. To check you are doing it right, look at the division example in our CRC handout; there C*Q+R should come out to the original dividend, M'.)

Plot the probability of an undetected error, that is P(E is nonzero and C divides E), as a function of p.