课程介绍

CS144: 什么,你学不会TCP?那就来自己写一个吧! - 胡津铭的文章 - 知乎
https://zhuanlan.zhihu.com/p/175998415

CS144 is an introductory course about computer networks. You will learn about the basic principles of computer networks, for example packet switching, layering, encapsulation and protocols; and you will learn how applications such as the world-wide-web, video streaming (e.g. Netfix and Hulu), video conferencing (e.g. Zoom and Skype) and BitTorrent use the network to communicate. You will spend quite a lot of time learning about the specifics of how the Internet works - which 1s of course by far the biggest computer network ever built. You will learn how applications communicate reliably over an unreliable Internet. And you will build portions of the Internet yourself! In fact, believe that in CS144 you build more parts of the Internet infrastructure than in any other undergraduate networking class anywhere. It’s really fun to see how the individual pieces work: You build an Internet router, and a reliable data delivery service, and then you use it to communicate with remote servers.

In addition to lectures, we will also have a few in-class guest lectures by outside speakers. All the guest lecturers are excellent speakers with many years of experience making networks work at huge scale. We will also have one Or more in-class exercises, which you will complete during the regular lecture time. These are designed to give you hands-on experience with tools that are useful for your labs.

参考资料

配置环境

1
2
3
wget https://web.stanford.edu/class/cs144/vm_howto/setup_dev_env.sh
chmod +x setup_dev_env.sh
./setup_dev_env

安装

1
2
sudo apt-get install doxygen clang-format
sudo apt install cmake

测试

1
2
git clone https://github.com/cs144/sponge
git checkout -b master origin/master
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$ tree .
.
├── apps
│   ├── CMakeLists.txt
│   └── webget.cc
├── CMakeLists.txt
├── compile_commands.json -> build/compile_commands.json
├── doctests
│   ├── address_dt.cc
│   ├── address_example_1.cc
│   ├── address_example_2.cc
│   ├── address_example_3.cc
│   ├── CMakeLists.txt
│   ├── parser_dt.cc
│   ├── parser_example.cc
│   ├── socket_dt.cc
│   ├── socket_example_1.cc
│   ├── socket_example_2.cc
│   └── socket_example_3.cc
├── etc
│   ├── build_defs.cmake
│   ├── build_type.cmake
│   ├── cflags.cmake
│   ├── clang_format.cmake
│   ├── clang_tidy.cmake
│   ├── cppcheck.cmake
│   ├── cppreference-doxygen-web.tag.xml
│   ├── Doxyfile.in
│   ├── doxygen.cmake
│   ├── linux-man-doxygen-web.tag.xml
│   ├── rfc-doxygen-web.tag.xml
│   ├── sponge_doxygen.css
│   ├── sponge_small.png
│   ├── tests.cmake
│   └── tunconfig
├── libsponge
│   ├── byte_stream.cc
│   ├── byte_stream.hh
│   ├── CMakeLists.txt
│   └── util
│   ├── address.cc
│   ├── address.hh
│   ├── buffer.cc
│   ├── buffer.hh
│   ├── eventloop.cc
│   ├── eventloop.hh
│   ├── file_descriptor.cc
│   ├── file_descriptor.hh
│   ├── parser.cc
│   ├── parser.hh
│   ├── socket.cc
│   ├── socket.hh
│   ├── tun.cc
│   ├── tun.hh
│   ├── util.cc
│   └── util.hh
├── README.md
├── tests
│   ├── byte_stream_capacity.cc
│   ├── byte_stream_construction.cc
│   ├── byte_stream_many_writes.cc
│   ├── byte_stream_one_write.cc
│   ├── byte_stream_test_harness.cc
│   ├── byte_stream_test_harness.hh
│   ├── byte_stream_two_writes.cc
│   ├── CMakeLists.txt
│   ├── test_err_if.hh
│   ├── test_should_be.hh
│   └── webget_t.sh
└── writeups
└── lab0.md

7 directories, 62 files
  • doctestsutil 的一些使用样例
  • etc 是配置文件
  • libsponge 是实验中要完善的代码文件
  • util 是实验提供的工具类
  • tests文件夹中是测试文件
1
2
3
4
mkdir build && cd build
cmake ..
make format
make -j4

出现以下报错

1
2
3
/home/ubuntu/cs144/sponge/libsponge/util/parser.cc:36:13: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
ret <<= 8;
^ ~

解决方法:
ret <<=8; 换成 ret = ret << 8 即可正常运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$ make -j4
[ 3%] Building CXX object tests/CMakeFiles/spongechecks.dir/byte_stream_test_harness.cc.o
[ 6%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/address.cc.o
[ 10%] Building CXX object libsponge/CMakeFiles/sponge.dir/byte_stream.cc.o
[ 13%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/buffer.cc.o
[ 16%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/eventloop.cc.o
[ 20%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/file_descriptor.cc.o
[ 23%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/parser.cc.o
[ 26%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/socket.cc.o
[ 30%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/tun.cc.o
[ 33%] Linking CXX static library libspongechecks.a
[ 33%] Built target spongechecks
[ 36%] Building CXX object libsponge/CMakeFiles/sponge.dir/util/util.cc.o
[ 40%] Linking CXX static library libsponge.a
[ 40%] Built target sponge
[ 43%] Building CXX object apps/CMakeFiles/webget.dir/webget.cc.o
[ 46%] Building CXX object tests/CMakeFiles/byte_stream_construction.dir/byte_stream_construction.cc.o
[ 50%] Building CXX object tests/CMakeFiles/byte_stream_one_write.dir/byte_stream_one_write.cc.o
[ 53%] Building CXX object tests/CMakeFiles/byte_stream_two_writes.dir/byte_stream_two_writes.cc.o
[ 56%] Linking CXX executable webget
[ 60%] Linking CXX executable byte_stream_construction
[ 60%] Built target webget
[ 60%] Built target byte_stream_construction
[ 63%] Building CXX object tests/CMakeFiles/byte_stream_many_writes.dir/byte_stream_many_writes.cc.o
[ 66%] Linking CXX executable byte_stream_one_write
[ 70%] Building CXX object tests/CMakeFiles/byte_stream_capacity.dir/byte_stream_capacity.cc.o
[ 73%] Linking CXX executable byte_stream_two_writes
[ 73%] Built target byte_stream_one_write
[ 73%] Built target byte_stream_two_writes
[ 76%] Building CXX object doctests/CMakeFiles/parser_dt.dir/parser_dt.cc.o
[ 80%] Building CXX object doctests/CMakeFiles/address_dt.dir/address_dt.cc.o
[ 83%] Linking CXX executable address_dt
[ 86%] Linking CXX executable parser_dt
[ 86%] Built target address_dt
[ 90%] Building CXX object doctests/CMakeFiles/socket_dt.dir/socket_dt.cc.o
[ 90%] Built target parser_dt
[ 93%] Linking CXX executable byte_stream_many_writes
[ 93%] Built target byte_stream_many_writes
[ 96%] Linking CXX executable byte_stream_capacity
[ 96%] Built target byte_stream_capacity
[100%] Linking CXX executable socket_dt
[100%] Built target socket_dt

调试方法