Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 088b000

Browse files
update cs144lab
1 parent 5321e94 commit 088b000

10 files changed

Lines changed: 156 additions & 25 deletions

‎.DS_Store‎

0 Bytes
Binary file not shown.

‎Notes/.DS_Store‎

0 Bytes
Binary file not shown.

‎Notes/C++.md‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
#### debug
44
[macOS上用VSCode](https://zhuanlan.zhihu.com/p/106935263?utm_source=wechat_session)
55

6-
[lldb的使用](https://www.jianshu.com/p/9a71329d5c4d)
7-
* breakpoint set -n main, run, print, next
6+
* [CS107 GDB and Debugging教程](https://web.stanford.edu/class/archive/cs/cs107/cs107.1202/resources/gdb)
7+
* [CS107 Software Testing Strategies](https://web.stanford.edu/class/archive/cs/cs107/cs107.1202/testing.html)
8+
9+
* [lldb的使用](https://www.jianshu.com/p/9a71329d5c4d)
10+
* breakpoint set -n main, run, print, next
11+
* 内存泄露问题
12+
* `cmake .. -DCMAKE_BUILD_TYPE=RelASan`
13+
* `valgrind`
14+
* `cmake .. -DCMAKE_BUILD_TYPE=Debug` + `gdb`
815

916
#### C
1017

@@ -57,6 +64,10 @@ public:
5764
```
5865
* 类的静态成员函数指针
5966
67+
#### 编程习惯
68+
RAII原则:Resource acquisition is initialization
69+
* [CppCoreGuidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md)
70+
* 用[CppCheck](http://cppcheck.net/)诊断,`make cppcheck`
6071
6172
#### 输入输出
6273
@@ -104,7 +115,7 @@ sort,自己定义cmp函数,注意cmp的定义:类内静态,传参引用
104115

105116

106117
##### \<deque>
107-
* deque,两端都能进出,双向队列
118+
* deque,两端都能进出,双向队列,[用法详解](https://blog.csdn.net/u011630575/article/details/79923132)
108119
* [STL之deque实现详解]( https://blog.csdn.net/u010710458/article/details/79540505?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-6&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-6)
109120
* deque的pop_front相当于queue的pop()
110121

‎Notes/Computer-Networking-Lab-CS144-Stanford.md‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,38 @@ void get_URL(const string &host, const string &path) {
124124
* <img src="Computer-Networking-Lab-CS144-Stanford/reassembler.png" alt="reassembler" style="zoom:100%;" />
125125

126126
#### lab2: the TCP receiver
127-
#####
127+
##### 3.1 Sequence Numbers
128+
129+
<img src="Computer-Networking-Lab-CS144-Stanford/001.jpg" alt="different index" style="zoom:100%;" />
130+
* 利用头文件中的函数简化代码
131+
* 计算出相对checkpoint的偏移量之后,再转化成离checkpoint最近的点,如果加多了就左移,注意返回值太小无法左移的情形。
132+
133+
```c++
134+
uint64_t unwrap(WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint) {
135+
uint32_t offset = n - wrap(checkpoint, isn);
136+
uint64_t ret = checkpoint + offset;
137+
// 取距离checkpoint最近的值,因此判断的情况是否左移ret
138+
//注意位置不够左移的情形!!!
139+
if (offset >= (1u << 31) && ret >= UINT32_LEN)
140+
ret -= (1ul << 32);
141+
return ret;
142+
}
143+
```
144+
##### 3.2 window
145+
* lower:ackno
146+
* higher~window size
147+
* window size = capacity - ByteStream.buffer_size()
148+
149+
##### 3.3 TCP receiver的实现
150+
1. receive segmentsfrom its peer
151+
2. reassemble the ByteStream using your StreamReassembler, and calculate the
152+
3. acknowledgment number (ackno)
153+
4. and the window size.
154+
155+
* `_reassembler`忽视SYN,所以要手动对index减1、ackno()加1
156+
* 非常规路线的处理:比如对于第二个SYN或者FIN信号,接收机选择忽视,具体见`bool TCPReceiver::segment_received(const TCPSegment &seg)`的实现
157+
158+
128159
129160
130161
#### 工程细节
@@ -140,7 +171,6 @@ string d(size, 0);
140171
generate(d.begin(), d.end(), [&] { return rd(); });
141172
```
142173

143-
144174
* 类cmp函数的定义,适用 `lower_bound()`方法
145175
* 两个**const**都不能掉!
146176
```c++
@@ -152,3 +182,4 @@ class typeUnassembled {
152182
bool operator<(const typeUnassembled &t1) const { return index < t1.index; }
153183
};
154184
```
185+
* `urg = static_cast<bool>(fl_b & 0b0010'0000); // binary literals and ' digit separator since C++14!!!`
76.7 KB
Loading[フレーム]

‎Notes/Computer-Networking-Lecture-CS144-Stanford.md‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ end-to-end check
336336

337337
<img src="Computer-Networking-Lecture-CS144-Stanford/013.jpg" alt="TCP Connection" style="zoom:100%;" />
338338

339-
##### 2-7 Flow Control: Stop-and-Wait
339+
* 非常规路线的处理:比如对于第二个SYN或者FIN信号,接收机选择忽视,具体见`bool TCPReceiver::segment_received(const TCPSegment &seg)`的实现
340+
341+
##### 2-7 Flow Control I: Stop-and-Wait
340342
* 核心是receiver给sender反馈,让sender不要送太多packets
341343
* 基本方法
342344
* stop and wait
@@ -351,8 +353,40 @@ end-to-end check
351353
<img src="Computer-Networking-Lecture-CS144-Stanford/014.jpg" alt="stop-and-wait" style="zoom:100%;" />
352354

353355
##### 2-7 Flow Control II: Sliding Window
354-
355-
356+
* Stop-and-Wait的性能:RTT=50ms, Bottleneck=10Mbps, Ethernet packet length=12Kb => 性能(2%)远远不到瓶颈
357+
* Sliding Window计算Window size填满性能
358+
359+
**Sliding Window Sender**
360+
361+
* Every segment has a sequence number (SeqNo)
362+
* Maintain 3 variables
363+
* Send window size(SWS)
364+
* Last acknowledgment(LAR)
365+
* Last segment sent(LSS)
366+
* Maintain invariant: $(LSS - LAR) \leq SWS$
367+
* Advance LAR on new acknowledgement
368+
* Buffer up to SWS segments
369+
370+
**Sliding Window Receiver**
371+
* Maintain 3 variables
372+
* Receive window size(RWS)
373+
* Last acceptable segment(LAS)
374+
* Last segment received(LSR)
375+
* Maintain invariant: $(LAS - LSR) \leq RWS$
376+
* 如果收到的packet比LAS小,则发送ack
377+
* 发送cumulative acks: 收到1, 2, 3, 5,发送3
378+
* TCP acks are next expected data,因此要加一,上个例子改为4,初值为0
379+
380+
**RWS, SWS, and Sequence Space**
381+
* $RWS \geq 1, SWS \geq 1, RWS \leq SWS$
382+
* if $RWS = 1,ドル "go back N" protocol ,need SWS+1 sequence numbers (需要多重传)
383+
* if $RWS = SWS,ドル need 2SWS sequence numbers
384+
* 通常需要$RWS+SWS$ sequence numbers:考虑临界情况,RWS最左侧的ACK没有成功发送,重传后收到了RWS最右侧的ACK
385+
386+
**TCP Flow Control**
387+
388+
* Receiver advertises RWS using window field
389+
* Sender can only send data up to LAR+SWS
356390

357391

358392

‎Notes/Output/C++.md‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### C++
22
[toc]
33
#### debug
4-
*[macOS上用VSCode](https://zhuanlan.zhihu.com/p/106935263?utm_source=wechat_session)
4+
[macOS上用VSCode](https://zhuanlan.zhihu.com/p/106935263?utm_source=wechat_session)
55

66
* [CS107 GDB and Debugging教程](https://web.stanford.edu/class/archive/cs/cs107/cs107.1202/resources/gdb)
77
* [CS107 Software Testing Strategies](https://web.stanford.edu/class/archive/cs/cs107/cs107.1202/testing.html)
@@ -13,9 +13,6 @@
1313
* `valgrind`
1414
* `cmake .. -DCMAKE_BUILD_TYPE=Debug` + `gdb`
1515

16-
17-
18-
1916
#### C
2017

2118
* volatile特性:这条代码不要被编译器优化,`volatile int counter = 0`,避免出现意料之外的情况,常用于全局变量
@@ -67,13 +64,11 @@ public:
6764
```
6865
* 类的静态成员函数指针
6966
70-
7167
#### 编程习惯
7268
RAII原则:Resource acquisition is initialization
7369
* [CppCoreGuidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md)
7470
* 用[CppCheck](http://cppcheck.net/)诊断,`make cppcheck`
7571
76-
7772
#### 输入输出
7873
7974
##### 输入用逗号间隔的数据
@@ -129,9 +124,6 @@ sort,自己定义cmp函数,注意cmp的定义:类内静态,传参引用
129124
* map<int,list<pair<int,int>>::iterator> m;
130125
* r.push_front(...), r.begin(), r.back()
131126

132-
##### \<set>
133-
* [multiset用法总结](https://blog.csdn.net/sodacoco/article/details/84798621)
134-
135127
##### \<vector>
136128
* 初始化,可以用列表
137129
* 也可以 `int a[10]={...};vector<int> b(a,a+10); ` 左闭右开
@@ -190,8 +182,6 @@ strcpy(buf, str.c_str());//strncpy(buf, str.c_str(), 10);
190182
* s.fin_first_not_of(s1) 查找s中第一个不属于s1中的字符的位置,并返回(包括0)
191183
* s.fin_last_not_of(s1) 查找s中最后一个不属于s1中的字符的位置,并返回(包括0)
192184
193-
* `basic_string::_M_create`错误:string用两个迭代器初始化第一个比第二个大。
194-
195185
196186
##### \<sys.h>
197187

‎Notes/Output/Computer-Networking-Lab-CS144-Stanford.md‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,38 @@ void get_URL(const string &host, const string &path) {
124124
* <img src="https://raw.githubusercontent.com/huangrt01/Markdown-Transformer-and-Uploader/master/Notes/Computer-Networking-Lab-CS144-Stanford/reassembler.png" alt="reassembler" style="zoom:100%;" />
125125

126126
#### lab2: the TCP receiver
127-
#####
127+
##### 3.1 Sequence Numbers
128+
129+
<img src="https://raw.githubusercontent.com/huangrt01/Markdown-Transformer-and-Uploader/master/Notes/Computer-Networking-Lab-CS144-Stanford/001.jpg" alt="different index" style="zoom:100%;" />
130+
* 利用头文件中的函数简化代码
131+
* 计算出相对checkpoint的偏移量之后,再转化成离checkpoint最近的点,如果加多了就左移,注意返回值太小无法左移的情形。
132+
133+
```c++
134+
uint64_t unwrap(WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint) {
135+
uint32_t offset = n - wrap(checkpoint, isn);
136+
uint64_t ret = checkpoint + offset;
137+
// 取距离checkpoint最近的值,因此判断的情况是否左移ret
138+
//注意位置不够左移的情形!!!
139+
if (offset >= (1u << 31) && ret >= UINT32_LEN)
140+
ret -= (1ul << 32);
141+
return ret;
142+
}
143+
```
144+
##### 3.2 window
145+
* lower:ackno
146+
* higher~window size
147+
* window size = capacity - ByteStream.buffer_size()
148+
149+
##### 3.3 TCP receiver的实现
150+
1. receive segmentsfrom its peer
151+
2. reassemble the ByteStream using your StreamReassembler, and calculate the
152+
3. acknowledgment number (ackno)
153+
4. and the window size.
154+
155+
* `_reassembler`忽视SYN,所以要手动对index减1、ackno()加1
156+
* 非常规路线的处理:比如对于第二个SYN或者FIN信号,接收机选择忽视,具体见`bool TCPReceiver::segment_received(const TCPSegment &seg)`的实现
157+
158+
128159
129160
130161
#### 工程细节
@@ -140,7 +171,6 @@ string d(size, 0);
140171
generate(d.begin(), d.end(), [&] { return rd(); });
141172
```
142173

143-
144174
* 类cmp函数的定义,适用 `lower_bound()`方法
145175
* 两个**const**都不能掉!
146176
```c++
@@ -152,3 +182,4 @@ class typeUnassembled {
152182
bool operator<(const typeUnassembled &t1) const { return index < t1.index; }
153183
};
154184
```
185+
* `urg = static_cast<bool>(fl_b & 0b0010'0000); // binary literals and ' digit separator since C++14!!!`

‎Notes/Output/Computer-Networking-Lecture-CS144-Stanford.md‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ end-to-end check
336336

337337
<img src="https://raw.githubusercontent.com/huangrt01/Markdown-Transformer-and-Uploader/master/Notes/Computer-Networking-Lecture-CS144-Stanford/013.jpg" alt="TCP Connection" style="zoom:100%;" />
338338

339-
##### 2-7 Flow Control: Stop-and-Wait
339+
* 非常规路线的处理:比如对于第二个SYN或者FIN信号,接收机选择忽视,具体见`bool TCPReceiver::segment_received(const TCPSegment &seg)`的实现
340+
341+
##### 2-7 Flow Control I: Stop-and-Wait
340342
* 核心是receiver给sender反馈,让sender不要送太多packets
341343
* 基本方法
342344
* stop and wait
@@ -351,8 +353,40 @@ end-to-end check
351353
<img src="https://raw.githubusercontent.com/huangrt01/Markdown-Transformer-and-Uploader/master/Notes/Computer-Networking-Lecture-CS144-Stanford/014.jpg" alt="stop-and-wait" style="zoom:100%;" />
352354

353355
##### 2-7 Flow Control II: Sliding Window
354-
355-
356+
* Stop-and-Wait的性能:RTT=50ms, Bottleneck=10Mbps, Ethernet packet length=12Kb => 性能(2%)远远不到瓶颈
357+
* Sliding Window计算Window size填满性能
358+
359+
**Sliding Window Sender**
360+
361+
* Every segment has a sequence number (SeqNo)
362+
* Maintain 3 variables
363+
* Send window size(SWS)
364+
* Last acknowledgment(LAR)
365+
* Last segment sent(LSS)
366+
* Maintain invariant: <img src="https://www.zhihu.com/equation?tex=%28LSS%20-%20LAR%29%20%5Cleq%20SWS" alt="(LSS - LAR) \leq SWS" class="ee_img tr_noresize" eeimg="1">
367+
* Advance LAR on new acknowledgement
368+
* Buffer up to SWS segments
369+
370+
**Sliding Window Receiver**
371+
* Maintain 3 variables
372+
* Receive window size(RWS)
373+
* Last acceptable segment(LAS)
374+
* Last segment received(LSR)
375+
* Maintain invariant: <img src="https://www.zhihu.com/equation?tex=%28LAS%20-%20LSR%29%20%5Cleq%20RWS" alt="(LAS - LSR) \leq RWS" class="ee_img tr_noresize" eeimg="1">
376+
* 如果收到的packet比LAS小,则发送ack
377+
* 发送cumulative acks: 收到1, 2, 3, 5,发送3
378+
* TCP acks are next expected data,因此要加一,上个例子改为4,初值为0
379+
380+
**RWS, SWS, and Sequence Space**
381+
* <img src="https://www.zhihu.com/equation?tex=RWS%20%5Cgeq%201%2C%20SWS%20%5Cgeq%201%2C%20RWS%20%5Cleq%20SWS" alt="RWS \geq 1, SWS \geq 1, RWS \leq SWS" class="ee_img tr_noresize" eeimg="1">
382+
* if <img src="https://www.zhihu.com/equation?tex=RWS%20%3D%201" alt="RWS = 1" class="ee_img tr_noresize" eeimg="1"> , "go back N" protocol ,need SWS+1 sequence numbers (需要多重传)
383+
* if <img src="https://www.zhihu.com/equation?tex=RWS%20%3D%20SWS" alt="RWS = SWS" class="ee_img tr_noresize" eeimg="1"> , need 2SWS sequence numbers
384+
* 通常需要 <img src="https://www.zhihu.com/equation?tex=RWS%2BSWS" alt="RWS+SWS" class="ee_img tr_noresize" eeimg="1"> sequence numbers:考虑临界情况,RWS最左侧的ACK没有成功发送,重传后收到了RWS最右侧的ACK
385+
386+
**TCP Flow Control**
387+
388+
* Receiver advertises RWS using window field
389+
* Sender can only send data up to LAR+SWS
356390

357391

358392

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#### [Stanford-CS144-Lecture](https://github.com/huangrt01/CS-Notes/blob/master/Notes/Output/Computer-Networking-Lecture-CS144-Stanford.md)しかくしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかく
4040

41-
#### [Stanford-CS144-Lab](https://github.com/huangrt01/CS-Notes/blob/master/Notes/Output/Computer-Networking-Lab-CS144-Stanford.md)しかくしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかく
41+
#### [Stanford-CS144-Lab](https://github.com/huangrt01/CS-Notes/blob/master/Notes/Output/Computer-Networking-Lab-CS144-Stanford.md)しかくしかくしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかく
4242

4343
#### [Computer-Networking-A-Top-Down-Approach](https://github.com/huangrt01/CS-Notes/blob/master/Notes/Output/Computer-Networking-A-Top-Down-Approach.md)しろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかくしろいしかく
4444

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /