67
CYC & WLB A True Story of Tanenbaum’s Protocol Simulator

A True Story of Tanenbaum's Protocol Simulator

  • Upload
    onesuper

  • View
    1.860

  • Download
    10

Embed Size (px)

DESCRIPTION

This presentation is about correcting a awful mistake in the program of Chapter 3, Computer Networks 4e(Pearson).

Citation preview

Page 1: A True Story of Tanenbaum's Protocol Simulator

CYC & WLB

A True Story of Tanenbaum’s Protocol Simulator

Page 2: A True Story of Tanenbaum's Protocol Simulator

协议回顾 (){

发现问题(){

模拟器实现( ) {

问题的解决() {

移植到XP(){

神秘人物(){

性能分析(){

其它问题(){

概要 Outline

东有谭浩强,西有谭那姆 一个肾的男人你伤不起

Page 3: A True Story of Tanenbaum's Protocol Simulator

协议回顾 Review

——温故而知新,可以为师矣。 Protocol Simulator

Page 4: A True Story of Tanenbaum's Protocol Simulator

协议回顾 Review

——东有谭浩强,西有谭那姆。 Protocol Simulator

Page 5: A True Story of Tanenbaum's Protocol Simulator

实现 双工

实现分帧

实现 错控

实现 流控

捎带 确认

窗口 大小

乱序 接受

发送方 计时器

辅助 计时器

P1 无限制单工

单 √ × × × × × × ×

P2 单工停等

单/半双 √ × √ × × × × ×

P3 有噪声单工

单/半双 √ √ √ × × × √ ×

P4 1位窗口

双/半双 √ √ √ √ 1 × √ ×

P5 回退n帧

双/半双 √ √ √ √ 7* × √ ×

P6 选择重传

双/半双 √ √ √ √ 4* √ √ √

协议回顾 Review

*这里按书上的3bit表示 Protocol Simulator

Page 6: A True Story of Tanenbaum's Protocol Simulator

实现 双工

实现 错控

实现 流控

捎带 确认

窗口 大小

乱序 接受

发送方 计时器

辅助 计时器

P1 无限制单工

单 × × × × × × ×

P2 单工停等

单/半双 × √ × × × × ×

P3 有噪声单工

单/半双 √ √ × × × √ ×

P4 1位窗口

双/半双 √ √ √ 1 × √ ×

P5 回退n帧

双/半双 √ √ √ 7* × √ ×

P6 选择重传

双/半双 √ √ √ 4* √ √ √

协议回顾 Review

*这里按书上的3bit表示 Protocol Simulator

Q:这里实现的时候为什么是半双工?

Page 7: A True Story of Tanenbaum's Protocol Simulator

协议回顾 Review

——How to play God? Protocol Simulator

fork()

准并行 quasi-parallel → 半双工 half -duplex

Page 8: A True Story of Tanenbaum's Protocol Simulator

Protocol Simulator

发现问题 Observation

Page 9: A True Story of Tanenbaum's Protocol Simulator

发现问题 Observation

——WHY so many warnings? 发现问题/观察

这儿多Warning!肿么办?

Page 10: A True Story of Tanenbaum's Protocol Simulator

Q:WHY deadlock? Q:WHY not p1?

主要参数:超时滴答数/丢帧率/错帧率

发现问题 Observation

P2:无错信道 error-free channel & 单工停等 stop and wait

Input:

Output:

Page 11: A True Story of Tanenbaum's Protocol Simulator

——人非圣贤,孰能无过 发现问题/生成假设

发现问题 Hypothesis Generation

坑 爹 呢

Page 12: A True Story of Tanenbaum's Protocol Simulator

——人非圣贤,孰能无过。 发现问题/生成假设

发现问题 Hypothesis Generation

1个“?”知道了,引发出更多的“?”

协议坑爹呢?

老谭坑爹呢?

老张坑爹呢?

……

坑 爹 呢

Page 13: A True Story of Tanenbaum's Protocol Simulator

——板凳坐得十年冷,文章不写半句空。 发现问题/生成假设

模拟器实现 Protocol Simulator

Page 14: A True Story of Tanenbaum's Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

模拟器实现 Protocol Simulator

老谭用迚程(process)来模拟通信的实体

Page 15: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

Page 16: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 发现问题/实验验证

Page 17: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 发现问题/实验验证

Page 18: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 发现问题/实验验证

Page 19: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 发现问题/实验验证

Page 20: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 ——步随流水觅溪源 解决问题/实验验证

Page 21: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

Page 22: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

Page 23: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 ——步随流水觅溪源 解决问题/实验验证

Page 24: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

这种主-从结构一定程度上保证了程序的安全性

——步随流水觅溪源 解决问题/实验验证

Page 25: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

用迚程来模拟有很多好处

M1、M2就像两个peer独立地运行在计算机上

可以利用IPC(迚程间通信)来模拟通信

——步随流水觅溪源 解决问题/实验验证

Page 26: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 发现问题/实验验证

迚程间通信有很多方法,老谭用了管道(pipe)

Page 27: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

Q:什么是管道?

——步随流水觅溪源 解决问题/实验验证

Page 28: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

Q:什么是管道?

在Unix中“一切皆文件”,因此管道也是一个文件

——步随流水觅溪源 解决问题/实验验证

Page 29: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源

管道在生活中应用:留言板

——步随流水觅溪源 解决问题/实验验证

Page 30: A True Story of Tanenbaum's Protocol Simulator

A想和B讲话,就向B的留言板写一个字符串

Page 31: A True Story of Tanenbaum's Protocol Simulator

B想回复A,也要去A的留言板留言,而丌是直接在自己的留言板回复

Page 32: A True Story of Tanenbaum's Protocol Simulator

一来一去,用两个文本就实现了通信~

Page 33: A True Story of Tanenbaum's Protocol Simulator

模拟器实现 Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

Page 34: A True Story of Tanenbaum's Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

Page 35: A True Story of Tanenbaum's Protocol Simulator

解决问题 Experimental Verification

Oberservation

Hypothesis Generation

Experimental Verification

——步随流水觅溪源 解决问题/实验验证

Page 36: A True Story of Tanenbaum's Protocol Simulator

在程序员的世界里,我们又称这种方法叫

Debugging

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

Page 37: A True Story of Tanenbaum's Protocol Simulator

调试工具:GDB + Code::Blocks

——工欲善其事,必先利其器 解决问题/实验验证

解决问题 Experimental Verification

Page 38: A True Story of Tanenbaum's Protocol Simulator

难点:调试器只能跟踪父迚程,而无法迚入子迚程(通信双方)

的代码

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

Page 39: A True Story of Tanenbaum's Protocol Simulator

发现Protocol2发生死锁的原因是,receiver迚程在

wait_for_event中陷入了一个绝望的循环

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

Page 40: A True Story of Tanenbaum's Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

Page 41: A True Story of Tanenbaum's Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

猜测:M1到M2的这根管道出了问题

Page 42: A True Story of Tanenbaum's Protocol Simulator

——步随流水觅溪源 解决问题/实验验证

解决问题 Experimental Verification

老谭在Queue_frame()函数中实现了“从管道中读取帧”的功能

因为管道文件的读取方式是“阻塞读”,因此在read之前要先看一眼管

道的size,防止read一个空的管道而阻塞。

Page 43: A True Story of Tanenbaum's Protocol Simulator

——You can never tell when things will happen out of control in our life.

解决问题/实验验证

解决问题 Experimental Verification

Page 44: A True Story of Tanenbaum's Protocol Simulator

——GOOGLE,总有一个人知道你的答案 解决问题/实验验证

解决问题 Experimental Verification

英特网上一个叫rob holland的人说:

这并丌是一个bug,在Linux下,你丌能用fstat查看管道文

件大小,但在UNIX下就可以

UNIX

Linux

Page 45: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

解决问题 Experimental Verification

为了验证他的话,我们把源代码拿到了Solaris上试了试

Page 46: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

解决问题 Experimental Verification

Page 47: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

解决问题 Experimental Verification

既然无法得到管道的大小,那就直接去读

为了防止read到一个空的管道

因此还要修改管道文件的属性,改为“非阻塞读”

Page 48: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

移植到XP

Page 49: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

移植到XP

难点:Windows和Unix的接口命名习惯丌同

就像tan()和tg()虽然实现的功能相同,名字却丌一样

Page 50: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

移植到XP

丌用改代码也能移植

就是在Windows下使用UNIX的API

主要用到Cygwin这个工具

Page 51: A True Story of Tanenbaum's Protocol Simulator

解决问题/实验验证

移植到XP

Cygwin的本质是一个叫cygwin.dll的动态链接库

它封装了所有win32中没有的Unix风格系统调用(如fork、signal)。

Page 52: A True Story of Tanenbaum's Protocol Simulator

神秘人物

Page 54: A True Story of Tanenbaum's Protocol Simulator

MIT

神秘人物

老戴 David Wetherall University of Washington

Page 55: A True Story of Tanenbaum's Protocol Simulator

Reply from David Wetherall

神秘人物

Page 56: A True Story of Tanenbaum's Protocol Simulator

你们是正确的,这个程序运行在现代Linux系统下的时候确实有BUG。

你们所发现的这个问题并且对这个问题特征的描述也是准确的(令我印象非常深刻!)

由于这个BUG,我们正在修改原来的程序,并且丌久之后会将新程序公布在官网上。

同时,附件里是我修正的程序源代码及其可执行文件。

你们可以用这个新程序来替换原来的程序。

我希望这些对你们有帮助,感谢你们的耐心。

加油,

老戴

Reply from David Wetherall

神秘人物

中文大意

Page 57: A True Story of Tanenbaum's Protocol Simulator

Throw a sprat to catch a whale.

性能分析

Page 58: A True Story of Tanenbaum's Protocol Simulator

Throw a sprat to catch a whale.

性能分析

1. For one or more selected protocols, make a study of protocol performance,

measured in payloads delivered per second, as a function of the checksum

error rate, lost packet rate, and timeout interval. For example, provide

graphs showing payloads/sec as a function of timeout interval, for

various error rates. What can you conclude?

Efficienciy = F ( timeout _interval , loss_rate , err_rate )

Page 59: A True Story of Tanenbaum's Protocol Simulator

性能分析

(3,99) , (0,99) , (0,99)

10^6

Page 60: A True Story of Tanenbaum's Protocol Simulator

Figure P5-234-234

性能分析

Page 61: A True Story of Tanenbaum's Protocol Simulator

Figure P5-234-234 Q: 990/1024

性能分析

Page 62: A True Story of Tanenbaum's Protocol Simulator

Figure P5-24-234 & Figure P5-34-234

性能分析

Page 63: A True Story of Tanenbaum's Protocol Simulator

Figure P5-234-234

性能分析

Page 64: A True Story of Tanenbaum's Protocol Simulator

Figure P5-14-124 & Figure P5-24-124

性能分析

Page 65: A True Story of Tanenbaum's Protocol Simulator

——One solved questions lead to more……

性能分析

Q:Compare the performance of protocols 5 and 6 in detail with respect to

payloads/sec and number of retransmissions for a wide variety of parameters. Under which circumstances is protocol 5 better? protocol 6?

Q: The function pick_event() has built-in priorities for events. For example, for protocol 5, frame arrivals go before timeouts. Experiment with

changing these priorities (by reordering the statements in pick_event(). What conclusions can you draw?

Q: Investigate the number of retransmitted frames as a function of the timeout interval for various parameters? Can you determine what the

optimum setting should be? Q:Presently, the simulator advances time one tick at a time. If both

processes are blocked on distant timeouts, this process goes slowly. Change the simulator to advance time more quickly when both processes

are blocked on the clock.

Q:In the simulator at present, packet delivery is essentially instanteous. Change it so that delivery times are variable with a user-settable variance. How does the variance affect protocol performance?

…… ……

Page 66: A True Story of Tanenbaum's Protocol Simulator

其它问题

Q:Simulation? loss/grb? 990 / 1024

Q:WHY NOT p1?

Page 67: A True Story of Tanenbaum's Protocol Simulator

END Thanks Your Attention

}

}

}

}

}

}

}

}

}