CSS 432
Program 2: Sliding Window
Professor Dimpsey
As a starting point for this program two classes have been provided: UdpSocket and Timer. These classes have been posted to Canvas. Please use these to implement this lab. The Timer class makes measuring an interval of time simple by calling the Start() member function at the beginning of the interval to measure and the End() at the conclusion. The details of UdpSocket are below.
Methods | Descriptions |
UdpSocket(int port) | A default constructor that opens a UDP datagram socket with a given port. Use the last five digits of your student ID as the port number. |
~UdpSocket() | A default destructor that closes the UDP datagram socket it has maintained. |
bool setDestAddress(char ipName[], int port) | Set the destination IP address corresponding to a given server ipName and port. This method must be called before sending the first UDP message to the server. |
int pollRecvFrom() | Check if this socket has data to read. The method returns the number of bytes to read or 0 if no messages have arrived. In general, a program is blocked to receive data if there are no data to receive. Call this method if you need to prevent your program from being blocked when receiving data. |
int sendTo(char msg[], int length) | Send msg[] of the length size from a client to a server. The server address is set by setDestAddress( ) before this call. If you send a single char variable, say c, your call should be sendTo( &c, sizeof(c) ). |
int recvFrom(char msg[], int length) | Receive data into msg[] of the length size. This method can be both used to receive a message from a client as well as an acknowledgment from a server. If you receive a single char variable, say c, your call should be recvFrom( &c, int sizeof(c) ). |
ackTo(char msg[], int length) | Send an acknowledgment from a server to a client. Prior to calling this method, a server must receive at least one message from a client, (i.e, call recvFrom() at least one time.) |
Details of each of these cases is provided below.
Case 1, Base UDP (unreliable): Sends 20,000 UDP packets from the client to a server. In this case if a packet is dropped along the way the server will not know and will hang continuing to wait for it. The actual implementation can be found in the hw2.cpp file in these functions:Case 2, Stop-and-wait test: Follows the stop-and-wait algorithm in that a client writes a message sequence number in message[0], sends message[] and waits until it receives an integer acknowledgment from a server, while the server receives message[], copies the sequence number from message[0] to an acknowledgment, and returns it to the client. You are to implement this algorithm in the following two functions:
Case 3, Sliding window: Implements the sliding window algorithm. The client keeps writing a message sequence number in message[0] and sending the message[] as long as the number of in-transit messages is less than a given window size. The server receives message[], records the sequence number in its array and returns as its acknowledgment the minimum sequence number of messages it has not yet received (called a cumulative acknowledgment). NOTE! the window size in our assignments means the number of messages but not the number of bytes. You are to implement this algorithm in the following two functions:
Compile the files with g++ to produce the executable hw2
$ g++ UdpSocket.cpp Timer.cpp hw2.cpp -o hw2Run this program both on a client and a server hosts. For the client-side pass in as an argument the host name of the server. The server does not take any arguments. The program will display the following messages to the standard error:
Client side example: $ ./hw2 csslab4 > data Choose a testcase 1: unreliable test 2: stop-and-wait test 3: sliding window --> Server side example: $ ./hw2 Choose a testcase 1: unreliable test 2: stop-and-wait test 3: sliding window -->Type 1, 2, and 3 for evaluating the performance of the three different test cases respectively. The main function in hw2.cpp will print out the resulting data to cout. In the above example on the client side this will re-direct to the file called data.
Test case #1 has already been implemented for you. Run this on the client and server to make sure you have proper connectivity. You can recompile and run hw2 in verbose mode to get a printout to cerr on each message. Run this test case a number of times until the server hangs which shows a dropped message. Nothing needs to be turned in for this test case.
For the test case #2, run your program in the linux lab a number of time with the client and server on different hosts. Average the times to get good measure on the elpased time for this algorithm.
For test case #3, measure the window size from 1 - 30.
Criteria | Percentage |
Documentation in detail of the the stop-and-wait and sliding-window algorithms including illustrations. | 4pts (20%) |
Source code that adheres to good modularization, coding style, and an appropriate amount of comments. The source code is graded in terms of (1) ClientStopAndWait( )'s message send and ack receive, (2) ClientStopAndWait( )'s timeout and message re-transfer, (3) ServerReliable()'s message receive and ack send, (4) ClientSlidingWindow()'s message transfer and ack receive, (5) ClientSlidingWindow()'s timeout and duplicated message re-transfer, (6) ServerEarlyRetrans()'s cumulative acknowledgment, and (7) coding guidelines. | 10pts (50%) |
Performance results in graph and discussion which illustrates the relative performance of stop-and-wait and sliding window with the differing window sizes from 1 - 30. Also, include discussions on the retransmission rate for the algorithms. | 6pts (30%) |
Total | 20pts (100%) |