Networking lecture 4 data link_layer_by_Mamun sir

Post on 22-Nov-2014

604 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

This a Class Lecture Sheet on Networking Class. Mamun Sir is the Lecturer of that class. Which was held in Atish Dipankar Uninersity.

Transcript

Data Link Layer

By Md. Abdullah al mamun

Sr. Lecturer

Computer Networks

Data Link Layer

• Provides a well-defined service interface to the network layer.

• Determines how the bits of the physical layer are grouped into frames (framing).

• Deals with transmission errors (CRC and ARQ).

• Regulates the flow of frames.

• Performs general link layer management.

Data Link Layer 2

Data Link Layer: IntroductionTerminology:• Hosts and routers/ bridges/

switches are nodes

• Communication channels that connect adjacent nodes along communication path are links, e.g.:– Wired links

– Wireless links

– LANs

• 2-PDU is a frame, encapsulates datagram

3

“link”

Data-link layer has the responsibility of transferring datagram from one node to adjacent node over a link

Data Link Layer Services (1)• Datagram transferred by different link protocols over

different links: – Ethernet, FDDI,802.11, etc– Different protocols different services

• Framing, link access:– Encapsulate datagram into frame, adding header, trailer– Channel access if shared medium– Physical addresses used in frame headers to identify source,

destination

• Reliable delivery between adjacent nodes– Rarely used on low bit error link (e.g., fiber)– Essential in links with high error rates

• e.g., wireless

4

Link Layer Services (2)

• Flow Control:– Pacing between adjacent sending and receiving nodes

• Error Detection:– Errors are caused by signal attenuation, noise. – Receiver detects presence of errors

• Either signals sender for retransmission or drops frame

• Error Correction:– Receiver identifies and corrects bit error(s) without resorting to

retransmission– Recovery depends on the encoding scheme

• Half-duplex and full-duplex– Half duplex nodes at both ends of link can transmit, but not at

same time

5

Adaptors Communicating

• Link layer implemented in network “adapter” – Ethernet card, PCMCI card,

802.11 card, …

• Sending side:– Encapsulates datagram in a

frame– Adds error checking bits, flow

control, etc.

• Receiving side– Looks for errors, flow control,

etc

– Extracts datagram, passes to receiving node

• Adapter is semi-autonomous link & physical layers

6

sendingnode

frame

receivingnode

datagram

frame

adapter adapter

link layer protocol

Error Detection

• EDC: Error Detection and Correction bits (redundancy)• D: Data protected by error checking,

– May include header fields

• Note: Error detection not 100% reliable!– Depends on the encoding– Larger EDC better error detection/correction capabilities

• Plus more overhead!7

Parity Checking

8

Single Bit Parity:Detect single bit errors

Two Dimensional Bit Parity:Detect and correct single bit errors

0 0

CRC: Cyclic Redundancy Check

• View data bits, D, as a binary number

• Choose r+1 bit pattern (generator), G

• Goal: Choose r CRC bits, R, such that– <D,R> exactly divisible by G (modulo 2)

– Receiver knows G, divides <D,R> by G.• If non-zero remainder error detected

• CRC can detect all burst errors less than r+1 bits

• Very practical, e.g., ATM, HDCL

9

CRC ExampleWant:

D.2r XOR R = nG

D.2r = nG XOR R Divide D.2r by G & take

the remainder R

10

Data Link Layer 11

3 2 11 2 3 2 11 2

21

Medium

1

2

Physical layer entity

Data link layer entity3 Network layer entity

PhysicalLayer

Data linkLayer

PhysicalLayer

Data linkLayer

A B

A B

Packets Packets

Frames

(a)

(b)

Figure 5.2

Data Link Layer 12

1 2 3 4 5

Data Data Data

ACK/NAK

Data

1 2 3 4 5Data Data Data Data

ACK/NAK

ACK/NAK

ACK/NAK

ACK/NA

K Figure 5.7

End to End

Hop by Hop

Leon-Garcia & Widjaja: Communication Networks

Copyright ©2000 The McGraw Hill Companies

Data Link Layer 13

Packetsequence

Error-free packet

sequence

Informationframes

Control frames

Transmitter Receiver

CRC

Informationpacket

Header

Station A Station B

Information Frame

Control frame

CRC Header

Figure 5.8Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Basic Elements of ARQ

Data Link Layer 14

ack seq kindinfo

buffer

physical layer

network layer

data link layer

frame

packet

In parts (a) and (b) transmitting station A acts the same way, but part (b) receiving station B accepts frame 1 twice.

Data Link Layer

15

(a) Frame 1 lost

A

B

frame 0

frame1

ACK

frame1

ACK

timeTime-out

frame2

(b) ACK lost

A

B

frame 0

frame1

ACK

frame1

ACK

timeTime-out

frame2

ACK

Figure 5.9

Ambiguities with Stop-and-Wait[unnumbered frames]

Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Transmitting station A misinterprets duplicate ACKs

Data Link Layer 16

A

B

frame 0 frame

0ACKframe

1ACK

timetime-out

frame2

Figure 5.10Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

PAR [OLD] problemAmbiguities when ACKs are not numbered

Data Link Layer 17

Transmitter Receiver

SlastRnext

0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

(0,0) (0,1)

(1,0) (1,1)

Timer

Global State:(Slast, Rnext)

Error-free frame 0arrives at receiver

ACK forframe 0

arrives attransmitter

ACK forframe 1

arrives attransmitter Error-free frame 1

arrives at receiver

Station A Station BRnext

Slast

Figure 5.11Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

State Machine for Stop-and-Wait

Sliding Window Protocols[Tanenbaum]

• Must be able to transmit data in bothdirections.

• Choices for utilization of the reverse channel:– mix DATA frames with ACK frames.

– Piggyback the ACK• Receiver waits for DATA traffic in the opposite direction.

• Use the ACK field in the frame header to send sequence number of frame being ACKed.

– better use of the channel capacity.

Data Link Layer 18

Sliding Window Protocols

• ACKs introduce a new issue – how long does receiver wait before sending ONLY an ACK frame.We need an ACKTimer!!

sender timeout period needs to set longer.

• The protocol must deal with the premature timeout problem and be “robust” under pathological conditions.

Data Link Layer 19

Sliding Window ProtocolsEach outbound frame must contain a sequence number. With n

bits for the sequence number field, maxseq = 2**n - 1 and the numbers range from 0 to maxseq.

Sliding window :: sender has a window of frames and maintains a list of consecutive sequence numbers for frames that it is permitted to send without waiting for ACKs.

receiver has a window that is a list of frame sequence numbers it is permitted to accept.

Note – sending and receiving windows do NOT have to be the same size.

Windows can be fixed size or dynamically growing and shrinking.

Data Link Layer 20

Sliding Window Protocols• Host is oblivious, message order at transport level

is maintained.

sender’s window :: frames sent but not yet ACKed.

– new packets from the Host cause the upper edge inside sender window to be incremented.

– ACKed frames from the receiver cause the lower edge inside window to be incremented.

• All frames in the sender’s window must be saved for possible retransmission and we need one timer per frame in the window.

Data Link Layer 21

Sliding Window Protocols

• If the maximum sender window size is B, the sender needs B buffers.

• If the sender window gets full (i.e., reaches its maximum window size, the protocol must shut off the Host (the network layer) until buffers become available.

• receiver windowFrames received with sequence numbers outside

the receiver window are not accepted.

Data Link Layer 22

Sliding Window Protocols

receiver window– Frames received with sequence numbers

outside the receiver window are not accepted.

– The receiver window size is normally static.

The set of acceptable sequence numbers is rotated as “acceptable” frames arrive.

a receiver window size = 1 the protocol only accepts frames in order.

There is referred to as Go Back N.

Data Link Layer 23

Data Link Layer 24

Standard Ways to ACK

1. ACK sequence number indicates the last frame successfully received.

2. ACK sequence number indicates the next frame the receiver expects to

receive.Both of these can be strictly individual

ACKs or represent cumulative ACKing.Cumulative ACKing is the most common

technique.

Data Link Layer 25

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr6

fr3

ACK1 error

Out-of-sequence frames

Go-Back-4: 4 frames are outstanding; so go back 4

fr5

fr6

fr4

fr7

fr8

fr9

ACK2

ACK3

ACK4

ACK5

ACK6

ACK7

ACK8

ACK9

Figure 5.13Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Go Back N

ACKing next frame expected

Data Link Layer 26

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr1

fr2

ACK1

error

Out-of-sequence

frames

Go-Back-7:

fr4

fr5

fr3

fr6

fr7

fr0

NAK1

ACK3

ACK4

ACK5

ACK6

ACK7

ACK2

Transmitter goes back to frame 1

Figure 5.17

Go Back Nwith NAK error recovery

Copyright ©2000 The McGraw Hill Companies

Data Link Layer 27

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr6

fr2

ACK1 error

fr8

fr9

fr7

fr10

fr11

fr12

ACK2

NAK2

ACK7

ACK8

ACK9

ACK10

ACK11

ACK12

ACK2

ACK2

ACK2

Figure 5.21

Selective Repeatwith NAK error recovery

Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Multiple Access Links and Protocols

• Link types:– Point-to-point, e.g.:

• PPP for dial-up access

• Point-to-point link between Ethernet switch and host

– Broadcast (shared wire or medium), e.g.:• traditional Ethernet

• 802.11 wireless LAN

28

Multiple Access Protocols

• Single shared broadcast channel

• Simultaneous transmissions interference only one node can send successfully at a time

• Multiple access protocol:

A distributed algorithm that determines how nodes share channel, i.e., determine when node can transmit.

• Note: Communication about channel sharing must use channel itself!

29

Protocol Requirements

• Assume broadcast channel of R bps

• Requirements:– When one node wants to transmit, it can send at rate R.

– When M nodes want to transmit, each can send at average rate R/M

– Fully decentralized:• no special node to coordinate transmissions

• no synchronization of clocks, slots

– Simple cheap to implement

30

Taxonomy of MAC Protocols

• Channel Partitioning– Divide channel into smaller “pieces”

• time slots• frequency• code

– Allocate piece to node for exclusive use

• Random Access– Channel not divided, allow collisions– Handle collisions

• Turn-taking– Tightly coordinate shared access to avoid collisions

31

Channel Partitioning: TDMA• TDMA: Time Division Multiple Access

– Slice bandwidth into time slots

– Each station gets fixed length slot (length = packet transmission time) in each round

– Unused slots go idle

• Example: – 6-station LAN,

– 1,3,4 have pkt, slots 2,5,6 idle:

32

Channel Partitioning: FDMA• FDMA: Frequency Division Multiple Access

– Channel spectrum divided into frequency bands– Each station assigned fixed frequency band– Unused transmission time in frequency bands go idle

• Example: – 6-station LAN, – 1,3,4 have pkt, frequency bands 2,5,6 idle

33

freq

uenc

y ba

nds

Channel Partitioning: CDMA

• Used mostly in wireless broadcast channels – cellular, satellite, etc

• CDMA: Code Division Multiple Access) – All users share same frequency, but

– each user has own “chipping” sequence (code) to encode data

– Allows multiple users to transmit simultaneously with minimal interference

• Encoding:– signal = (original data) X (chipping sequence)

• Decoding: – inner-product of encoded signal and chipping sequence

34

CDMA Encoding/Decoding

35

CDMA: Handling Interference

36

Random Access Protocols

• When node has packet to send:– Transmits at full channel data rate R– with no a priori coordination among nodes

• Two or more transmitting nodes collision• Random access MAC protocol specifies:

– How to detect collisions– How to recover from collisions

• e.g., via delayed retransmissions

• Examples of random access MAC protocols:– Slotted ALOHA– ALOHA– CSMA, CSMA/CD, CSMA/CA

37

Slotted ALOHA (1)

Assumptions• All frames same size• Time is divided into equal

size slots == time to transmit 1 frame

• Nodes start to transmit frames only at beginning of slots

• Nodes are synchronized• If 2 or more nodes transmit

in slot, all nodes detect collision

Operation

• When node obtains fresh frame, it transmits in next slot

• No collision node can send new frame in next slot

• Collision, node retransmits frame in each subsequent slot with probability p until success

38

Slotted ALOHA (2)

Pros• Single active node can

continuously transmit at full rate of channel

• Decentralized: – only slots in nodes need to be

in sync

• Simple

Cons

• Collisions wasted slots

• Idle slots

• Nodes may be able to detect collision in less than time to transmit packet

39

Slotted ALOHA Efficiency

Analysis:• Suppose N nodes with many

frames to send, each transmits in slot with probability p

• Probability that 1st node has success in a slot:

p(1-p)N-1

• Probability that any node has a success

Np(1-p)N-1

• Max efficiency:Find p* that maximizes

Np(1-p)N-1

• For many nodes:

40

Efficiency:long-run Efficiency:long-run fraction of successful slots given many nodes with many frames to send

At best: channel used At best: channel used for useful transmissions ~37% of time!

epNpN

/11lim **

Pure (Unslotted) ALOHA• Same as slotted but no synchronization:

– When frame first arrives transmit immediately

Collision probability increases!

41

Efficiency = 1/(2e)Efficiency = 1/(2e)

CSMA: Carrier Sense Multiple Access

• CSMA:– Listen before transmit:

• If channel sensed idle: transmit entire frame

• If channel sensed busy, defer transmission

• Human analogy– Don’t interrupt others!

42

CSMA Collisions

• Collisions can still occur:– propagation delay means

two nodes may not hear each other’s transmission

• On collision:– entire packet transmission

time wasted

• Collision probability– depends on propagation

delay

43

CSMA/CD (Collision Detection)• CSMA/CD: Carrier sensing, deferral as in CSMA

– Collisions detected within short time– Colliding transmissions aborted

• Collision detection:– On wired LANs:

• measure signal strengths, • compare transmitted & received signals

– On wireless LANs: • receiver shut off while transmitting

• Human analogy: – the polite conversationalist

44

CSMA/CD Collision Detection

45

Turn-Taking MAC Protocols

• Channel partitioning:– High load efficiently and fair– Low load inefficient

• 1/N bandwidth allocated even if only 1 active node!

• Random access:– Low load efficient

• single node can fully utilize channel

– High load inefficient• collision overhead

• Turn-taking protocols:Look for best of both worlds!

46

“Taking Turns” MAC protocolsPolling:• Designated “master”

node• Master node invites

“slave” nodes to transmit– Round robin– Max frames

• Concerns:– Polling overhead – Latency– Single point of failure

47

Token passing: Control token passed from

one node to next sequentially. Concerns:

Token overhead Latency Single point of failure (token)

Summary of MAC Protocols

• Sharing of shared media:– Channel (static) partitioning

• by time, frequency, code• TDMA, FDMA, CDMA

– Random (dynamic) partitioning • carrier sensing: collision detection• easy in wire technologies,harder in wireless• ALOHA, S-ALOHA, CSMA, CSMA/CD• CSMA/CD used in Ethernet

– Turn-Taking• polling from a central site• token passing

48

top related