Bidirectional Algo For Stop and Wait
Bidirectional Algo For Stop and Wait
Review Questions
1. The two main functions of the data link layer are data link control and media
access control. Data link control deals with the design and procedures for commu-
nication between two adjacent nodes: node-to-node communication. Media access
control deals with procedures for sharing the link.
2. The data link layer needs to pack bits into frames. Framing divides a message into
smaller entities to make flow and error control more manageable.
3. In a byte-oriented protocol, data to be carried are 8-bit characters from a coding
system. Character-oriented protocols were popular when only text was exchanged
by the data link layers. In a bit-oriented protocol, the data section of a frame is a
sequence of bits. Bit-oriented protocols are more popular today because we need to
send text, graphic, audio, and video which can be better represented by a bit pat-
tern than a sequence of characters.
4. Character-oriented protocols use byte-stuffing to be able to carry an 8-bit pattern
that is the same as the flag. Byte-stuffing adds an extra character to the data section
of the frame to escape the flag-like pattern. Bit-oriented protocols use bit-stuffing
to be able to carry patterns similar to the flag. Bit-stuffing adds an extra bit to the
data section of the frame whenever a sequence of bits is similar to the flag.
5. Flow control refers to a set of procedures used to restrict the amount of data that
the sender can send before waiting for acknowledgment. Error control refers to a
set of procedures used to detect and correct errors.
6. In this chapter, we discussed two protocols for noiseless channels: the Simplest
and the Stop-and-Wait.
7. In this chapter, we discussed three protocols for noisy channels: the Stop-and-Wait
ARQ, the Go-Back-N ARQ, and the Selective-Repeat ARQ.
8. Go-Back-N ARQ is more efficient than Stop-and-Wait ARQ. The second uses
pipelining, the first does not. In the first, we need to wait for an acknowledgment
for each frame before sending the next one. In the second we can send several
frames before receiving an acknowledgment.
1
2
9. In the Go-Back-N ARQ Protocol, we can send several frames before receiving
acknowledgments. If a frame is lost or damaged, all outstanding frames sent before
that frame are resent. In the Selective- Repeat ARQ protocol we avoid unnecessary
transmission by sending only the frames that are corrupted or missing. Both Go-
Back-N and Selective-Repeat Protocols use sliding windows. In Go-Back-N ARQ,
if m is the number of bits for the sequence number, then the size of the send win-
dow must be at most 2m1; the size of the receiver window is always 1. In Selec-
tive-Repeat ARQ, the size of the sender and receiver window must be at most 2m1.
10. HDLC is a bit-oriented protocol for communication over point-to-point and multi-
point links. PPP is a byte-oriented protocol used for point-to-point links.
11. Piggybacking is used to improve the efficiency of bidirectional transmission.
When a frame is carrying data from A to B, it can also carry control information
about frames from B; when a frame is carrying data from B to A, it can also carry
control information about frames from A.
12. Only Go-Back-N and Selective-Repeat protocols use pipelining.
Exercises
13. We give a very simple solution. Every time we encounter an ESC or flag character,
we insert an extra ESC character in the data part of the frame (see Figure 11.1).
ESC ESC ESC Flag ESC ESC ESC ESC ESC ESC ESC Flag
00011111011001111100100011111011111010000111110
15. We write two very simple algorithms. We assume that a frame is made of a one-
byte beginning flag, variable-length data (possibly byte-stuffed), and a one-byte
ending flag; we ignore the header and trailer. We also assume that there is no error
during the transmission.
a. Algorithm 11.1 can be used at the sender site. It inserts one ESC character
whenever a flag or ESC character is encountered.
if (character = = ESC)
{
Discard (character); // Un-stuff
ExtractFrame (character); // Extract flag or ESC as data
}
InsertBuffer (character);
}
Discard (character); // Discard ending flag
16. We write two very simple algorithms. We assume that a frame is made of an 8-bit
flag (01111110), variable-length data (possibly bit-stuffed), and an 8-bit ending
flag (0111110); we ignore header and trailer. We also assume that there is no error
during the transmission.
a. Algorithm 11.3 can be used at the sender site.
if (counter = = 5)
{
InsertFrame (bit 0); // Bit stuff
counter = 0;
}
}
InsertFrame (8-bit flag); // Insert ending flag
4
b. Algorithm 11.4 can be used at the receiver’s site. Note that when the algorithm
exits from the loop, there are six bits of the ending flag in the buffer, which need
to be removed after the loop.
if (counter < 5)
{
if (bit is 0) counter = 0;
if (bit is 1) counter = counter + 1;
InsertBuffer (bit);
}
}
ExtractBuffer (last 6 bits); // These bits are part of flag
Discard (6 bits);
17. A five-bit sequence number can create sequence numbers from 0 to 31. The
sequence number in the Nth packet is (N mod 32). This means that the 101th
packet has the sequence number (101 mod 32) or 5.
18.
19. See Algorithm 11.5. Note that we have assumed that both events (request and
arrival) have the same priority.
20. See Algorithm 11.6. Note that in this algorithm, we assume that the arrival of a
frame by a site also means the acknowledgment of the previous frame sent by the
same site.
Algorithm 11.6
while (true) // Repeat forever
{
canSend = true;
WaitForEvent (); // Sleep until an event occurs
if (Event (RequestToSend) AND canSend) // A packet can be sent
{
GetData ();
MakeFrame ();
SendFrame (); // Send the frame
canSend = false;
}
21. Algorithm 11.7 shows one design. This is a very simple implementation in which
we assume that both sites always have data to send.
22. Algorithm 11.8 shows one design. This is a very simple implementation in which
we assume that both sites always have data to send.
if (Event (ArrivalNotification))
{
Receive (Frame);
if (corrupted (ACK)) Sleep();
if ((ackNo > Sf) AND (ackNo <= Sn)) // If a valid ACK
{
7
23. Algorithm 11.9 shows one design. This is a very simple implementation in which
we assume that both sites always have data to send.
if (FrameType is Data)
{
if (corrupted (Frame)) AND (NOT NakSent)
{
SendNAK (Rn);
NakSent = true;
Sleep();
}
24. State Sn = 0 means the sender has sent Frame 1, but is waiting for the acknowledg-
ment. State S n = 1 means the sender has sent Frame 0, but is waiting for the
acknowledgment. We can then say
25. State Rn = 0 means the receiver is waiting for Frame 0. State Rn = 1 means the
receiver is waiting for Frame 1. We can then say
26. We can say that in this case, each state defines that a frame or an acknowledgment
in transit. In other words,
(1 , 0) o Frame 0 is in transit (1 , 1) o ACK 1 is in transit
(0 , 1) o Frame 1 is in transit (0 , 0) o ACK 0 is in transit
27. Figure 11.3 shows the situation. Since there are no lost or damaged frames and the
round trip time is less than the time-out, each frame is sent only once.
Sender A B Receiver
Start Frame 0
4 ms
Stop ACK 1
Start Frame 1
4 ms
Stop ACK 0
Start Frame 0
4 ms
Stop ACK 1
Start Frame 1
4 ms
Stop ACK 0
10
28. Figure 11.4 shows the situation. Here, we have a special situation. Although no
frame is damaged or lost, the sender sends each frame twice. The reason is that the
the acknowledgement for each frame reaches the sender after its timer expires. The
sender thinks that the frame is lost.
Sender A B Receiver
Start Frame 0
4 ms
6 ms Time-out, restart Frame 0 ACK 1
Stop Discarded
Start Frame 1
4 ms
6 ms Time-out, restart Frame 1 ACK 0
Stop Discarded
Start Frame 0
4 ms
6 ms Time-out, restart Frame 0 ACK 1
Stop Discarded
Start Frame 1
4 ms
6 ms Time-out, restart Frame 1 ACK 0
Stop Discarded
29. Figure 11.5 shows the situation. In this case, only the first frame is resent; the
acknowledgment for other frames arrived on time.
Sender A B Receiver
Start Frame 0
6 ms
30. We need to send 1000 frames. We ignore the overhead due to the header and
trailer.
31. In the worst case, we send the a full window of size 7 and then wait for the
acknowledgment of the whole window. We need to send 1000/7 | 143 windows.
We ignore the overhead due to the header and trailer.
32. In the worst case, we send the a full window of size 4 and then wait for the
acknowledgment of the whole window. We need to send 1000/4 250 windows.
We ignore the overhead due to the header and trailer.