CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

26
CS 453 CS 453 Computer Networks Computer Networks Lecture 9 Lecture 9 Layer 2 – Data Link Layer Layer 2 – Data Link Layer

Transcript of CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Page 1: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

CS 453CS 453Computer NetworksComputer Networks

Lecture 9Lecture 9

Layer 2 – Data Link LayerLayer 2 – Data Link Layer

Page 2: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

TopicsTopics

Introduction to the Data Link LayerIntroduction to the Data Link Layer Data Link Layer functionalityData Link Layer functionality Data framingData framing Error correction and detectionError correction and detection Flow controlFlow control

Page 3: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Remember Layer 1Remember Layer 1

In the Physical layer we were concerned In the Physical layer we were concerned with with Physical connectivity – wires, fiber, lasers, Physical connectivity – wires, fiber, lasers,

etc.etc. Pushing bit – causing bits to traverse the Pushing bit – causing bits to traverse the

physical mediumphysical medium

So, is that enoughSo, is that enough

Page 4: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Remembering Layer 1Remembering Layer 1

Obviously, No.Obviously, No.While we can build a physical While we can build a physical infrastructure, we still have a number of infrastructure, we still have a number of problemsproblems Given a stream of incoming bit, how do we Given a stream of incoming bit, how do we

know where a given parcel of data starts and know where a given parcel of data starts and stopsstops

How do we detect errors in the bit streamHow do we detect errors in the bit stream What do we do about errors if we detect themWhat do we do about errors if we detect them ……and other issuesand other issues

Page 5: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

While Layer 1 is responsible for delivering While Layer 1 is responsible for delivering bit…bit…Layer 2 – Data Link Layer – is, generally Layer 2 – Data Link Layer – is, generally speaking, responsible for delivering bit speaking, responsible for delivering bit streams…streams… In some recognizable/usable formIn some recognizable/usable form … … and relatively cleanlyand relatively cleanly

Layer 2 – to establish a logical channel Layer 2 – to establish a logical channel that is “wirelike”that is “wirelike”

Page 6: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

On the source end of the link, the data link layer On the source end of the link, the data link layer takes data from the network layertakes data from the network layer Packages it for “shipping”Packages it for “shipping” Hands it off to the physical layer for transmissionHands it off to the physical layer for transmission

On the receiving end, the data link layerOn the receiving end, the data link layer takes the incoming data from the physical layertakes the incoming data from the physical layer Checks it for errorsChecks it for errors ““Unpackages” it Unpackages” it Hands it off to the network layer on the receiving Hands it off to the network layer on the receiving

machinemachine

Page 7: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Data Link Layer functionsData Link Layer functions Provide services to the Network Layer and the Provide services to the Network Layer and the

Physical LayerPhysical Layer Provide a service interface to the Network Provide a service interface to the Network

Layer and Physical LayerLayer and Physical Layer Handle data errorsHandle data errors Manage data traffic flowManage data traffic flow

Page 8: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Usually responsible for media access Usually responsible for media access control (MAC)control (MAC) If you have a shared media how does a If you have a shared media how does a

send/receiver get access and use of the send/receiver get access and use of the mediamedia

In competition with other senders/receiversIn competition with other senders/receivers Can’t be done in a free-for-all fashionCan’t be done in a free-for-all fashion Must be arbitrated in an orderly mannerMust be arbitrated in an orderly manner

Page 9: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Data Link Layer servicesData Link Layer services Unacknowledged connectionless serviceUnacknowledged connectionless service

Data transmitted toward receiverData transmitted toward receiver No steps to establish connection (logical channel)No steps to establish connection (logical channel) No acknowledgement from receiverNo acknowledgement from receiver If errors or lost frames – sender never knowsIf errors or lost frames – sender never knows

Maybe good for low error mediaMaybe good for low error mediaReal-time data transmissionReal-time data transmission

Can’t retransmit – late data can’t be used, better to drop Can’t retransmit – late data can’t be used, better to drop the framethe frame

Sort of like sending a letter in regular mailSort of like sending a letter in regular mail No inherent acknowledgmentNo inherent acknowledgment

Page 10: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Data Link Layer servicesData Link Layer services Acknowledged connectionless serviceAcknowledged connectionless service

No connection (logical channel) established No connection (logical channel) established between sender and receiver, butbetween sender and receiver, but

After transmission receiver sends an After transmission receiver sends an acknowledgement – received-good or received-acknowledgement – received-good or received-badbad

If received-bad can retransmitIf received-bad can retransmit

Sort of like registered mail – return receiptSort of like registered mail – return receipt

Page 11: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Flow control Flow control Acknowledged Connect-oriented serviceAcknowledged Connect-oriented service

Connection between sender and receiver before Connection between sender and receiver before data transmission started (logical channel or data transmission started (logical channel or logical circuit)logical circuit)

All transmissions acknowledgedAll transmissions acknowledged

Wide area network (WAN) linksWide area network (WAN) links Sort of like a phone call or a fax transmissionSort of like a phone call or a fax transmission

Page 12: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link LayerFlow controlFlow control Note in acknowledged services we saidNote in acknowledged services we said That the receive can send a received-good or a That the receive can send a received-good or a

received-bad acknowledgement, but…received-bad acknowledgement, but… What if the sender never receives an What if the sender never receives an

acknowledgement?acknowledgement? If sender is stuck waiting for an acknowledgement, If sender is stuck waiting for an acknowledgement,

but the acknowledgement is lost, all communications but the acknowledgement is lost, all communications is deadlockedis deadlocked

Solution: sender sets clock on each transmitted frameSolution: sender sets clock on each transmitted frameIf now acknowledgement when clock runs out – Time-out If now acknowledgement when clock runs out – Time-out errorerror

Page 13: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

FramingFraming In the physical layer we have bits flowing from In the physical layer we have bits flowing from

one machine, across a physical transmission one machine, across a physical transmission medium and pouring into another machinemedium and pouring into another machine

……but how does the receiving machine know but how does the receiving machine know where one unit of data starts and where it where one unit of data starts and where it stops? Where does one end and the next stops? Where does one end and the next one start. At the physical layer level its just a one start. At the physical layer level its just a continuous or non continuous flow of bitscontinuous or non continuous flow of bits

Page 14: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

FramingFraming The data link layer structures data streams The data link layer structures data streams

from the network layer (on the sending end) in from the network layer (on the sending end) in framesframes

And, extracts the data from the frames on the And, extracts the data from the frames on the receiving end… and hands it to the network receiving end… and hands it to the network layerlayer

Can’t count on clocks to resolve data Can’t count on clocks to resolve data boundariesboundaries

Build framesBuild frames

Page 15: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Frames are generally data packages Frames are generally data packages composed of composed of A header or a header/trailer combinationA header or a header/trailer combination The data from/for the network layerThe data from/for the network layer The data is referred to as the payloadThe data is referred to as the payload

Data

DataHeader Trailer

Data

DataHeader Trailer

Page 16: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Four ways to make framesFour ways to make frames Byte CountByte Count

First byte of a frame always hold the count of the First byte of a frame always hold the count of the number of bytes in the frame that follows it.number of bytes in the frame that follows it.

Receiving data link layer gets incoming data – Receiving data link layer gets incoming data – reads number in first byte and extracts that number reads number in first byte and extracts that number of bytes from the frameof bytes from the frame

Next incoming byte must be a frame byte countNext incoming byte must be a frame byte count

Page 17: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

FramesFrames Bytes counts – some serious problemsBytes counts – some serious problems

What if there is an error in the byte count of a What if there is an error in the byte count of a frameframeSuppose the frame byte count = 5… a one bit error Suppose the frame byte count = 5… a one bit error could make that value 7could make that value 7Now the data link layer sees 7 as the byte count Now the data link layer sees 7 as the byte count and extracts 7 bytes from the frameand extracts 7 bytes from the frameIt believes the next bytes is a byte count (it isn’t) It believes the next bytes is a byte count (it isn’t) and uses it to read the next N bytesand uses it to read the next N bytesData link layer has lost synchronization and there Data link layer has lost synchronization and there is no way to get it backis no way to get it back

Page 18: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link LayerFramingFraming Flag bytes Flag bytes

Add a special flag byte to the beginning of the Add a special flag byte to the beginning of the frame (header).frame (header).When the data link layer sees that flag byte that is When the data link layer sees that flag byte that is the beginning of the framethe beginning of the frameWhen it sees the next flag byte, that is the When it sees the next flag byte, that is the beginning of the next framebeginning of the next frame……but what if the flag byte occurs naturally in the but what if the flag byte occurs naturally in the data stream?data stream?……use a special escape byte in front of the use a special escape byte in front of the accidental “flag byte”accidental “flag byte”Using the escape byte is called “byte stuffing”Using the escape byte is called “byte stuffing”

Page 19: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

FramingFraming Start/Stop flags with bit stuffingStart/Stop flags with bit stuffing Start and end frame with same special bit Start and end frame with same special bit

sequencesequence When the sender data link layer sees the flag When the sender data link layer sees the flag

bit sequence in the data stream, it stuffs it bit sequence in the data stream, it stuffs it with 0 bit.with 0 bit.

When the receiver data link layer sees the When the receiver data link layer sees the flag bit sequence with a 0 at the end , it strips flag bit sequence with a 0 at the end , it strips the 0 bit and considers the rest datathe 0 bit and considers the rest data

Page 20: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

FramingFraming Special data encodingSpecial data encoding

Represent each bit in the data stream with a Represent each bit in the data stream with a special codespecial code

0 = 010 = 01 1 = 101 = 10 00 and 11 then used for frame flags00 and 11 then used for frame flags

Page 21: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Data Link Layer is responsible for Data Link Layer is responsible for Error detection and error correctionError detection and error correction

In designing the Data Link Layer you can-In designing the Data Link Layer you can- Add a minimal amount of redundancy to Add a minimal amount of redundancy to

you’re the data and detect errors but not you’re the data and detect errors but not correctcorrect

Add considerable redundancy to your data Add considerable redundancy to your data and correct errorsand correct errors

Page 22: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link LayerError correction is more expensive than error Error correction is more expensive than error detection in terms of detection in terms of bandwidthbandwidth ComputationallyComputationally

Fiber optics transmissions are relatively error Fiber optics transmissions are relatively error freefree More effective – detect and retransmitMore effective – detect and retransmit

Wireless media tend to have high error ratesWireless media tend to have high error rates If clean data depended on retransmission, large If clean data depended on retransmission, large

percentage of data would be retransmitted – not percentage of data would be retransmitted – not efficientefficient

More efficient – add error correction code to More efficient – add error correction code to transmitted datatransmitted data

Let receiver detect and correct bad data, up to a pointLet receiver detect and correct bad data, up to a point

Page 23: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Flow controlFlow control We have no inherent constraints on how We have no inherent constraints on how

much data can flow across a data link and much data can flow across a data link and how fasthow fast

How do you keep a data sender from How do you keep a data sender from overrunning a receiver with too much data too overrunning a receiver with too much data too fast?fast?

Page 24: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Flow controlFlow control Feedback flow control – Feedback flow control –

Negoitated/collaborative flow controlNegoitated/collaborative flow control

Sender can only send when it have permission from receiverSender can only send when it have permission from receiver Sender transmits a request-to-sendSender transmits a request-to-send Receiver replies with ok-to-send or not-ok-to-sendReceiver replies with ok-to-send or not-ok-to-send Sender transmits fixed quantity of data, etc…Sender transmits fixed quantity of data, etc…

Receiver grants “license” to senderReceiver grants “license” to sender Receiver sends “ok to send n frames”Receiver sends “ok to send n frames” Sender transmits n framesSender transmits n frames Sender waits for next “ok to send”Sender waits for next “ok to send”

Page 25: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.

Data Link LayerData Link Layer

Flow controlFlow control Rate base flow controlRate base flow control

Data flow is controlled by a built in mechanismData flow is controlled by a built in mechanism Like clockLike clock Data rate limited to something less than the medium and Data rate limited to something less than the medium and

receiver can handlereceiver can handle No conversation between sender and receiverNo conversation between sender and receiver

Page 26: CS 453 Computer Networks Lecture 9 Layer 2 – Data Link Layer.