Successfully reported this slideshow.

Networking lecture 4 data link_layer_by_Mamun sir

838 views

Published on

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

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Networking lecture 4 data link_layer_by_Mamun sir

  1. 1. Computer Networks Data Link Layer By Md. Abdullah al mamun Sr. Lecturer
  2. 2. 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
  3. 3. Data Link Layer: Introduction “link”Terminology:• 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 Data-link layer has the responsibility of transferring datagram from one node to adjacent node over a link 3
  4. 4. 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
  5. 5. 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
  6. 6. Adaptors Communicating datagram link layer protocolsending receiving node node frame frame adapter adapter • Link layer implemented in • Receiving side network “adapter” – Looks for errors, flow control, – Ethernet card, PCMCI card, etc 802.11 card, … – Extracts datagram, passes to • Sending side: receiving node – Encapsulates datagram in a • Adapter is semi- frame – Adds error checking bits, flow autonomous link & physical control, etc. layers 6
  7. 7. 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
  8. 8. Parity CheckingSingle Bit Parity: Two Dimensional Bit Parity:Detect single bit errors Detect and correct single bit errors 0 0 8
  9. 9. 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
  10. 10. CRC ExampleWant: D.2r XOR R = nGD.2r = nG XOR R Divide D.2r by G & take the remainder R 10
  11. 11. Packets Packets(a) Data link Data link Layer Frames Layer A B Physical Physical Layer Layer(b) 12 3 21 12 3 21 Medium 2 A B 1 1 Physical layer entity 3 Network layer entity 2 Data link layer entity Figure 5.2 Data Link Layer 11
  12. 12. End to End ACK/NAK 1 2 3 4 5 Data Data Data Data Hop by Hop Data Data Data Data 1 2 3 4 5 ACK/ ACK/ ACK/ ACK NAK NAK NAK /NA K Figure 5.7Copyright ©2000 The McGraw Hill Companies Data Link Layer 12 Leon-Garcia & Widjaja: Communication Networks
  13. 13. Basic Elements of ARQ Information Error-free Packet frames packet sequence sequence Transmitter Receiver Station A Control Station B frames CRC CRC Header Information Header Control frame packet Information FrameCopyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.8 Data Link Layer 13
  14. 14. packetnetwork layer buffer framedata link layer info ack seq kindphysical layer Data Link Layer 14
  15. 15. Ambiguities with Stop-and-Wait [unnumbered frames] (a) Frame 1 lost Time-out time A frame frame frame frame 0 1 1 2 ACK ACK B (b) ACK lost Time-out time A frame frame frame frame 0 1 1 2 ACK ACK ACK B In parts (a) and (b) transmitting station A acts the same way, but part (b) receiving station B accepts frame 1 twice.Copyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.9 Data Link Layer 15
  16. 16. PAR [OLD] problem Ambiguities when ACKs are not numbered time-out time A frame 0 frame frame frame 0 1 2 ACK ACK B Transmitting station A misinterprets duplicate ACKsCopyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.10 Data Link Layer 16
  17. 17. State Machine for Stop-and-Wait 0 10 10 10 1 0 10 10 10 1 Slast Rnext Timer Slast Transmitter Receiver Station A Rnext Station B (0,0) Error-free frame 0 (0,1) arrives at receiver Global State: ACK for (Slast, Rnext) ACK for frame 0 frame 1 arrives at arrives at transmitter transmitter Error-free frame 1 arrives at receiver (1,0) (1,1) Leon-Garcia & Widjaja: Communication Networks Figure 5.11Copyright ©2000 The McGraw Hill Companies Data Link Layer 17
  18. 18. Sliding Window Protocols [Tanenbaum]• Must be able to transmit data in both directions.• 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
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. 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 window Frames received with sequence numbers outside the receiver window are not accepted. Data Link Layer 22
  23. 23. Sliding Window Protocolsreceiver 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
  24. 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 24
  25. 25. Go Back N Go-Back-4: 4 frames are outstanding; so go back 4 fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 3 4 5 6 3 4 5 6 7 8 9 A B A A A Out-of-sequence frames A A A A A A C C C C C C C C C K K K K K K K K K 1 2 3 error 4 5 6 7 8 9 ACKing next frame expectedCopyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.13 Data Link Layer 25
  26. 26. Go Back N with NAK error recovery Transmitter goes back to frame 1 Go-Back-7: fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 3 4 5 1 2 3 4 5 A 6 7 0 B A N Out-of- A A A A A A C A sequence C C C C C C K K frames K K K K K K 1 1 2 3 4 5 6 7 errorCopyright ©2000 The McGraw Hill Companies Figure 5.17 Data Link Layer 26
  27. 27. Selective Repeat with NAK error recovery fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 3 4 5 6 2 7 8 9 A 10 11 12 B A A N A A A A A A A A A C C A C C C C C C C C C K K K K K K K K K K K K 1 2 2 2 2 2 7 8 9 1 1 1 error 0 1 2Copyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.21 Data Link Layer 27
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. 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
  32. 32. 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
  33. 33. 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 frequency bands 33
  34. 34. 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
  35. 35. CDMA Encoding/Decoding 35
  36. 36. CDMA: Handling Interference 36
  37. 37. 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
  38. 38. Slotted ALOHA (1) OperationAssumptions • When node obtains fresh• All frames same size frame, it transmits in next• Time is divided into equal slot size slots == time to • No collision  node can transmit 1 frame send new frame in next• Nodes start to transmit slot frames only at beginning of slots • Collision, node retransmits frame in each subsequent• Nodes are synchronized slot with probability p until• If 2 or more nodes transmit success in slot, all nodes detect collision 38
  39. 39. Slotted ALOHA (2)Pros Cons• Single active node can • Collisions  wasted slots continuously transmit at full • Idle slots rate of channel • Nodes may be able to detect• Decentralized: collision in less than time to – only slots in nodes need to be in sync transmit packet• Simple 39
  40. 40. Slotted ALOHA EfficiencyEfficiency:long-run • Max efficiency:fraction of successful Find p* that maximizesslots given many nodes Np(1-p)N-1with many frames to send • For many nodes:Analysis:• Suppose N nodes with many frames to send, each transmits in   lim Np * 1  p *  1 / e N slot with probability p• Probability that 1st node has success in a slot: p(1-p)N-1 At best: channel used At• Probability that any node has a success for useful transmissions Np(1-p)N-1 ~37% of time! 40
  41. 41. Pure (Unslotted) ALOHA• Same as slotted but no synchronization: – When frame first arrives transmit immediately  Collision probability increases! Efficiency = 1/(2e) 41
  42. 42. 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
  43. 43. 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
  44. 44. 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
  45. 45. CSMA/CD Collision Detection 45
  46. 46. 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
  47. 47. “Taking Turns” MAC protocolsPolling: Token passing:• Designated “master”  Control token passed from node one node to next sequentially.• Master node invites  Concerns: “slave” nodes to  Token overhead transmit  Latency – Round robin  Single point of failure (token) – Max frames• Concerns: – Polling overhead – Latency – Single point of failure 47
  48. 48. 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

×