Implement the simplex protocol for a noisy channel (Fig. 3-12 from Tannenbaum).

General rules: source code must be commented and a description how to run the programs must be attached.

The goal is to implement a data transmission programs that involve two layers:
Physical layer and Data link layer.
We will simulate the physical layer by the transport layer using the programs described in the lecture
"Unix Network Programming".
For the programs on the data link layer follow the Fig. 3-12.
You will need to modify the meaning of functions in Fig. 3-12 so that they relate to the regular 
Unix Network Programming functions.

Sender sends data every Pt = 500ms and always has data to send.
Sender timeout is Rt = 1 sec. Send packets over UDP.

Sender follows the usual logic.
We need to simulate losses since our network will almost never lose packet. At the receiver, write additional code in two places

  1. As soon as the receives gets a packet (before any update to variables): Ignore the packet with probability P = 0.2. This simulates a lost data packet.
  2. Just before the receiver sends an ack (after updating variables): Don't send the ack with probability P = 0.2. This simulates a lost ack.

How to drop/ignore packet with probability P ?
Generate a random float point number p, between 0 and 1. If p < P then drop/ignore packet, else handle packet.

Packet format

First byte : type (0 for data packet, 1 for ack)
Second byte: seqNo
Remaining bytes: 0

Output format

Both sender and receiver must write log statement at a output file for every significant event. The log statement should have the following format:

<Timestamp>: <Event> <Event parameters>
For example, the sender log might look like the following:
19:32:31.234543: Sent_packet seqnum=0
19:32:31.234712: Received_ack seqnum=0
19:32:31.756743: Sent_packet seqnum=1
19:32:31.756943  Received_ack seqnum=1
19:32:31.756743: Sent_packet seqnum=0
19:32:32.845435: Timeout seqnum=0
19:32:32.845455: Sent_packet seqnum=0 Retransmit
19:32:32.845655: Received_ack seqnum=0 
This shows what the sends log would like with a data packet is lost and timer expires.

Play around with with varying Pt, Rt and P values and see if the results are as expected. It is best to accept these values as command line parameters so that it is easy to experiment.