Module 2
Module 2
COMPUTER NETWORKS
Module-2
Data Link Layer
1
Overview of Data Link Layer
The data link layer transforms the physical layer, a raw transmission facility, to
a link responsible for node-to-node (hop-to-hop) communication. Specific
responsibilities of the data link layer include framing, addressing, flow control,
error control, and media access control.
2
Data Link Layer
3
Figure: Relationship of layers and addresses in TCP/IP
4
Data Link Layer
Sub-layers of Data Link Layer
5
Error Control
Networks must be able to transfer data from one device to another with acceptable
accuracy. For most applications, a system must guarantee that the data received are
identical to the data transmitted.
Any time data are transmitted from one node to the next, they can become corrupted
in passage. Many factors can alter one or more bits of a message.
Some applications require a mechanism for detecting and correcting errors.
Some applications can tolerate a small level of error. For example, random errors in
audio or video transmissions may be tolerable, but when we transfer text, we expect
a very high level of accuracy.
6
Types of Errors
There are two main types of errors in transmissions:
1. Single bit error : It means only one bit of data unit is changed from 1 to 0
or from 0 to 1.
2. Burst error : It means two or more bits in data unit are changed from 1 to 0
from 0 to 1. In burst error, it is not necessary that only consecutive bits are
changed. The length of burst error is measured from first changed bit to last
changed bit
7
Error Detection vs Error Correction
There are two types of attacks against errors:
Error Detecting Codes: Include enough redundancy bits to detect errors
and use ACKs and retransmissions to recover from the errors.
Error Correcting Codes: Include enough redundancy to detect and
correct errors. The use of error-correcting codes is often referred to as
forward error correction.
8
Cntd…
Redundancy
The central concept in detecting or correcting errors is redundancy. To be able to detect or
correct errors, we need to send some extra bits with our data.
These redundant bits are added by the sender and removed by the receiver. Their presence
allows the receiver to detect or correct corrupted bits.
Detection versus Correction
The correction of errors is more difficult than the detection. In error detection, we are looking
only to see if any error has occurred. The answer is a simple yes or no. We are not even interested
in the number of errors. A single-bit error is the same for us as a burst error.
In error correction, we need to know the exact number of bits that are corrupted and more
importantly, their location in the message. The number of the errors and the size of the message
are important factors.
9
Cntd…
Forward Error Correction versus Retransmisson
There are two main methods of error correction. Forward error correction is
the process in which the receiver tries to guess the message by using
redundant bits. This is possible, as we see later, if the number of errors is
small.
Correction by retransmission is a technique in which the receiver detects the
occurrence of an error and asks the sender to resend the message. Resending
is repeated until a message arrives that the receiver believes is error-free
10
Cntd…
Coding
Redundancy is achieved through various coding schemes. The sender adds redundant bits
through a process that creates a relationship between the redundant bits and the actual data bits.
The receiver checks the relationships between the two sets of bits to detect or correct the
errors. The ratio of redundant bits to the data bits and the robustness of the process are important
factors in any coding scheme.
Figure shows the general idea of coding.
11
Block Coding
In block coding, we divide our message into blocks, each of k bits, called
datawords. We add r redundant bits to each block to make the length n = k + r. The
resulting n-bit blocks are called codewords.
How the extra r bits is chosen or calculated is something we will discuss later.
For the moment, it is important to know that we have a set of datawords, each
of size k, and a set of codewords, each of size of n.
With k bits, we can create a combination of 2k datawords; with n bits, we can create a
combination of 2n codewords. Since n > k, the number of possible codewords is larger
than the number of possible datawords.
12
HAMMING DISTANCE
10.
13
Find the minimum Hamming distance of the coding scheme
Solution
We first find all Hamming distances.
10.
14
Find the minimum Hamming distance of the coding scheme
Solution
We first find all the Hamming distances.
10.
15
Minimum Distance for
Error Detection
10.
16
Geometric concept for finding dmin in error detection
17
Example
Solution
This code guarantees the detection of up to three errors
(s = 3).
10.
18
Some Linear Block Codes
Let us now study some linear block codes. These codes are trivial because we can easily find
the encoding and decoding algorithms and check their performances.
Simple Parity-Check Code
Perhaps the most familiar error-detecting code is the simple parity-check
code. In this code, a k-bit dataword is changed to an n-bit codeword where n =
k + 1.
The extra bit, called the parity bit, is selected to make the total number of 1s
in the codeword even.
Although some implementations specify an odd number of 1s, we discuss
the even case.
19
We can count the number of 1s in the Xoring of two words
10.
20
Cntd…
Our first code (Table 1) is a parity-check code with k = 2 and n =3. The code in Table 3 is also
a parity-check code with k =4 and n =5.
21
Cntd…
Figure below shows a possible structure of an encoder (at the sender) and a decoder (at the
receiver).
22
Cntd…
At the sender, the generator takes a copy of a 4-bit dataword (a0, a1, a2, and a3) and generates a
parity bit r0. The dataword and the parity bit create the 5-bit codeword.
The parity bit that is added makes the number of 1s in the codeword even.
This is normally done by adding the 4 bits of the dataword (modulo-2); the result is the parity
bit. In other words,
r0 = a3 + a2 + a1 + a0 (modulo-2)
If the number of 1s is even, the result is 0; if the number of 1s is odd, the result is 1. In both
cases, the total number of 1s in the codeword is even.
The sender sends the codeword which may be corrupted during transmission. The receiver
receives a 5-bit word.
The checker at the receiver does the same thing as the generator in the sender with one
exception: The addition is done over all 5 bits.
23
Cntd…
The result, which is called the syndrome, is just 1 bit. The syndrome is 0 when the
number of 1s in the received codeword is even; otherwise, it is 1.
s0 = b3 + b2 + b1 + b0 + q0 (modulo-2)
The syndrome is passed to the decision logic analyzer.
If the syndrome is 0, there is no error in the received codeword; the data portion of
the received codeword is accepted as the dataword.
If the syndrome is 1, the data portion of the received codeword is discarded. The
dataword is not created.
Example
Let us look at some transmission scenarios. Assume the sender sends the dataword 1011.
The codeword created from this dataword is 10111, which is sent to the receiver. We
examine five cases:
1. No error occurs; the received codeword is 10111. The syndrome is 0. The dataword
1011 is created.
2. One single-bit error changes a1 . The received codeword is 10011. The syndrome is 1.
No dataword is created.
3. One single-bit error changes r0 . The received codeword is 10110. The syndrome is 1.
No dataword is created. Note that although none of the dataword bits are corrupted,
no dataword is created because the code is not sophisticated enough to show the
position of the corrupted bit.
25
Cntd…
4. An error changes r0 and a second error changes a3 .The received codeword is 00110. The
syndrome is 0. The dataword 0011 is created at the receiver. Note that here the dataword is
wrongly created due to the syndrome value. The simple parity-check decoder cannot detect an
even number of errors.
5. Three bits—a3, a2, and a1—are changed by errors. The received codeword is 01011. The
syndrome is 1.The dataword is not created. This shows that the simple parity check, guaranteed
to detect one single error, can also find any odd number of errors.
26
CYCLIC CODES
Cyclic codes are special linear block codes with one extra
property. In a cyclic code, if a codeword is cyclically shifted
(rotated), the result is another codeword.
Topics discussed in this section:
Cyclic Redundancy Check
Polynomials
Hardware Implémentation
Advantages of Cyclic Codes
27
Cyclic Codes
Cyclic codes are special linear block codes with one extra property. In a cyclic code,
if a codeword is cyclically shifted (rotated), the result is another codeword.
For example, if 1011000 is a codeword and we cyclically left-shift, then 0110001 is
also a codeword.
Cyclic Redundancy Check
28
Cntd…
Table A CRC code with C(7, 4)
29
CRC encoder and decoder
30
Cntd…
In the encoder, the dataword has k bits (4 here); the codeword has n bits (7 here). The size of the
dataword is augmented by adding n - k (3 here) 0s to the right-hand side of the word.
The n-bit result is fed into the generator. The generator uses a divisor of size n - k + 1 (4 here),
predefined and agreed upon.
The generator divides the augmented dataword by the divisor (modulo-2 division).
The quotient of the division is discarded; the remainder (r2r1 r0) is appended to the dataword to create
the codeword.
The decoder receives the possibly corrupted codeword. A copy of all n bits is fed to the checker
which is a replica of the generator.
The remainder produced by the checker is a syndrome of n - k (3 here) bits, which is fed to the
decision logic analyzer.
The analyzer has a simple function. If the syndrome bits are all 0s, the 4 leftmost bits of the
codeword are accepted as the dataword (interpreted as no error); otherwise, the 4 bits are
discarded (error).
31
Encoder
32
Decoder
33
Cntd…
The codeword can change during transmission. The decoder does the same division process as
the encoder.
The remainder of the division is the syndrome. If the syndrome is all 0s, there is no error; the
dataword is separated from the received codeword and accepted.
Otherwise, everything is discarded.
Figure below shows two cases: The left hand figure shows the value of syndrome when no
error has occurred; the syndrome is 000.
The right-hand part of the figure shows the case in which there is one single error. The
syndrome is not all 0s (it is 011)
34
A polynomial to represent a binary word
35
Advantages of Cyclic Codes
37
FLOW CONTROL
38
Data Link Protocols
The protocols are normally implemented in software
by using one of the common programming languages
• A Simple Protocol
• A Stop-and-Wait Protocol
39
A simple protocol
• In order to appreciate the step by step development of efficient and complex
protocols we will begin with a simple but unrealistic protocol. In this
protocol: Data are transmitted in one direction only
• The transmitting (Tx) and receiving (Rx) hosts are always ready
• Processing time can be ignored
• Infinite buffer space is available
• No errors occur; i.e. no damaged frames and no lost frames (perfect
channel)
40
A stop-and-wait protocol
• In this protocol we assume that Data are transmitted in one direction only
• No errors occur (perfect channel)
• The receiver can only process the received information at a finite rate
• These assumptions imply that the transmitter cannot send frames at a rate
faster than the receiver can process them.
• The problem here is how to prevent the sender from flooding the receiver.
• A general solution to this problem is to have the receiver provide some sort
of feedback to the sender. The process could be as follows: The receiver
send an acknowledge frame back to the sender telling the sender that the
last received frame has been processed and passed to the host; permission
to send the next frame is granted. The sender, after having sent a frame,
must wait for the acknowledge frame from the receiver before sending
another frame.
• This protocol is known as stop-and-wait.
41
Stop & Wait Protocol
The sender sends one frame and waits for feedback from the
receiver. When the ACK arrives, the sender sends the next
frame
42
STOP AND WAIT PROTOCOL
Imagine a situation where the receiver has just sent an ACK frame back to the sender
saying that it correctly received and already passed a frame to its host. However, the ACK
frame gets lost completely, the sender times out and retransmits the frame. There is no
way for the receiver to tell whether this frame is a retransmitted frame or a new frame, so
the receiver accepts this duplicate happily and transfers it to the host. The protocol thus
fails in this aspect.
STOP-AND-WAIT, LOST FRAME Stop-and-Wait, lost ACK frame
43
STOP AND WAIT PROTOCOL
44
Flow Diagram of a Stop & Wait Protocol
45
MULTIPLE ACCESS PROTOCOL
• The medium access control (MAC) is a sublayer of the data link layer.
• The MAC sublayer emulates a full-duplex logical communication channel in
a multipoint network.
• This channel may provide unicast, multicast, or broadcast communication
service.
• The MAC sublayer uses MAC protocols to ensure that signals sent from
different stations across the same channel don't collide. Eg: two people speak
• A multiple-access protocol to coordinate access to the link (multipoint or
broadcast link).
• Many protocols have been devised to handle access to a shared link.
46
Taxonomy of Multiple-access protocols
47
Random Access Protocols
48
ALOHA
• Aloha is the type of Random access protocol
• ALOHA, was developed at the University of Hawaii in early 1970.
• It was designed for a radio (wireless) LAN, but it can be used on any
shared medium.
• It has two types :one is Pure Aloha and another is Slotted Aloha.
• There is a potential of collisions
• The medium is shared between the stations.
• When a station sends data, another station may attempt to do so at
the same time.
• The data from the two stations collide and become garbled.
49
Pure ALOHA
• The original ALOHA protocol is called pure ALOHA.
51
Procedure for pure ALOHA protocol
52
Slotted ALOHA
• Slotted Aloha divides the time of shared channel into discrete intervals
called as time slots.
• Any station can transmit its data in any time slot.
• The only condition is that station must start its transmission from the
beginning of the time slot.
• If the beginning of the slot is missed, then station has to wait until the
beginning of the next time slot.
• A collision may occur if two or more stations try to transmit data at the
beginning of the same time slot.
• Slotted ALOHA was invented to improve the efficiency of pure
ALOHA.
53
Slotted ALOHA
54
CSMA(Carrier Sense Multiple Access)
• To minimize the chance of collision and to increase the
performance
• Principle of CSMA: “sense before transmit” or “listen before talk”
55
Collision in CSMA
56
Persistence Methods
57
1-Persistent
58
Non-persistent
• In the non-persistent method, a station that has a frame to send senses the line
• If the line is idle, it sends immediately.
• If the line is not idle, it waits a random amount of time and then senses the
line again.
• The nonpersistent approach reduces the chance of collision
59
p-Persistent
• If the channel has time slots with a slot duration equal to or greater than the
maximum propagation time.
• The p-persistent approach combines the advantages of the other two strategies.
• It reduces the chance of collision and improves efficiency.
60
CSMA/CD
61
Collision and abortion in CSMA/CD
62
At time t1, station A has executed its persistence procedure and starts sending the bits of its frame.
At time t2, station C has not yet sensed the first bit sent by A.
Station C executes its persistence procedure and starts sending the bits in its frame, which
propagate both to the left and to the right.
The collision occurs sometime after time t2.
Station C detects a collision at time t3 when it receives the first bit of A’s frame.
Station C immediately aborts transmission.
Station A detects collision at time t4 when it receives the first bit of C’s frame; it also
immediately aborts transmission.
Looking at the figure, we see that A transmits for the duration t4 − t1; C transmits for the duration
t3 − t2.
63
CSMA/CD: Flow Diagram
64
CSMA/CA
65
CSMA/CA
Interframe space (IFS)
• When an idle channel is found, the station does not send immediately.
• It waits for a period of time called the interframe space or IFS.
Contention Window
• The contention window is an amount of time divided into slots.
• if station determine that the channel is free, they wait a random amount of time before
they start sending.
• This time window doubles with each collision and corresponds to the binary
exponential backoff (BEB) that is familiar from CSMA/CD.
Acknowledgment:
• The positive acknowledgment and the time-out timer can help guarantee that the
receiver has received the frame.
66
67
CSMA/ CA and NAV
68
CONTROLLED ACCESS
• In controlled access, the stations consult one another to find which station
has the right to send.
69
Reservation
• A station needs to make a reservation before sending data.
• Time is divided into intervals.
• In each interval, a reservation frame precedes the data frames sent in
that interval.
• If there are N stations in the system, there are exactly N reservation
minislots in the reservation frame.
70
Polling
• Primary device controls the link; the secondary devices follow its
instructions.
71
Select and poll functions in polling-access method
Select
The select function is used whenever the primary device has something to send.
Poll
The poll function is used by the primary device to solicit transmissions from the secondary
devices.
72
Token Passing
• The stations in a network are organized in a logical ring.
• For each station, there is a predecessor and a successor.
• The right to this access has been passed from the predecessor to the current station.
• The right will be passed to the successor when the current station has no more data
to send.
• The RIGHT passed from by means of special packet called “TOKEN”.
7
3
Channelization
• Similar to multiplexing
• Three schemes
• Frequency-Division Multiple Access (FDMA)
• Time-Division Multiple Access (TDMA)
• Code-Division Multiple Access (CDMA)
74
Frequency-Division Multiple Access (FDMA)
75
Time-Division Multiple Access (TDMA)
• Stations share the bandwidth of the channel in time.
• Each station is allocated a time slot during which it can send data.
76
Code-Division Multiple Access (CDMA)
77
END OF MODULE 2
78