Design Issue
Design Issue
FRAMING
Framing
• The usual approach is for the data link layer to break up the bit
stream into discrete frames, compute a short token called a
checksum for each frame, and include the checksum in the frame
when it is transmitted.
• When a frame arrives at the destination, the checksum is
recomputed.
• If the newly computed checksum is different from the one contained
in the frame, the data link layer knows that an error has occurred
and takes steps to deal with it (e.g., discarding the bad frame and
possibly also sending back an error report).
Framing cont.
• A good design must make it easy for a receiver
to find the start of new frames while using little
of the channel bandwidth.
– 1. Byte count.
– 2. Flag_bytes with byte stuffing.
– 3. Flag_bits with bit stuffing.
– 4. Physical layer coding violations.
Byte count
• The first framing method uses a field in the header to specify the number of bytes
in the frame.
• When the data link layer at the destination sees the byte count, it knows how
many bytes follow and hence where the end of the frame is.
Byte count
• For example, if the byte count of 5 in the second frame of Fig. (b)
becomes a 7 due to a single bit flip, the destination will get out of
synchronization.
• It will then be unable to locate the correct start of the next frame.
• Even if the checksum is incorrect so the destination knows that the
frame is bad, it still has no way of telling where the next frame starts.
• Sending a frame back to the source asking for a retransmission does
not help either, since the destination does not know how many bytes
to skip over to get to the start of the retransmission.
• For this reason, the byte count method is rarely used by itself.
Flag bytes with byte stuffing
• Each frame start and end with special bytes called a
flag byte used as both the starting and ending delimiter
• Two consecutive flag bytes indicate the end of one
frame and the start of the next
• Thus, if the receiver ever loses synchronization it can
just search for two flag bytes to find the end of the
current frame and the start of the next frame.
Byte stuffing
• It may happen that the flag byte occurs in the data, especially when binary
data such as photographs or songs are being transmitted.
• This situation would interfere with the framing.
• One way to solve this problem is to have the sender’s data link layer insert a
special escape byte (ESC) just before each ‘‘accidental’’ flag byte in the data.
• Thus, a framing flag byte can be distinguished from one in the data by the
absence or presence of an escape byte before it.
• The data link layer on the receiving end removes the escape bytes before
giving the data to the network layer.
• This technique is called byte stuffing.
a) A frame delimited by flag bytes
b) Four examples of byte sequences before and after byte stuffing.
Bit stuffing
• The third method of delimiting the bit stream gets around a
disadvantage of byte stuffing, which is that it is tied to the use of
8-bit bytes.
• Framing can be also be done at the bit level, so frames can
contain an arbitrary number of bits made up of units of any size.
• It was developed for the once very popular HDLC (High level Data
Link Control) protocol.
• Each frame begins and ends with a special bit pattern, 01111110
or 0x7E in hexadecimal. This pattern is a flag byte.
Bit stuffing cont.
• When ever the sender’s data link layer encounters five consecutive 1s in the data, it automatically
stuffs a 0 bit into the outgoing bit stream.
• This bit stuffing is analogous to byte stuffing, in which an escape byte is stuffed into the outgoing
character stream before a flag byte in the data.
• It also ensures a minimum density of transitions that help the physical layer maintain
synchronization.
• USB (Universal Serial Bus) uses bit stuffing for this reason.
FLOW CONTROL
ACK-NACK from receiver
• To ensure reliable delivery is to provide the sender with some
feedback about what is happening at the other end of the line.
• The protocol calls for the receiver to send back special control frames
bearing positive or negative acknowledgements about the incoming
frames.
• If the sender receives a positive acknowledgement about a frame, it
knows the frame has arrived safely.
• On the other hand, a negative acknowledgement means that
something has gone wrong and the frame must be transmitted again.
Some issues
• An additional complication comes from the possibility that hardware
troubles may cause a frame to vanish completely (e.g., in a noise burst).
• In this case, the receiver will not react at all, since it has no reason to
react.
• Similarly, if the acknowledgement frame is lost, the sender will not
know how to proceed.
• It should be clear that a protocol in which the sender transmits a frame
and then waits for an acknowledgement, positive or negative, will hang
forever if a frame is ever lost due to, for example, malfunctioning
hardware or a faulty communication channel.
Solution: Timer
• When the sender transmits a frame, it generally also starts
a timer.
• The timer is set to expire after an interval long enough for
the frame to reach the destination, be processed there, and
have the acknowledgement propagate back to the sender.
• Normally, the frame will be correctly received and the
acknowledgement will get back before the timer runs out,
in which case the timer will be canceled.
Problem: Duplicate frames
• However, if either the frame or the acknowledgement is
lost, the timer will go off, alerting the sender to a
potential problem.
• The obvious solution is to just transmit the frame again.
• However, when frames may be transmitted multiple
times there is a danger that the receiver will accept the
same frame two or more times and pass it to the
network layer more than once.
Solution: Sequence No.
• To prevent this from happening, it is generally
necessary to assign sequence numbers to outgoing
frames, so that the receiver can distinguish
retransmissions from originals.
• The whole issue of managing the timers and sequence
numbers so as to ensure that each frame is ultimately
passed to the network layer at the destination exactly
once
Problem
• Even if the transmission is error free, the
receiver may be unable to handle the frames
as fast as they arrive and will lose some.
Solution: Flow control
a. Feedback-based flow control, the receiver sends back
information to the sender giving it permission to send
more data, or at least telling the sender how the
receiver is doing (at Data link Layer).
b. 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.(as part of the transport layer)
A Simplex Stop-and-Wait Protocol for an Error-Free Channel
Window Window
opened closed by
by 2 1 due to
receipt of
Ack for
packet 0
Receiver side
Timers
• Although there can be a timer for each packet
that is sent, in our protocol we use only one.
• The reason is that the timer for the first
outstanding packet always expires first.
• We resend all outstanding packets when this
timer expires.
Resending packets
• When the timer expires, the sender resends all outstanding
packets. For example, suppose the sender has already sent packet
6 (Sn, Next packet to be sent = 7), but the only timer expires.
• If Sf, firtst sent packet = 3, this means that packets 3, 4, 5, and 6
have not been acknowledged; the sender goes back and resends
packets 3, 4, 5, and 6.
• That is why the protocol is called Go-Back-N.
• On a time-out, the machine goes back N locations and resends all
packets.
ERROR DETECTION AND CORRECTION
ERROR CONTROL
• While transmitting the data errors occurs due to noise
• Two basic strategies for dealing with errors
1. Include enough redundant information to enable the receiver to deduce
what the transmitted data must have been using error-correcting codes.
– Used for (unreliable) wireless channel
– particularly for real-time media
2. Enough redundancy to allow the receiver to detect that an error has
occurred, using error-detecting codes
– Used in reliable channel (Optical fiber, Coaxial cables, STP, UTP )
– commonly used in link, network (to detect error in header), and transport layers (to
detect errors in pay load ie data)
Error-Correcting Codes
1. Hamming codes.
2. Binary convolutional codes.
3. Reed-Solomon codes.
4. Low-Density Parity Check codes.
• All of these codes add redundancy to the information that
is sent.
• A frame consists of m data (i.e., message) bits and r
redundant (i.e. check) bits.
Error-Detecting Codes
1. Parity: a single parity bit is appended to the
data
2. Checksums.
3. Cyclic Redundancy Checks (CRCs).
• The parity bit is chosen so that the number of 1 bits in the
codeword is even (or odd).
• Doing this is equivalent to computing the (even) parity bit as the
modulo 2 sum or XOR of the data bits.
• For example, when 1011010 is sent in even parity, a bit is added
to the end to make it 10110100.
• With odd parity 1011010 becomes 10110101.
• One difficulty with this scheme is that a single parity bit can only
reliably detect a single-bit error in the block.
• we can compute the parity bits over the data in a different order than the order
in which the data bits are transmitted. Doing so is called interleaving
• This transmission order is shown in Fig. for n = 7 and k = 7.
• n= parity bits, k= no. of n bit words
Computed parity at
receiver
Miss
1000000
Received parity match
bits Error Detected
• In Fig. when a burst error of length n=7occurs, the bits that are in
error are spread across different columns.
• (A burst error does not imply that all the bits are wrong; it just
implies that at least the first and last are wrong.
• In Fig. four bits were flipped over a range of 7 bits.)
• At most 1bit in each of then columns will be affected, so the parity
bits on those columns will detect the error.
• This method uses n parity bits on blocks of k*n data bits to detect
a single burst error of length n or less.
checksum
• The checksum is usually placed at the end of the
message, as the complement of the sum function.
• Errors may be detected by summing the entire
received code word, both data bits and checksum.
• If the result comes out to be zero, no error has
been detected.
modulo 2 arithmetic
• Polynomial arithmetic is done modulo 2
• It does not have carries for addition or borrows for subtraction.
• Both addition and subtraction are identical to exclusive OR
Example of checksum
• 1100 • 1100
Modulo 2 sum
• 1010 transmitted along • 1010
with data
• 1110 • 1110
Modulo 2 sum
• 1101 received along • 1101
with data
• 0101 • 0101 All zeros,
Modulo 2 sum No error in
along with data
and received
• 0000 received
data
check sum
Example of checksum
• 1100 • 1100
Modulo 2 sum
• 1010 transmitted along • 1000
with data
• 1110 • 1110
Modulo 2 sum
• 1101 received along • 1101
with data
• 0101 • 0101 No all
zeros,
Modulo 2 sum error in
along with data
and received
• 0010 received
data
check sum
Cyclic Redundancy Check
• The sender and receiver must agree upon a generator polynomial, G(x), in
advance.
• Both the high- and low order bits of the generator polynomial must be 1.
• To compute the CRC for some frame with m bits corresponding to the
polynomial M(x), the frame must be longer than the generator polynomial.
• The idea is to append a CRC to the end of the frame in such a way that the
polynomial represented by the checksummed frame is divisible by G(x).
• When the receiver gets the checksummed frame, it tries dividing it by G(x).
• If there is a remainder, there has been a transmission error.
G(x)= x4+x1+x0=10011, r=4
• The algorithm for computing the CRC is as follows:
1. Let r be the degree of G(x). Append r zero bits to the low-order end of the
frame so it now contains m + r bits and corresponds to the polynomial
M(x).
2. Divide the bit string corresponding to G(x) into the bit string
corresponding to M(x), using modulo 2 division.
3. Subtract the remainder (which is always r or fewer bits) from the bit
string corresponding to M(x) using modulo 2 subtraction.
• The result is the check-summed frame to be transmitted.
• Call it a polynomial T(x).
• Upon receiving the check-summed frame, the
receiver divides it by G(x); that is, it computes
[T(x) + E(x)]/G(x).
– E(X) is an error vector, T(X): original data
• T(x)/G(x) is 0, so the result of the computation
is simply E(x)/G(x).
modulo 2 arithmetic
• Polynomial arithmetic is done modulo 2
• It does not have carries for addition or borrows for subtraction.
• Both addition and subtraction are identical to exclusive OR
G(x)
Being degree of
G(x) is 4