Você está na página 1de 24

Computer Networks III B.

TECH I SEM PACE ITS

UNIT-III
Framing:
Framing in the data link layer separates a message from one source to a destination or from
other messages to other destinations, by adding a sender address and a destination address.
When a message is carried in one very large frame, even a single bit error would require the
retransmission of the whole message. When a message is divided into smaller frames, a
single bit error affects only that small frame.

Framing is of two types,

1. Fixed-size framing
2. Variable-size framing

Fixed-size framing , the frames are of fixed size, specifying the start of frame and end of the
frame is not necessary.

Variable-size framing, the size of frames changes. Here it is necessary to specify end of
frame and the beginning of next frame. We are used two approaches for this framing.

a) Character oriented protocols


b) Bit oriented protocols

Character oriented protocols: In a character oriented protocol, data to be carried are


8-bit characters from a coding system. The header field carries the source and destination
addresses and other control information. The trailer field carries error detection or error
correction redundant bits. A flag is added at the beginning and end of a frame. It composed
of protocol dependent special characters, signals the start or end of a frame.

In character oriented framing, only text was exchanged by the data link layers. The flag
could be selected to be any character not used for text communication. Any pattern used
for the flag could also be part of the information. If the receiver encounters this pattern in
the middle of the data, thinks it has reached the end of the frame. To fix this problem, a
byte stufing strategy was added to character oriented framing. In byte stuffing a special
byte is added to the data secton of the frame when there is a character with the same
pattern as the flag.

B.SRIKANTH,ASST.PROF Page 1
Computer Networks III B.TECH I SEM PACE ITS

Byte stuffing is the process of adding 1 extra byte whenever there is a flag or escape
character in the text.

Bit oriented protocol:


The data section of a frame is a sequence of bits to be interpreted by the upper layer as
text, graphic, audio and video. In addition to headers we still need a delimiter to separate
one frame from the other. Most protocols use a special 8-bit patern flag 01111110 as the
delimiter to define the beginning and the end of the frame.

The new technique allows data frames to contain an arbitrary number of bits. Each frame
begins and ends with a special bit patern, 01111110 (in fact, a flag byte). Whenever 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 is known as bit stufing. When the receiver sees five
consecutive incoming 1 bits, followed by a 0 bit, it automatically de-stuffs (i.e., deletes) the
0 bit.

B.SRIKANTH,ASST.PROF Page 2
Computer Networks III B.TECH I SEM PACE ITS

Error Control:

Error control is both error detection and error correction. It allows the receiver to inform
the sender of any frames lost or damaged in transmission and coordinates the
retransmission of those frames by the sender.

Any time an error is detected in an exchange, specified frames are retransmitted. This
process is called automatic repeat request.

Flow Control:

It is the responsibility of the data link layer is what to do with a sender that
systematically wants to transmit frames faster than the receiver can accept them. This
situation can easily occur when the sender is running on a fast computer and the receiver is
running on a slow machine. at a certain point the receiver will simply be unable to handle
the frames as they arrive and will start to lose some.

The protocol has a built-in mechanism that limits the rate at which senders may transmit
data, without using feedback from the receiver

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.

Error Detection and Correction:

Networks must be able to transfer data from one device to another with acceptable
accuracy. Any time data are transmitted from one node to the next, they can be corrupted
in passage. Many factors can alter one or more bits of a message.

B.SRIKANTH,ASST.PROF Page 3
Computer Networks III B.TECH I SEM PACE ITS

Types of Errors:

Whenever bits flow from one point to another, they are unpredictable changes because of
interference. This interference can change the shape of the signal.

a) Single bit error


b) Burst error

Single bit error:

Only 1 bit of a given data unit is changed from 1 to 0 or from 0 to 1.

Burst error:

A burst error means that 2 or more bits in the data unit have changed.

The duration of noise is normally longer than the duration of 1 bit, which means that when
noise affects data, it affects a set of bits.

Redundancy:

The central concept in detecting or correcting errors is redundancy. For 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.

B.SRIKANTH,ASST.PROF Page 4
Computer Networks III B.TECH I SEM PACE ITS

Coding:

 Process of adding redundancy for error detection or correction.


 The sender adds redundant bits and the actual data bits.
 The receiver checks the relationships between the two sets of bits to detect or
correct the errors.
 Two types:
 Block codes
 Divides the data to be sent into a set of blocks
 Extra information atached to each block
 Memoryless
 Convolutional codes
 Treats data as a series of bits, and computes a code over a contnuous
series.
 The code computed for a set of bits depends on the current and
previous input

Modular arithmetic:

 Main operation for computing error detection/correction codes


 Similar to modulo-2 addition. Here we use only the integers 0 to n-1.

Block Coding:

 Message is divided into k-bit blocks, Known as data words.


 r redundant bits are added, blocks become n=k+r bits, Known as code words.
 Since n>k, the number of possible code words is larger than the number of
possible data words.

B.SRIKANTH,ASST.PROF Page 5
Computer Networks III B.TECH I SEM PACE ITS

Example: 4B/5B Block Coding

Data Code Data Code

0000 11110 1000 10010


0001 01001 1001 10011
0010 10100 1010 10110

0011 10101 1011 10111

0100 01010 1100 11010


0101 01011 1101 11011
0110 01110 1110 11100

0111 01111 1111 11101

Error Detection in Block Coding:

If the following two conditions are met, the receiver can detect a change in the original code
word.

1. The receiver has a list of valid codewords.


2. The original codeword has changed to an invalid one.

B.SRIKANTH,ASST.PROF Page 6
Computer Networks III B.TECH I SEM PACE ITS

Sender creates codewords out of datawords by using a generator that applies the rules and
procedures of encoding. Each encode sent to the receiver may change during transmission.
If the received codeword is the same as one of the valid codewords, the word is accepted.
The corresponding dataword is extracted for use. If the received codeword is not valid, it is
discarded.

Data words Code words


00 000
01 011
10 101
11 110

Assume the sender encodes the dataword 01 as 011 and sends it to the receiver. Consider
the following cases.

1. The receiver receives 011. It is valid codeword. The receiver extracts the dataword
01 from it.
2. Te codeword is corrupted during transmission and 111 is received. This is not a valid
codeword and is discarded.
3. The codeword is corrupted during transmission and 000 is received. This is a valid
codeword. The receiver incorrectly extracts the dataword 00. Two corrupted bits
have made the error undectable.
4. An error detecting code can detect only the types of errors for which it is designed,
other types of errors may remain undetected.

B.SRIKANTH,ASST.PROF Page 7
Computer Networks III B.TECH I SEM PACE ITS

Error Correction:

The idea of error correction is same as error detection but the checker function are much
more complex.

Example: Error Correction Code

Here we are adding more redundant bits to see, if the receiver can correct an error without
knowing what was actually sent. We add 3 redundant bits for a 2 bit dataword to make 5 bit
codewords.

Assume the dataword is 01. The sender consults to create a codeword 01011. The codeword
is corrupted during transmission, and 01001 is received. First the receiver finds that the
received codeword is in table or not. It checks which one is nearest to the codewords in the
table.

Hamming Distance:

Hamming Distance between two words is the number of diferences between


corresponding bits.

 d(01, 00) = ?
 d(11, 00) = ?

B.SRIKANTH,ASST.PROF Page 8
Computer Networks III B.TECH I SEM PACE ITS

 d(010, 100) = ?
 d(0011, 1000) = ?
 How many 8-bit words are n bits away from 10000111?

Minimum Hamming Distance:

The minimum Hamming distance is the smallest Hamming distance between all possible
pairs in a set of words.

 Find the minimum Hamming Distance of the following codebook

d(000, 011) = 2 d(000,101) = 2 d(011,110) = 2 d(101,110) = 2

the dmin in this case is 2.

Hamming distance and error:

The hamming distance between the received codeword and the sent codeword is the
number of bits that are corrupted during transmission.

Minimum distance for error detection:

Using the minimum hamming distance in a code, we detect up to s errors. If s errors occur
during transmission, the hamming distance between the sent codeword and received
codeword is s. If our code is to detect up to s errors, the minimum distance between the
valid codes must be s+1.

Minimum distance for error correction:

Error correction is more complex than error detection. When a received codeword is not a
valid codeword, the receiver needs to decide which valid codeword was actually sent.

To guarantee correction of up to t errors in all cases, the minimum distance in a block code
must be dmin = 2t+1.

B.SRIKANTH,ASST.PROF Page 9
Computer Networks III B.TECH I SEM PACE ITS

Linear block code:

Linear block code is a code in which the exclusive OR of two valid codewords creates
another valid codeword.

Simple Parity check code:

In this code, k-bit dataword is changed to an n-bit codeword where n=k+1. The extra bit
called parity bit, is selected to make the total number of 1’s in the codeword even.

It is a single bit error detecting code in which n=k+1 with dmin = 2

Dataword Codeword Dataword Codeword


0000 00000 1000 10001
0001 00011 1001 10010
0010 00101 1010 10100
0011 00110 1011 10111
0100 01001 1100 11000
0101 01010 1101 11011
0110 01100 1110 11101
0111 01111 1111 11110

Parity Check:

 Most common, least complex


 Single bit is added to a block
 Two schemes:
 Even parity – Maintain even number of 1s
 E.g., 1011  10111
 Odd parity – Maintain odd number of 1s
 E.g., 1011  10110

Example: Parity Check

Suppose the sender wants to send the word world. In ASCII the five characters are coded
(with even parity) as

1110111 1101111 1110010 1101100 1100100

The following shows the actual bits sent

11101110 11011110 11100100 11011000 11001001

B.SRIKANTH,ASST.PROF Page 10
Computer Networks III B.TECH I SEM PACE ITS

Parity-Check: Encoding/Decoding

The encoder uses a generator that takes a copy of a 4-bit dataword (a0, a1, a2, a3) and
generates a parity bit r0. The dataword bits and the parity bit create the 5-bit codeword. The
parity bit that is added makes the number of 1s in the codeword even.

r0 = a3+a2+a1+a0 ( modulo-2)

if the number of 1s is even, the result is 0. If the number of 1 is odd, the result is 1.

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 result is called 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 ( modulo-2)

2D Parity Check:

The dataword is organized in a table as in the form of rows and columns.

The dataword to be sent give 7-bit bytes are put in separate rows. For each row and each
column, 1 parity check bit is calculated.

The shole table is then sent to receiver, which finds the syndrome for each row and each
column.

B.SRIKANTH,ASST.PROF Page 11
Computer Networks III B.TECH I SEM PACE ITS

B.SRIKANTH,ASST.PROF Page 12
Computer Networks III B.TECH I SEM PACE ITS

Cyclic codes:

Cyclic codes are special linear block codes with one extra property. In a cyclic code, if a
codeword is cyclically shifed the result is another codeword.

For example, if 1011000 is a codeword and we cyclically left shift, then 0110001 is also a
codeword. In this case, if we call the bits in the first word a0 to a6, and the bits in the second
word b0 to b6.

b1=a0 b2=a1 b3=a2 b4=a3 b5=a4 b6=a5


b7=a6

Cyclic Redundancy Check:

 In a cyclic code, rotating a codeword always results in another codeword


 Example:

In the encoder, the data work has k bits(4), the codeword has n bits (7). The size of the
dataword is augmented by using n-k. we can add 0’s 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. The
generator divides the augmented dataword by the divisor.

The quotient of the division is discarded. The remainder (r2,r1,r0) is appended to the
dataword to create the codeword.

B.SRIKANTH,ASST.PROF Page 13
Computer Networks III B.TECH I SEM PACE ITS

CRC Encoder/Decoder

CRC Generator

Checking CRC

B.SRIKANTH,ASST.PROF Page 14
Computer Networks III B.TECH I SEM PACE ITS

Polynomials:

A pattern of 0’s and 1’s can be represented as a polynomial with coeficients of 0 and 1. The
power of each term shows the positions of the bit, the coefficient shows the value of bit.

 More common representation than binary form


 Easy to analyze
 Divisor is commonly called generator polynomial

The main advantage is, a 7 bit patern can be replaced by three terms.

Degree of a polynomials:

The degree of a polynomial is the highest power in the polynomial.

6
Eg: x + x + 1, degree is 6.

Adding and subtracting polynomials:

Adding and subtracting polynomials is done by combining terms and deleting pairs of
identical terms.
5 4 2 6 4 2
Polynomials are x +x +x and x +x +x
6 5
Additional / subtraction of the polynomials are x +x .

Divide and multiplying terms:

Multiplying a term by another term by adding the powers.

4 3 4+3 7
x +x =x =x

For dividing, just subtract the power of the second term from the power of first.
4 3
x /x is x.

B.SRIKANTH,ASST.PROF Page 15
Computer Networks III B.TECH I SEM PACE ITS

Division Using Polynomial

Decoder:
3 6 3 2 3
x + x + 1 ) x + x + x + x (x +x
6 4 3
x +x +x
4 2
x +x +x
4 2
x +x +x

0 0 0

Strength of CRC

 Can be analyzed using polynomial


 M(x) – Original message
 G(x) – Generator polynomial of degree n
 R(x) – Generated CRC
 Transmitted message is M(x) – R(x)

B.SRIKANTH,ASST.PROF Page 16
Computer Networks III B.TECH I SEM PACE ITS

which is divisible by G(x)

 Received message is

M(x) – R(x) + E(x)

where E(x) represents bit errors

 Receiver does not detect any error when E(x) is divisible by G(x), which means
either:
 E(x)  0  No error
 E(x)  0  Undetectable error

 If G(x) contains at least two terms, then all single-bit errors can be detected
t
 If G(x) cannot divide x + 1 (0  t < n), then all isolated double errors can be detected
 If G(x) contains a factor of (x+1), all odd-numbered errors can be detected

Standard Polynomials

Checksum:

Checksum is an error detection method. The checksum is used in the internet by several
protocols. Like linear and cyclic codes, the checksum is based on the concept of redundancy.

For example, data is a list of five 4-bit numbers that we want to send a destination. In
addition to sending these numbers, we send the sum of numbers.

B.SRIKANTH,ASST.PROF Page 17
Computer Networks III B.TECH I SEM PACE ITS

Original data: (7,11,12,0,6)

Sending data: (7,11,12,0,6,36)

At the receiver side, receiver adds 5 numbers and compares the result with the sum. If the
two are same, the receiver assumes no error.

In the job of receiver easer if we send the negative of the sum, called checksum.

Original data: (7,11,12,0,6)

Sending data: (7,11,12,0,6,-36)

Receiver adds 5 numbers and it checks the result is 0, it assumes no error, otherwise, there
is an error.

One’s complement:

In the above example, we add only 4-bit data, except checksum. If the data is more than 4-
bit, we use this one’s complement method.
n
In this we can represent unsigned numbers between 0 to 2 -1.

For example,

7 7
11 11
12 12
0 7,11,12,0,6,9 0
6 6
0 9
Sum ----36 Sum ----45
Wrapped sum –6 Wrapped sum 15
Checksum -----9 Checksum -----0

B.SRIKANTH,ASST.PROF Page 18
Computer Networks III B.TECH I SEM PACE ITS

At sender site:

sum is 36

in bit format: 100100

we remove highest degree bits remaining of 4-bits and add that bits to 4-bit data.

0100

10

0110 ----- 6

1’s complement 1001 ------ 9

At receiver site:

Sum is 45

In bit format: 101101

we remove highest degree bits remaining of 4-bits and add that bits to 4-bit data.

1101

10

1111 ----- 15

1’s complement 0000 ----- 0

Internet checksum:

The internet has been using a 16-bit checksum.

The sender calculates the checksum by following these steps.

1. The message is divided into 16-bit words.


2. The value of the checksum word is set to 0.
3. All words including the checksum are added using 1’s complement addition.
4. The sum is complemented and becomes the checksum.
5. The checksum is sent with the data.

B.SRIKANTH,ASST.PROF Page 19
Computer Networks III B.TECH I SEM PACE ITS

The receiver uses the following steps for error detection.

1. The message including checksum is divided into 16-bit words.


2. All words are added using 1’s complement addition.
3. The sum is complemented and becomes the new checksum.
4. If the value of checksum is 0m the message is accepted, otherwise it is rejected.

For example, the checksum for a text of 8 characters (“Forouzan”). The text needs to be
divided into 2-byte(16-bit) words. We use ASCII to change each byte t a 2-digit hexa decimal.

Note:

a b c d e f g h i j k l m
Decimal 97 98 99 100 101 102 103 104 105 106 107 108 109
Hexa 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D

n o p q r s t u v w x y Z
Decimal 110 111 112 113 114 115 116 117 118 119 120 121 122
Hexa 6E 6F 70 71 72 73 74 75 76 77 78 79 7A

Similarly

A B C D E F
Decimal 65 66 67 68 69 70
Hexa 41 42 43 44 45 46
sender site receiver site
4 6 6 F (Fo) 4 6 6 F (Fo)
7 2 6 F (ro) 7 2 6 F (ro)
7 5 7 A (uz) 7 5 7 A (uz)
6 1 6 E (an) 6 1 6 E (an)
0 0 0 0 (intial checksum) 7 0 3 8 (intial checksum)
1 0 1 3 1 0 1 3
8 F C 6 F F F E
1 1
8 F C 7 Sum F F F F
15'
Comp 7 0 3 8 (Checksum) 0 0 0 0 (checksum new)

B.SRIKANTH,ASST.PROF Page 20
Computer Networks III B.TECH I SEM PACE ITS

Performance:

The traditional checksum uses a small number of bits (16 bits) to detect errors in a message
of any size. However, it is not as strong as the CRC in error checking capability.

For example, if the value of one word is incremented and the value of another word is
decremented by the same amount, the two errors can not be detected. Because the sum
and checksum remain the same.

Elementary Data Link Protocols:

To start with, we consider that

 The physical layer, data link layer, and network layer are independent processes that
communicate by passing messages back and forth.
 In many cases, the physical and data link layer processes will be running on a
processor inside a special network I/O chip and the network layer code will be
running on the main CPU.
 the physical and data link layers as procedures called by the network layer process.
 Another key assumption is that machine A wants to send a long stream of data to
machine B, using a reliable, connection-oriented service.
 We also assume that machines do not crash. i.e these protocols deal with
communication errors, but not hardware problems .

When the data link layer accepts a packet, it encapsulates the packet in a frame by adding a
data link header and trailer to it.

Thus, a frame consists of control information (in the header), and a checksum (in the
trailer). The frame is then transmited to the data link layer on the other machine. The
transmiting hardware computes and appends the checksum

When a frame arrives at the receiver, the hardware computes the checksum. If the
checksum is incorrect then the data link layer sent, event = cksum_err.

If the frame arrived undamaged, the data link layer is also informed

event = frame_arrival

 Then the receiving data link layer checks the control information in the header, and
if it is right, passes the packet portion to the network layer.
 There is a good reason why the network layer must never be given any part of the
frame header: to keep the network and data link protocols completely separate.

B.SRIKANTH,ASST.PROF Page 21
Computer Networks III B.TECH I SEM PACE ITS

 some declarations common to many of the protocols

Five data structures are defined there:

 boolean, A boolean is an enumerated type and can take on the values true and false
 seq_nr, A seq_nr is a small integer used to number the frames. These sequence
numbers run from 0 up to and including MAX_SEQ
 packet, A packet is the unit of information exchanged between the network layer
and the data link layer on the same machine
 frame_kind, this define the type if the frame that is control or information frame.
 frame.

A frame is composed of four fields:

1. kind, The kind field tells whether there are any data in the frame
2. seq, The seq field is used for sequence numbers
3. ack, The ack field is used for acknowledgements
4. info, The info field of a data frame contains a single packet. A more realistic
implementation would use a variable-length info field
5. The first three of which contain control information and the last of which may
contain actual data to be transferred. These control fields are collectively
called the frame header.
6. Note: it is important that the relationship between a packet and a frame.
7. The network layer builds a packet by taking a message from the transport
layer and adding the network layer header to it. This packet is passed to the
data link layer for inclusion in the info field of an outgoing frame.
8. When the frame arrives at the destination, the data link layer extracts the
packet from the frame and passes the packet to the network layer.

A number of procedures are implemented

 wait_for_event sits in a tight loop waiting for something to happen


 to_network_layer and from_network_layer are used by the data link layer to pass
packets to the network layer and accept packets from the network layer
 from_physical_layer and to_physical_layer pass frames between the data link layer
and physical layer.
 Start_timer and stop_timer turn the timer on and of, respectively.
 Start_ack_timer and stop_ack_timer control an auxiliary timer used to generate
acknowledgements under certain conditions.
 Enable_network_layer and disable_network_layer are used where the network
layer always has packets to send. When the data link layer enables the network
layer, the network layer is then permitted to interrupt when it has a packet to be
sent.
 Frame sequence numbers are always in the range 0 to MAX_SEQ. It is frequently
necessary to advance a sequence number by 1 circularly i.e., MAX_SEQ is followed
by 0
 The macro inc performs this incrementing.

B.SRIKANTH,ASST.PROF Page 22
Computer Networks III B.TECH I SEM PACE ITS

There are three types of protocols exist.

1. An Unrestricted Simplex Protocol


2. A Simplex Stop-and-Wait Protocol
3. A Simplex Protocol for a Noisy Channel

An Unrestricted Simplex Protocol:-

We will consider a protocol by assuming,

 Data are transmitted in one direction only.


 Both the layers are always ready.
 Processing time can be ignored.
 Infinite buffer space is available.
 The communication channel between the data link layers of both machines are
never damaged or lost frames.
 This protocol is also known as ''utopia''.

An unrestricted simplex protocol.

The protocol consists of two distinct procedures,

a) A sender
b) A receiver.

The sender runs in the data link layer of the source machine, and the receiver runs in the
data link layer of the destination machine.

 No sequence numbers or acknowledgements are used.


 The only event type is frame_arrival .
 The sender is in an infinite while loop just pumping data out onto the line as fast as it
can.
 The body of the loop consists of three actions:

 go fetch a packet from the (always obliging) network layer


 construct an outbound frame using the variable s,
 send the frame on its way.

B.SRIKANTH,ASST.PROF Page 23
Computer Networks III B.TECH I SEM PACE ITS

NOTE: Only the info field of the frame is used by this protocol, because there are no errors
or flow control restrictions here.

A Simplex Stop-and-Wait Protocol:-

Now we will drop the most unrealistic restriction used in Unrestricted Simplex Protocol, the
ability of the receiving network layer to process incoming data infinitely.

 The communication channel is still assumed to be error free


 The data traffic is still simplex.

The main problem we have to deal with here is how to prevent the sender from flooding the
receiver with data faster than the later is able to process them. In essence, if the receiver
requires a time t to execute from_physical_layer plus to_network_layer, the sender must
transmit at an average rate less than one frame per time t. Moreover, if we assume that no
automatic buffering and queuing are done within the receiver's hardware, the sender must
never transmit a new frame until the old one has been fetched by from_physical_layer, lest
the new one overwrite the old one. A solution to this problem is to have the receiver
provide feedback to the sender. After having passed a packet to its network layer, the
receiver sends a litle dummy frame back to the sender which, in efect, gives the sender
permission to transmit the next frame. Protocols in which the sender sends one frame and
then waits for an acknowledgement before proceeding are called stop-and-wait

A simplex stop-and-wait protocol.

Advantages:-

 frames travel in both directions i.e. A half- duplex transmission


 It maintains Control flow
 Afer delivering a packet to receiver, receiver sends an acknowledgement frame back
to the sender before the next frame sent.

Disadvantages: Inefficient that is slow.

B.SRIKANTH,ASST.PROF Page 24

Você também pode gostar