Simulation of ARQ
By Yuanhua Wang, Haitang Wang, Yong Xu
Problem Background:
A major concern in data communications is the control of transmission errors caused by channel noise so that error-free data can be delivered to the user. Error control systems that rely only on a one directional (forward) channel are called forward error correction (FEC) systems. Systems that make use of a reverse or feedback channel are called automatic repeat request (ARQ) systems and are based on protocols that request retransmission of data blocks when errors are detected. ARQ systems trade time for link margin and aim at returning all of the data reliably. Working at the link layer, ARQ operates on blocks of data, known as frames, and attempts to deliver frames from the link sender to the link receiver over a channel. The channel provides the physical-layer connection over which the link protocol operates. A channel may be a direct physical-layer connection between the two link nodes (e.g., across a length of cable or over a wireless medium). ARQ may also be used edge-to-edge across a subnetwork, where the path includes more than one physical-layer medium. ARQ mechanism relies on an integrity check for each frame (e.g., CRC) to detect channel errors, and uses a retransmission process to retransmit lost (i.e., missing or corrupted) frames. ARQ requires both a forward and return path, and should be used over links that employ full- or half-duplex links.
ARQ protocol uses a link protocol mechanism to allow the sender to detect lost or corrupted frames and to schedule retransmission. Detection of frame loss may be via a link protocol timer, by detecting missing positive link acknowledgement frames, by receiving explicit negative acknowledgement frames and/or by polling the link receiver status. Whatever mechanisms are chosen, there are two easily-described categories of ARQ retransmission process that are widely used: Stop-And-Wait ARQ A sender using stop-and-wait ARQ (sometimes known as 'Idle ARQ') transmits a single frame and then waits for an acknowledgement from the receiver for that frame. The sender then either continues transmission with the next frame, or repeats transmission of the same frame if the acknowledgement indicates that the original frame was lost or corrupted.Stop-and-wait ARQ is simple, if inefficient, for protocol designers to implement, and therefore popular, e.g., tftp at the transport layer. However, when stop-and-wait ARQ is used in the link layer, it is well-suited only to links with low bandwidth-delay products. This technique is not discussed further in this document. Sliding-Window ARQ A protocol using sliding-window ARQ numbers every frame with a unique sequence number, according to a modulus. The modulus defines the numbering base for frame sequence numbers, and the size of the sequence space. The largest sequence number value is viewed by the link protocol as contiguous with the first (0), since the numbering space wraps around. TCP is itself a sliding-window protocol at the transport layer, so similarities between a link-interface-to-link-interface protocol and end-to-end TCP may be recognizable. A sliding-window link protocol is much more complex in implementation than the simpler stop-and-wait protocol described in the previous section, particularly if per-flow ordering is preserved. At any time the link sender may have a number of frames outstanding and awaiting acknowledgements, up to the space available in its transmission window. A sufficiently-large link sender window (equivalent to or greater than the number of frames sent, or larger than the bandwidth*delay product capacity of the link) permits continuous transmission of new frames. A smaller link sender window causes the sender to pause transmission of new frames until a timeout or a control frame, such as an acknowledgement, is received. When frames are lost, a larger window, i.e., more than the link's bandwidth*delay product, is needed to allow continuous operation while frame retransmission takes place. The modulus numbering space determines the size of the frame header sequence number field. This sequence space needs to be larger than the link window size and, if using selective repeat ARQ, larger than twice the link window size. For continuous operation, the sequence space should be larger than the product of the link capacity and the ARQ persistence, so that in-flight frames can be identified uniquely. As with TCP, which provides sliding-window delivery across an entire end-to-end path rather than across a single link, there are a large number of variations on the basic sliding-window implementation, with increased complexity and sophistication to make them suitable for various conditions. Selective Repeat (SR), also known as Selective Reject (SREJ), and Go-Back-N, also known as Reject (REJ), are examples of ARQ techniques using protocols implementing sliding window ARQ.
Implement
ARQ schemes:
In this project, we want to simulate three schemes of ARQ: Stop-and-Wait ARQ(SAW ARQ) , Go-Back-N ARQ (GBN ARQ), and Selective-Repeat ARQ ( AR ARQ).
We use JAVA to implement three schemes all together. All of our project can be divided into six classes: Windows.class, Sender.class, Receiver.class, Timer.class, media.class Pack.class and Global.class.
Description of main class:
Class1: Windows
Windows.class extends JPanel , Panel is an intermediate container. It can simplify the positioning of the Swing components, like: Combo box, button, check boxes, menus etc. Our interface contain two panel: ControlPanel() and DisplayPanel. ContolPanel is composed by ButtonPanel() in which are two buttons, SchemList() in which is a Combo box, and MessPanel which contains information of this project. DisplayPanel is to display the action of selected scheme. In the class of DisplayPanel we generate three threads: one is for Panel, the others for sender and receiver to implement actions of send information packets and receive information packets.
Class2: Timer:
We use Class Timer to tell if the information packets are lost or not while sending process. We create an entity t of Class Date. At the beginning of the transmission, we get the time t1 through t.getTime(), during the transmission (when Boolean variable stop = false), we also get the time t2 through t.getTime() . If t2-t1 is greater than the Max_delay, then we can tell that the packet is lost. The implementation of code is :
if(stop == false)
{
Date
t = new Date();
t2
= t.getTime();
System.out.println("inter
is "+interval+"
"+(t2-t1));
Global.Time_LEFT
= interval-(t2-t1);
if((t2
- t1)> interval)
Sender.retran=true;
}
Class3: Sender:
The Class Sender is responsible for the function of sending packets. At the constructor of the Class Sender, we need to compute the Max_delay.
packet_waiting_for_ack = 0;
RTT = media.RTT;
Max_delay =
(long)(RTT*1.3);
Interval =
RTT/(Max_Packet_In_One_Way);
When the sender begins to run, we first generate a thread for Class
Timer entity t. So when we start to send a packet, system firstly reset a timer
for this transmission. We need to tell the scheme of ARQ through the globe
variable Global.type_ARQ, then according to the scheme of ARQ, we call the
different sender method: Sender.Stop_and_Wait(), Sender.Go_Back_N() and Sender.Slective_Repeat().
if((Global.start)
&& (!Global.stop))
{
stop =
false;
System.out.println("Construct
a new timer");
seq_timer =
0;
timer.reset(Max_delay);
if(Global.type_ARQ ==
Global.Go_Back_N_E)
Go_Back_N();
else if(Global.type_ARQ
== Global.Stop_and_Wait_E)
Stop_And_Wait();
else if(Global.type_ARQ
== Global.Selective_Repeat_E)
Selective_Repeat();
}
Class4: Receiver:
Class Receiver is used to tell whether the receiver has received the packet or not and send the correct type of acknowledgement packets. In this Class, we use a private method Is_Good_Packet to tell whether the packet is correctly received or not.
private
boolean IsGoodPacket(packet pa)
{
if(pa.status == packet.GOOD)
return true;
else
return false;
}
Furthermore,
after the packet arrives, we call the method Is_Good_Packet to tell it, then
decide the type the acknowledgement.
For example in Stop_and_Wait:
if(msg_arrive)
{
if(IsGoodPacket(msg_packet))
media.newPacket(packet.ACK,msg_packet.sequence);
else
media.newPacket(packet.NAK,msg_packet.sequence);
msg_arrive = false;
}
At last we need to tell the scheme of ARQ through the globe variable
Global.type_ARQ, then according to the scheme of ARQ, we call the different
receiver method:
while(true)
{
if((Global.start) && (!Global.stop))
{
stop =
false;
if(Global.type_ARQ ==
Global.Go_Back_N_E)
Go_Back_N();
else if(Global.type_ARQ
== Global.Stop_and_Wait_E)
Stop_And_Wait();
else if(Global.type_ARQ
== Global.Selective_Repeat_E)
Selective_Repeat();
}
Class5: media:
Class media is
used to implement the animation of the process of the ARQ. In this Class, we
define several methods to implementation the animation. These methods are
shift(), paintFrame(Graphics g), update(Graphics g), makeDirty(),
InsertMsg(String msg), and newPackt(int type, int sequen).
Class6: Global:
In class Global,
we define several important global variables:
class Global
{
public static final int
Stop_and_Wait_E = 4 ;
public static final int Go_Back_N_E
= 5 ;
public static final int
Selective_Repeat_E = 6;
public static final int HIGH = 100 ;
public static final int MIDDLE = 50
;
public static final int LOW = 0;
public static boolean start;
public static boolean stop;
public static int type_ARQ = Stop_and_Wait;
public static int SPEED
= MIDDLE;
public static int ERROR
= MIDDLE;
public static int
factor_LOST = 2677;
public static int
factor_DIRTY = 1999;
public static int step
= 25;
public static long
Time_LEFT = 0;
public static String[] msg =
{"","","",""};
}
Class7 : packet:
In class packet,
we define some character of different types of packets, including the sequence
number of the packet, color of the packet and content of the packet. We use
switch…case to tell the type of the message and define the character of them.
switch (type){
case O_MSG:
x
= media.w1+10;y = 100;dx = 2;
tag
= "PAK"+sequ;
color
= Color.black;
content
= O_MSG;
break;
case R_MSG:
x
= media.w1+10;y = 100;dx = 2;
tag
= "PAK"+sequ;
color
= Color.pink;
content
= R_MSG;
break;
case ACK:
x
= media.d.width-media.w2-40;y = 50;dx = -2;
tag
= "ACK "+sequ;
color
= Color.green;
content
= ACK;
break;
case NAK:
x
= media.d.width-media.w2-40;y = 50;dx = -2;
tag
= "NAK "+sequ;
color
= Color.red;
content
= NAK;
break;
}
Implement result:
1.
Stop-and-Wait
(SNW ARQ)
2.
Go-Back-N(GBN
ARQ)
3.
Seletive-Repeat(
SR ARQ)
Reference:
1.
2.
Appendix: Source code