CPS 365 Theophilus Benson. Today’s Lecture Recap last class Error detection code – Parity –...

Post on 12-Jan-2016

220 views 0 download

transcript

CPS 365

Theophilus Benson

Today’s Lecture• Recap last class

• Error detection code– Parity– Check-Sum– Error-Correcting-Codes

• Error correcting code– Sophisticated code that can correct errors

• Multiple Access Link– Ethernet– Token ring– Note: understand the concepts

Last Class

• Approaches to Framing• Latency Breakdown• Reliable Delivery

– Stop and Wait V. At-Most-Once• Ensuring high throughput

– Sliding Window – Seq # V SWS

At Most Once

SW1 SW2 SW3

Goal: send two packets from SW1 to SW3Assumptions: No Packet LossAlgorithm: At-Most-Once

At Most Once SW1 SW2 SW3

Sliding Window

SW1 SW2 SW3

Goal: send two packets from SW1 to SW3Assumptions: No Packet LossAlgorithm: Sliding Window

Bandwidth-Delay Product: 4 packetSWS=4RWS=4

1 2 3 4 5 6

SWS

LFS

LAR

Sliding Window SW1 SW2 SW3

At Most Once Sliding Window

Today’s Lecture• Recap last class

• Error detection code– Parity– Check-Sum– Error-Correcting-Codes

• Error correcting code– Sophisticated code that can correct errors

• Multiple Access Link– Ethernet– Token ring– 802.11 (WiFi)– Note: understand the concepts

Why Should You Care About Errors?

• Still happens in:– Wireless networks– Cellular networks

• Error detection + Correction is fundamental– Used to in Storage/Operating Systems

• Crucial in data centers

– Facebook uses advanced forms to protect data

Error Detection

• Must add bits to catch errors in packet• Sometimes can also correct errors

– If enough redundancy– Might have to retransmit

• Used in multiple layers• Three examples today:

– Parity– Internet Checksum– CRC

Errors Abound

1 0

SW1 SW2

Errors Abound

• Can we detect the error?

1 1

SW1 SW2

Simplest Schemes: Repeat Frame N times (FEC)

1 0 1 0 1 0

SW1 SW2

• Can we detect the error?• Can we correct errors?• What is the problem?

Simplest Schemes:Repeat Frame N times (FEC)

1 1 1 0 1 0

SW1 SW2

• Add a parity bit to the end of a word

Simplest Schemes: Parity Bit

1 0 1

SW1 SW2

• Add a parity bit to the end of a word• Can we detect the error?• Can we correct the error?

Simplest Schemes: Parity Bit1 Error

0 0 1

SW1 SW2

Parity

1 1 0

1 0 1

0 1 1

0 0 0

• Add a parity bit to the end of a word• Can we detect error when

there are two errors?

Simplest Schemes: Parity Bit2 Errors

0 1 1

SW1 SW2

Parity

1 1 0

1 0 1

0 1 1

0 0 0

• Add a parity bit to the end of a word• Can we detect error when

there are two errors?

Simplest Schemes: Parity Bit2 Errors

0 1 1

SW1 SW2

Parity

1 1 0

1 0 1

0 1 1

0 0 0If using this parity, you can only detect an ‘odd’ number of errors!!!!

XoR encoding

1 1 1 0 1 0

SW1 SW2

XoR encoding

1 1 1 0 1 0

SW1 SW2

1 0 1

1 1 1 0 1 0 1 0 1XOR

XoR encoding

1 1 1 0 1 0

SW1 SW2

0 0 1

Error in correcting codeno one cares

• What happens when there’s an error…– In the Correcting Code

XoR encoding

• What happens when there’s an error…– In the Correcting Code– How about in the data?

1 0 0 0 1 0

SW1 SW2

1 0 1

Error in Data!!!Code RED!!!

• What happens when there’s an error…– In the Correcting Code– How about in the data?

• How do we correct this?

XoR encoding

1 0 0 0 1 0

SW1 SW2

1 0 1

1 1 10 1 0 1 0 1XOR

2-D Parity

• Add 1 parity bit for each 7 bits• Add 1 parity bit for each bit position across the frame)

– Can correct single-bit errors– Can detect 2- and 3-bit errors, most 4-bit errors

• Find a 4-bit error that can’t be corrected

Internet checksum algorithm:IP Checksum

• Fixed-length code– n-bit code should capture all but 2-n fraction of errors

• Why?

– Trick is to make sure that includes all common errors• IP Checksum is an example: 16-bits

– 1’s complement of 1’s complement sum of every 2 bytes

uint16 cksum(uint16 *buf, int count) {uint32 sum = 0;while (count--)

if ((sum += *buf++) & 0xffff0000) // carrysum = (sum & 0xffff) + 1;

return ~(sum & 0xffff);}

1’s complement

• -x is each bit of x inverted• If there is a carry bit, add 1 to the sum• Example: 4-bit integer

– -3: 1100 (invert of 0011)– -4: 1011 (invert of 0100)– -3 + -4 = 0111 + 1 = 1000 (invert of 0111 (-7))

How good is it?• 16 bits not very long: misses how many errors?

– 1 in 216, or 1 in 64K errors• Checksum detects all 1-bit errors• But not all 2-bit errors

– E.g., increment word ending in 0, decrement one ending in 1

• Checksum also optional in UDP– All 0s means no checksums calculated– If checksum word gets wiped to 0 as part of error,

bad news

From rfc791 (IP)

“This is a simple to compute checksum and experimental evidence indicates it is adequate,

but it is provisional and may be replaced by a CRC procedure, depending on further

experience.”

Cyclic Redundancy Check

• A branch of finite fields

• Goal: maximize protection, minimize bits

• High-level idea:– Represent an n+1-bit message with an n degree polynomial

M(x)

– Each bit is one coefficient– E.g., message 10101001 -> m(x) = x7 + x5+ x3 + 1– E.g., 11111111-> m(x) = x8+x7 +x6+ x5+x4 +x3+x2+x1 + 1

CRC• Checking CRC is easy

– Reduce message by C(x), make sure remainder is 0

An example

• 8-bit msg: 10011010• Divisor (3bit CRC):101• Calculating Checksum

– Select a divisor polynomial C(x), degree k

– Let n(x) = m(x)xk (add k 0’s to m)

– Compute r(x) = n(x) mod C(x)

– New P(x) = n(x) – r(x)

• Checking the Checksum– P(x) mod C(x) = 0

C(x) N(x)

K-bit CRC

Add k 0’sOriginal MsgM(x)

n(x)

Why is this good?• Suppose you send m(x), recipient gets m’(x)

– E(x) = m’(x) – m(x) (all the incorrect bits)– If CRC passes, C(x) divides m’(x)– Therefore, C(x) must divide E(x)

• Choose C(x) that doesn’t divide any common errors!– All single-bit errors caught if xk, x0 coefficients in C(x) are 1– All 2-bit errors caught if at least 3 terms in C(x)– Any odd number of errors if last two terms (x + 1)– Any error burst less than length k caught

Common CRC Polynomials

• Polynomials not trivial to find– Some studies used (almost) exhaustive search

• CRC-8: x8 + x2 + x1 + 1• CRC-16: x16 + x15 + x2 + 1• CRC-32: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 +

x8 + x7 + x5 + x4 + x2 + x1 + 1• CRC easily computable in hardware

Why is this good?

• Easy to Implement in Hardware– All routers must implement this

• Calculating Checksum– Select a divisor polynomial C(x),

degree k– Let n(x) = m(x)xk (add k 0’s to m)– K-bit shift registers– Compute r(x) = n(x) mod C(x)– Mod is XOR– New m(x) = n(x) – r(x)– Subtraction is also XOR

An alternative for reliability• Erasure coding

– Assume you can detect errors– Code is designed to tolerate entire missing frames

• Collisions, noise, drops because of bit errors

– Forward error correction• Examples: Reed-Solomon codes, LT Codes, Raptor

Codes• Property:

– From K source frames, produce B > K encoded frames– Receiver can reconstruct source with any K’ frames, with

K’ slightly larger than K– Some codes can make B as large as needed, on the fly

Trade-Off: Efficiency Versus Reliability

No Codes

FEC

Parity

2d-ParityXOR

IP-Checkum

Today’s Lecture• Recap last class

• Error detection code– Parity– Check-Sum– Error-Correcting-Codes

• Error correcting code– Sophisticated code that can correct errors

• Multiple Access Link– Ethernet– Token ring– 802.11 (WiFi)– Note: understand the concepts

Media Access Control• Control access to shared physical medium

– E.g., who can talk when?– If everyone talks at once, no one hears anything– Job of the Link Layer

• Two conflicting goals– Maximize utilization when one node sending– Approach 1/N allocation when N nodes sending

Different Approaches• Partitioned Access

– Time Division Multiple Access (TDMA)– Frequency Division Multiple Access (FDMA)– Code Division Multiple Access (CDMA)

• Random Access– ALOHA/ Slotted ALOHA– Carrier Sense Multiple Access / Collision Detection

(CSMA/CD)– Carrier Sense Multiple Access / Collision Avoidance

(CSMA/CA)– RTS/CTS (Request to Send/Clear to Send)– Token-based

Case Study: Ethernet (802.3)• Dominant wired LAN technology

– 10BASE2, 10BASE5 (Vampire Taps)– 10BASET, 100BASE-TX, 1000BASE-T, 10GBASE-

T,…• Both Physical and Link Layer specification• CSMA/CD

– Carrier Sense / Multiple Access / Collision Detection

• Frame Format (Manchester Encoding):

Ethernet Addressing

• Globally unique, 48-bit unicast address per adapter– Example: 00:1c:43:00:3d:09 (Samsung adapter)– 24 msb: organization– http://standards.ieee.org/develop/regauth/oui/ou

i.txt• Broadcast address: all 1s• Multicast address: first bit 1• Adapter can work in promiscuous mode

Ethernet MAC: CSMA/CD• Problem: shared medium

– 10Mbps: 2500m, with 4 repeaters at 500m• Transmit algorithm

– If line is idle, transmit immediately– Upper bound message size of 1500 bytes– Must wait 9.6μs (96-bit time) between back to back

frames• (Old limit) To give time to switch from tx to rx mode

– If line is busy: wait until idle and transmit immediately

Handling Collisions• Collision detection (10Base2 Ethernet)

– Uses Manchester encoding. Why does that help?– Constant average voltage unless multiple

transmitters• If collision

– Jam for 32 bits, then stop transmitting frame• Collision detection constrains protocol

– Imposes min. packet size (64 bytes or 512 bits)– Imposes maximum network diameter (2500m)– Must ensure transmission time ≥ 2x propagation

delay (why?)

Collision Detection

Me you

Check to see If any one is tx

Check to see If any one is tx

Detects collision

Doesn’t detectcollisions

Collision Detection

Me you

Check to see If any one is tx

Check to see If any one is tx

Detects collision

detectcollisions

When to transmit again?

• Delay and try again: exponential backoff• nth time: k × 51.2μs, for k = U{0..2min(n,10)-1}

– 1st time: 0 or 51.2μs– 2nd time: 0, 51.2, 102.4, or 153.6μs

• Give up after several times (usually 16)

Capture Effect

• Exponential backoff leads to self-adaptive use of channel

• A and B are trying to transmit, and collide• Both will back off either 0 or 51.2μs• Say A wins.• Next time, collide again.

– A will wait between 0 or 1 slots– B will wait between 0, 1, 2, or 3 slots

• …

Ethernet experience

• 30% utilization is heavy• Most Ethernets are not light loaded• Very successful

– Easy to maintain– Price: does not require a switch which used to be

expensive

Wireless links

Most common Asymmetric: base station and client node

Point-to-multipoint Radio waves can be received simultaneously

by many devices

Wireless access control

• Can’t use Ethernet protocol– A node on an Ethernet receives every other node’s

transmissions– A node on an 802.11 network may be too far from

certain other nodes to receive their transmissions (and vice versa)

– Problems: hiddlen terminal & exposed terminal

Wireless access control

– Hidden terminal• A and C can’t hear each other’s collision at B

– Exposed terminal• B can send to A; C can send to D• C’s transmission to D will not interfere with A’s ability

to receive from B

802.11 (WiFi) Multiple access with collision avoidance

• Sender and receiver exchange control frames– Sender receiver: Request to send (RTS)

• Specifies the length of frame– Receiver sender: Clear to send (CTS)

• Echoes length of frame– Sender receiver: frame– Receiver sender: ack– Other nodes can send after hearing ACK

• Node sees CTS– Too close to receiver, can’t transmit– Addressing hidden terminals

• Node only sees RTS– Okay to transmit– Addressing exposed terminals

MACA – Multiple Access Collision Avoidance

• Use of additional control frames– Sender asks receiver whether it is able to receive a

transmission - Request to Send (RTS)– Receiver agrees, sends out a Clear to Send (CTS)– Sender sends, receiver Acknowledgements (ACKs)

A

B

C

RTS

CTS ACK

DATA

time

B

CA

1 2

3

4

Detect Collision

Find Transmission Complete

Exposed Terminal

MACA – continued• When a node hears an RTS from a

neighboring node, but not the corresponding CTS, that node can deduce that it is an exposed terminal and is permitted to transmit to other neighboring nodes.

A D

B C

RTS

CTS

DATA

C

A

time

B

D

RTS

CTS

t1 t2 t3 t4 t5 t6

DATA

1

2

3 4

5

6

How to resolve collision

• Two or more nodes detect an idle link and try to transmit an RTS frame at the same time..

• Sender can’t do collision detection– Single antenna can’t send and receive at the same

time

• If no CTS after a period of time, then RTS collide

• Exponential backoff to retransmit

Summary

• Error Detection and Correction– FEC– Simple-XOR-FEC (Parity Bit)– XOR-error-correcting codes– IP-Checksum

• Multiple access links– Ethernet– 802.11 (WiFi)– Note: understand the concepts