Link Layer

2-6 Link Layer: Framing Messages

Methods for framing:

  • Byte count:

(idex) length filed + frame

next frame begin at: idex + length

Difficult to re-synchronize after framing error…

  • Byte stuffing (use in practice):

use a special flag byte value that means start / end of frame

ESC to escape code #转义字符

FLAG header … ESC … FLAG … tailer FLAG

=> FLAG header … ESC ESC … ESC FLAG … tailer FLAG

  • Bit stuffing

(slightly less overhead, but more complicate)

five one one zero

2-7 Link Example: PPP over SONET

  • PPP: Point to Point Protocol

PPP is used to carry the IP packets over SONET optical links.

using byte stuffing: FLAG = 0x7E (01111110), ESC: 0x7D (01111101)

  • detail: (in practice)

you also XOR(异或) the byte which follows the escape character with 0x20 = 00100000

Method:

0x7E -> 0x7D 0x7E (01111101 01111110) – XOR 0x20 -> 0x7D 0x5E

0x7d -> 0x7d 0x7d (01111101 01111101) – XOR 0x20 -> 0x7d 0x5D

The virtue of using this scheme is that we’ve completely removed the occurrences of the FLAG character , 0x7E, from the contents of the frame.

【注】实际中,不仅在frame内部使用转移字符ESC(0x7D),而且将出现在frame中的FLAG和ESC用0x20异或,这样只有在头尾有FLAG, 而在frame中就彻底不会出现FLAG和ESC了,防止转义字符ESC本身失效导致的识别错误

hexadecimal notation ( 十六进制表示 )

2-8 Error Coding Overview

Approach-> Add Redundancy (Check Bits)

  • Copies:

send two copies, error if different:

->can’t correct

(We want to handle more errors with less overhead)

  • Using Error Codes

frame = Data bits | Check bits

类似密码本,发送一套映射规则,receiver收到frame后,用这套规则处理Data bits,看是否和 Check bits 一致

when the error be in the Check bits, it would be no use.

Also The probability to correct the code is 1/2R (which resulted by 2D / 2D+R)

  • Hamming code

-> Error Detecting and Error Correcting Codes, BSTJ, 1950

-> You and Your Research, 1986

  • Hamming Distance

The distance is the number of bit flips you need to change or it says, D + R1 to D + R2.
The Hamming Distance of a code is the minimum distance between any pair of codewords that are in the code.

【注】海明距:distance = 两段代码不同digit的位数 --> 一组编码集中任意两个码字之间最小的distance

eg. the basic hamming distance of 101 and 000 is 2, because checking every bit we can detect two filps, 1-0 0-0 1-0 .
and The Hanmming Distance: if we have {101, 000, 111} -->{101, 000} = 2, {101, 111} = 1, {000, 111} = 3, so the Hamming DIstance is 1, which is minimul of all the distances.

One of the Hamming result is:

if you want to do error detection, if you have a code whose distance is D plus 1, then it is able to detect up to D errors always.

Other Hamming result for error correction is:

For a code of distance 2d + 1, up to d errors can always be corrected by mapping to the closest codeword

  • vocabulary:

owning modest computation

patented

diving into

2-9 Error Detection

Parity Bit

D(data)+1(check bit)

Add 1 check bit that is the sum (Modulo 2) of the D bits

eg. 1001100 – code --> 1001100(1)

  • properties
DistanceDetectcorrect
210

The distance is 2 (Because if we flip one bit we can detect the wrong, but if we flip another it devaild --> the minimul )

  • Only can detect all the odd numbers of errors, not even numbers.

Checksums

sum up data in N-bit words (TCP, IP, UPD all use a 16-bit checksum)

Internet Checksums:
you sum up all of the data, 16 bits at a time. And then you negate(取反) it. So you come up with a negative sum. (with 1’s complement addition)

when it overflow, what we’re going to do is take that back and add any carryover back;

【注】把数据每16位一组对齐求和,如果结果超过16位,将溢出的高位与低位继续求和,结果取反(Complement,二进制取反)作为校验位,接收端收到和求和(同样方式:分组->求和->处理溢出->取反)应为0,否则出错

complement addition 补码加法;
complement notation: 补码记数法
1的补码计数法 简写为: 1’s comp – [add 1] --> 2的补码计数法-> 2’s comp

  • 一的补码(one’s complement) 指的是正数=原码,负数=反码
  • 二的补码(two’s complement) 指的就是通常所指的补码

>>>参考内容<<<

  • how well does it work?
DistanceDetectcorrect
210

the point is, we could make two corresponding errors, and fool this sum.

  • The larger errors:
    Random data, the probability is: 1 in 2 to the 16 (1 / 216) chance that the checksum will actually match the data.

Cyclic Redundancy Check: CRC -> [In practice]

Based on the mathematics of finite fields

Represent polynomials:
x4 + x1 + 1 --> 10011

[modular 2 addition]

Take that remainder and use it to modify the bits that are transmitted

The Standard CRC-32 is used on ethernet, wi-fi, all sorts of places.
Hammint Distance of it is 4,

Error Detection in Practice:

DetectionsLayerPotocols
CRCsLinkEthernet, 802.11, ADSL, Cable
ChecksumInternetIP, TCP, UDP (weak)
ParityLittle used

2-10 Error Correction

Hamming Code

Uses n = 2k - k - 1

Check bit in position p is parity of positions with a p term in their values.
(such as (assume we have 3 check bit): 1=20=001, 2=21=010, 4=22=100)

Each check bit covers the data postion that has same digital “1” in binary expression. --> using it to calculate what check bit is with parity bit rules.

Example:
data: 0101 -> we need 2k - k >= 4, k = 3 check bits.

  • original:

-----------------
_ _ 0 _ 1 0 1
1 2 3 4 5 6 7
-----------------

  • code: calculate with parity bit rules by group to get all check bits;

p1(001) = p3(011) + p5(101) + p7(111) = 0 + 1 + 1 = 0
p2(010) = p3(011) + p6(110) + p7(111) = 0 + 0 + 1 = 1
p4(100) = p5(101) + p6(110) + p7(111) = 1 + 0 + 1 = 0

=>

-----------------
0 1 0 0 1 0 1
1 2 3 4 5 6 7
-----------------

  • decode: calculate with parity bit rules by group (including check bits)

if the original data become (with error) : 01001(1)1
-----------------
0 1 0 0 1 1 1
1 2 3 4 5 6 7
-----------------

p1 = p1 + p3 + p5 + p7 = 0 + 0 + 1 + 1 = 0
p2 = p2 + p3 + p6 + p7 = 1 + 0 + 1 + 1 = 1
p4 = p4 + p5 + p6 + p7 = 0 + 1 + 1 + 1 = 1

Syndrome = 110 -> p6 is worng
Data = 0111 --correct–> 0101

Other Error Correction Codes -> [in practice]

convolutional codes: They tend to take a stream of data and they output a mixed bits in all positions. This mixing process makes the output a bit less fragile. --> decoded with Viterbi algorithm

LDPC: Low density parity check code , are based on the mathematics of sparse matrices and they’re decoded iteratively using what’s called a belief propagation algorithm.

Detection vs. Correction

Two Module:
Random error:
Burst error (some like a sequence of errors):

=>detection needs less overheads.

  • Summary:

detection is usually more efficient when errors aren’t the expected case (random errors), so sending along error correcting code information would just signal bits which are wasted, or when errors are large when they do occur, because in that case you would need an awful lot of error correcting code bits.

correction is most useful when the errors are expected, ther’re also useful when no time to do a retransmission, because you need information to look at quickly (real time)

3-1 Overview of the Link Layer

  • Framing: the ability to deliver the start and end of messages --> a complete unit of information, called frames.

  • Error detection/ correction

  • Retransmissions: handling loss, which is quite common in link layer.

  • Multiple Access: a manage schema

  • Switching: Modern Ethernet

3-2 Retransmissions

Reliability: The higher layer is mostly concerned with correctness and usually recovery actions rather than performance.

ARQ(Automatic Repeat reQuest)

Detect errors and retransmit frame:
-> Wi-fi、TCP

Sender --Frame–> Receiver
Receiver --ACK–> Sender
Sender --【automaticaly】resend frame (Timeout: Not receive ACK in time)–> Receiver

  • Two Problems:
  1. Timeout
  2. Duplicate: ACK loss --> Stop-and-Wait

Stop and Wait

  1. Sequence number
  2. Flag 0 / 1: To distinguish current frame from next
  • Limitation:
    Rate ceil: Frame/sec

Sliding Window

Twice the delay = RTT

3-3 Multiplexing

  • Time Division Multiplexing (TDM)
  • Frequency DIvision Multiplexing (FDM) --> Same Bandwidth

–> Statistical Multiplexing

3-4 Randomized Multiple Access

  • How to share signle link?

Multiplexing scheme: TDM,FDM (divide up the link in terms of either time or frequency) -->They’re well suited for continuous traffic, but not very well suited for computer networking where the traffic is brusting

MAC (Multiple Access control)

The basis of classic Ethernet

AlOHA Protocol

When there is a collision (no ACK received) then wait a random time and resend

–> Collision -> not efficient under high load
==》Improvement: Divide time into slots

CSMA (Carrier Sense Multiple Access)

ALOHA --Node listen for activity–> CSMA (do easy in wire [Eternet], not wireless)

CSMA is a good defense against collisions only when this bandwidth delay product is small (Much less than one packet).

CSMA/CD (with Collision Detection)

How every node is going to realize that a collision has happened.
–> By imposing a minimum frame time, we require nodes to send frames (At least minimum frame, which takes at least 2*RTT seconds)

The minimum frame for an Ethernet is 64 bytes. (if smaller ,you shoud pedded out)

There is a window of time (propagation delay of the medium) during which a node can detect a collision.

  • When detected a collision, how long shoud wait?
  1. non-persistent: if busy, it give up listening.
  2. 1-presistent: All Other nodes wait for someone finished --> They all collide then.
  3. p-presistent: N queued senders, send probability = 1 / N (But in distributed system, we don’t know N --> BEB (Binary Exponential Backoff))

BEB (Binary Exponential Backoff)

doubling the interval for which waiting over with each successive collision.

The solution that Classic Ethernet uses is 1-presistent CSMA/CD with BEB

Ethernet Frame Format

Modern Ethernet

Modern Ethernet doesn’t use Multiple Access Control protocol --> It’s really based on switches.

3-5 Wireless Multiple Access

Wi-fi

Two Issuses:

Different coverage areas.

  • Hidden Terminals:
    A -> B <- C D --> A and C are hidden terminals
    B canNOT seperate the message from A and C simultaneously

  • Exposed Terminals:
    A <- B C -> D–> B and C and hear each other, but can send messages at same time

Inability to detect collisions

-> In wire link: we can engineer the relative strengths of the transmission and reception signals.

MACA (Multiple Access with Collision Avoidance)

  • to solve Hidden terminals
1. [A] --RTS--> [B] [C] [D]
2. [A] <--CTS-- [B] --CTS--> [C] [D]
3. C slient until A over (CTS with the fram lenth --- time)
  • to solve Exposed Terminals
1. [A] <--RTS-- [B] <--RTS--> [C] --RTS--> [D]
2. [A] --CTS--> [B]           [C] <--CTS-- [D]
3. B and C all ok

802.11 (WiFi)

all device to connect The Internet through Access Point (AP).

  • in Link Layer:

CSMA/CA (with Collision Avoidance)

  • RTS / CTS --> not tend to be used very much in practice
  • Sender avoids collisions by inserting small random gaps --> in practice
  • ACK / ARQ

3-6 Contention Free Multiple

A approach to multiple access: Based on turns, not randomization

–> randomization: only perform good in low load

–> The order means which nodes get a chance to send --> Token Ring、Addresses、…

Token Ring

Token rotate " permission to send" to each node in turn;

  • disadvantages:
  1. Token errors --> generate a new token …

3-7 LAN Switches

switched is now widely used in practice --> Mordern Ethernet

Hub: one host sent, the message was received on the wire, at all of the other hosts. --> Two host couldn’t sent at the same time.

Switch: has a buffering to solve N hosts sent messages to one host.

The Algorithm

Backward Learning

use port:
step 1: build up a table, fill the table
step 2: update this table dynamically

Learing with Multiple Switches

Broadcast

3-7 Switch Spanning Tree Algorithm

Loop: "You might think we could just look at the content, but you don’t know whether this is a second message from A or not. --> broadcast storm

–> A spanning tree: is a simply a subset of links of the topology which is a tree.

  • Algorithm:

step 1: select a root (switch with lowest address)
step 2: grow a tree (choice the node with shortest path to root one by one, if there is a tie choice the lowest address one)
step 3: turn off other ports

  • Details:

Each round, every node broadcast the messages, such as: (C, A, 2) which means “I’m switch C, the root is A, it’s 2 hops away from A”, and update each other’s table continuely, until here is a spanning tree.

==>All the frame only transmit on the spanning tree’s edge, even if there is a better way to through. --> Network Layer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值