1 多点访问和生成树 罗忠文 内容取自 ucb 的教程 [email protected]

58
1 多多多多多多多多 罗罗罗 http://xgxy.cug.edu.cn/rjgcx/lzw 罗罗罗罗 UCB 罗罗罗 [email protected]

Upload: baldwin-pierce

Post on 25-Dec-2015

295 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

1

多点访问和生成树

罗忠文http://xgxy.cug.edu.cn/rjgcx/lzw

内容取自 UCB 的教程

[email protected]

Page 2: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Upcoming lectures

•Security

•Wireless

•review– and then finals….

2

Page 3: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Today

•Study two algorithms that are dying out– But both important conceptually!

•Multiple Access in wired media (extinct)

•Spanning Tree (endangered algorithms list)

3

Page 4: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

4

Point-to-Point vs. Broadcast Media•Point-to-point: dedicated pairwise communication– Long-distance fiber link– Point-to-point link between Ethernet switch and

host

•Broadcast: shared wire or medium– Traditional Ethernet– 802.11 wireless LAN

Page 5: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

5

Multiple Access Algorithm

•Single shared broadcast channel– Must avoid having multiple nodes speaking at

once– Otherwise, collisions lead to garbled data– Need distributed algorithm for sharing the

channel– Algorithm determines which node can transmit

•Classes of techniques– Channel partitioning: divide channel into pieces– Taking turns: scheme for trading off who gets to

transmit– Random access: allow collisions, and then recover

Page 6: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

6

Channel Partitioning: TDMA

TDMA: Time Division Multiple Access

•Access to channel in "rounds" – Each station gets fixed length slot in each round

•Time-slot length is packet transmission time – Unused slots go idle

•Example: 6-station LAN with slots 0, 3, and 4Rounds

0 1 2 3 4 5 0 1 2 3 4 5Slots =

Page 7: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

7

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

frequ

ency

bands time

FDM cable

Page 8: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

8

“Taking Turns” MAC protocols

Polling

•Master node “invites” slave nodes to transmit in turn

•Concerns:– Polling overhead – Latency– Single point of failure

(master)

Token passing

• Control token passed from one node to next sequentially

• Node must have token to send

• Concerns:– Token overhead – Latency– At mercy of any node

master

slaves

poll

data

data

Page 9: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

None of these are the “Internet way”…•Why not?

•What’s wrong with– TDMA– FDMA– Polling– Token passing

•Turn to random access– Optimize for the common case (no collision)– Don’t avoid collisions, just recover from them….

o Sound familiar?9

Page 10: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

10

Random Access MAC Protocols

Page 11: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

11

Random Access MAC Protocols

•When node has packet to send– Transmit at full channel data rate– No a priori coordination among nodes

•Two or more transmitting nodes collision– Data lost

•Random access MAC protocol specifies: – How to detect collisions– How to recover from collisions

•Examples – ALOHA and Slotted ALOHA– CSMA, CSMA/CD, CSMA/CA (wireless, covered

later)

Page 12: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

12

Key Ideas of Random Access

•Carrier sense– Listen before speaking, and don’t interrupt– Checking if someone else is already sending data– … and waiting till the other node is done

•Collision detection– 如果其他人同时开始交谈 , 停止– Realizing when two nodes are transmitting at once– …by detecting that the data on the wire is garbled

•Randomness– Don’t start talking again right away– Waiting for a random time before trying again

Page 13: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

13

Where it all Started: AlohaNet

•Norm Abramson left Stanford to surf

•Set up first data communication system for Hawaiian islands

•Hub at U. Hawaii, Oahu

•Had two radio channels:– Random access:

o Sites sending data– Broadcast:

o Hub rebroadcasting data

Page 14: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Aloha Signaling

•Two channels: random access, broadcast

•Sites send packets to hub (random)– If received, hub sends ACK (random)– If not received (collision), site resends

•Hub sends packets to all sites (broadcast)– Sites can receive even if they are also sending

•Questions:– When do you resend? Resend with probability p– How does this perform? Need a clean model….14

Page 15: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

15

Slotted ALOHA

Assumptions

• All frames same size

• Time divided into equal slots (time to transmit a frame)

• Nodes are synchronized

• Nodes begin to transmit frames only at start of slots

• If multiple nodes transmit, nodes detect collision

Operation

• When node gets fresh data, transmits in next slot

• No collision: success!

• Collision: node retransmits with probability p until success

Page 16: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

16

Slot-by-Slot Example

Page 17: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

17

Efficiency of Slotted Aloha

Page 18: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

18

Pros and Cons of Slotted Aloha

Pros

• Single active node can continuously transmit at full rate of channel

• Highly decentralized: only need slot synchronization

• Simple

Cons

• Wasted slots:– Idle– Collisions

• Collisions consume entire slot

• Clock synchronization

Page 19: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

19

改进 Slotted Aloha

•Fewer wasted slots– 需要减少冲突和空 slots

•冲突时不浪费整个 slots– 需要减少检测冲突的时间

•避免同步的需求– 同步很难达到

Page 20: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

20

CSMA (Carrier Sense Multiple Access)

•CSMA: 发送前先监听– 感知到通道空闲 : 发送整个帧– 感知到通道忙 , 延后发送

•Human analogy: don’t interrupt others!

•消除了所有冲突吗 ?– No, because of nonzero propagation delay

Page 21: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

21

CSMA冲突传播延时 : 两个结点可能在传送前没听到对方讲话 .

Would slots hurt or help?

CSMA reduces but does not eliminate collisions

Biggest remaining problem?

Collisions still take full slot!How do you fix that?

Page 22: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

22

CSMA/CD (Collision Detection)

•CSMA/CD: carrier sensing, deferral as in CSMA– Collisions detected within short time– Colliding transmissions aborted, reducing wastage

•Collision detection easy in wired LANs:– Compare transmitted, received signals

•无线局域网中,冲突检测困难 :– 传送时接收端关闭 ( 当然 , 也可能不 )– 非完美广播 ( 有限范围 ) 因此局部冲突– 导致使用 collision avoidance ( 后面讲 )

Page 23: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

23

CSMA/CD Collision Detection

B 和 D 可知冲突发生 .

注意 : 此能工作 , 需要限制最小帧尺寸和最大距离 . 为什么 ?

Page 24: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

24

CSMA/CD Collision Detection

B 和 D 可知冲突发生 .

注意 : 此能工作 , 需要限制最小帧尺寸和最大距离 . 为什么 ?

Page 25: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

25

Limits on CSMA/CD Network Length

•Latency depends on physical length of link– 包从一端到另一端的传播时间

• Suppose A sends a packet at time t– And B sees an idle line at a time just before t+d– … so B happily starts transmitting a packet

•B 检测到冲突 , 并发送 jamming signal– But A can’t see collision until t+2d

latency dA B

Page 26: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

26

Limits on CSMA/CD Network Length

•A 需要等待 2d 时长来检测冲突– So, A should keep transmitting during this period– … and keep an eye out for a possible collision

•引入限制 . 如 , 对于 10Mbps Ethernet:– Maximum length of the wire: 2,500 meters– Minimum length of a frame: 512 bits (64 bytes)

o 512 bits = 51.2 sec (at 10 Mbit/sec)o For light in vacuum, 51.2 sec ≈ 15,000 meters

vs. 5,000 meters “round trip” to wait for collision– What about 10Gbps Ethernet?

latency dA B

Page 27: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

27

Performance of CSMA/CD•Time wasted in collisions

– Proportional to distance d

•Time spend transmitting a packet– Packet length p divided by bandwidth b

•效率的粗略估计 (K 是某个常数 )

•Note:– For large packets, small distances, E ~ 1– As bandwidth increases, E decreases– That is why high-speed LANs are all switched

Page 28: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

28

Ethernet Multiple Access

首个广泛部署的多点访问

Page 29: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

29

Benefits of Ethernet

•Easy to administer and maintain

•Inexpensive

•Increasingly higher speed

•Evolvable!

Page 30: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Ethernet的演化•Changed everything except the frame format

– From single coaxial cable to hub-based star– From shared media to switches– From electrical signaling to optical

•Lesson #1– The right interface can accommodate many

changes – Implementation is hidden behind interface

•Lesson #2– Really hard to displace the dominant technology– Slight performance improvements are not enough

30

Page 31: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

31

Ethernet: CSMA/CD Protocol

•Carrier sense: wait for link to be idle

•Collision detection: 传输时监听– No collision: transmission is complete– Collision: abort transmission & send jam signal

•Random access: binary exponential back-off– 冲突后 , 在重发前等待随机时间– 在第 m 次冲突后 , 从 {0, …, 2m-1} 中随机选择 K– … 重发前,等待 K*512 位时间

o Using min packet size as “slot”o 如果当发送时,检测到有传输 , 等到传输结束 (CSMA)

Page 32: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Binary Exponential Backoff (BEB)•Think of time as divided in slots

•After each collision, pick a slot randomly within next 2m slots– Where m is the number of collisions since last

successful transmission

•Questions:– Why backoff (退避) ? – Why random? – Why 2m?– Why not listen while waiting?

32

Page 33: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Behavior of BEB Under Light LoadLook at collisions between two nodes

•首次冲突 : pick one of the next two slots– Chance of success after first collision: 50%– Average delay 1.5 slots

•第二次冲突 : pick one of the next four slots– Chance of success after second collision: 75%– Average delay 2.5 slots

•In general: after mth collision– Chance of success: 1-2-m

– Average delay (in slots): ½ + 2(m-1)

33

Page 34: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

BEB: Theory vs Reality

In theory, there is no difference between theory and practice. But, in practice, there is.

34

Page 35: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

BEB Reality

•Performs well (far from optimal, but no one cares)– Large packets are ~23 times as large as minimal

slot

•Is mostly irrelevant– Almost all current ethernets are switched

35

Page 36: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

BEB Theory

•A very interesting algorithm

•Stability for finite N only proved in 1985– Ethernet 可以处理非零流量负载,而不会崩溃

•对无限 N ,所有 backoff 算法不稳定 (1985)– Poisson model: infinite user pool, total demand is

finite

•没有实用兴趣 , 但给出了重要的洞察力( insight)– Multiple access should be in your “bag of tricks”36

Page 37: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Question

•Two hosts, each with infinite packets to send

•What happens under BEB?

•Throughput high or low?

•Bandwidth shared equally or not?

37

Page 38: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

The BEB Game Show!

•Starring two enthusiastic volunteers

38

Page 39: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

MAC “Channel Capture” in BEB

•Finite chance that first one to have a successful transmission will never relinquish(放弃) the channel– The other host will never send a packet

•Therefore, asymptotically channel is fully utilized and completely allocated to one host

39

Page 40: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Example

•Two hosts, each with infinite packets to send– Slot 1: collision– Slot 2: each resends with prob ½

o Assume host A sends, host B does not

– Slot 3: A and B both send (collision)– Slot 4: A sends with probability ½, B with prob. ¼

o Assume A sends, B does not

– Slot 5: A definitely sends, B sends with prob. ¼o Assume collision

– Slot 6: A 以概率 ½ 发送 , B with prob. 1/8

•结论 : 如果 A 先通过 , the prob. of B sending successfully halves with each collision 40

Page 41: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Another Question

•Hosts now have large but finite # packets to send

•What happens under BEB?

•Throughput high or low?

41

Page 42: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Answer

•Efficiency less than one, no matter how many packets

•Time you wait for loser to start is proportion to time winner was sending….

42

Page 43: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Different Backoff Functions

•Exponential: backoff ~ ai

– Channel capture?– Efficiency?

•Superlinear polynomial: backoff ~ ip p>1– Channel capture?– Efficiency?

•Sublinear polynomial: backoff ~ ip p≤1– Channel capture?– Efficiency?

43

Page 44: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Different Backoff Functions

•Exponential: backoff ~ ai

– Channel capture (loser might not send until winner idle)

– 效率小于 1 (time wasted waiting for loser to start)

•Superlinear polynomial: backoff ~ ip p>1– Channel capture– Efficiency is 1 (for any finite # of hosts N)

•Sublinear polynomial: backoff ~ ip p≤1– No channel capture (loser not shut out)

– 效率小于 1 (and goes to zero for large N)o Time wasted resolving collisions 44

Page 45: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

Why Do I Care?

•Why do you like music?

•It makes me happy….

•But also, until this work was done, no one knew about capture, or what properties of the backoff enabled it.

•You don’t understand something until you’ve played with it. Just getting it to work isn’t enough.

45

Page 46: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

46

Hooking Together Multiple Ethernets

Page 47: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

47

Shuttling Data at Different Layers•Different devices switch different things

– Physical layer: electrical signals (hubs)– Link layer: frames (switches)– Network layer: packets (routers)

Application gatewayTransport gateway

Router

Switch

Hub

Frameheader

Packetheader

TCPheader

Userdata

Page 48: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

48

Switches Enable Concurrent Comm.•Host A can talk to C, while B talks to D

switch

A

B

C

D

• Completely avoids collisions (if hosts directly attached)• No need for carrier sense, collision detection, and so on• Change in nature of multiple access, but same framing

Page 49: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

49

Self Learning

•Maps destination MAC to outgoing interface

•Construct switch table automatically

•Floods when does have entry in table

switch

A

B

C

D

Page 50: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

50

Flooding Can Lead to Loops•Flooding can lead to forwarding loops

– E.g., if the network contains a cycle of switches– “Broadcast storm”

Page 51: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

51

Solution: Spanning Trees

•Ensure the forwarding topology has no loops– Avoid using some of the links when flooding– … to prevent loop from forming

•Spanning tree – 子图 包括所有结点,但无环– 不在生成树中的链路不转发帧

Graph Has Cycles!

Graph Has No Cycles!

Page 52: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

You: Design a Spanning Tree Algorithm•Distributed

•No global information

•Neighbors can exchange information

•Must adapt when failures occur– But don’t worry about that on first try…

52

Page 53: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

What Do We Know?

•Shortest paths to (or from) a node form a tree

•So, algorithm has two aspects :– Pick a root– Compute shortest paths to it

•Only keep the links on shortest-path

53

Page 54: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

54

Constructing a Spanning Tree

•Switches need to elect a root– The switch w/ smallest identifier (MAC addr)

•Each switch determines if each interface is on the shortest path from the root– Excludes it from the tree if not

•Messages (Y, d, X)– From node X– Proposing Y as the root– And the distance is d

root

One hop

Three hops

Page 55: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

55

Steps in Spanning Tree Algorithm•开始时 , 每个交换机建议自己是 root

– Switch sends a message out every interface– … proposing itself as the root with distance 0– Example: switch X announces (X, 0, X)

•Switches update their view of the root– 当从 Z 处接收到消息 (Y, d, Z), 检查 Y 的 id– 如果新 id 更小 , 将该交换机看成是 root

•Switches compute their distance from the root– 把从邻居得到的距离加 1– 确定不在最短路径的接口– … 并将其从生成树中去除

•如果 root 或者到根的最短距离改变 , “flood” updated message (Y, d+1, X)

Page 56: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

56

Example From Switch #4’s Viewpoint•4 号交换机认为自己是 root

– 发送 (4, 0, 4) 消息到 2 和 7

•拘捕 , switch #4 hears from #2– 从 2 接收到 (2, 0, 2)– … 从而认为 2 号是 root– 并认识到其到它的距离是一跳

•Then, switch #4 hears from #7– Receives (2, 1, 7) from 7– 并认识到这是更长的路径– 因此 , 更偏好自己的一跳路径– 从树中移去 4-7 链路

1

2

3

4

5

67

Page 57: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

57

Example From Switch #4’s Viewpoint•2 号交换机听到 1 号交换机

– 2 号交换机从 3 号处听到 (1, 1, 3)– 交换机 2 开始把 1 作为 root– 并发送 (1, 2, 2) 到其邻居

•交换机 4 从交换机 2 听到– 交换机 4 把 1 作为 root– 发送 (1, 3, 4) 到邻居

•交换机 4 从交换机 7 听到– 交换机 4 从 7 接收到 (1, 3, 7)– 并认识到这是更长的路径– 因此更偏好自己的三跳路径– 从树中移去 4-7 链路

1

2

3

4

5

67

Page 58: 1 多点访问和生成树 罗忠文  内容取自 UCB 的教程 24035234@qq.com

58

Robust Spanning Tree Algorithm

•Algorithm must react to failures– Failure of the root node

o Need to elect a new root, with the next lowest identifier

– Failure of other switches and linkso Need to recompute the spanning tree

•Root switch continues sending messages–周期性的公告自己是根 (1, 0, 1)– Other switches continue forwarding messages

•通过超时检测失效( soft state)– 如果没有从 root 收到信息 , 超时并声称自己是 root– 重新建立生成树的延时是主要问题– Work on rapid spanning tree algorithms…