Lecture 3: Data Link (A. Pattavina, Chapter 4 and 15)
Data Link Layer The main tasks of the data link layer are: Transfer data from the network layer of one machine to the network layer of another machine Convert the raw bit stream of the physical layer into groups of delimited bits ( frames ) Addressing the devices Error control: improving PHY performance by detecting and correcting errors; Flow control: avoiding buffer overflows by controlling transmission rates Network Layer Data Link Layer Physical Layer Network Layer Data Link Layer Physical Layer
Two types of networks at the data link layer Point-to-Point Networks: Pairs of hosts (or routers) are directly connected Broadcast Networks: All stations share a single communication channel Broadcast Network Typically, wide area networks (WANs) are point-to-point and local area networks (LANs) are broadcast. Point-to-Point Network
Wide Area Networks
MAC and LLC In any broadcast network, the stations must ensure that only one station transmits at a time on the shared communication channel The protocol that determines who can transmit on a broadcast channel are called Medium Access Control (MAC) protocol The MAC protocol are implemented in the MAC sublayer which is the lower sublayer of the data link layer The higher portion of the data link layer is often called Logical Link Control (LLC) Data Link Layer Logical Link Control Medium Access Control to Network Layer to Physical Layer
Framing How to recognize transmission units? One possibility is to insert gaps between frames but there is no guarantee about timing from the network. Start and end of frame marked by Character count Starting and ending chars with char stuffing Starting & ending flags with bit stuffing Physical layer coding violations
Character count Even if checksum is incorrect, the destination does not know where the bad frame starts.
Starting and ending chars w/ character stuffing Use ASCII chars DLE STX (Data Link Escape, Start TeXt) and DLE ETX (End TeXt). If receiver loses frame boundaries it should look for DLE STX and DLE ETX Problem: Binary data. DLE STX/ETX could occur and ruin framing. Stuffing:Add an ASCII DLE before each DLE in the binary data.
Starting & Ending Characters A B C D Data From Network Layer DLE STX A B C D DLE ETX Start Of Frame Data End Of Frame Starting & Ending Characters Added By Link Layer
Character Stuffing A B DLE C D data on Sender side DLE STX A B DLE DLE C D DLE ETX Start Of Frame Data A B DLE C D End Of Frame data on Reciever side
Start & end flags w/ bit stuffing Frame begins and ends with 01111110 called flag byte. When senders DLL senses 5 consecutive 1 s it stuffs a 0 into the bit stream. Receiver sees the 5 consecutive 1 s followed by a 0 and destuffs it (i.e., deletes the 0). Bit stuffing unambiguously locates frame boundaries.
Starting & ending Flags With Bit Stuffing. 01010011 1 1 0 101 01111110 01111110 Starting flag Bit Shifted Bit 01010011 1 110101 BIT stuffing Ending Flag BIT Data received by Network layer On reciever side After Performing Destuffing By data link Layer Stuffing Performed By Data Link layer
Point-to-Point Links
ErrorControl Solutions Two possible approaches Forward error correction (FEC) Control information transmitted with data frames for correcting transmission errors Overhead added regardless of link conditions Automatic repeat request (ARQ) Control information for detecting transmission errors (e.g. parity checks) Explicit acknowledgements or retransmission requests with overheads depending on error rates!» STOP&WAIT» CONTINOUS ARQ
Retransmission scenarios referred to as ARQ schemes (Automatic Retransmission request) COMPONENTS: a) error checking at receiver; b) feedback to sender; c) retx SRC Basic ACK idea DST Error Check: OK Automatic retransmit SRC DST Basic NACK idea Error Check: corrupted SRC DST SRC DST SRC DST Retx Timeout (RTO) Error Check: corrupted Basic ACK/Timeout idea
Error Detection Schemes Parity Send an additional parity bit (H) per character Even parity: if # of 1 s in character is odd, H = 1; else H = 0 Odd parity: if # of 1 s in character is odd, H = 0; else H = 1 Cannot detect even numbers of bit errors Checksum Treat data as sequence of integers Compute and send arithmetic sum (H) Handles multiple bit errors, but not all errors Cyclic Redundancy Check (CRC)
Checksum Examples Checksum computed over data Checksum appended to frame 15+20+84+1(19)=20 2 nd bit reversed in each item, but checksum is the same
CRC Example 10110110 110011 ) 1110001100000 110011 101111 110011 111000 110011 101100 110011 111110 110011 11010 = R T = M R = 1110001111010
Sequencenumbers a must Sender side: Receiver side: RTO rtx DATALINK or NETWORK (ACK lost) New data? Old data? Need to univocally label all packets circulating in the network between two end points. 1 bit (0-1) enough for Stop-and-wait
Stop & Wait Protocol description without errors Efficiency Protocol operation in case of errors Timeouts Sequence numbers 0/1 Efficiency for fixed bit error rates Timeout effects on efficiency Ack numbering 0/1
NormalOperation The sender will not send the next piece of data until it is sure that the current one is correctly received sequence number necessary to check for duplicated packets No NACK when packet is corrupted duplicate ACKs instead REMARK: throughput always lower than Available link rate!
Lost or damaged frameroundtrip delay + processing in the receiver
Lost ACK- Importance of numbering
Delayed ACK- Importance of ACK numbering
Duplex Stop-and-Wait ARQ Piggybacking combine data with ACK (less overhead saves bandwidth)
Performance Figures Utilization (U) fraction of time the link is used for transmitting data Throughput (b/s) effective b/s as experienced by user data Throughput = C * U (b/s) Throughput (frame/s) average data frames per second the link is supporting Throughput = C*U/data_frame_size (frame/sec) A frame ACK frame ACK frame ACK B frame ACK frame ACK frame ACK
Efficiency After every frame, source must wait till acknowledgment Hence link propagation time is significant Total time to for one frame: T_total = Tf + 2τ + Tp + Ta if we ignore Tp and Ta (usually very small) T_total = Tf + 2τ Link utilization, U is equal to U = Tf/ (T_total), or =1 / (1+2τ /Tf) = 1 / (1 + 2 a) where a = τ /Tf = length of link in bits If a < 1 (i.e. Tf > τ when 1st transmitted bit reaches destination, source will still be transmitting U is close 100% If a > 1 (i.e. Tf < τ frame transmission is completed before 1st bit reaches destination U is low T f τ T p τ T a Source time Destination
Efficiencywith errors Assume a frame is in error with probability P Therefore, average utilization can be written as U = Tf / (Nr * T_total) Nr is the average number of transmissions of a frame, while T_total is equal to Tf + 2 τ. For stop-and-wait, Nr is given by Nr = E[no of transmissions] = Σ i *Prob[ i transmissions]= Σ i *P i-1 (1-P)= 1/(1-P) Therefore, utilization is given by U = (1-P)/(1+2a) Note that for P = 0 (i.e. error free), the expression reduced to the previous result! A timeout frame ACK frame frame ACK B frame ACK frame frame ACK
stop-and-wait: upper bound/1 MSG = 1500 bytes Under-utilization with: 1) high capacity links, 2) large RTT links Bianchi, Tinnirello
stop-and-wait: upper bound/2 MSG = 1500 bytes Under-utilization with: 1) high capacity links, 2) large RTT links Bianchi, Tinnirello
Example Lf = 1500 bytes 2τ = 10 ms 2τ=100ms Link rate (kbps) throughput efficiency throughput efficiency 33 32,12 97,32% 25,88 78,43% 128 115,66 90,36% 61,94 48,39% 1.000 545,45 54,55% 107,14 10,71% 10.000 1071,43 10,71% 118,58 1,19% 100.000 1185,77 1,19% 119,86 0,12% 1.000.000 1198,56 0,12% 119,99 0,01% INFINITE 1200,00 N/A 120,00 N/A Lf Lf thr = lim = C 2τ + L / C 2τ f
Drawbacks of Stop-and-Wait After sending each frame, the host must wait for an ACK inefficient use of bandwidth To improve efficiency, ACK should be sent after multiple frames Alternatives: Sliding Window protocols 1. Go-back-N ARQ 2. Selective Repeat ARQ
Pipelining One task begins before the other one ends increases efficiency in transmission There is no pipelining in Stop-and- Wait ARQ
Pipelining Idea W=1 W=4 W=10 Send up to W frames before receiving the first ACK!
Sliding Window Protocol Stop-and-Wait can be very inefficient when a > 1 Protocol: Assumes full duplex line Source A and Destination B have buffers each of size W frames For k-bit sequence numbers: Frames are numbered: 0, 1, 2,, 2 k -1, 0, 1, (modulo 2 k ) ACKs (RRs) are numbered: 0, 1, 2,, 2 k -1, 0, 1, (modulo 2 k ) A is allowed to transmit up to W frames without waiting for an ACK B can receive up to W consecutive frames ACK J (or RR J), where 0<=J<= 2 k -1, sent by B means B have received frames up to frame J-1 and is ready to receive frame J Window size, W can be less or equal to 2 k -1
Example: k=3, W=7 Observations: A may tx W = 7 frames (F0, F1,, F6) After F0, F1, & F2 are txed, window is shrunk (i.e. can not transmit except F3, F4,, F6) When B sends RR3, A knows F0, F1 & F2 have been received and B is ready to receive F3 Window is advanced to cover 7 frames (starting with F3 up to F1) A sends F3, F4, F5, & F6 B responds with RR4 when F3 is received A advances the window by one position to include F2 W W W W W W = distance between first unacknowledged frame and last frame that can be sent
Piggybacking When using sliding window protocol in full duplex connections: Node A maintains its own transmit window Node B maintains its own receive window A frame contains: data field + ACK field There is a sequence number for the data field, and a sequence number for the ACK field
Efficiency: W>=2a+1 Assume k=3, W = 7 (ignoring Ta) Source can continuously keep transmitting!! Because the ACK can arrive to source before the window is completed Utilization = 100% T f τ τ time Source Destination W T f Sending ACK0 as soon as F0 is received is the maximum help the destination can do to increase utilization
Efficiency: W<2a+1 Assume k = 3, W = 3 (ignoring Ta) Source can NOT continuously keep transmitting!! T f Because the ACK can NOT arrive to source before the window is completed τ Source Destination W T f W * Tf Utilization = ------------------ Tf + 2 *τ W = ------------ 1 + 2a time
Pipelining summary τ(+1tx) W=4? W=10 time time UNDER-SIZED WINDOW: THROUGHPUT INEFFICIENCY thr = Bianchi, Tinnirello min C, W 2τ + WINDOW SIZING that allows CONTINUOUS TRANSMISSION L L f f / C
Sliding Window Protocol Sliding Window Protocol Simulation (http://www.cs.stir.ac.uk/~kjt/softwa re/comms/jasper/swp3.html)
Question What is the consequence of the window size in case of transmission errors? Frames can be received out of order Definition of receiver window window size 1 means that the packets have to be received in order Window size > 1 means that packets are buffered up to the window size for waiting for the missed packets.
Go Back N protocol Sequence number: b bits N=2 b values Repeated modulo N Sender window Ws=N-1 number of possible sequence numbers minus 1 Receiver rules RX: accept frames only if received in strict sequence!! If out of order frame, reply with NACK NACK(i) = I have received ALL frames up to (i-1) mod N, but I haven t received i-th frame
GBN example 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 7 0 1 4 5 6 NACK 7 7 4 5 6 7 0 1 2 3 4 5 6 7 Bianchi, Tinnirello
Frame 2 Frame 3 Frame 0 Frame 1 W=N=4 WhyWs= N-1? Frame X-1 = ACK 1 Frame 2 Frame 3 Frame 0 Frame 1 W=N=4 Frame X-1 = ACK 1 Frame X = ACK 1 Frame X = ACK 1 All successful OR all lost??????????????? Bianchi, Tinnirello
Go-back-N Inefficient all out of order received packets are discarded This is a problem in a noisy link many frames must be retransmitted -> bandwidth consuming Solution re-send only the damaged frames Selective Repeat ARQ avoid unnecessary retransmissions
SelectiveRepeat Key RX difference: Received frames buffered also if out of order New parameter: Receiver Window Wr New window sizing rule: GBN: Ws < N SR: Ws + Wr N TO N=4; Ws=3; Wr=2 2 3 0 ACK 0 2 retx Rx window 2 3 0 1 2 3 2 3 0 1 2 3 2 3 0 1 2 3 2 3 0 1 2 3 NEW!! GBN = special case Wr=1 Bianchi, Tinnirello
Choiceofwindows N=8 Wr > 4 not useful not enough in-fly frames since Ws<4 Ws > 4 out of order may harm not enough RX window size to capture all possible out of order cases Most appropriate choice: Wr=Ws=4 but remember throughput limits, though! Bianchi, Tinnirello
SR exampleand TX operation 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 4 7 5 0 6 1 2 NACK 7 3 7 4 5 ACK 3 7,0,1,2,3 6 Bianchi, Tinnirello
Go-Back-N: Efficiency With Errors Remember that Go-back-N ARQ utilization for error-free channels is given by: U = 1 for W > 2a + 1 U= W/(2a+1) for W < 2a + 1 Assume a data frame can be in error with probability P With Go-back-N, if one frame in error, we may retransmit a number of frames, on average K, and NOT only one! The average number of transmitted frames to transmit one frame correctly, Nr, is given by Nr = E[number of transmitted frames to successfully transmit one frame] = Σ f(i) x P i-1 (1-P) If a frame is transmitted i times (i.e. first (i-1) times are erroneous while it was received correctly in the ith time), then f(i) is the total number of frame transmissions if our original frame is in error: f(i) is given by = 1 + (i-1)k Substituting f(i) in the above relation, yields Nr = (1-P+KP)/(1-P) Examining the operation of Go-back-N, an approximate value for K is 2a+1; Then utilization with errors is given by U = (1-P)/(1+2aP) for W > 2a+1 U=(1-P)W/{(2a+1)(2-P+WP)} for W < 2a+1
Selective Repeat: Efficiency With Errors Remember that Selective Reject utilization for error-free channels is given by: U = 1 for W > 2a + 1 U = W/(2a+1) for W < 2a + 1 Assume a data frame can be in error with probability P With Selective Reject if one frame in error, we retransmit only the required frame The average number of transmitted frames to transmit one frame correctly, Nr, is given by Nr = E[number of transmitted frames to successfully transmit one frame] = Σ i x P i-1 (1-P) = 1/(1-P) Then utilization with errors is given by U =1-P for W > 2a+1 U=(1-P)W/(2a+1) for W < 2a+1
ARQ Utilization as a Function of a Remember a is given by τ/tf i.e. the length of the link in bits The curves are for P = 10-3 Note for W = 1, go-back-n and selective reject degenerate to the case of stop-and-wait Please note that the previous analyses are only approximate errors in ACKs were ignored. Furthermore, in the case of go-back-n, errors in retransmitted frames other than the frame of interest were also ignored
Broadcast Links
Random Access Protocols: Why? When multiple nodes share a common channel, the channel is not multiplexed a priori e.g. wireless networks Basic Idea: nodes which need to transmit a packet, try to access the channel at random instants using the whole capacity channel is used only by nodes which need it! Trading off simplicity with efficiency No a priori coordination or little coordination among the nodes Resource wastes are possible if multiple nodes transmit simultaneously
Random Access Protocols: Where? Several real networks make use of random access protocols Alohanet (early 70 s) Ethernet WiFi Cellular networks
How do theywork? Basic Operations: Transmit at random time instants Feedback is known without errors Success/Collision e.g. by means of ACK/ACK Timeout on an independent channel Reschedule transmissions in case of collisions Several protocol variants according to the way in which random instants and retransmissions are managed Aloha, Slotted Aloha Carrier Sense Multiple Access CMSA/CD, CSMA/CA
Whichefficiency? How much wastes on channel resources? Because channel is idle Because of collisions: when two or more transmissions overlap! Intuition: In case of low traffic, collisions are uncommon but channel is mostly idle In case of high traffic, several transmissions but a lot of collisions Are there possible optimizations? Which measure? Assuming all the frames have equal size: Successful_Transmission_Time / Total_Channel_Time #Successful_Frames/#Pkt_Times=E[Succesful frames]/pkt_time Packet T Packet T Packet T Collision Collision Packet T
Simplest case: ALOHA No synchronization at all If a pkt needs transmission: send immediately Collision is detected at the end of transmission (e.g. ACK) Reschedule transmission after a random time until it is successfully transmitted rnd RTX delay packet packet packet packet new frame arrival new frame arrival new frame arrival
Analysis of Pure ALOHA Notation: T = pkt_time S: Average number of successful transmissions per pkt_time ; that is, the throughput or efficiency. e.g. 2frames/7pkt_time G: Average number of total frames transmitted per pkt_time e.g. 2frames/7pkt_time in the first case, 6frames/7pkt_time in the second case Packet T Packet T Packet T Packet TPacket T Packet Packet T T Packet T
Modeling Assumptions Infinite number of stations a new frame arrival is managed by a new contending station All frames are of constant length, whose duration is T The channel is noise-free; the errors are only due to collisions Frame arrival rate Poisson process. X frames/s; XT frames/pkt_time; In equilibrium conditions: arrival_rate=s! Each new packet takes the place of a successful packet leaving contention Frame transmission rate (including retransmissions) Poisson process Λ frames/s; ΛT frames/pkt_time; G = ΛT frames/pkt_time >= S!
Vulnerabilityperiod: 2T T T Target STA Packet T OK! Interfering STA Collision on initial part of the pkt Collision on final part of the pkt
Analysis of Pure ALOHA Since S represents the number of good transmissions per pkt_time, and G represents the total number of attempted transmissions per pkt_time, then we have: S = G (Probability of good transmission) G = ΛT Good transmissions are performed if no transmission attempt is originated in a vulnerable time of 2T Remind that transmissions attempts are a Poisson process..
Analysis of Pure ALOHA Using Pr to have k tx in t: P k ( t) = k ( Λt) e k! Λt and considering: Λ 2 T = 2G S we have: S = G ( ) k 2G 2G 2G k! e k = 0 = Ge G
Maximumthroughput ( ) ( ) 0.18394 2 1 2 2 1 2 1 0 2 1 2 2 1/ max 2 2 ' 2 = = = = = = = = e e e S G Ge e G S Ge G S G G G Can we do better?
Slotted ALOHA Channel is slotted Channel access times are discrete Slot size equal to pkt_time A new frame can be transmitted only at the beginning of the next slot In case of collision Reschedule transmission after a random number of slots Now.. synchronization is required among nodes! packet collision packet new frame arrival channel access time k channel access time k+1 new frame arrivals rnd RTX delay
Vulnerabilityperiod: T slot k-1 slot k slot k+1 Target STA Packet T Interfering STA Synchronized collisions!
SlottedAlohaimprovements Being the vulnerability period T only.. S S k G G G = G e = Ge k! k = 0 1 = = 0.36788 for G e max Throughput doubled with respect to un-slotted version, but SYNC required! = 1 0.4 0.3 0.2 0.1 0.5 1.0 1.5 2.0 G = offered load Slotted Aloha Pure Aloha
Random Access Instability What happens if the offered load slightly changes? Case A: G increases, S increases thus reducing G to the old value Case B: G increases, S decreases thus further increasing G If backlog increases beyond stable point, S will reach 0! A B S G
CSMA: Motivations The capacity of ALOHA or slotted ALOHA is limited by the large vulnerability period of a packet. By listening before transmitting, stations try to reduce the vulnerability period to one propagation delay. Useful if propagation delay τ is smaller than packet duration!
Vulnerabilityperiod: τ Target STA Busy defer tx! Packet T Propagation delay τ Packet T Busy Interfering STAs Collision!
CSMA: Protocol Families CSMA: listen before transmit: If channel sensed idle: transmit entire frame If channel sensed busy, defer transmission Non-persistent CSMA: retry after random backoff interval Persistent CSMA: retry immediately with probability p (even p=1) when channel becomes idle, wait a fixed time with probability 1-p Continuously sense the channel Slotted, Unslotted human analogy: don t interrupt others!
CSMA Examples
EfficiencyExample: non-persistent CSMA STA A Packet T τ STA B Packet T τ Packet T τ STA C y Packet T τ busy idle busy idle Channel time organized into cycles Busy, Idle intervals Busy intervals defined as the total time in which the channel is sensed busy If the delay is constant per each source-destination pair, we get a lower performance bound
Efficiency(2)
CSMA versus Aloha Comparison of the channel utilization versus load for various random access protocols.
CSMA/CD CSMA with collision detection. Problem: when frames collide, medium is unusable for duration of both (damaged) frames. For long frames (when compared to propagation time), considerable waste. What if station listens while transmitting? If collision detected, transmit brief jamming signal and abort transmission. After aborting, wait random time, try again Is listening always possible? No, in wireless networks, where received and transmitted power levels are very different!!
Taking Turns MAC protocols Polling: master node invites slave nodes to transmit in turn Request to Send, Clear to Send msgs concerns: polling overhead latency single point of failure (master) Token passing: control token passed from one node to next sequentially. token message concerns: token overhead latency single point of failure (token)
Reservation-based protocols Distributed Polling: time divided into slots begins with N short reservation slots reservation slot time equal to channel end-end propagation delay station with message to send posts reservation reservation seen by all stations after reservation slots, message transmissions ordered by known priority
Backup Slides
Delay Note that G/S represents the total number of transmissions for each packet generated into the systems Nrtx = G/S -1 =e 2G -1 for Aloha Nrtx= G/S=e G -1 for Slotted Aloha Each retransmission requires the packet transmission time T + the ACK timeout (2τ) + the random delay +(slot waiting time for slotted Aloha) E[rtx]=T+2τ+E[rnd] D=T+τ+Nrtx E[rtx]; Normalized D/T log(d/t) 4.5 4 3.5 3 2.5 2 1.5 1 0.5 0 0 0.05 0.1 0.15 0.2 S E[rnd]=50T E[rnd]=5T E[rnd]=T
Efficiency with finite users Slotted Aloha Previous models refer to the case of infinite users.. What happens in real networks? Consider slotted Aloha with N stations generating the offered load G each transmits in slot with probability G/N probability of successful transmission for each node is: G/N (1-G/N) (N-1) S=G(1-G/N) N-1 ; S max =S(1)=(1-1/N) N-1 N=1: Smax=1! N=2: Smax=1/2; N=3: Smax =4/9; N=5: Smax = 0.41; N=10: Smax=0.39; N= : Smax=0.368 With ten or a few tens of stations performance approaches the limit case!