Simulating Stop N Wait Protocol

Port 4000
Abby and Ben

Receiver Side

The receiver must be started first before any connection can be established. We have used a random port that is higher than the assigned ports. Once the receiver is started it waits until it receives a message from the sender.

logmsg fuction - This is a one line function that prints a message to the screen stating that a connection has been established with a certain machine at that given time.

The next 15 lines of code were given to the class in server.pl from Charlie. This code established a connection between a server and a client.

In the following while loop the frames are received in from the sender. Each time a frame is received it is sent to a Check function (see below for description). The check funtion uses the CRC modulo 2 code to check if the remainder after the division is 0. If so, the check function returns a 1 but if a error an occurred it will return a -1. This result will be sent back to the sender to let it know if it needs to re-send the frame or send the next frame.

Check funtion - Most of the details were just described above. This function also has the job of unpacking the frame and separating the checksum and the data.

Generate_CRC function - The CRC (Cyclic Redundancy Check) function is a piece of error detection code that can use a couple of different mathmatical methods to check. Our implementation uses modulo 2 division by having some given binary pattern divide a binary message to define the checksum. This 2 byte checksum is added onto the end of the message and sent to the sender. Our given pattern must have both the high and low order bits equal to 1.

Sender Side

The initial job of the sender is to read in from the command line the name of the input file and the probability of whether or not 1, 2 or 3 bits will be flipped by a Gremlin function. The next job of the sender is to read in 8 bytes the input from a file at a time until the end of file. Once this occurs, the last frame is padded with 0's or a final frame of all 0's is sent to signify the end of the message passing. Each frame will be passed to the Generate_CRC funtion that will provide a checksum to be passed along as the last two bytes of the frame. Once this has occurred the Gremlin and Client function are called for corruption and message passing.

Gremlin function - The gremlin function needs to have a random number generator to use for comparison with the probability to see whether or not a bit will be flipped. If the random number is less than the probability then a series of three if statements will determine how many bits to flip. If random is less than .5 then one bit will be flipped. If random is less than .3 then two bits will be flipped or if random is less than .2 then three bits will be flipped. If a bit is to be flipped then the entire frame is sent to the flip function that will randomly flip the correct number of bits in the frame.

Client function - This also contains a code that Charlie gave us in client.pl for starting up a client to communicate with the server. Once the connection has been established the buffer is flushed and the frame is sent across the socket. Since this is the stop and wait protocol the sender must wait before sending any more packets until it has received some kind of acknowledgement from the receiver. If the receiver acknowledges with a positive responce the sender can send the next frame else it must re-send the same frame.