CN Unit 3
CN Unit 3
CN Unit 3
Networks:
Unit 3: DLL
Prof. Swarnalata Bollavarapu
Contact: swarnalata.b@nmims.edu
Contents
Data link layer design issues
error detection and correction
elementary data link protocols
Sliding Window Protocols
Example of Data Link Protocol: HDLC
Each frame will have start and end with special bytes called a flag bytes
If receiver loses sync it can just search for the flag byte to find the end
of the current frame
Two consecutive flag bytes indicate the end of one frame and starting
of another
Framing
Framing
Problem: it may easily happen that the flag byte’s bit pattern appears in
data
Solution: sender’s data link layer insert a special escape byte just
before each “accidental” flag byte in the data.
The DLL at receiving side removes the escape byte before the data are
given to the network layer
Bit stuffing
(a) The original data.
(b) The data as they appear on the line.
(c) The data as they are stored in receiver’s memory after
destuffing
Error Control
To ensure reliable delivery : provide some feedback to sender
Protocol should be designed in such a way for receiver to send some
special control frames to sender
Special control frames include positive or negative ack
If sender receives positive ack, it knows frame has been received
correctly
If negative ack then something has gone wrong and frame must be
retransmitted
If frame is lost due to hardware problem receiver will do nothing,
sender will go on waiting for ack.
Error Control
Solution : timers in DLL
When sender transmits frame it starts timer
The timer is set to expire after an interval long enough for the frame
to reach destination, be processed there and time taken for ack to
reach back to sender
If timer expires and no ack is received sender will notice some
problem and retransmit frame
Problem: Reciever might receive same frame twice
Solution : Give sequence number to each frame
Flow Control
Occurs when sender want to transmit frames faster than receiver can
accept them
Occurs when sender is running on fast computer and receiver is
running on slow computer
Even if transmission is error free, at certain point of time receiver
will be not able to handle frames and start losing it
To prevent this two approaches are there:
Feedback based flow control
Rate based flow control
Flow Control
In feedback based flow control receiver sends back information to
sender giving it permission to send more data
For example, when a connection is set up, the receiver might say:
''You may send me n frames now, but after they have been sent, do
not send any more until I have told you to continue.'' We will
examine the details shortly.
In the second one, rate-based flow control, the protocol has a built-in
mechanism that limits the rate at which senders may transmit data,
without using feedback from the receiver.
Error Detection and Error
Correction
Two basic strategies for dealing with errors:
Error correcting codes
Error detecting codes
• At sender:
• Add k bits of redundant data to a m bit message
• K is derived from orginal message through some algorithm
• At receiver: reapply same algorithm as sender to detect errors, take
corrective action if necessary
Recap
Goals of DLL
Services provided by DLL/Design issues of DLL
Types of transmission errors
Error detection and correction
Basic framework
Types of transmission errors
Error Detection
Wireless transmission : more errors : requires error correcting codes
rather than retransmission
Copper wire : less errors: requires error detecting codes and initiate
retransmission
Error Detection techniques
• Parity check
• Checksum
• Cyclic Redundancy Check (CRC)
Error Detection
• Parity Check:
The parity check is done by adding an extra bit, called parity bit to the data to
make a number of 1s either even in case of even parity or odd in case of odd
parity.
While creating a frame, the sender counts the number of 1s in it and adds the
parity bit in the following way
•In case of even parity: If a number of 1s is even then parity bit value is 0. If the
number of 1s is odd then parity bit value is 1.
•In case of odd parity: If a number of 1s is odd then parity bit value is 0. If a
number of 1s is even then parity bit value is 1.
On receiving a frame, the receiver counts the number of 1s in it. In case of even
parity check, if the count of 1s is even, the frame is accepted, otherwise, it is
rejected.
Error Detection
• Advantage: detects any single-bit error. Infact, detects odd number of bits
Error Detection
• Checksum:
•In checksum error detection scheme, the data is divided into k segments
each of m bits.
•In the sender’s end the segments are added using 1’s complement arithmetic
to get the sum. The sum is complemented to get the checksum.
•The checksum segment is sent along with the data segments.
•At the receiver’s end, all received segments are added using 1’s
complement arithmetic to get the sum. The sum is complemented.
•If the result is zero, the received data is accepted; otherwise discarded.
Error Detection
• Checksum:
• Add two binary numbers 11100 and 10101
Error Detection
• Checksum:
Error Detection
• CRC:
•Basic idea: treat string of bits as coefficients of a polynomial that uses
modulo 2 arithmetic – Ex. 1 0 1 0 0 1 represents x 5 + x 3 + 1
•Based on binary division.
•In CRC, a sequence of redundant bits, called cyclic redundancy check bits,
are appended to the end of data unit so that the resulting data unit becomes
exactly divisible by a second, predetermined binary number.
•At the destination, the incoming data unit is divided by the same number. If
at this step there is no remainder, the data unit is assumed to be correct and
is therefore accepted.
•A remainder indicates that the data unit has been damaged in transit and
therefore must be rejected.
Error Detection
• CRC:
Error Detection
• Example:
• Find the CRC for the frame 100100 transmitted using divisor 1101
Error Detection
• CRC:
Error Correction : Hamming Codes
Given any two codewords say, 10001001 and 10110001—
it is possible to determine how many corresponding bits differ. In this
case, 3 bits differ. To determine how many bits differ, just XOR the two
codewords and count the number of 1 bits in the result.
10001001
10110001
00111000
• The number of bit positions in which two code words differ is called
the Hamming distance (Hamming, 1950).
At receiver end:
• 1. calculate the no. of redundant bits
• 2. Determine the position of the redundant bits
• 3. parity checking
• 4. error detection or correction
Error Correction
At sender end:
• 1. calculate the no. of redundant bits
• 2. Determine the position of the redundant bits
• 3. Calculate the values of the redundant bits
The bits that are power of 2 (1,2,4,8,16 etc..) are check bits
All other bit positions are for the data to be encoded. (positions
3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.)
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.
Calculating the Hamming
Code(how to create code word)
Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc.
(1,3,5,7,9,11,13,15,...)
Disadvantages:
Flooding
A Simplex Stop and Wait protocol
• Assumptions:
Communication channel is error free
Data traffic is in one direction
Receiver has only finite buffer capacity and finite processing
speed
After sending frame sender will wait for dummy frame from
receiver
Protocols in which the sender sends one frame and then waits
for an acknowledgement before proceeding are called stop-and-
wait.
Unrestricted Simplex protocol
void sender (void) void receiver (void)
{ {
frame s; frame r, s;
packet buffer; event_type event;
event_type event; while (true)
while (true) { wait_for_event(&event);
{ from_network_layer(& from_physical_layer(&r);
buffer); to_network_layer(&r.info);
s.info = buffer; to_physical_layer(&s);
to_physical_layer(&s); }
wait_for_event(&event); }
}}
A Simplex
Stop and
Wait protocol
A Simplex Stop and Wait protocol
• Advantages:
• Simple reliable transmission
• Disadvantages:
• Sender always wait for the ack frame to send the next frame
• If the ack frame gets corrupted the sender cannot perform
any anymore
A Simplex protocol for noisy
channel
Assumptions:
data transfer is only in one direction
Finite processing capacity and speed at the receiver
Errors in the data frames or ack frames are expected
Timer is kept, if the ack is not received withing the time frame,
the frame gets retransmitted
A Simplex protocol for noisy
channel
The network layer on A gives packet 1 to its data link layer. The
packet is correctly received at B and passed to the network layer on
B. B sends an acknowledgement frame back to A.
The data link layer on A eventually times out. Not having received an
acknowledgement, it (incorrectly) assumes that its data frame was
lost or damaged and sends the frame containing packet 1 again.
The duplicate frame also arrives at the data link layer on B perfectly
and is unwittingly passed to the network layer there. If A is sending a
file to B, part of the file will be duplicated (i.e., the copy of the file
made by B will be incorrect and the error will not have been
detected). In other words, the protocol will fail.
A Simplex protocol for noisy
channel
Problem : Some way is required for the receiver to
distinguish a frame
The maximum is 2n -1 .
Protocol:
Define the format of frames
In response to frames, action to be taken by nodes
Example: Ethernet, PPP etc
Example: HDLC
DLL is divided into two sub-layers: logic link control (LLC) and
Media Access Control (MAC)
LLC : interface between network layer and MAC sub-layer
Responsible for:
Error detection and correction
Flow control