Stop and Wait Protocol Laboratory Introduction A data file is to be transferred from one computer to another computer. For our purpose, only half duplex transmission is required. The file is to be segmented into a number of frames. Frames are then transmitted one after another. Frame size can be variable or fixed. If the frame size is not fixed, then data indicating the end of the frame or frame size has to be included in each frame for transmission. For the ease of implementation, fixed frame size is used. A frame consists of a. STX – start of frame indicator b. Header – refer to lecture for usage of header [Sequence no, flow control commands etc] c. BCC d. EOT – end of frame indicator A frame format has to be defined. For simplicity, ASCII data text file is to be used for transmission. Since only ASCII text data is expected, control characters as defined in the ASCII table can be used for control, command and frame delimiter. STX, EOT etc as defined in the ASCII table can be used. In our lab, we have to define the frame FORMAT ie STX, EOT, Header and frame size etc. After defining the frame format, one has to draw two flow charts, one for the transmission and one for reception of frames according to the stop and wait protocol. Student should refer to text books for detailed description of stop and wait protocol. Commands required for the flow control and implementation of the protocol has to be defined. Bit pattern or code representing each command is also to be defined and written as a “.h” file. After defining the commands and its corresponding codes, one should follow the flow chart closely and prepare the corresponding psuedo code. Before start writing program codes to implement the work required, one should write individual simple programs to try and test out various individual functions which is expected to be used in the program. Functions include open and close files, initialization of serial ports, interrupt timer, keyboard scan, display of received characters, user interface, BCC calculation etc. After one has tried out all the function calls and proved that each piece of code work properly then implementation of the psuedo code will become a simple job. To help implementation, sample drivers are provided. Student should ask the lab technician to locate the sample drivers in the PC directory. Following describe the usage of BCC in checking transmission error. In our experiment, we use the RS232 port for transmission. We use start bit, stop bit, party bit and 8 data bit for transmission. The format is handled by build-in hardware and can not be accessed by software. Also the distance of transmission from one PC to another PC is very short. We do not expect any transmission error. For testing purpose, errors will be artificially introduced by interrupting the transmission path manually. This can be achieved by shorting the Tx to ground for a short period. Error is detected by calculating the BCC or Check Sum. Following is an example of BCC. On transmitter side Data0 0x03 Data1 0x3e Data2 0xf0 -----0x31 (Sum) ----0xce (complement) 1 (add 1) -----BCC 0xcf On receiving side, Data Data Data BCC 0x03 0x3e 0xf0 0xcf -----0x00 => no error detected Depends on the duration of open circuit or short circuit, a fame can be corrupted, disappeared or shortened with a few bytes disappeared. It is up to the flow control and error control to detect and handle the situation. User interface Friendly interface is required. The screen should display the frame number, the flow control commands transmitted and received. The start and end time as well as the transfer duration, number of frames transmitted and corrupted should also be displayed. As a pre-lab homework, student should study the stop and wait protocol for file transfer and draw a detailed flow chart for transferring a disk file from one PC to another PC. The protocol or logic for the flow control should be able to handle 1. error frame 3. lost data frame 2. link disconnect 4. loss Ack frame Briefing on Stop and Wait protocol Laboratory 3. Borland C language – [Students should be well familiar with the C language and should have tried out the following functions] File handling – open and close, end of file detection, file size etc. Serial I/O handling – read and write of Com ports – scanning or interrupt Scanning – program check ports faster than incoming baud rate Interrupt – Put data into buffer Check buffer and do flow control Real time clock and timer interrupt – For trip delay calculation For communication link error control Keyboard scanning – detect keyboard entry Display – format output on CRT display 4. Driver and sample program provided a. Driver to initiate PC com port b. Driver to handle COM port interrupt c. Sample to scan keyboard d. Sample to display on CRT e. Sample main program to scan keyboard and transmit key board code to IO port f. Sample main program to detect I/O input and display on CRT To get familiar with the development platform student should 1. Restart the PC and select DOS mode 2. Enter “BC” to start the Borland C compiler 3. Locate the com1.c driver 4. Copy the file to another name of your own. 5. Recompile and run the program. Following info is useful for program development. Student should make use of the drivers provided. 1. On Tx side: Write a program to detect keyboard hit and put the detected character byte into com port driver for transmission. [ note: Low level transmission signal requirement such as start bit, stop bit, party bits etc will be handled by hardware and is not accessible from software. It is being done automatically.] 2. 3. On Rx side: Write a program to detect character byte received from com-port driver and display the character on screen. On Tx side : Define an array as a Tx-buffer for transmission and write a buffer transmission function program. When the function is being called, the program will transfer the content of the array byte by byte to the com-port for transmission. On Rx side : Define an array as a Rx-buffer for receiving character bytes from com-port driver and write a receive function program. The program will check the com-port driver for any input data. If an input byte is ready, the program will transfer the byte from the com-port driver buffer into the Rx-buffer array. On Tx side : Write a function to do the following i. open a text file located in hard disk drive. ii. Read the file and transfer the content of the file byte by byte to the Tx-buffer array. When the Txbuffer is full, call the buffer transmission function to send the content of the Tx-buffer to comport. iii. Repeat the above process until the whole content of the file is transmitted through the com-port. On Rx side : Write a function to check the content of the Rx-buffer array. If the Rx-buffer is full, then transfer the content of the buffer into a hard disk file. The file has to be opened before it can be written and closed after the whole file content has been written. 4. The Tx-buffer and Rx-buffer can be considered as a frame. A frame can be divided into different fields including data, BCC, header, frame sequence etc. 5. On Tx side : Write a function to calculate the BCC for the content of the data in the frame and put the result into the BCC-byte. On Rx side : Write a function to check the content of the received frame. If no error is detected, an Ack should be returned else a NAck should be returned through the com-port to the receiver. 6. On Tx side : After a frame has been transmitted, start a timer and wait for acknowledgement. If positive Ack is received then prepare another frame for transmission If negative Ack is received then retransmit the old frame. If no Ack after timer time out then retransmit the frame. If no Ack after a number of retransmission then indicate link down 7. Modify the program according to the pre-lab homework flow-chart or psuedo code. To monitor the status of the data transfer, the following information should be displayed on the screen. 1. frame number 2. error frame and retransmit indicator and total number of error frame detected 3. File transfer time information 4. File size, frame size and total number of good frames transmitted 5. file name Student should compare the file transfer time for various frame sizes. Repeat the above with link interruption.