All tasks are completed.
In this assignment, the main task is to implement the Sliding Window Protocol (SWP) in java. However, the sample code provided in the lecture notes is in C. Therefore, this main task is divided into the following sub-tasks:
Port the SWP code to Java
Implement missing timer related classes and functions
The following sections will cover these three sub-tasks.
Porting the code
Minor changes were made in order to change the syntax of the code to Java.
As seq_nr was not specified in the given files, it was replaced with int type.
In the original code, to declare a frame named s, it used the following syntax:
However, to create a frame object in Java, the code was modified accordingly.
The same change was made to the following code:
The resulting code was shown below.
The out_buf and event were not declared here because they were pre-set in the given code. In order to make the piece of code below work, credits were added as parameter.
As a result, it was changed to
NR_BUFS was the maximum buffer size (window size) that could be held to avoid redundant retransmission. Therefore, it was put in as credit to initialize the network layer with the same number of buffers.
Implementation of classes and functions
Two timer related classes were implemented for different timer purposes.
PacketTimeOut
PacketTimeOut was to monitor and time how long had passed since a packet was transmitted.
AckTimeOut
AckTimeOut was to monitor the expiration of an acknowledgement timer.
Both of them extended from the TimerTask class and overrode the run() method to generate acktimeout_event.
On the other hand, five functions were implemented to complete the protocol.
Private void start_timer(int seq)
The start_timer started a timer function for each packet transmitted. If a packet timer already existed, it was cancelled. When the timer of a packet had expired (time_out),
that