EC4060 Lab3 Data-Link Layer
EC4060 Lab3 Data-Link Layer
SUBMISSION INSTRUCTIONS:
• Include a cover page with your Registration number and date to your submission content.
• Attach appropriate screenshots with annotation. (use colored fonts)
• Save your report as a PDF file in following format. (include codes and captured files (if any))
o LAB0X_201XEXXX.PDF (Where XXX is your registration number)
LAB INSTRUCTIONS:
Note: You are free to use any programming language (C, C++, C#, Python, Java etc.) and any IDE to create
the simulation programs. Make sure your codes should contain appropriate comments (Uncommented lines
are not considered as valid answers)
CRC codes are often used for error detection over frames or vectors of a certain length. To get a
convenient mathematical notation of the positions in the frame it can be expressed as a polynomial in 𝑥,
where the exponent of 𝑥 is the place marker of the coefficient.
The vector 𝑎 = 𝑎𝐿−1 𝑎𝐿−2 … … … … 𝑎1 𝑎0 length 𝐿 is represented by the degree 𝐿 − 1 polynomial
𝐿−1
𝑎(𝑥) = 1𝑥 6 + 0𝑥 5 + 0𝑥 4 + 0𝑥 3 + 0𝑥 2 + 1𝑥 2 + 1𝑥 0
= 𝑥6 + 𝑥 + 1
Algorithm: -
1. Given a bit string, append 0S to the end of it (the number of 0s is the same as the degree of the
generator polynomial) let 𝑎(𝑥) be the polynomial corresponding to 𝑎.
2. Divide 𝑎(𝑥) by some agreed on polynomial 𝐺(𝑥) (generator polynomial) and determine the
remainder 𝑅(𝑥). This division is to be done using Modulo 2 Division.
3. Define 𝑇(𝑥) = 𝑎(𝑥) – 𝑅(𝑥)
6. Let T’ represent the bit stream the receiver gets and 𝑇’(𝑥) the associated polynomial. The receiver
divides 𝑇 ′ (𝑥) by 𝐺(𝑥). If there is a 0 remainder, the receiver concludes 𝑇 = 𝑇’ and no error
occurred otherwise, the receiver concludes an error occurred and requires a retransmission
Task 1: Write a program for error detecting code using CRC-CCITT (16-bits).
2. Hamming Codes
The key to the Hamming Code is the use of extra parity bits to allow the identification of a single error.
Create the code word as follows:
1. Mark all bit positions that are powers of two as parity bits. (1, 2, 4, 8, 16, 32, 64, ….)
2. All other bit positions are for the data to be encoded. (3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, ….)
3. Each parity bit calculates the parity for some of the bits in the code word. The position of the
parity bit determines the sequence of bits that it alternately checks and skips.
Position 1: check 1 bit, skip 1 bit. (1, 3, 5, 7, 9, 11, 13, 15,...)
Position 2: check 2 bits, skip 2 bits. (2, 3, 6, 7, 10, 11, 14, 15,...)
Position 4: check 4 bits, skip 4 bits. (4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23,...)
Position 8: check 8 bits, skip 8 bits (8-15,24-31, 40-47, ...)
Position 16: check 16 bits, skip 16 bits (16-31, 48-63, 80-95, ...)
Position 32: check 32 bits, skip 32 bits (32-63, 96-127, 160-191, ...)
4. Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit to
0 if the total number of ones in the positions it checks is even.
• Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0
Calculate the parity for each parity bit (a ? represents the bit position being set):
• Position 1 checks bits 1,3,5,7,9,11:
? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0
• Position 2 checks bits 2,3,6,7,10,11:
0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0
• Position 4 checks bits 4,5,6,7,12:
0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0
• Position 8 checks bits 8,9,10,11,12:
0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0
Reference: http://users.cis.fiu.edu/~downeyt/cop3402/hamming.html
Task 2: Write a program for Hamming Code generation for error detection and correction
3. Sliding window protocol (Go back N ARQ)
Sliding window protocols, each outbound frame contains a sequence number, ranging from 0 up to some
maximum. The maximum is usually 2n - 1 so the sequence number fits exactly in an n-bit field.
The essence of all sliding window protocols is that at any instant of time, the sender maintains a set of
sequence numbers corresponding to frames it is permitted to send. These frames are said to fall within the
sending window. Similarly, the receiver also maintains a receiving window corresponding to the set of
frames it is permitted to accept. The sender’s window and the receiver’s window need not have the same
lower and upper limits or even have the same size. In some protocols they are fixed in size, but in others
they can grow or shrink over the course of time as frames are sent and received. Although these protocols
give the data link layer more freedom about the order in which it may send and receive frames.
In Go-Back-N Automatic Repeat Request, we can send several frames before receiving acknowledgments;
we keep a copy of these frames until the acknowledgments arrive. If there is one frame k missing, the
receiver simply discards all subsequent frames k+1, k+2, ..., sending no acknowledgments. So, the sender
will retransmit frames from k onwards.
Task 3: Write a program to perform simulation on sliding window (Go Back N) protocol.