├── .gitignore
├── LICENSE
├── Project1-MinNE-python
├── README.md
├── bin
│ ├── OneTouchToClose.bat
│ ├── OneTouchToGo-stage2.bat
│ ├── OneTouchToGo-stage3.bat
│ ├── OneTouchToGo-stage4.bat
│ └── phy.exe
├── config
│ ├── batch-backup
│ │ ├── 2.bat
│ │ ├── 3.bat
│ │ └── 4.bat
│ ├── batch.bat
│ ├── devicemap-backup
│ │ ├── 2.json
│ │ ├── 3.json
│ │ └── 4.json
│ ├── devicemap.json
│ ├── ne-backup
│ │ ├── 2.txt
│ │ ├── 3.txt
│ │ └── 4.txt
│ └── ne.txt
├── design
│ ├── coding-pic.drawio
│ ├── coding-unicode.drawio
│ ├── frame-uml.drawio
│ ├── frame.drawio
│ ├── layer-inheritance.drawio
│ ├── ne-layer.drawio
│ ├── topology-2.drawio
│ ├── topology-3.drawio
│ ├── topology-4-0.drawio
│ └── topology-4.drawio
├── report
│ ├── ber-speed.py
│ ├── images
│ │ ├── batchfile.png
│ │ ├── cmd.png
│ │ ├── coding-pic.png
│ │ ├── coding-unicode.png
│ │ ├── frame-uml.png
│ │ ├── frame.png
│ │ ├── layer-inheritance.png
│ │ ├── ne-layer.png
│ │ ├── ne.png
│ │ ├── redundancy.png
│ │ ├── stage1.png
│ │ ├── stage2-1-1.png
│ │ ├── stage2-1-2.png
│ │ ├── stage2-2-1.png
│ │ ├── stage2-2-2.png
│ │ ├── stage2-3.png
│ │ ├── stage2-4-1.png
│ │ ├── stage2-4-2.png
│ │ ├── stage2-5.png
│ │ ├── stage3-1.png
│ │ ├── stage3-2.png
│ │ ├── stage3-3.png
│ │ ├── stage3-4.png
│ │ ├── stage4-1-1.png
│ │ ├── stage4-1-2.png
│ │ ├── stage4-1-3.png
│ │ ├── stage4-1-4.png
│ │ ├── stage4-1-5.png
│ │ ├── stage4-2.png
│ │ ├── stage4-3.png
│ │ ├── stage4-4.png
│ │ ├── topology-2.png
│ │ ├── topology-3.png
│ │ ├── topology-4-0.png
│ │ └── topology-4.png
│ ├── report.md
│ └── report.pdf
└── src
│ ├── app.py
│ ├── cmd.py
│ ├── interface
│ ├── __init__.py
│ ├── cmd.py
│ └── cmd.ui
│ ├── layer
│ ├── __init__.py
│ ├── _abstract.py
│ ├── app.py
│ ├── cmd.py
│ ├── net.py
│ ├── router.py
│ └── switch.py
│ ├── net.py
│ ├── router.py
│ ├── routertable-testbench.py
│ ├── start.py
│ ├── switch.py
│ └── utils
│ ├── __init__.py
│ ├── coding.py
│ ├── frame.py
│ ├── io.py
│ └── params.py
├── Project2-PacketTracer
├── README.md
├── Stage1
│ ├── design
│ │ ├── ip-distribution.drawio
│ │ └── ip-distribution.xlsx
│ └── report
│ │ ├── images
│ │ ├── 2021-10-15-22-36-17.png
│ │ ├── 2021-10-15-23-23-41.png
│ │ ├── 2021-10-15-23-49-19.png
│ │ ├── 2021-10-16-00-02-35.png
│ │ └── 2021-10-16-00-06-37.png
│ │ ├── report.md
│ │ └── report.pdf
└── Stage2
│ └── report.pdf
├── Project3-Wireshark
├── README.md
├── Stage1
│ ├── images
│ │ ├── 2021-10-17-10-57-24.png
│ │ ├── 2021-10-17-10-59-23.png
│ │ ├── 2021-10-17-11-00-57.png
│ │ ├── 2021-10-17-11-04-44.png
│ │ ├── 2021-10-17-11-05-57.png
│ │ ├── 2021-10-17-11-08-52.png
│ │ ├── 2021-10-17-11-11-23.png
│ │ ├── 2021-10-17-11-13-29.png
│ │ ├── 2021-10-17-11-15-41.png
│ │ ├── 2021-10-17-11-23-05.png
│ │ ├── 2021-10-17-11-23-45.png
│ │ ├── 2021-10-17-11-24-30.png
│ │ ├── 2021-10-17-11-25-03.png
│ │ ├── 2021-10-17-11-25-50.png
│ │ ├── 2021-10-17-11-32-38.png
│ │ ├── 2021-10-17-11-34-41.png
│ │ ├── 2021-10-17-11-44-44.png
│ │ ├── 2021-10-17-11-45-29.png
│ │ ├── 2021-10-17-11-46-12.png
│ │ ├── 2021-10-17-12-22-30.png
│ │ ├── 2021-10-17-12-24-01.png
│ │ └── tcp.png
│ ├── report.md
│ └── report.pdf
└── Stage2
│ ├── images
│ ├── 2021-10-17-10-57-24.png
│ ├── 2021-10-17-10-59-23.png
│ ├── 2021-10-17-11-00-57.png
│ ├── 2021-10-17-11-04-44.png
│ ├── 2021-10-17-11-05-57.png
│ ├── 2021-10-17-11-08-52.png
│ ├── 2021-10-17-11-11-23.png
│ ├── 2021-10-17-11-13-29.png
│ ├── 2021-10-17-11-15-41.png
│ ├── 2021-10-17-11-23-05.png
│ ├── 2021-10-17-11-23-45.png
│ ├── 2021-10-17-11-24-30.png
│ ├── 2021-10-17-11-25-03.png
│ ├── 2021-10-17-11-25-50.png
│ ├── 2021-10-17-11-32-38.png
│ ├── 2021-10-17-11-34-41.png
│ ├── 2021-10-17-11-44-44.png
│ ├── 2021-10-17-11-45-29.png
│ ├── 2021-10-17-11-46-12.png
│ ├── 2021-10-17-12-22-30.png
│ ├── 2021-10-17-12-24-01.png
│ ├── 2021-10-30-15-39-53.png
│ ├── 2021-10-30-16-01-26.png
│ ├── 2021-10-30-19-20-27.png
│ ├── 2021-10-30-19-20-59.png
│ ├── iograph.png
│ ├── length.png
│ ├── lengthplot.png
│ ├── protocol.png
│ ├── stevens.png
│ ├── stream.png
│ ├── tcp.png
│ └── throughput.png
│ ├── report.md
│ └── report.pdf
├── Project4-Simulink
├── README.md
├── Stage1
│ ├── report
│ │ ├── images
│ │ │ ├── BASK1.png
│ │ │ ├── BASK2.png
│ │ │ ├── BASK3.png
│ │ │ ├── BFSK1.png
│ │ │ ├── BFSK2.png
│ │ │ ├── BFSK3.png
│ │ │ ├── BPSK1.png
│ │ │ ├── BPSK2.png
│ │ │ ├── BPSK3.png
│ │ │ └── ber.png
│ │ ├── report.md
│ │ └── report.pdf
│ └── src
│ │ ├── BASK.slx
│ │ ├── BFSK.slx
│ │ └── BPSK.slx
└── Stage2
│ ├── design
│ ├── qam1.drawio
│ ├── qam1.png
│ ├── qam2.drawio
│ ├── qam2.png
│ ├── qpsk1.drawio
│ ├── qpsk1.png
│ ├── qpsk2.drawio
│ └── qpsk2.png
│ ├── report
│ ├── images
│ │ ├── QAM1.png
│ │ ├── QAM2.png
│ │ ├── QAM3.png
│ │ ├── QAM4-10.png
│ │ ├── QAM4-20.png
│ │ ├── QAM4-30.png
│ │ ├── QPSK1.png
│ │ ├── QPSK2.png
│ │ ├── QPSK3.png
│ │ ├── QPSK4-10.png
│ │ ├── QPSK4-20.png
│ │ └── QPSK4-30.png
│ ├── report.md
│ └── report.pdf
│ └── src
│ ├── QAM.slx
│ └── QPSK.slx
├── README.md
├── Unit1
├── discussion.pdf
├── discussion.pptx
├── exercise.md
├── exercise.pdf
├── mindmap.png
└── vocabulary.pdf
├── Unit2
├── discussion.pdf
├── discussion.pptx
├── exercise.md
├── exercise.pdf
├── images
│ └── 2021-12-13-13-40-52.png
├── mindmap.png
└── vocabulary.pdf
├── Unit3
├── discussion.pdf
├── discussion.pptx
├── exercise.md
├── exercise.pdf
├── mindmap.png
└── vocabulary.pdf
├── Unit4
├── discussion.pdf
├── discussion.pptx
├── exercise.md
├── exercise.pdf
├── images
│ ├── 2021-12-13-20-38-02.png
│ └── 2021-12-14-11-35-23.png
├── mindmap.png
└── vocabulary.pdf
└── Unit5
├── discussion.pdf
├── discussion.pptx
├── exercise.md
├── exercise.pdf
├── images
└── 2021-12-14-09-47-41.png
├── mindmap.png
└── vocabulary.pdf
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 | test
3 | debug
4 | *.log
5 | *.docx
6 | Hash
7 | test.*
8 | manager.jar
9 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/README.md:
--------------------------------------------------------------------------------
1 | # 1 - MinNE
2 |
3 | ## 项目介绍
4 |
5 | 利用项目提供的物理层模拟软件,在两个只能传输 0 和 1 数据的程序(物理层实体的仿真)之间通过增加各种控制功能,形成多层结构网元,网元之间形成多种拓扑结构,通过网元传输包含中文、英文、标点符号(大约 50 个字符)和图片文件等。
6 |
7 | ## 阶段要求
8 |
9 | ### 阶段一
10 |
11 | 基于套接字的简单通信程序。
12 |
13 | 客户端定时每 500ms 向服务器发送一个随机整数,范围在 1-500 之间;
14 |
15 | 服务器每收到一份数据也同时产生随机整数与收到的数据相加,只有在结果大于 100 时才会把计算结果返回给客户端,而客户端收到超出 100 的结果则立即产生一个新的数据,而不是在间隔 500ms 后。
16 |
17 | 客户机需要产生 20 份数据,如果有超过 100 的结果,总运行时间应接近 10-N*0.5 ,N 为超过 100 的结果的数量。
18 |
19 | ### 阶段二
20 |
21 | #### 基本要求
22 |
23 | 1. 帧同步与定位;
24 | 2. 差错检测;
25 | 3. 至少实现一种差错控制协议;
26 | 4. 简单的流量控制,对发送速度有约束;
27 | 5. 简单的点对点性能测试。(受误码率影响、重传处理后的有效吞吐量)
28 |
29 | #### 进阶要求
30 |
31 | 1. 端到端的差错控制协议;(点到点和端到端的差错控制协议可以只选其中一层实现)
32 | 2. 面向连接协议;(较为完整)
33 | 3. 流量控制,或者含拥塞控制的流控,参考 TCP,有测量,有计算,有缓存,有动态调整;
34 | 4. 分帧,将用户单次大数据分成更适合传输的,符合流控限制的多个帧;
35 | 5. 多角度的性能测试;(不同帧长及其它可调整参数下的延时、有效吞吐量等性能表现)
36 | 6. 其它相关。
37 |
38 | ### 阶段三
39 |
40 | #### 基本要求
41 |
42 | 1. 共享信道技术仿真实验和仿真设计;
43 | 2. 单播目的地址判收;
44 | 3. 支持广播;
45 | 4. 有端口地址表;
46 | 5. 反向地址学习;
47 | 6. 简单的性能测试。(含交换机的延时,有效吞吐量)
48 |
49 | #### 进阶要求
50 |
51 | 1. 多个交换机,无生成树时环形交换机拓扑时的奇特效果;
52 | 2. 简单的生成树算法,解决环状拓扑问题;
53 | 3. 友好的应用层,方便灵活的控制——数据产生、接收数据的展示等,设计了图形化界面等;
54 | 4. 其它相关。
55 |
56 |
57 | ### 阶段四
58 |
59 | #### 基本要求
60 |
61 | 1. 实体编址,高层实体到低层实体的地址映射技术,解决各层实体的标定区分和数据投递;
62 | 2. 路由表,记录路由;
63 | 3. 按路由转发;
64 | 4. 端到端的信息交换;
65 | 5. 简单的性能测试。(端到端吞吐量、延时)
66 |
67 | #### 进阶要求
68 |
69 | 1. 类似 ARP 的,即相互独立,又能方便实现高、低层地址映射的技术;
70 | 2. 实现动态路由算法;
71 | 3. 多种多层网元体系基本完整——即能实现包含交换机、路由器等设备的多种网元的端到端数据交流;
72 | 4. 多角度性能测试;
73 | 5. 友好的应用层,方便灵活的控制——数据产生、接收数据的展示等,设计了图形化界面等;
74 | 6. 为最终成果汇报制定清晰的演示计划(脚本)
75 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/bin/OneTouchToClose.bat:
--------------------------------------------------------------------------------
1 | taskkill /f /t /im python.exe
2 | taskkill /f /t /im phy.exe
3 | taskkill /f /t /im windowsterminal.exe
--------------------------------------------------------------------------------
/Project1-MinNE-python/bin/OneTouchToGo-stage2.bat:
--------------------------------------------------------------------------------
1 | cd %~dp0
2 | start python ../src/start.py 2
--------------------------------------------------------------------------------
/Project1-MinNE-python/bin/OneTouchToGo-stage3.bat:
--------------------------------------------------------------------------------
1 | cd %~dp0
2 | start python ../src/start.py 3
--------------------------------------------------------------------------------
/Project1-MinNE-python/bin/OneTouchToGo-stage4.bat:
--------------------------------------------------------------------------------
1 | cd %~dp0
2 | start python ../src/start.py 4
--------------------------------------------------------------------------------
/Project1-MinNE-python/bin/phy.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/bin/phy.exe
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/batch-backup/2.bat:
--------------------------------------------------------------------------------
1 | @REM ------------------------------ cd to /config
2 | cd %~dp0
3 | @REM ------------------------------ CMD
4 | start python ../src/cmd.py
5 | @REM ------------------------------ Host 1
6 | start python ../src/app.py 1
7 | start python ../src/net.py 1
8 | start ../bin/phy.exe 1 PHY 0
9 | @REM ------------------------------ Host 2
10 | start python ../src/app.py 2
11 | start python ../src/net.py 2
12 | start ../bin/phy.exe 2 PHY 0
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/batch-backup/3.bat:
--------------------------------------------------------------------------------
1 | @REM ------------------------------ cd to /config
2 | cd %~dp0
3 | @REM ------------------------------ CMD
4 | start python ../src/cmd.py
5 | @REM ------------------------------ Host 1
6 | start python ../src/app.py 1
7 | start python ../src/net.py 1
8 | start ../bin/phy.exe 1 PHY 0
9 | @REM ------------------------------ Host 2
10 | start python ../src/app.py 2
11 | start python ../src/net.py 2
12 | start ../bin/phy.exe 2 PHY 0
13 | @REM ------------------------------ Host 3
14 | start python ../src/app.py 3
15 | start python ../src/net.py 3
16 | start ../bin/phy.exe 3 PHY 0
17 | @REM ------------------------------ Switch 4
18 | start python ../src/switch.py 4
19 | start ../bin/phy.exe 4 PHY 0
20 | start ../bin/phy.exe 4 PHY 1
21 | start ../bin/phy.exe 4 PHY 2
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/batch-backup/4.bat:
--------------------------------------------------------------------------------
1 | @REM ------------------------------ cd to /config
2 | cd %~dp0
3 | @REM ------------------------------ CMD
4 | start python ../src/cmd.py
5 | @REM ------------------------------ Host 1
6 | start python ../src/app.py 1
7 | start python ../src/net.py 1
8 | start ../bin/phy.exe 1 PHY 0
9 | @REM ------------------------------ Host 2
10 | start python ../src/app.py 2
11 | start python ../src/net.py 2
12 | start ../bin/phy.exe 2 PHY 0
13 | @REM ------------------------------ Switch 3
14 | start python ../src/switch.py 3
15 | start ../bin/phy.exe 3 PHY 0
16 | start ../bin/phy.exe 3 PHY 1
17 | start ../bin/phy.exe 3 PHY 2
18 | @REM ------------------------------ Host 4
19 | start python ../src/app.py 4
20 | start python ../src/net.py 4
21 | start ../bin/phy.exe 4 PHY 0
22 | @REM ------------------------------ Switch 5
23 | start python ../src/switch.py 5
24 | start ../bin/phy.exe 5 PHY 0
25 | start ../bin/phy.exe 5 PHY 1
26 | @REM ------------------------------ Router 6
27 | start python ../src/router.py 6
28 | start ../bin/phy.exe 6 PHY 0
29 | start ../bin/phy.exe 6 PHY 1
30 | start ../bin/phy.exe 6 PHY 2
31 | @REM ------------------------------ Host 7
32 | start python ../src/app.py 7
33 | start python ../src/net.py 7
34 | start ../bin/phy.exe 7 PHY 0
35 | @REM ------------------------------ Router 8
36 | start python ../src/router.py 8
37 | start ../bin/phy.exe 8 PHY 0
38 | start ../bin/phy.exe 8 PHY 1
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/batch.bat:
--------------------------------------------------------------------------------
1 | @REM ------------------------------ cd to /config
2 | cd %~dp0
3 | @REM ------------------------------ CMD
4 | start python ../src/cmd.py
5 | @REM ------------------------------ Host 1
6 | start python ../src/app.py 1
7 | start python ../src/net.py 1
8 | start ../bin/phy.exe 1 PHY 0
9 | @REM ------------------------------ Host 2
10 | start python ../src/app.py 2
11 | start python ../src/net.py 2
12 | start ../bin/phy.exe 2 PHY 0
13 | @REM ------------------------------ Switch 3
14 | start python ../src/switch.py 3
15 | start ../bin/phy.exe 3 PHY 0
16 | start ../bin/phy.exe 3 PHY 1
17 | start ../bin/phy.exe 3 PHY 2
18 | @REM ------------------------------ Host 4
19 | start python ../src/app.py 4
20 | start python ../src/net.py 4
21 | start ../bin/phy.exe 4 PHY 0
22 | @REM ------------------------------ Switch 5
23 | start python ../src/switch.py 5
24 | start ../bin/phy.exe 5 PHY 0
25 | start ../bin/phy.exe 5 PHY 1
26 | @REM ------------------------------ Router 6
27 | start python ../src/router.py 6
28 | start ../bin/phy.exe 6 PHY 0
29 | start ../bin/phy.exe 6 PHY 1
30 | start ../bin/phy.exe 6 PHY 2
31 | @REM ------------------------------ Host 7
32 | start python ../src/app.py 7
33 | start python ../src/net.py 7
34 | start ../bin/phy.exe 7 PHY 0
35 | @REM ------------------------------ Router 8
36 | start python ../src/router.py 8
37 | start ../bin/phy.exe 8 PHY 0
38 | start ../bin/phy.exe 8 PHY 1
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/devicemap-backup/2.json:
--------------------------------------------------------------------------------
1 | {
2 | "host": [
3 | "1",
4 | "2"
5 | ]
6 | }
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/devicemap-backup/3.json:
--------------------------------------------------------------------------------
1 | {
2 | "switch": {
3 | "4": {
4 | "phynum": 3
5 | }
6 | },
7 | "host": [
8 | "1",
9 | "2",
10 | "3"
11 | ]
12 | }
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/devicemap-backup/4.json:
--------------------------------------------------------------------------------
1 | {
2 | "router": {
3 | "6": {
4 | "LAN": {
5 | "1": "16100",
6 | "2": "16100",
7 | "4": "16101"
8 | },
9 | "WAN": {
10 | "8": {
11 | "exit": "16102",
12 | "cost": 1
13 | }
14 | }
15 | },
16 | "8": {
17 | "LAN": {
18 | "7": "18100"
19 | },
20 | "WAN": {
21 | "6": {
22 | "exit": "18101",
23 | "cost": 1
24 | }
25 | }
26 | }
27 | },
28 | "switch": {
29 | "3": {
30 | "phynum": 3
31 | },
32 | "5": {
33 | "phynum": 2
34 | }
35 | },
36 | "host": [
37 | "1",
38 | "2",
39 | "4",
40 | "7"
41 | ]
42 | }
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/devicemap.json:
--------------------------------------------------------------------------------
1 | {
2 | "router": {
3 | "6": {
4 | "LAN": {
5 | "1": "16100",
6 | "2": "16100",
7 | "4": "16101"
8 | },
9 | "WAN": {
10 | "8": {
11 | "exit": "16102",
12 | "cost": 1
13 | }
14 | }
15 | },
16 | "8": {
17 | "LAN": {
18 | "7": "18100"
19 | },
20 | "WAN": {
21 | "6": {
22 | "exit": "18101",
23 | "cost": 1
24 | }
25 | }
26 | }
27 | },
28 | "switch": {
29 | "3": {
30 | "phynum": 3
31 | },
32 | "5": {
33 | "phynum": 2
34 | }
35 | },
36 | "host": [
37 | "1",
38 | "2",
39 | "4",
40 | "7"
41 | ]
42 | }
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/ne-backup/2.txt:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------
2 | 1 PHY0 NET0 APP0
3 | 2 PHY0 NET0 APP0
4 | ---------------------------------------------------------
5 | 1,0--2,0
6 | ---------------------------------------------------------
7 | errorProb = 0
8 | bufferSize = 1500
9 | ---------------------------------------------------------
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/ne-backup/3.txt:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------
2 | 1 PHY0 NET0 APP0
3 | 2 PHY0 NET0 APP0
4 | 3 PHY0 NET0 APP0
5 | 4 PHY0 NET0
6 | PHY1
7 | PHY2
8 | ---------------------------------------------------------
9 | 1,0--4,0
10 | 2,0--4,1
11 | 3,0--4,2
12 | ---------------------------------------------------------
13 | errorProb = 0
14 | bufferSize = 1500
15 | ---------------------------------------------------------
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/ne-backup/4.txt:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------
2 | 1 PHY0 NET0 APP0
3 | 2 PHY0 NET0 APP0
4 | 3 PHY0 NET0
5 | PHY1
6 | PHY2
7 | 4 PHY0 NET0 APP0
8 | 5 PHY0 NET0
9 | PHY1
10 | 6 PHY0 NET0
11 | PHY1
12 | PHY2
13 | 7 PHY0 NET0 APP0
14 | 8 PHY0 NET0
15 | PHY1
16 | ---------------------------------------------------------
17 | 1,0--3,0
18 | 2,0--3,1
19 | 3,2--6,0
20 | 4,0--5,0
21 | 5,1--6,1
22 | 6,2--8,1
23 | 7,0--8,0
24 | ---------------------------------------------------------
25 | errorProb = 0
26 | bufferSize = 1500
27 | ---------------------------------------------------------
--------------------------------------------------------------------------------
/Project1-MinNE-python/config/ne.txt:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------
2 | 1 PHY0 NET0 APP0
3 | 2 PHY0 NET0 APP0
4 | 3 PHY0 NET0
5 | PHY1
6 | PHY2
7 | 4 PHY0 NET0 APP0
8 | 5 PHY0 NET0
9 | PHY1
10 | 6 PHY0 NET0
11 | PHY1
12 | PHY2
13 | 7 PHY0 NET0 APP0
14 | 8 PHY0 NET0
15 | PHY1
16 | ---------------------------------------------------------
17 | 1,0--3,0
18 | 2,0--3,1
19 | 3,2--6,0
20 | 4,0--5,0
21 | 5,1--6,1
22 | 6,2--8,1
23 | 7,0--8,0
24 | ---------------------------------------------------------
25 | errorProb = 0
26 | bufferSize = 1500
27 | ---------------------------------------------------------
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/coding-pic.drawio:
--------------------------------------------------------------------------------
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 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/coding-unicode.drawio:
--------------------------------------------------------------------------------
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 |
74 |
75 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/frame-uml.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/frame.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/layer-inheritance.drawio:
--------------------------------------------------------------------------------
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 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/ne-layer.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/topology-2.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/topology-3.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/design/topology-4-0.drawio:
--------------------------------------------------------------------------------
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 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/ber-speed.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | import matplotlib.pyplot as plt
4 | import numpy as np
5 | from numpy.core.fromnumeric import mean
6 |
7 | plt.style.use(["fast"])
8 |
9 | ber = np.linspace(0, 1, 11)
10 |
11 | send_speed_uni = [
12 | 1299.8999999999999,
13 | 1025.2666666666667,
14 | 645.2666666666668,
15 | 653.5666666666666,
16 | 893.1333333333333,
17 | 777.5,
18 | 381.0,
19 | 476.63333333333327,
20 | 372.5333333333333,
21 | 418.9666666666667,
22 | 310.06666666666666,
23 | ]
24 | recv_speed_uni = [
25 | 1510.2333333333336,
26 | 1163.2333333333333,
27 | 1141.9666666666667,
28 | 1062.2,
29 | 1084.3666666666668,
30 | 869.4666666666667,
31 | 414.93333333333334,
32 | 603.8333333333333,
33 | 428.06666666666666,
34 | 502.2333333333333,
35 | 354.1333333333334,
36 | ]
37 |
38 | with open("log/1.log", "r", encoding="utf-8") as fr:
39 | send_speed_bro = np.array(
40 | [float(speed) for speed in re.findall(r": (.*?)bps", fr.read())]
41 | )
42 | send_speed_bro = [
43 | mean(send_speed_bro[i : i + 3]) for i in range(0, len(send_speed_bro), 3)
44 | ]
45 | print(send_speed_bro)
46 |
47 | with open("log/2.log", "r", encoding="utf-8") as fr:
48 | recv_speed_bro = np.array(
49 | [float(speed) for speed in re.findall(r": (.*?)bps", fr.read())]
50 | )
51 | recv_speed_bro = [
52 | mean(recv_speed_bro[i : i + 3]) for i in range(0, len(recv_speed_bro), 3)
53 | ]
54 | print(recv_speed_bro)
55 |
56 | fig, axes = plt.subplots(1, 2, sharex=True)
57 |
58 | plt.subplot(1, 2, 1)
59 | plt.title("Unicast")
60 | plt.xlim(0, 1)
61 | plt.ylim(0, 3000)
62 | plt.plot(ber, send_speed_uni, label="Send")
63 | plt.plot(ber, recv_speed_uni, label="Receive")
64 | plt.legend()
65 | plt.grid()
66 |
67 | plt.subplot(1, 2, 2)
68 | plt.title("Broadcast")
69 | plt.xlim(0, 1)
70 | plt.ylim(0, 3000)
71 | plt.plot(ber, send_speed_bro, label="Send")
72 | plt.plot(ber, recv_speed_bro, label="Receive")
73 | plt.legend()
74 | plt.grid()
75 |
76 | fig.add_subplot(111, frameon=False)
77 | plt.tick_params(labelcolor="none", top=False, bottom=False, left=False, right=False)
78 | plt.suptitle("BER's Impact on Throughput")
79 | plt.xlabel("Bit Error Rate (%)")
80 | plt.ylabel("Speed (bps)")
81 | plt.show()
82 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/batchfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/batchfile.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/cmd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/cmd.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/coding-pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/coding-pic.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/coding-unicode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/coding-unicode.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/frame-uml.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/frame-uml.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/frame.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/frame.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/layer-inheritance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/layer-inheritance.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/ne-layer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/ne-layer.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/ne.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/ne.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/redundancy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/redundancy.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-1-1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-1-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-2-1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-2-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-2-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-3.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-4-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-4-1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-4-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-4-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage2-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage2-5.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage3-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage3-1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage3-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage3-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage3-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage3-3.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage3-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage3-4.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-1-1.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-1-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-1-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-1-3.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-1-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-1-4.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-1-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-1-5.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-3.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/stage4-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/stage4-4.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/topology-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/topology-2.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/topology-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/topology-3.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/topology-4-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/topology-4-0.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/images/topology-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/images/topology-4.png
--------------------------------------------------------------------------------
/Project1-MinNE-python/report/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project1-MinNE-python/report/report.pdf
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/app.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from layer import AppLayer
4 | from utils import *
5 |
6 | if __name__ == "__main__":
7 | # 解析参数。
8 | if len(sys.argv) != 2:
9 | print("[Error] Device ID expected")
10 | exit(-1)
11 |
12 | # 创建主机应用层。
13 | device_id = sys.argv[1]
14 | app = AppLayer(device_id)
15 | print(app)
16 |
17 | # 开始运作。
18 | while True:
19 | # 持续等待,直到有消息可读。
20 | if not app.readable:
21 | continue
22 | first_message, is_from_cmd = app.receive_all()
23 |
24 | # 如果消息来自控制台,说明本机成为发送端。
25 | if is_from_cmd:
26 | # 解析控制台传来的数据。
27 | data: dict = eval(first_message)
28 | if data["dst"] == Topology.BROADCAST_PORT:
29 | print("[Broadcast]", end=" ")
30 | else:
31 | print(f"[Unicast to {data['dst'][1]}]", end=" ")
32 | text = data.pop("text")
33 | file = data.pop("file")
34 | # 如果消息类型是文本。
35 | if data["msgtype"] == MessageType.TEXT:
36 | print(text)
37 | data["message"] = encode_unicode(text)
38 | # 如果消息类型是图片。
39 | else:
40 | print(file)
41 | data["message"] = encode_file(file)
42 | # 发送给本机网络层。
43 | app.send_to_net(str(data))
44 |
45 | # 如果消息来自本机网络层,说明本机成为接收端。
46 | else:
47 | # 解析本机网络层传来的数据。
48 | data: dict = eval(first_message)
49 | print(f"[Receive from {data['src'][1]}]", end=" ")
50 | # 如果消息类型是文本。
51 | if data["msgtype"] == MessageType.TEXT:
52 | text = decode_unicode(data["message"])
53 | print(text)
54 | # 如果消息类型是文件。
55 | else:
56 | # 如果解码失败。
57 | file, decoded = decode_file(data["message"])
58 | if not decoded:
59 | print("File decoding failed")
60 | continue
61 | # 如果保存失败。
62 | filepath, saved = save_rsc(file)
63 | if not saved:
64 | print("File saving failed")
65 | else:
66 | print(filepath)
67 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/cmd.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from PyQt5.QtWidgets import QApplication
4 |
5 | from layer import CommandLayer
6 |
7 | if __name__ == "__main__":
8 | cmd_app = QApplication(sys.argv)
9 | cmd = CommandLayer()
10 | print(cmd)
11 |
12 | cmd.show()
13 | sys.exit(cmd_app.exec_())
14 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/interface/__init__.py:
--------------------------------------------------------------------------------
1 | from interface.cmd import CommandUI
2 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/interface/cmd.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 300
10 | 210
11 |
12 |
13 |
14 |
15 | Microsoft YaHei UI
16 | 12
17 |
18 |
19 |
20 | MainWindow
21 |
22 |
23 |
24 |
25 |
26 | 10
27 | 40
28 | 281
29 | 41
30 |
31 |
32 |
33 | -
34 |
35 |
36 |
37 | Microsoft YaHei UI
38 | 10
39 |
40 |
41 |
42 | 源
43 |
44 |
45 | Qt::AlignCenter
46 |
47 |
48 | src_combo
49 |
50 |
51 |
52 | -
53 |
54 |
55 | -
56 |
57 |
58 |
59 | Microsoft YaHei UI
60 | 10
61 |
62 |
63 |
64 | 目的
65 |
66 |
67 | Qt::AlignCenter
68 |
69 |
70 | dst_combo
71 |
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | 140
83 | 0
84 | 151
85 | 41
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 | 0
94 | 0
95 |
96 |
97 |
98 |
99 | Microsoft YaHei UI
100 | 10
101 |
102 |
103 |
104 | 单播
105 |
106 |
107 |
108 | -
109 |
110 |
111 |
112 | Microsoft YaHei UI
113 | 10
114 |
115 |
116 |
117 | 广播
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 | 10
127 | 160
128 | 281
129 | 36
130 |
131 |
132 |
133 |
134 | Microsoft YaHei UI
135 | 10
136 |
137 |
138 |
139 | 发送
140 |
141 |
142 |
143 |
144 |
145 | 10
146 | 0
147 | 131
148 | 41
149 |
150 |
151 |
152 |
153 | Microsoft YaHei UI
154 | 12
155 | 75
156 | true
157 |
158 |
159 |
160 | 💻 控制台
161 |
162 |
163 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
164 |
165 |
166 |
167 |
168 |
169 | 80
170 | 84
171 | 210
172 | 33
173 |
174 |
175 |
176 |
177 | 210
178 | 0
179 |
180 |
181 |
182 |
183 | 210
184 | 16777215
185 |
186 |
187 |
188 |
189 |
190 |
191 | 80
192 | 124
193 | 210
194 | 32
195 |
196 |
197 |
198 |
199 | 210
200 | 0
201 |
202 |
203 |
204 |
205 | Microsoft YaHei UI
206 | 10
207 |
208 |
209 |
210 | 选择文件
211 |
212 |
213 |
214 |
215 |
216 | 10
217 | 80
218 | 63
219 | 81
220 |
221 |
222 |
223 | -
224 |
225 |
226 |
227 | Microsoft YaHei UI
228 | 10
229 |
230 |
231 |
232 | 文本
233 |
234 |
235 |
236 | -
237 |
238 |
239 |
240 | Microsoft YaHei UI
241 | 10
242 |
243 |
244 |
245 | 图片
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 | unicast_radio
255 | broadcast_radio
256 | src_combo
257 | dst_combo
258 | text_radio
259 | text_edit
260 | file_radio
261 | file_btn
262 | send_btn
263 |
264 |
265 |
266 |
267 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/__init__.py:
--------------------------------------------------------------------------------
1 | from layer.app import AppLayer
2 | from layer.cmd import CommandLayer
3 | from layer.net import NetLayer
4 | from layer.router import RouterLayer
5 | from layer.switch import SwitchLayer
6 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/_abstract.py:
--------------------------------------------------------------------------------
1 | import socket
2 | from select import select
3 |
4 | from utils.params import Network
5 |
6 |
7 | class AbstractLayer:
8 | """各网元层的抽象工厂。
9 |
10 | 实现了套接字相关的基本功能。
11 | """
12 |
13 | def __init__(self, port: str) -> None:
14 | """初始化抽象层。
15 |
16 | 创建绑定在指定端口的套接字,并设置默认超时时间。
17 |
18 | Args:
19 | port: 套接字要绑定的端口。
20 | """
21 | self.__socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
22 |
23 | try:
24 | self.__socket.bind(("127.0.0.1", int(port)))
25 | except OSError:
26 | print(f"[Error] Port {port} is currently occupied.")
27 | exit(-1)
28 |
29 | self.__socket.settimeout(Network.USER_TIMEOUT)
30 |
31 | def _receive(
32 | self,
33 | bufsize: int = Network.INTER_NE_BUFSIZE,
34 | timeout: int = Network.USER_TIMEOUT,
35 | ) -> tuple[str, str, bool]:
36 | """接收数据。
37 |
38 | 使用指定大小的缓存区,在指定超时时间内,接收发到本套接字的数据。
39 |
40 | Args:
41 | bufsize: 可选,缓存区大小,单位为位;默认为 `INTER_NE_BUFSIZE`。
42 | timeout: 可选,超时时间,单位为秒;默认为 `USER_TIMEOUT`。
43 |
44 | Returns:
45 | - [0] 接收到的数据。
46 | - [1] 发来该数据的地址的端口号。
47 | - [2] 接收成功为 `True`,接收超时为 `False`。
48 | """
49 | timeout_assigned = timeout != Network.USER_TIMEOUT
50 |
51 | # 如果指定了超时时间,就在发送前设置。
52 | if timeout_assigned:
53 | self.__socket.settimeout(timeout)
54 |
55 | result = ("", "", False)
56 | # 尝试接收数据。
57 | try:
58 | data, (_, port) = self.__socket.recvfrom(bufsize)
59 | # 如果接收超时,不进行异常处理。
60 | except socket.timeout:
61 | pass
62 | # 如果接收成功,则将接收到的 `bytes` 转码为 `str`。
63 | else:
64 | result = (data.decode("utf-8"), str(port), True)
65 | # 不管超不超时,都要恢复默认超时值。
66 | finally:
67 | if timeout_assigned:
68 | self.__socket.settimeout(Network.USER_TIMEOUT)
69 | return result
70 |
71 | def _send(self, data: str, port: str) -> int:
72 | """向指定地址发送数据。
73 |
74 | Args:
75 | data: 要发送的数据。
76 | port: 指定地址的端口号。
77 |
78 | Returns:
79 | 总共发送的字节数。
80 | """
81 | return self.__socket.sendto(data.encode("utf-8"), ("127.0.0.1", int(port)))
82 |
83 | @property
84 | def readable(self) -> bool:
85 | """检测是否有消息发到本层。
86 |
87 | 使用 `select()` 方法检测本层套接字可读性。
88 |
89 | Returns:
90 | 可读为 `True`,不可读为 `False`。
91 | """
92 | ready_sockets, _, _ = select([self.__socket], [], [], Network.SELECT_TIMEOUT)
93 | return len(ready_sockets) != 0
94 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/app.py:
--------------------------------------------------------------------------------
1 | from utils.params import *
2 |
3 | from layer._abstract import AbstractLayer
4 |
5 |
6 | class AppLayer(AbstractLayer):
7 | """主机应用层。
8 |
9 | 实现了控制台 -> 主机应用层 <-> 主机网络层的消息收发。
10 | """
11 |
12 | def __init__(self, device_id: str) -> None:
13 | """初始化主机应用层。
14 |
15 | Args:
16 | device_id: 该主机的设备号。
17 | """
18 | self.__device_id = device_id
19 | self.__port = f"1{device_id}300"
20 | self.__net = f"1{device_id}200"
21 | super().__init__(self.__port)
22 |
23 | def __str__(self) -> str:
24 | """打印设备号与端口号。"""
25 | return f"[Device {self.__device_id}] \n{'-'*30}"
26 |
27 | def receive_all(self) -> tuple[str, bool]:
28 | """接收来自控制台与本机网络层的消息。
29 |
30 | Returns:
31 | - [0] 接收到的消息。
32 | - [1] 控制台发来为 `True`,本机网络层发来为 `False`。
33 | """
34 | while True:
35 | message, port, _ = self._receive(bufsize=Network.IN_NE_BUFSIZE)
36 | if port == Topology.CMD_PORT:
37 | return message, True
38 | elif port == self.__net:
39 | return message, False
40 | else:
41 | continue
42 |
43 | def receive_from_cmd(self) -> str:
44 | """接收来自控制台的消息。
45 |
46 | Returns:
47 | 接收到的消息。
48 | """
49 | port = ""
50 | while port != Topology.CMD_PORT:
51 | message, port, _ = self._receive(bufsize=Network.IN_NE_BUFSIZE)
52 | return message
53 |
54 | def receive_from_net(self) -> str:
55 | """接收来自本机网络层的消息。
56 |
57 | Returns:
58 | 接收到的消息。
59 | """
60 | port = ""
61 | while port != self.__net:
62 | message, port, _ = self._receive(bufsize=Network.IN_NE_BUFSIZE)
63 | return message
64 |
65 | def send_to_net(self, message: str) -> int:
66 | """向本机网络层发送消息。
67 |
68 | Args:
69 | message: 要发送的消息。
70 |
71 | Returns:
72 | 总共发送的字节数。
73 | """
74 | return self._send(message, self.__net)
75 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/cmd.py:
--------------------------------------------------------------------------------
1 | from interface.cmd import CommandUI
2 | from utils.params import *
3 |
4 | from layer._abstract import AbstractLayer
5 |
6 |
7 | class CommandLayer(AbstractLayer, CommandUI):
8 | """控制台。
9 |
10 | 实现了 GUI -> 控制台 -> 主机应用层的消息发送。
11 | """
12 |
13 | def __init__(self) -> None:
14 | """初始化控制台。"""
15 | AbstractLayer.__init__(self, Topology.CMD_PORT)
16 | CommandUI.__init__(self)
17 |
18 | def __str__(self) -> str:
19 | """打印端口号。"""
20 | return f"[CMD] \n{'-'*30}"
21 |
22 | def _onclick_send_btn(self) -> None:
23 | """发送按钮点击事件。
24 |
25 | 重载 GUI 类的点击事件,将 GUI 打包的用户数据发送到源主机应用层。
26 | """
27 | super()._onclick_send_btn()
28 | src = self._user_data.pop("src")
29 | self._send(str(self._user_data), src)
30 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/net.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 |
3 | from utils.coding import *
4 | from utils.frame import *
5 | from utils.params import *
6 |
7 | from layer._abstract import AbstractLayer
8 |
9 |
10 | class NetLayer(AbstractLayer):
11 | """主机网络层。
12 |
13 | 实现了主机应用层 <-> 主机网络层 <-> 主机物理层的消息收发。
14 | """
15 |
16 | def __init__(self, device_id: str) -> None:
17 | """初始化主机网络层。
18 |
19 | Args:
20 | device_id: 该主机的设备号。
21 | """
22 | self.__device_id = device_id
23 | self.__app = f"1{device_id}300"
24 | self.__port = f"1{device_id}200"
25 | self.__phy = f"1{device_id}100"
26 | super().__init__(self.__port)
27 |
28 | self.__normal_builder = FrameBuilder()
29 | self.__normal_builder.build(
30 | src=self.__app,
31 | reply_state=ReplyState.ACK,
32 | )
33 | self.__reply_builder = FrameBuilder()
34 | self.__reply_builder.build(
35 | src=self.__app,
36 | session_state=SessionState.NORMAL,
37 | data="",
38 | )
39 | self.__parser = FrameParser()
40 |
41 | def __str__(self) -> str:
42 | """打印设备号与端口号。"""
43 | return f"[Device {self.__device_id}] \n{'-'*30}"
44 |
45 | def receive_all(self) -> tuple[str, bool]:
46 | """接收来自本机应用层与本机物理层的消息。
47 |
48 | Returns:
49 | - [0] 接收到的消息。
50 | - [1] 本机应用层发来为 `True`,本机物理层发来为 `False`。
51 | """
52 | while True:
53 | message, port, _ = self._receive(bufsize=Network.IN_NE_BUFSIZE)
54 | if port == self.__app:
55 | return message, True
56 | elif port == self.__phy:
57 | return bits_to_string(message), False
58 | else:
59 | continue
60 |
61 | def receive_from_app(self) -> str:
62 | """接收来自本机应用层的消息。
63 |
64 | Returns:
65 | 接收到的消息。
66 | """
67 | port = ""
68 | while port != self.__app:
69 | message, port, _ = self._receive(bufsize=Network.IN_NE_BUFSIZE)
70 | return message
71 |
72 | def receive_from_phy(self, timeout: int = Network.RECV_TIMEOUT) -> tuple[str, bool]:
73 | """接收来自本机物理层的消息。
74 |
75 | Args:
76 | timeout: 可选,接收超时时间,单位为秒,默认为 `RECV_TIMEOUT`。
77 |
78 | Returns:
79 | - [0] 接收到的消息。
80 | - [1] 接收成功为 `True`,接收超时为 `False`。
81 | """
82 | binary, _, success = self._receive(timeout=timeout)
83 | binary = bits_to_string(binary) if success else binary
84 | return binary, success
85 |
86 | def send_to_app(self, message: str) -> int:
87 | """向本机应用层发送消息。
88 |
89 | Args:
90 | message: 要发送的消息。
91 |
92 | Returns:
93 | 总共发送的字节数。
94 | """
95 | return self._send(message, self.__app)
96 |
97 | def send_to_phy(self, binary: str) -> int:
98 | """向本机物理层发送消息。
99 |
100 | Args:
101 | binary: 要发送的消息。
102 |
103 | Returns:
104 | 总共发送的字节数。
105 | """
106 | # 流量控制。
107 | sleep(Network.FLOW_INTERVAL)
108 | return self._send(string_to_bits(binary), self.__phy)
109 |
110 | def should_receive(self, port: str) -> bool:
111 | """判断本层是否应该接收某帧。
112 |
113 | Args:
114 | 发来的帧的目的端口号。
115 |
116 | Returns:
117 | 应该接收为 `True`,不应该接收为 `False`。
118 | """
119 | return port in (self.__app, Topology.BROADCAST_PORT)
120 |
121 | def build_pool(self, app_data: dict) -> list[Frame]:
122 | """将消息打包为帧。
123 |
124 | Args:
125 | app_data: 本机应用层传来的消息数据。
126 |
127 | Returns:
128 | 打包的帧列表。
129 | """
130 | message = app_data["message"]
131 | frame_num = Frame.calc_num(message)
132 |
133 | # 第一帧是请求帧。
134 | request_frame = self.__normal_builder.build(
135 | session_state=SessionState.REQ_TXT
136 | if app_data["msgtype"] == MessageType.TEXT
137 | else SessionState.REQ_IMG,
138 | dst=app_data["dst"],
139 | )
140 | frame_pool = [request_frame]
141 |
142 | # 中间的帧是常规帧。
143 | frame_pool.extend(
144 | [
145 | self.__normal_builder.build(
146 | session_state=SessionState.NORMAL,
147 | data=message[
148 | i * FrameParam.DATA_LEN : (i + 1) * FrameParam.DATA_LEN
149 | ],
150 | )
151 | for i in range(frame_num - 1)
152 | ]
153 | )
154 |
155 | # 最后一帧是结束帧。
156 | final_frame = self.__normal_builder.build(
157 | session_state=SessionState.FIN,
158 | data=message[(frame_num - 1) * FrameParam.DATA_LEN :],
159 | )
160 | frame_pool.append(final_frame)
161 |
162 | return frame_pool
163 |
164 | def build_ack(self, dst: str) -> Frame:
165 | """生成 ACK 帧。
166 |
167 | Args:
168 | dst: ACK 的目的地,即原消息的源。
169 |
170 | Returns:
171 | 生成的 ACK 帧。
172 | """
173 | return self.__reply_builder.build(reply_state=ReplyState.ACK, dst=dst)
174 |
175 | def build_nak(self, dst: str) -> Frame:
176 | """生成 NAK 帧。
177 |
178 | Args:
179 | dst: NAK 的目的地,即原消息的源。
180 |
181 | Returns:
182 | 生成的 NAK 帧。
183 | """
184 | return self.__reply_builder.build(reply_state=ReplyState.NAK, dst=dst)
185 |
186 | def parse_reply(self, binary: str) -> bool:
187 | """解析回复。
188 |
189 | Args:
190 | binary: 含有回复的 01 字符串。
191 |
192 | Returns:
193 | ACK 为 `True`,NAK 为 `False`。
194 | """
195 | response = self.__parser.parse(binary)
196 | return True if response.reply_state == ReplyState.ACK else False
197 |
198 | def parse_message(self, binary: str) -> Frame:
199 | """解析消息。
200 |
201 | Args:
202 | binary: 含有消息的 01 字符串。
203 |
204 | Returns:
205 | 收到的消息帧。
206 | """
207 | return self.__parser.parse(binary)
208 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/layer/switch.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | from utils.coding import bits_to_string, string_to_bits
4 | from utils.io import get_switch_config
5 | from utils.params import *
6 |
7 | from layer._abstract import AbstractLayer
8 |
9 |
10 | class SwitchTable:
11 | """端口地址表。
12 |
13 | - 键:本地物理层端口号。
14 | - 值:远程端口状态。
15 | - 键:远程应用层端口号。
16 | - 值:该远程端口号在表内的剩余寿命。
17 |
18 | 实现了单播、广播、学习、清除。
19 | """
20 |
21 | def __init__(self) -> None:
22 | """初始化内部字典。"""
23 | self._table = defaultdict(dict[str, int])
24 |
25 | def __str__(self) -> None:
26 | """打印端口地址表。"""
27 | head = f"{'-'*24}\n|{' '*7}|{'Remote'.center(14)}|\n|{'Local'.center(7)}|{'-'*14}|\n|{' '*7}|{'Port'.center(7)}|{'Life'.center(6)}|"
28 | body = "\n".join(
29 | filter(
30 | None,
31 | [
32 | "|----------------------|\n"
33 | + "\n".join(
34 | [
35 | f"|{local.center(7)}|{port.center(7)}|{str(life).center(6)}|"
36 | for port, life in remotes.items()
37 | ]
38 | )
39 | if len(remotes.items()) != 0
40 | else None
41 | for local, remotes in self._table.items()
42 | ],
43 | )
44 | )
45 | return f"{head}\n{body}\n{'-'*24}"
46 |
47 | def update(self, local: str, remote: str) -> bool:
48 | """更新端口地址表。
49 |
50 | Args:
51 | local: 当前激活的本地端口。
52 | remote: 当前激活的远程端口。
53 |
54 | Returns:
55 | 端口地址表是否有更新,有更新为 `True`,没有更新为 `False`。
56 | """
57 | updated = False
58 |
59 | # 查询是否有该关系,没有就会迎来更新。
60 | if remote not in self._table[local].keys():
61 | updated = True
62 |
63 | # 不管之前有没有这对关系,它们的寿命都要重置为最大值+1。(后面的遍历会扣回最大值。)
64 | self._table[local].update({remote: Network.REMOTE_MAX_LIFE + 1})
65 |
66 | # 所有远程端口寿命-1。
67 | for remotes in self._table.values():
68 | for port, life in remotes.copy().items():
69 | life -= 1
70 | if life == 0:
71 | remotes.pop(port)
72 | updated = True
73 | else:
74 | remotes.update({port: life})
75 |
76 | return updated
77 |
78 | def search_locals(self, remote: str) -> list[str]:
79 | """在端口地址表中查找本地端口号。
80 |
81 | Args:
82 | remote: 某一远程应用层的端口号。
83 |
84 | Returns:
85 | 对应的本地物理层端口号列表。
86 | """
87 | return list(
88 | filter(
89 | lambda local: remote in self._table[local].keys(),
90 | self._table.keys(),
91 | )
92 | )
93 |
94 | def search_remotes(self, local: str) -> list[str]:
95 | """在端口地址表中查找远程端口号。
96 |
97 | Args:
98 | local: 某一本地物理层的端口号。
99 |
100 | Returns:
101 | 对应的远程应用层端口号列表。
102 | """
103 | return list(self._table.get(local, {}).keys())
104 |
105 |
106 | class SwitchLayer(AbstractLayer, SwitchTable):
107 | """交换机网络层。
108 |
109 | 实现的消息收发: 交换机网络层 -> 交换机物理层。(单播、广播)
110 | """
111 |
112 | def __init__(self, device_id: str) -> None:
113 | """初始化交换机网络层。
114 |
115 | Args:
116 | device_id: 该交换机的设备号。
117 | """
118 | # 初始化套接字。
119 | self.__device_id = device_id
120 | self.__port = f"1{device_id}200"
121 | self.__phys = [
122 | f"1{device_id}10{i}" for i in range(get_switch_config(device_id))
123 | ]
124 | AbstractLayer.__init__(self, self.__port)
125 |
126 | # 初始化端口地址表。
127 | SwitchTable.__init__(self)
128 | self._table.update(
129 | dict([phy, {Topology.BROADCAST_PORT: float("inf")}] for phy in self.__phys)
130 | )
131 |
132 | def __str__(self) -> str:
133 | """打印设备号与端口号。"""
134 | return f"[Device {self.__device_id}] \n{'-'*30}"
135 |
136 | def receive_from_phys(self) -> tuple[str, str]:
137 | """接收来自本机物理层的消息。
138 |
139 | Returns:
140 | - [0] 接收到的消息。
141 | - [1] 发来消息的本地物理层端口。
142 | """
143 | binary, port, success = self._receive()
144 | binary = bits_to_string(binary) if success else binary
145 | return binary, port
146 |
147 | def unicast_to_phy(self, binary: str, port: str) -> int:
148 | """向本机指定物理层单播消息。
149 |
150 | Args:
151 | binary: 要发送的消息。
152 | port: 信息要送到的本地物理层端口。
153 |
154 | Returns:
155 | 总共发送的字节数。
156 | """
157 | return self._send(string_to_bits(binary), port)
158 |
159 | def broadcast_to_phys(self, binary: str, port: str) -> str:
160 | """向所有物理层广播消息,除了指定的端口。
161 |
162 | 指定的端口一般是当次发来消息的端口。
163 |
164 | Args:
165 | binary: 要发送的消息。
166 | port: 指定的端口号。
167 |
168 | Returns:
169 | 发送到的端口列表字符串。
170 | """
171 | target_phys = list(filter(lambda phy: phy != port, self.__phys))
172 | for phy in target_phys:
173 | self.unicast_to_phy(binary, phy)
174 | return f"[{' '.join(target_phys)}]"
175 |
176 | def show_table(self) -> None:
177 | """打印端口地址表。"""
178 | print(SwitchTable.__str__(self))
179 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/net.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from time import time
3 |
4 | from layer import NetLayer
5 | from utils import *
6 |
7 | if __name__ == "__main__":
8 | # 解析参数。
9 | if len(sys.argv) != 2:
10 | print("[Error] Device ID expected")
11 | exit(-1)
12 |
13 | # 创建主机网络层。
14 | device_id = sys.argv[1]
15 | net = NetLayer(device_id)
16 | print(net)
17 |
18 | recv_frame = Frame()
19 | resp_frame = Frame()
20 |
21 | # 开始运作。
22 | while True:
23 | # 持续等待,直到有消息可读。
24 | if not net.readable:
25 | continue
26 | first_message, is_from_app = net.receive_all()
27 |
28 | # 如果消息来自本机应用层,说明本机成为发送端。
29 | if is_from_app:
30 | # 逐帧封装。
31 | send_data: dict = eval(first_message)
32 | frame_pool = net.build_pool(send_data)
33 | send_total = len(frame_pool) - 1
34 |
35 | # 逐帧发送。
36 | send_cnt = keepalive_cnt = 0
37 | write_log(device_id, "Send start")
38 | start_tick = time()
39 | while True:
40 | # 向物理层发送消息。
41 | net.send_to_phy(frame_pool[send_cnt].binary)
42 | print(f"{frame_pool[send_cnt]} | Sent, ", end="")
43 |
44 | # 如果是单播,只有接收到 ACK 才发下一帧。
45 | if send_data["dst"] != Topology.BROADCAST_PORT:
46 | resend_flag = True
47 | resp_binary, success = net.receive_from_phy()
48 | # 如果超时,就累加 1 次超时次数。
49 | if not success:
50 | keepalive_cnt += 1
51 | print("Timeout")
52 | # 如果有回复。
53 | else:
54 | # 重置超时次数。
55 | keepalive_cnt = 0
56 | # 解包读取回复。
57 | is_ack = net.parse_reply(resp_binary)
58 | if is_ack:
59 | print("ACK")
60 | resend_flag = False
61 | else:
62 | print("NAK")
63 |
64 | # 如果是广播,只要至少有一次 ACK 就发下一帧,不检查 ACK 数量。
65 | else:
66 | has_at_least_one_response = resend_flag = False
67 | ack_cnt = nak_cnt = 0
68 | # 持续等待回复。
69 | while True:
70 | resp_binary, success = net.receive_from_phy()
71 | # 如果没有回复,说明之后也没有信息会发来了。
72 | # ! 这是一个潜在的bug,有可能回复因为延时没到达。
73 | if not success:
74 | # 如果一次回复都没收到,说明这帧超时,就累加 1 次超时次数。
75 | if not has_at_least_one_response:
76 | keepalive_cnt += 1
77 | resend_flag = True
78 | break
79 |
80 | # 一旦有回复,就重置超时次数。
81 | keepalive_cnt = 0
82 | has_at_least_one_response = True
83 | # 解包读取回复。
84 | is_ack = net.parse_reply(resp_binary)
85 | if is_ack:
86 | ack_cnt += 1
87 | else:
88 | nak_cnt += 1
89 | resend_flag = True
90 | print(f"{ack_cnt} ACK, {nak_cnt} NAK")
91 |
92 | # 如果连续多次超时,就停止重传。
93 | if keepalive_cnt == Network.KEEPALIVE_MAX_RETRY:
94 | print("[Warning] Keepalive max retries")
95 | break
96 | # 如果不必重传,就可以发送下一帧。
97 | if not resend_flag:
98 | send_cnt += 1
99 | # 如果没有下一帧了,就跳出循环。
100 | if send_cnt == send_total + 1:
101 | break
102 |
103 | # 释放这些帧的空间。
104 | del frame_pool
105 |
106 | # 计算网速。
107 | end_tick = time()
108 | speed = 16 * len(send_data["message"]) / (end_tick - start_tick)
109 | write_log(device_id, f"Send finish: {round(speed, 1)}bps")
110 |
111 | # 如果消息来自本机物理层,说明本机成为接收端。
112 | else:
113 | cur_seq, keepalive_cnt = -1, 0
114 | recv_msgtype = recv_message = ""
115 | is_first_recv = True
116 | recv_finish = False
117 | # 持续接收消息。
118 | while True:
119 | # 从物理层接收消息。
120 | if is_first_recv:
121 | recv_binary, success = first_message, True
122 | is_first_recv = False
123 | else:
124 | recv_binary, success = net.receive_from_phy()
125 |
126 | # 如果超时,就累加1次超时次数。
127 | if not success:
128 | keepalive_cnt += 1
129 |
130 | # 如果有消息。
131 | else:
132 | # 重置超时次数。
133 | keepalive_cnt = 0
134 | # 解析接收到的帧。
135 | recv_frame = net.parse_message(recv_binary)
136 |
137 | # 第一帧收到的必须有 REQ 标志,不然就不能接收。
138 | if recv_binary == first_message:
139 | try:
140 | assert recv_frame.session_state in SessionState.REQ_LIST
141 | except AssertionError:
142 | is_first_recv = True
143 | break
144 | else:
145 | start_tick = time()
146 | write_log(device_id, "Recv start")
147 |
148 | # 如果帧不是给自己的,就什么都不做,重新开始等待。
149 | if not net.should_receive(recv_frame.dst):
150 | print(f"{recv_frame} | Not for me")
151 | continue
152 |
153 | # 如果序号重复,就丢弃这帧,再回复一遍 ACK。
154 | if cur_seq == recv_frame.seq:
155 | print(f"{recv_frame} | Repeated")
156 | ack = net.build_ack(dst=recv_frame.src)
157 | net.send_to_phy(ack.binary)
158 | continue
159 |
160 | # 如果校验未通过,就丢弃这帧,回复 NAK。
161 | if not recv_frame.verified:
162 | print(f"{recv_frame} | Invalid")
163 | nak = net.build_nak(dst=recv_frame.src)
164 | net.send_to_phy(nak.binary)
165 | continue
166 |
167 | # 如果帧信息正确,就接收这帧,回复 ACK。
168 | cur_seq = recv_frame.seq
169 | if recv_frame.session_state == SessionState.REQ_TXT:
170 | recv_msgtype = MessageType.TEXT
171 | elif recv_frame.session_state == SessionState.REQ_IMG:
172 | recv_msgtype = MessageType.FILE
173 | elif recv_frame.session_state == SessionState.FIN:
174 | recv_message += recv_frame.data
175 | recv_finish = True
176 | else:
177 | recv_message += recv_frame.data
178 |
179 | print(f"{recv_frame} | Verified")
180 | ack = net.build_ack(dst=recv_frame.src)
181 | net.send_to_phy(ack.binary)
182 |
183 | # 如果超时次数达到 Keepalive 机制上限,就不再接收。
184 | if keepalive_cnt == Network.KEEPALIVE_MAX_RETRY:
185 | print(f"[Warning] Keepalive max retries")
186 | break
187 | # 如果接收结束,就退出循环。
188 | if recv_finish:
189 | break
190 |
191 | # 如果什么都没收到,就继续开始等待双端消息。
192 | if not recv_message:
193 | continue
194 |
195 | # 如果接收到了消息,就将消息传给应用层。
196 | net.send_to_app(
197 | str(
198 | {
199 | "msgtype": recv_msgtype,
200 | "message": recv_message,
201 | "src": recv_frame.src,
202 | }
203 | )
204 | )
205 |
206 | # 计算网速。
207 | end_tick = time()
208 | speed = 16 * len(recv_message) / (end_tick - start_tick)
209 | write_log(device_id, f"Recv finish: {round(speed, 1)}bps")
210 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/router.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from layer import RouterLayer
4 | from utils import *
5 |
6 | if __name__ == "__main__":
7 | # 解析参数。
8 | if len(sys.argv) != 2:
9 | print("[Error] Device ID expected")
10 | exit(-1)
11 |
12 | # 创建路由器网络层。
13 | device_id = sys.argv[1]
14 | router = RouterLayer(device_id)
15 | print(router)
16 |
17 | # 合并其它路由器的路由表。
18 | router.static_merge()
19 | router.show_table()
20 |
21 | # 开始运作。
22 | parser = FrameParser()
23 | while True:
24 | # 持续等待,直到有消息可读。
25 | if not router.readable:
26 | continue
27 | binary, in_port = router.receive_from_phys()
28 | frame = parser.parse(binary)
29 |
30 | print(f"[Log] {frame.src}-{in_port}-", end="")
31 | # 如果是局域网广播帧,就向局域网广播。
32 | if frame.dst == Topology.BROADCAST_PORT:
33 | print(router.broadcast_to_LAN(binary, in_port), end="")
34 |
35 | # 如果是单播帧。
36 | else:
37 | # 寻找本地物理层出口。
38 | exit_port = router.search(frame.dst)
39 | # 如果没找到,说明目的地没有上级路由器,或者不知道给哪个交换机。
40 | if not exit_port:
41 | print("Abandon")
42 | continue
43 | # 如果找到的和发来的是一个端口,就不用再发一遍了。
44 | elif exit_port == in_port:
45 | print("Abandon")
46 | continue
47 | # 如果找到了,就向其单播。
48 | else:
49 | print(exit_port, end="")
50 | router.unicast_to_phy(binary, exit_port)
51 |
52 | print(f"-{frame.dst}")
53 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/routertable-testbench.py:
--------------------------------------------------------------------------------
1 | from layer.router import RouterTable
2 |
3 | for i in range(5):
4 | table = RouterTable(str(i + 1))
5 | table.static_merge()
6 | print(f"Router table {i + 1}")
7 | print(table)
8 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/start.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from utils.io import cover_batch, cover_devicemap, cover_ne, run_batch
4 |
5 | if __name__ == "__main__":
6 | # 读取阶段。
7 | if len(sys.argv) != 2:
8 | print("[Error] Stage required")
9 | exit(-1)
10 | stage = sys.argv[1]
11 |
12 | # 写入阶段配置。
13 | cover_batch(stage)
14 | cover_devicemap(stage)
15 | cover_ne(stage)
16 |
17 | # 运行批处理文件。
18 | run_batch()
19 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/switch.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from layer import SwitchLayer
4 | from utils import *
5 |
6 | if __name__ == "__main__":
7 | # 解析参数。
8 | if len(sys.argv) != 2:
9 | print("[Error] Device ID expected.")
10 | exit(-1)
11 |
12 | # 创建交换机网络层。
13 | device_id = sys.argv[1]
14 | switch = SwitchLayer(device_id)
15 | print(switch)
16 |
17 | # 开始运作。
18 | parser = FrameParser()
19 | while True:
20 | # 持续等待,直到有消息可读。
21 | if not switch.readable:
22 | continue
23 | binary, in_port = switch.receive_from_phys()
24 | frame = parser.parse(binary)
25 |
26 | # 刷新端口地址表。
27 | if switch.update(local=in_port, remote=frame.src):
28 | switch.show_table()
29 |
30 | # 查找应该从哪个端口送出。
31 | out_ports = switch.search_locals(frame.dst)
32 |
33 | print(f"[Log] {frame.src}-{in_port}-", end="")
34 | # 如果查出是单播,就直接向端口发送。
35 | if len(out_ports) == 1:
36 | out_port = out_ports[0]
37 | switch.unicast_to_phy(binary, out_port)
38 | print(out_port, end="")
39 |
40 | # 如果没查到或者是广播,就向所有端口发送。
41 | else:
42 | print(switch.broadcast_to_phys(binary, in_port), end="")
43 |
44 | print(f"-{frame.dst}")
45 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/utils/__init__.py:
--------------------------------------------------------------------------------
1 | from utils.coding import *
2 | from utils.params import *
3 | from utils.frame import *
4 | from utils.io import *
5 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/utils/coding.py:
--------------------------------------------------------------------------------
1 | from base64 import b64decode, b64encode
2 | from re import findall
3 |
4 | BITS_PER_ASCII = 8
5 | BITS_PER_UNICODE = 16
6 |
7 |
8 | def string_to_bits(string: str) -> str:
9 | """将01字符串转换为01比特流。
10 |
11 | Args:
12 | string: 01字符串。
13 |
14 | Returns:
15 | 转换后的01比特流。
16 | """
17 | return "".join(list(map(lambda char: chr(ord(char) - ord("0")), string)))
18 |
19 |
20 | def bits_to_string(bits: str) -> str:
21 | """将01比特流转换为01字符串。
22 |
23 | Args:
24 | bits: 01比特流。
25 |
26 | Returns:
27 | 转换后的01字符串。
28 | """
29 | return "".join(list(map(lambda bit: chr(ord(bit) + ord("0")), bits)))
30 |
31 |
32 | def encode_ascii(ascii: str) -> str:
33 | """将ASCII字符编码为01字符串。
34 |
35 | Args:
36 | ascii: 要编码的ASCII字符。
37 |
38 | Returns:
39 | 编码所得的01字符串。
40 | """
41 | return "".join(
42 | str(bin(ord(char)))[2:].zfill(BITS_PER_ASCII) for char in ascii
43 | )
44 |
45 |
46 | def decode_ascii(binary: str) -> str:
47 | """将01字符串解码为ASCII字符。
48 |
49 | Args:
50 | binary: 要解码的01字符串。
51 |
52 | Returns:
53 | 解码所得的ASCII字符。
54 | """
55 | return "".join(
56 | [
57 | chr(int(char, 2))
58 | for char in findall(f".{{{BITS_PER_ASCII}}}", binary)
59 | ]
60 | )
61 |
62 |
63 | def encode_unicode(unicode: str) -> str:
64 | """将Unicode字符编码为01字符串。
65 |
66 | Args:
67 | unicode: 要编码的Unicode字符。
68 |
69 | Returns:
70 | 编码所得的01字符串。
71 | """
72 | return "".join(
73 | str(bin(ord(char)))[2:].zfill(BITS_PER_UNICODE) for char in unicode
74 | )
75 |
76 |
77 | def decode_unicode(binary: str) -> str:
78 | """将01字符串解码为Unicode字符。
79 |
80 | Args:
81 | binary: 要解码的01字符串。
82 |
83 | Returns:
84 | 解码所得的Unicode字符。
85 | """
86 | return "".join(
87 | [
88 | chr(int(char, 2))
89 | for char in findall(f".{{{BITS_PER_UNICODE}}}", binary)
90 | ]
91 | )
92 |
93 |
94 | def encode_file(filepath: str) -> str:
95 | """将文件编码为01字符串。
96 |
97 | Args:
98 | filename: 要编码的文件的绝对路径。
99 |
100 | Returns:
101 | 编码所得的01字符串。
102 | """
103 | with open(filepath, mode="rb") as fr:
104 | secret = b64encode(fr.read()).decode("utf-8")
105 | return encode_ascii(secret)
106 |
107 |
108 | def decode_file(binary: str) -> tuple[bytes, bool]:
109 | """将01字符串解码为文件。
110 |
111 | Args:
112 | binary: 要解码的01字符串。
113 |
114 | Returns:
115 | - [0] 解码所得的文件的字节串。
116 | - [1] 是否成功解码,成功为`True`,失败为`False`。
117 | """
118 | try:
119 | data = b64decode(decode_ascii(binary).encode("utf-8"))
120 | except Exception:
121 | return b"", False
122 | else:
123 | return data, True
124 |
125 |
126 | if __name__ == "__main__":
127 | message = "Hello"
128 |
129 | message_bits = string_to_bits(message)
130 | message_string = bits_to_string(message_bits)
131 | print(f"{message_bits=}")
132 | print(f"{message_string=}")
133 |
134 | ascii_encoded = encode_ascii(message)
135 | ascii_decoded = decode_ascii(ascii_encoded)
136 | print(f"{ascii_encoded=}")
137 | print(f"{ascii_decoded=}")
138 |
139 | unicode_encoded = encode_unicode(message)
140 | unicode_decoded = decode_unicode(unicode_encoded)
141 | print(f"{unicode_encoded=}")
142 | print(f"{unicode_decoded=}")
143 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/utils/io.py:
--------------------------------------------------------------------------------
1 | import os
2 | from datetime import datetime, timedelta, timezone
3 | from json import loads
4 |
5 | # 各重要目录名。
6 | CONFIG_DIR = "config"
7 | RSC_DIR = "resource"
8 | LOG_DIR = "log"
9 |
10 | # 获取当前目录和上级目录。
11 | cwd = os.getcwd()
12 | cwd_parent = os.path.dirname(cwd)
13 |
14 | # 如果 config 目录在上级目录下,那么根目录是上级目录。
15 | if os.path.exists(os.path.join(cwd_parent, CONFIG_DIR)):
16 | rootdir = cwd_parent
17 |
18 | # 如果 config 目录在当前目录下,那么当前目录为根目录。
19 | elif os.path.exists(os.path.join(cwd, CONFIG_DIR)):
20 | rootdir = cwd
21 |
22 | # 定位 config 目录与配置文件。
23 | config_dir = os.path.join(rootdir, CONFIG_DIR)
24 | batch_dir = os.path.join(config_dir, "batch-backup")
25 | devicemap_dir = os.path.join(config_dir, "devicemap-backup")
26 | ne_dir = os.path.join(config_dir, "ne-backup")
27 |
28 | batch_file = os.path.join(config_dir, "batch.bat")
29 | devicemap_file = os.path.join(config_dir, "devicemap.json")
30 | ne_file = os.path.join(config_dir, "ne.txt")
31 |
32 | # 定位 rsc 目录。
33 | rsc_dir = os.path.join(rootdir, RSC_DIR)
34 | if not os.path.exists(rsc_dir):
35 | os.mkdir(rsc_dir)
36 |
37 | # 定位 log 目录。
38 | log_dir = os.path.join(rootdir, LOG_DIR)
39 | if not os.path.exists(log_dir):
40 | os.mkdir(log_dir)
41 |
42 | # 时区设置。
43 | timezone(timedelta(hours=8))
44 |
45 |
46 | def write_log(device_id: str, message: str) -> None:
47 | """记录日志。
48 |
49 | Args:
50 | device_id: 发起记录请求的设备号。
51 | message: 要记录的日志消息。
52 | """
53 | log_path = os.path.join(log_dir, f"{device_id}.log")
54 | with open(log_path, "a", encoding="utf-8") as fa:
55 | fa.write(f"[{datetime.now().strftime('%H:%M:%S.%f')[:-3]}] {message}\n")
56 |
57 |
58 | def cover_batch(stage: str) -> None:
59 | """将一键启动文件改为阶段对应配置。
60 |
61 | Args:
62 | stage: 指定阶段。
63 | """
64 | src = os.path.join(batch_dir, f"{stage}.bat")
65 |
66 | # 读取阶段配置。
67 | with open(src, "r", encoding="utf-8") as fr:
68 | config = fr.read()
69 |
70 | # 写入正式配置。
71 | with open(batch_file, "w", encoding="utf-8") as fw:
72 | fw.write(config)
73 |
74 |
75 | def cover_ne(stage: str) -> None:
76 | """将物理层配置文件改为阶段对应配置。
77 |
78 | Args:
79 | stage: 指定阶段。
80 | """
81 | src = os.path.join(ne_dir, f"{stage}.txt")
82 |
83 | # 读取阶段配置。
84 | with open(src, "r", encoding="utf-8") as fr:
85 | config = fr.read()
86 |
87 | # 写入正式配置。
88 | with open(ne_file, "w", encoding="utf-8") as fw:
89 | fw.write(config)
90 |
91 |
92 | def cover_devicemap(stage: str) -> None:
93 | """将设备拓扑文件改为阶段对应配置。
94 |
95 | Args:
96 | stage: 指定阶段。
97 | """
98 | src = os.path.join(devicemap_dir, f"{stage}.json")
99 |
100 | # 读取阶段配置。
101 | with open(src, "r", encoding="utf-8") as fr:
102 | config = fr.read()
103 |
104 | # 写入正式配置。
105 | with open(devicemap_file, "w", encoding="utf-8") as fw:
106 | fw.write(config)
107 |
108 |
109 | def run_batch() -> None:
110 | """运行一键启动文件。"""
111 | os.system(batch_file)
112 |
113 |
114 | def get_host_config() -> list[str]:
115 | """获取主机配置。
116 |
117 | Returns:
118 | 拓扑内的主机设备号列表。
119 | """
120 | # 打开配置文件。
121 | try:
122 | with open(devicemap_file, "r", encoding="utf-8") as fr:
123 | # 读取该设备配置。
124 | try:
125 | hosts = loads(fr.read())["host"]
126 | except KeyError:
127 | print(f"[Error] Hosts absence")
128 | exit(-1)
129 | else:
130 | return hosts
131 | except FileNotFoundError:
132 | print(f"[Error] {devicemap_file} not found")
133 | exit(-1)
134 |
135 |
136 | def get_switch_config(device_id: str) -> int:
137 | """获取交换机配置。
138 |
139 | Args:
140 | device_id: 设备号。
141 |
142 | Returns:
143 | 物理层数量。
144 | """
145 | # 打开配置文件。
146 | try:
147 | with open(devicemap_file, "r", encoding="utf-8") as fr:
148 | # 读取该设备配置。
149 | try:
150 | num = loads(fr.read())["switch"][device_id]["phynum"]
151 | except KeyError:
152 | print(f"[Error] Device {device_id} absence")
153 | exit(-1)
154 | else:
155 | return num
156 | except FileNotFoundError:
157 | print(f"[Error] {devicemap_file} not found")
158 | exit(-1)
159 |
160 |
161 | def get_router_WAN(device_id: str) -> dict[str, dict]:
162 | """获取路由表广域网环境。
163 |
164 | Args:
165 | device_id: 路由器设备号。
166 |
167 | Returns:
168 | 路由器广域网环境。
169 | - 键: 相邻路由器的网络层端口号。
170 | - 值: 到达该路由器的路径信息,包含下列两个键:
171 | - "exit": 要到达该路由器,消息应该从哪个本地物理层端口送出。
172 | - "cost": 到达该路由器的费用。
173 | """
174 | # 打开配置文件。
175 | try:
176 | with open(devicemap_file, "r", encoding="utf-8") as fr:
177 | # 读取初始路由表。
178 | try:
179 | WAN_env: dict = loads(fr.read())["router"][device_id]["WAN"]
180 | except KeyError:
181 | print(f"[Error] Device {device_id} absence")
182 | exit(-1)
183 | else:
184 | return WAN_env
185 | except FileNotFoundError:
186 | print(f"[Error] {devicemap_file} not found")
187 | exit(-1)
188 |
189 |
190 | def get_router_LAN(device_id: str) -> dict[str, str]:
191 | """获取路由表局域网环境。
192 |
193 | Args:
194 | device_id: 路由器设备号。
195 |
196 | Returns:
197 | 路由器局域网环境。
198 | - 键: 所属主机的设备号。
199 | - 值: 到达该主机的本地物理层端口号。
200 | """
201 | # 打开配置文件。
202 | try:
203 | with open(devicemap_file, "r", encoding="utf-8") as fr:
204 | # 读取初始路由表。
205 | try:
206 | LAN_env: dict = loads(fr.read())["router"][device_id]["LAN"]
207 | except KeyError:
208 | print(f"[Error] Device {device_id} absence")
209 | exit(-1)
210 | else:
211 | return LAN_env
212 | except FileNotFoundError:
213 | print(f"[Error] {devicemap_file} not found")
214 | exit(-1)
215 |
216 |
217 | def save_rsc(data: bytes) -> tuple[str, bool]:
218 | """保存文件至资源目录。
219 |
220 | Args:
221 | data: 字节形式的文件内容。
222 |
223 | Returns:
224 | 保存成功为`True`,保存失败为`False`。
225 | """
226 | filepath = os.path.join(
227 | rsc_dir, f"received-{datetime.now().strftime('%H%M%S')}.png")
228 | try:
229 | with open(filepath, "wb") as fw:
230 | fw.write(data)
231 | except Exception:
232 | return "", False
233 | else:
234 | return filepath, True
235 |
--------------------------------------------------------------------------------
/Project1-MinNE-python/src/utils/params.py:
--------------------------------------------------------------------------------
1 | class MessageType:
2 | """消息类型。"""
3 |
4 | TEXT = "1"
5 | FILE = "2"
6 |
7 |
8 | class Mode:
9 | """发送模式。"""
10 |
11 | UNICAST = "1"
12 | BROADCAST = "2"
13 |
14 |
15 | class Network:
16 | """通信网络约束。"""
17 |
18 | INTER_NE_BUFSIZE = 1024
19 | IN_NE_BUFSIZE = 8 * 1024 * 1024
20 |
21 | USER_TIMEOUT = 180
22 | SELECT_TIMEOUT = 0.5
23 | RECV_TIMEOUT = 0.5
24 | FLOW_INTERVAL = 0.02
25 |
26 | KEEPALIVE_MAX_RETRY = 8
27 |
28 | REMOTE_MAX_LIFE = 100
29 |
30 | ROUTER_SPREAD_INTERVAL = 10
31 |
32 |
33 | class Topology:
34 | """网络拓扑。"""
35 |
36 | CMD_PORT = "20000"
37 | BROADCAST_PORT = "65535"
38 |
--------------------------------------------------------------------------------
/Project2-PacketTracer/README.md:
--------------------------------------------------------------------------------
1 | # 2-PacketTracer
2 |
3 | ## 项目介绍
4 |
5 | 使用Packet Tracer软件,实现一个简单的校园互联网。
6 |
7 | ## 阶段要求
8 |
9 | ### 阶段一
10 |
11 | IP网络规划,根据需求为每个子网分配合适的IP子网,为主要的计算机和路由器分配IP地址。
12 |
13 | ### 阶段二
14 |
15 | IP网络仿真配置,在Packet Tracer软件中放置合适的路由器和连接线路,实现基本的地址配置、接口配置和路由配置。
16 |
17 | ### 阶段三
18 |
19 | 测通,在不同子网计算机之间通过`ping`命令测通。使用`tracert`命令,测试路径是否正确。
20 |
21 | ## 项目需求
22 |
23 | 网络由分布在ABCD四栋楼内的网络设备及计算机构成。
24 |
25 | ABCD四楼各有一台路由器,他们相连称为园区主干,其中A楼是中心。在拓扑连接上,各楼都直接连接中心,即C不经过D中转;当A中心瘫痪时,网络其余部分也是联通的,且整体线路数量最少。
26 |
27 | 四台路由器之间采用光纤线路。
28 |
29 | A楼有2个子网:A1为10台,A2为90台;(A1是服务器子网)
30 | B楼有2个子网:B1为30台,B2为20台;
31 | C楼有1个子网:C1为70台;
32 | D楼有2个子网:D1为5台,D2有30台。(D1是办公计算机)
33 |
34 | 假设使用172.16.0.0号段。每个子网的地址容量尽量与设计规模相当,可留有少量余量。总的IP地址消耗越小越好。
35 |
36 | 以配通各子网之间的通信为主要目标,没有防火墙、策略路由等需求;如果考虑到A中心的容灾,可启动动态路由(作为加分项)。请尽量考虑路由表中的子网聚合,各子网需要至少配置两台计算机(最小地址和最大地址),实现与其他子网的通联测试。
37 |
38 | 各子网内可使用适合的二层交换机;或者将楼栋路由器替换为三层交换机,减少二层交换机的使用。
39 |
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/design/ip-distribution.drawio:
--------------------------------------------------------------------------------
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 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/design/ip-distribution.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/design/ip-distribution.xlsx
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/images/2021-10-15-22-36-17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/images/2021-10-15-22-36-17.png
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/images/2021-10-15-23-23-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/images/2021-10-15-23-23-41.png
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/images/2021-10-15-23-49-19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/images/2021-10-15-23-49-19.png
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/images/2021-10-16-00-02-35.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/images/2021-10-16-00-02-35.png
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/images/2021-10-16-00-06-37.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/images/2021-10-16-00-06-37.png
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/report.md:
--------------------------------------------------------------------------------
1 | # 项目二阶段一报告
2 |
3 | > 组号:2
4 | > 组员:蔡与望,党一琨,郭培琪,陶砚青
5 |
6 | ---
7 |
8 | ## 一、基础知识
9 |
10 | ### 1.1 IP地址
11 |
12 | 对于互联网中的一台设备,IP地址是它独特的一个编号,以此在通信时与其他设备区分。
13 |
14 | 它是一个32位的二进制数,共有4段,每段8位;常见的IP地址使用十进制表示,如127.0.0.1。
15 |
16 | IP地址可以分为前后两段,分别是网络号和这个网络下的主机号。
17 |
18 | 
19 |
20 | ### 1.2 子网掩码
21 |
22 | 为了更充分地利用有限的地址,引入子网概念,网络层次变为网络→子网→主机。子网向主机号借用若干位,作为自己的子网号,然后剩下的主机号隶属于这个子网。
23 |
24 | 子网掩码是这样的32位二进制数:网络号与子网号的位置全为`1`,主机号的位置全为`0`。它可以用来检测两台主机是否处于同一子网下。
25 |
26 | 将子网掩码和主机IP地址作“与”运算,就能够得到这台主机所处的子网地址;就好像经过这次运算之后,主机IP掩藏在子网地址之下,故称为子网掩码。
27 |
28 | 主机地址:`11000000 10101000 00000011 10000100`(192.168.3.132)
29 | 子网掩码:`11111111 11111111 11111111 00000000`(255.255.255.0)
30 | ↓与运算↓
31 | 子网地址:`11000000 10101000 00000011 00000000`(192.168.3.0)
32 |
33 | ### 1.3 子网的划分
34 |
35 | 1. 首先确定需要$n$个子网,该子网下的主机数$s$。
36 | 2. 算上保留的子网标识地址和广播地址,共需$s+2$个地址。
37 | 3. 找到最小的$b$,使得 $2^b \ge s+2$,$b$就是主机号长度。
38 | 4. 找到最小的$a$,使得 $2^a \ge n$,$a$就是子网号最小长度。
39 | 5. 如果$a+b$没有溢出能够分配的地址长度,则该划分问题有解;向上补位子网号长度$a$。
40 | 6. 根据长度确定子网地址、主机地址、广播地址、子网掩码。
41 |
42 | ---
43 |
44 | ## 二、IP地址分配方案
45 |
46 | 题目中提供的`172.16.0.0`是一个B类地址,地址的第3、4段都可以用来分配子网号、主机号。
47 |
48 | 根据上面的知识和划分方法,同时综合考虑了IP地址利用率,我们得到了下面三套各有优劣的方案。
49 |
50 | ### 2.1 方案一
51 |
52 | 首先,我们小组想到的是把每个子网单独安排到第3段,第4段分配给子网下的主机号。
53 |
54 | 
55 |
56 | 这套方案的优点在于,每一栋楼都拥有单独的网络地址,逻辑清晰;但其缺点也十分显然,即对同一个子网地址的利用率低下:如D1楼只有5台主机,却霸占了整个`172.16.6.0`分段。
57 |
58 | 因此,我们规划了第二套方案。
59 |
60 | ### 2.2 方案二
61 |
62 | 把主机数量规模相似的安排到同一子网地址下:如A2(90)和C1(70)都需要7位的主机号,就把它们放到同一子网下,享用同一子网掩码。
63 |
64 | 
65 |
66 | 同一背景色代表主机号长度相同。(A1与D1的主机号长度虽然不同,但无论如何排布都得使用`172.16.3.0`分段,所以干脆选择将它们放在一组)这套方案的优点在于,充分利用了IP地址;但缺点是同一子网掩码下ABC楼混杂,调试时尚且未知是否会出现不必要的问题。
67 |
68 | 因此,我们规划了第三套方案。
69 |
70 | ### 2.3 方案三
71 |
72 | 
73 |
74 | 结合了方案一和二各自的优点:ABC三楼逻辑清晰、优于方案二,IP利用率也高于方案一。
75 |
76 | 这三套方案均有各自的优劣之处,在后续的调试过程中,我们优先选择方案三;如果调不通,则继续尝试方案一;如果调通,则继续尝试方案二。
77 |
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage1/report/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage1/report/report.pdf
--------------------------------------------------------------------------------
/Project2-PacketTracer/Stage2/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project2-PacketTracer/Stage2/report.pdf
--------------------------------------------------------------------------------
/Project3-Wireshark/README.md:
--------------------------------------------------------------------------------
1 | # 3-Wireshark
2 |
3 | ## 项目介绍
4 |
5 | 利用WireShark软件,抓取自己计算机在网络上传输的数据包,选取其中的内容进行分析。
6 |
7 | ## 阶段要求
8 |
9 | ### 阶段一
10 |
11 | 1. 针对3个报文完成细致的层次化封装分析;
12 | 2. 对TCP报文或其他具有多次交互特点的协议,完成交互时序分析;
13 | 3. 对抓取的至少5个不同类型报文查对应的协议及功能。
14 |
15 | ### 阶段二
16 |
17 | 完成至少1000个报文抓包后,利用Wireshark软件内的工具,分析流量成分和变化,流量成分至少从三种不同角度。
18 |
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-10-57-24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-10-57-24.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-10-59-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-10-59-23.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-00-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-00-57.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-04-44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-04-44.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-05-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-05-57.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-08-52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-08-52.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-11-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-11-23.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-13-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-13-29.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-15-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-15-41.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-23-05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-23-05.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-23-45.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-23-45.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-24-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-24-30.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-25-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-25-03.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-25-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-25-50.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-32-38.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-32-38.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-34-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-34-41.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-44-44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-44-44.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-45-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-45-29.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-11-46-12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-11-46-12.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-12-22-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-12-22-30.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/2021-10-17-12-24-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/2021-10-17-12-24-01.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/images/tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/images/tcp.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage1/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage1/report.pdf
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-10-57-24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-10-57-24.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-10-59-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-10-59-23.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-00-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-00-57.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-04-44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-04-44.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-05-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-05-57.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-08-52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-08-52.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-11-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-11-23.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-13-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-13-29.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-15-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-15-41.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-23-05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-23-05.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-23-45.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-23-45.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-24-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-24-30.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-25-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-25-03.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-25-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-25-50.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-32-38.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-32-38.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-34-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-34-41.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-44-44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-44-44.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-45-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-45-29.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-11-46-12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-11-46-12.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-12-22-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-12-22-30.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-17-12-24-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-17-12-24-01.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-30-15-39-53.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-30-15-39-53.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-30-16-01-26.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-30-16-01-26.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-30-19-20-27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-30-19-20-27.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/2021-10-30-19-20-59.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/2021-10-30-19-20-59.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/iograph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/iograph.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/length.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/length.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/lengthplot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/lengthplot.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/protocol.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/protocol.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/stevens.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/stevens.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/stream.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/stream.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/tcp.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/images/throughput.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/images/throughput.png
--------------------------------------------------------------------------------
/Project3-Wireshark/Stage2/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project3-Wireshark/Stage2/report.pdf
--------------------------------------------------------------------------------
/Project4-Simulink/README.md:
--------------------------------------------------------------------------------
1 | # 4-Simulink
2 |
3 | ## 项目介绍
4 |
5 | 利用MATLAB中的Simulink仿真平台完成数字数据的调制和解调。
6 |
7 | ## 阶段要求
8 |
9 | ### 阶段一
10 |
11 | 普通调制技术。
12 |
13 | 1. 完成2ASK、2FSK与2PSK数字通信系统的搭建;
14 | 2. 利用数字比特序列,产生2ASK、2FSK与2PSK信号,并观察每种信号的时域波形;
15 | 3. 完成上述3种数字调制信号的解调,观察接收波形与发送波形之间的差异,并分析原因。
16 |
17 | ### 阶段二
18 |
19 | 1. 完成QPSK、QAM(选做)数字通信系统的搭建;
20 | 2. 利用数字比特序列,产生QPSK信号与QAM,并观察每种信号的时域波形与星座图。(星座图选做)
21 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BASK1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BASK1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BASK2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BASK2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BASK3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BASK3.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BFSK1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BFSK1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BFSK2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BFSK2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BFSK3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BFSK3.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BPSK1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BPSK1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BPSK2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BPSK2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/BPSK3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/BPSK3.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/images/ber.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/images/ber.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/report.md:
--------------------------------------------------------------------------------
1 | # 项目四阶段一报告
2 |
3 | > 姓名:蔡与望
4 | >
5 | > 学号:2020010801024
6 |
7 | ---
8 |
9 | - [项目四阶段一报告](#项目四阶段一报告)
10 | - [一、调制-解调系统的基本原理](#一调制-解调系统的基本原理)
11 | - [1.1 BASK](#11-bask)
12 | - [1.1.1 调制原理](#111-调制原理)
13 | - [1.1.2 解调原理](#112-解调原理)
14 | - [1.2 BFSK](#12-bfsk)
15 | - [1.2.1 调制原理](#121-调制原理)
16 | - [1.2.2 解调原理](#122-解调原理)
17 | - [1.3 BPSK](#13-bpsk)
18 | - [1.3.1 调制原理](#131-调制原理)
19 | - [1.3.2 解调原理](#132-解调原理)
20 | - [二、基于Simulink对调制-解调系统的仿真](#二基于simulink对调制-解调系统的仿真)
21 | - [2.1 BASK](#21-bask)
22 | - [2.2 BFSK](#22-bfsk)
23 | - [2.3 BPSK](#23-bpsk)
24 | - [三、信道环境对信号的影响](#三信道环境对信号的影响)
25 | - [四、附录](#四附录)
26 | - [4.1 SNR-BER绘图源码](#41-snr-ber绘图源码)
27 |
28 | ## 一、调制-解调系统的基本原理
29 |
30 | ### 1.1 BASK
31 |
32 | 二进制幅移键控调制(Binary Amplitude-Shift Keying),通过控制载波的**幅度**来调制信号。
33 |
34 | #### 1.1.1 调制原理
35 |
36 | 假设原始信号为$s(t)$,载波信号$f_c(t)=A\cos(\omega_c t+\theta)$,则调制后的信号为
37 |
38 | $$f(t)=\begin{cases}
39 | s(t)f_c(t), s(t)=1\\\\
40 | 0, s(t)=0
41 | \end{cases}$$
42 |
43 | #### 1.1.2 解调原理
44 |
45 | 先使用带通滤波器,让BASK信号完整通过,滤去其他频段的噪声。然后乘上与调制时完全相同的一列载波,信号被解调为
46 |
47 | $$f(t)=\begin{cases}
48 | \frac{A^2}{2}s(t)+\frac{A^2}{2}\cos(2\omega_ct+2\theta), s(t)=1\\\\
49 | 0, s(t)=0
50 | \end{cases}$$
51 |
52 | 再通过低通滤波器,滤去高频成分$\frac{A^2}{2}\cos(2\omega_ct+2\theta)$。至此,代表“1”的信号段振幅应接近$\frac{A^2}{2}$,代表“0”的信号段振幅应接近0。
53 |
54 | 最后,通过参数合适的滞回比较器,就能够还原初始的电平信号。
55 |
56 | ### 1.2 BFSK
57 |
58 | 二进制频移键控调制(Binary Frequency-Shift Keying),通过控制载波的**频率**来调制信号。
59 |
60 | #### 1.2.1 调制原理
61 |
62 | 假设原始信号为$s(t)$,载波信号$f_{c_1}(t)=A\cos(\omega_1t+\theta_1)$,$f_{c_2}(t)=A\cos(\omega_2t+\theta_2)$,则调制后的信号为
63 |
64 | $$f(t)=\begin{cases}
65 | f_{c_1}(t), s(t)=1\\\\
66 | f_{c_2}(t), s(t)=0
67 | \end{cases}$$
68 |
69 | #### 1.2.2 解调原理
70 |
71 | 先仿照BASK,使用带通滤波器、相同载波、低通滤波器解调,高低频载波各得到一个解调信号。这两个解调信号,一个的“1”对应高电平,另一个的“1”对应低电平。然后通过比较器比较这两个电平,就能够判断出真实的原始电平。
72 |
73 | ### 1.3 BPSK
74 |
75 | 二进制相移键控调制(Binary Phase-Shift Keying),通过控制载波的**相位**来调制信号。
76 |
77 | #### 1.3.1 调制原理
78 |
79 | 由于在BPSK中,两列载波的相位之差为$\pi$,即瞬时值刚好互为相反数,所以我们可以考虑预先将原始信号变为双极性信号,即将原始信号的0映射到-1;这样我们就可以只使用一列载波,为调制解调大大减少了麻烦。而这样的映射可以通过$s-\overline{s}$实现。
80 |
81 | 假设原始信号为$s(t)$,载波信号$f_c(t)=A\cos(\omega t+\theta)$,则调制后的信号为
82 |
83 | $$f(t)=\begin{cases}
84 | f_c(t), s(t)=1\\\\
85 | -f_c(t), s(t)=0
86 | \end{cases}$$
87 |
88 | #### 1.3.2 解调原理
89 |
90 | 与BASK基本相同,使用带通滤波器、相同载波、低通滤波器解调,此时代表“1”的信号段振幅约为$\frac{A^2}{2}$,代表“0”的信号段振幅约为$-\frac{A^2}{2}$。
91 |
92 | 所以当信号振幅跨越0时,就代表着原始信号0和1的变化,因此使用滞回比较器就能够还原原始信号。
93 |
94 | ## 二、基于Simulink对调制-解调系统的仿真
95 |
96 | ### 2.1 BASK
97 |
98 | 
99 |
100 | 上图为BASK仿真系统的结构,可分为调制、信道、解调、输出、检测五大模块。
101 |
102 | - **调制**
103 | - 【伯努利二进制数生成器】1秒设10k个采样点,即基带信号频率为10kHz。
104 | - 【正弦波】根据采样定理,采样点不能少于20k个;由于是模拟仿真,我们直接设100k个采样点。又因载波频率应远大于基带信号频率,所以我们取正弦波频率为100kHz。
105 |
106 | - **信道**
107 | - 【加性高斯白噪声】模拟真实信道的噪声,这里设SNR=2。
108 |
109 | - **解调**
110 | - 【带通滤波器】下通带截止频率为90kHz(载波频率-信号频率),上通带截止频率为110kHz(载波频率+信号频率)。
111 | - 【正弦波】由BASK原理可知,参数与调制载波严格一致。
112 | - 【低通滤波器】截止频率为10kHz(信号频率),因为要把200kHz左右的成分滤掉。
113 | - 【滞回比较器】阈值需要根据示波器输出进行调试,最终确定在0.25。
114 |
115 | - **输出**
116 | - 【示波器】各端口代表意义见实验结果分析。
117 |
118 | - **检测**
119 | - 【延时模块】接收端信号相比起发送端有一定延迟,所以要将原始信号延时一定时间再进行对比。
120 | - 【误码率计算器&显示器】显示总传输码元数、误码码元数、误码率。
121 |
122 | 其余参数均为软件默认值。
123 |
124 | 下面是仿真结果。
125 |
126 | 
127 |
128 | 可以看到,调制后的信号、解调后的信号基本都与原理中所描述的一致。接收端最后能基本正确地还原发送端信号,误码率稳定在0.12%,延迟约2bps。
129 |
130 | 
131 |
132 | ### 2.2 BFSK
133 |
134 | 
135 |
136 | 上图为BFSK仿真系统的结构,同样可分为调制、信道、解调、输出、检测五大模块。与BASK相同的器件参数在本处不再提及。
137 |
138 | - **调制**
139 | - 【正弦波1】频率为100kHz。
140 | - 【正弦波2】频率为200kHz。
141 | - 【选择器】当输入为0时,选择200kHz载波;当输入为1时,选择100kHz载波。
142 |
143 | - **解调**
144 | - 【带通滤波器1】下通带截止频率为90kHz(载波1频率-信号频率),上通带截止频率为110kHz(载波1频率+信号频率)。
145 | - 【带通滤波器2】下通带截止频率为190kHz(载波2频率-信号频率),上通带截止频率为210kHz(载波2频率+信号频率)。
146 | - 【正弦波1】由原理,与调制载波1严格一致。
147 | - 【正弦波2】由原理,与调制载波2严格一致。
148 | - 【“大于”计算器】当信号1大于信号2,输出1;反之输出2。
149 |
150 | - **检测**
151 | - 【转换为double】由于“大于”计算器的结果是布尔类型,所以在输入误码率计算器前,先将其转换为浮点类型。
152 |
153 | 下面是仿真结果。
154 |
155 | 
156 |
157 | 可以看到,调制后的信号、解调后的信号基本都与原理中所描述的一致。接收端最后能基本正确地还原发送端信号,误码率接近于0,延迟约2bps。
158 |
159 | 但在每次仿真的最开始,接收端都会出现一个高电平毛刺,这一毛刺经过我多次改变元件的尝试,均无法消除。推测其出现的原因是,发送端与接收端之间有延迟,在接收端收到第一个信号前,比较器的输入处于高阻状态,所以输出有异常。但这一毛刺对实际解调的结果没有影响,所以在总的仿真过程中,选择将其忽略不计。
160 |
161 | 
162 |
163 | ### 2.3 BPSK
164 |
165 | 
166 |
167 | 上图为BPSK仿真系统的结构,同样可分为调制、信道、解调、输出、检测五大模块。与上面相同的器件参数在本处不再提及。
168 |
169 | - **调制**
170 | - 【非运算&减法器】将单极性信号转换为双极性信号。原理:$f(x)=x-\overline{x}$,$f(1)=1,f(0)=-1$。
171 |
172 | 下面是仿真结果。
173 |
174 | 
175 |
176 | 可以看到,调制后的信号、解调后的信号基本都与原理中所描述的一致。接收端最后能基本正确地还原发送端信号,误码率稳定在0.18%,延迟约2bps。
177 |
178 | 
179 |
180 | ## 三、信道环境对信号的影响
181 |
182 | 我们容易知道,信噪比SNR越高,误码率BER应当越低。现以BPSK仿真为例,改变AWGN的SNR,记录每次对应的BER并绘图。(绘图源代码见附录)
183 |
184 | 
185 |
186 | 可以看到,结果与预测基本一致:信噪比越高,误码率越低。当SNR=15时,误码率已经低于万分之一。
187 |
188 | ## 四、附录
189 |
190 | ### 4.1 SNR-BER绘图源码
191 |
192 | ```python
193 | import matplotlib.pyplot as plt
194 | import numpy as np
195 |
196 | plt.style.use(['ggplot', 'fast'])
197 |
198 | EbNo = np.arange(1, 15.5, 0.5)
199 | BER = np.array([
200 | 1.064e-1, # 1.0
201 | 9.929e-2, # 1.5
202 | 9.329e-2, # 2.0
203 | 8.939e-2, # 2.5
204 | 8.139e-2, # 3.0
205 | 7.579e-2, # 3.5
206 | 6.279e-2, # 4.0
207 | 6.019e-2, # 4.5
208 | 5.399e-2, # 5.0
209 | 4.790e-2, # 5.5
210 | 4.210e-2, # 6.0
211 | 3.560e-2, # 6.5
212 | 3.140e-2, # 7.0
213 | 2.510e-2, # 7.5
214 | 1.970e-2, # 8.0
215 | 1.780e-2, # 8.5
216 | 1.460e-2, # 9.0
217 | 1.160e-2, # 9.5
218 | 9.099e-3, # 10.0
219 | 7.399e-3, # 10.5
220 | 5.399e-3, # 11.0
221 | 4.100e-3, # 11.5
222 | 3.300e-3, # 12.0
223 | 1.800e-3, # 12.5
224 | 9.999e-4, # 13.0
225 | 6.999e-4, # 13.5
226 | 4.000e-4, # 14.0
227 | 2.000e-4, # 14.5
228 | 1.000e-4, # 15.0
229 | ])
230 | BERlg = np.log10(BER)
231 |
232 | plt.title("AWGN's impact on BER")
233 | plt.xlabel('SNR(dB)')
234 | plt.ylabel('$\lgBER$')
235 | plt.yticks(np.arange(-4, 0, 0.5))
236 |
237 | plt.plot(EbNo, BERlg)
238 | plt.show()
239 | ```
240 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/report/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/report/report.pdf
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/src/BASK.slx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/src/BASK.slx
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/src/BFSK.slx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/src/BFSK.slx
--------------------------------------------------------------------------------
/Project4-Simulink/Stage1/src/BPSK.slx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage1/src/BPSK.slx
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qam1.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qam1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/design/qam1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qam2.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qam2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/design/qam2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qpsk1.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qpsk1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/design/qpsk1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qpsk2.drawio:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/design/qpsk2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/design/qpsk2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM3.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM4-10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM4-10.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM4-20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM4-20.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QAM4-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QAM4-30.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK1.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK2.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK3.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK4-10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK4-10.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK4-20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK4-20.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/images/QPSK4-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/images/QPSK4-30.png
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/report/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/report/report.pdf
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/src/QAM.slx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/src/QAM.slx
--------------------------------------------------------------------------------
/Project4-Simulink/Stage2/src/QPSK.slx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Project4-Simulink/Stage2/src/QPSK.slx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 计算机网络与通信技术
2 |
3 | 电子科技大学 2020 级《计算机网络与通信技术》课程代码。
4 |
5 | ## ✨ 项目介绍
6 |
7 | 1. 最小网元设计(Socket)
8 | 2. 校园互联网(Packet Tracer)
9 | 3. 网络流量抓包分析(WireShark)
10 | 4. 数字数据调制解调(Simulink)
11 | 5. 各单元作业
12 | - 词汇解释
13 | - 教材习题
14 | - 思维导图
15 | - 课堂讨论
16 |
17 | ## 📄 许可证
18 |
19 | [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/)
20 |
--------------------------------------------------------------------------------
/Unit1/discussion.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit1/discussion.pdf
--------------------------------------------------------------------------------
/Unit1/discussion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit1/discussion.pptx
--------------------------------------------------------------------------------
/Unit1/exercise.md:
--------------------------------------------------------------------------------
1 | # 单元一习题
2 |
3 | ## 第 1 题
4 |
5 | > 假设一只狗已经受训可以携带 4 个U盘,每个U盘 32GB 容量,小狗的速度是 18km/h,请问在什么距离范围内,小狗的数据传输速率会超过 300Mbps 的 Wi-Fi 网络?
6 |
7 | 设两点间距离为 $l$ 米。由题要使
8 |
9 | $$
10 | \frac{l}{18\div3.6}<\frac{4\times32\times1024\times8}{300}
11 | $$
12 |
13 | 所以
14 |
15 | $$
16 | l<17476.3
17 | $$
18 |
19 | ## 第 2 题
20 |
21 | > 系统具有 A 层结构,从最底一层传出 L 字节数据。假设除了最底层外,每层需要封装 H 字节的头部控制信息,请问,这些开销在总量中的比例为多大。
22 |
23 | 顶层与底层不封装,所以有 $A-2$ 层封装了协议头。
24 |
25 | $$
26 | \eta=\frac{H(A-2)}{L}
27 | $$
28 |
29 | ## 第 3 题
30 |
31 | > 请分别描述 OSI 模型和 TCP/IP 模型的层次化结构、各层功能。
32 |
33 | ### OSI 模型
34 |
35 | 1. **应用层**:显示用户能够理解的信息,与用户交互;
36 | 2. **表示层**:为信息提供语法、语义表示,加密、压缩信息;
37 | 3. **会话层**:管理会话的时间、参与者、对话模式、状态等;
38 | 4. **传输层**:适配各种网络,管理分流与复用、并发通信,控制流量等;
39 | 5. **网络层**:选择低耗费的路由,报文分段和重组,拥塞控制、网络互连和组网;
40 | 6. **数据链路层**:数据成帧、差错的检测和处理,控制线路两端速率一致;
41 | 7. **物理层**:比特流的表示、同步、收发,提供物理介质的驱动。
42 |
43 | ### TCP/IP 模型
44 |
45 | 1. **应用层**:语义化、用户交互;
46 | 2. **传输层**:使用分组交换技术,确保通信的可靠和有效;
47 | 3. **网络层**:提供多种传输服务,控制双方传输速度差异;
48 | 4. **物理层**:传输实际的比特流。
49 |
50 | > TCP/IP 的物理层之上可能还有数据链路层。
51 |
52 | ## 第 4 题
53 |
54 | > 设误帧率为 0.01,对错误的帧将采用重传,直到正确为止,请计算平均需要传多少次。
55 |
56 | $$
57 | E(N)=\sum_{k=1}^{\infty}p^{k-1}(1-p)=\frac{1}{1-p}=1.01
58 | $$
59 |
60 | ## 第 5 题
61 |
62 | > 设一个报文分成 10 帧传输,误帧率为 0.01 ,现有两种重传策略:
63 | >
64 | > 1. 收方对每帧都进行确认,发方一旦发现某个帧出现错误,就重传该帧;
65 | >
66 | > 2. 收方在收完 10 帧后,进行一次确认,如果有错,则发方重新传这10个帧。
67 | >
68 | > 请分别计算这两种策略下,将整个报文正确传输下来,平均传输的帧数量。
69 |
70 | ### 方案 1
71 |
72 | $$
73 | N=\frac{1}{1-p}=10.1
74 | $$
75 |
76 | ### 方案 2
77 |
78 | $$
79 | N=\frac{10}{(1-p)^{10}}=11.1
80 | $$
81 |
82 | ## 第 6 题
83 |
84 | > 两地相距 10km,连接两地的电缆长度为 15km,分别以 1Mbps 和 1Gbps 工作时,信道的传输延迟和位长分别为多少?
85 | >
86 | > 信道位长:当接收方接收第一个信号时,发送方已经发送了多少位数据了,即有多少位数据“在信道上”。
87 |
88 | 电缆传播速率为 $v=\frac{2}{3}c$,传输延迟二者相同,为
89 |
90 | $$
91 | \Delta t=\frac{15\times10^3}{\frac{2}{3}\times 3\times 10^8}=7.5\times10^{-5}s
92 | $$
93 |
94 | 当工作在 1Mbps,$N=\Delta t\times1024^2=78.6$
95 |
96 | 当工作在 1Gbps,$N=\Delta t\times1024^3=80530.6$
97 |
--------------------------------------------------------------------------------
/Unit1/exercise.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit1/exercise.pdf
--------------------------------------------------------------------------------
/Unit1/mindmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit1/mindmap.png
--------------------------------------------------------------------------------
/Unit1/vocabulary.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit1/vocabulary.pdf
--------------------------------------------------------------------------------
/Unit2/discussion.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/discussion.pdf
--------------------------------------------------------------------------------
/Unit2/discussion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/discussion.pptx
--------------------------------------------------------------------------------
/Unit2/exercise.md:
--------------------------------------------------------------------------------
1 | # 单元二习题
2 |
3 | ## 第 1 题
4 |
5 | > 研究香农和奈奎斯特关于信道容量的理论,两者从不同的角度出发为信道的比特率设置了上限。它们两者之间的关系是什么?
6 |
7 | - **相同**:都描述了信道容量和它的制约因素。
8 | - **不同**:
9 | - 奈奎斯特定理只描述了理想信道中的信道容量;而香农定理在此基础上,考虑了噪声的影响;
10 | - 奈奎斯特定理的计算需要知道具体的调制技术(M 电平),而香农定理的计算不考虑调制技术,只需要知道信噪比。
11 |
12 | ## 第 2 题
13 |
14 | > 假设一个信道的容量为 1MHz,SNR为 63。
15 | >
16 | > 1. 该信道的数据率上限是多少?
17 | >
18 | > 2. 上一问得到的是一个上限。但实际上,较低的数据率可以得到较好的差错表现。假设我们选择的数据率为最高理论上限,要达到这个数据率需要有几个电平的信号?
19 |
20 | 1. 数据率上限为
21 |
22 | $$
23 | C=B\log_{2}(1+SNR)=6Mbps
24 | $$
25 |
26 | 2. 需要的电平数为
27 |
28 | $$
29 | \frac{2}{3}\times 6Mbps=2B\log_2M\Rightarrow M=4
30 | $$
31 |
32 | ## 第 3 题
33 |
34 | > 假设数据被存储在容量为 8.54GB 的单面双层 DVD 中,每张 DVD 的质量为 15g。假设一列从伦敦开往巴黎的欧洲之星列车上装载了 $10^4$kg 的这种 DVD。行程总长度为 640km,列车运行时间为 2 小时 15 分钟。这个系统的数据传输率是多少比特每秒?
35 |
36 | $$
37 | C=\frac{8.54\times \frac{10^4\times10^3}{15}\times 8}{135\times 60}=5623Gbps
38 | $$
39 |
40 | ## 第 4 题
41 |
42 | > 请计算当传输频率增加一倍,并且发射天线和接收天线之间的距离增加一倍时的接收功率的衰减比例。
43 |
44 | 由衰减公式
45 |
46 | $$
47 | L_{dB}=20\lg{f}+20\lg{d}-147.56dB
48 | $$
49 |
50 | 显然可得衰减
51 |
52 | $$
53 | \Delta L_{dB}=20\lg{2}+20\lg{2}=40\lg{2}=12.04dB
54 | $$
55 |
56 | ## 第 5 题
57 |
58 | > 假设发送器产生的功率为 50W。
59 | > 1. 请写出以 dBm 和 dBW 为单位的发送功率。
60 | > 2. 如果将发送器的功率应用到单位增益天线,且载波为 900MHz,那么在自由空间距离为 100m 的地方接收到的功率为多少 dBm?
61 | > 3. 如果其他条件不变,距离变为 10km,那么接收到的功率又是多少 dBm?
62 | > 4. 在第 3 问基础上,现在假设接收天线的增益为 2,那么接收到的功率又是多少 dBm?
63 |
64 | 1. 以 dBm 为单位的发送功率为
65 |
66 | $$
67 | P_{dBm}=10\lg{\frac{50\times10^3mW}{1mW}}=47.0dBm
68 | $$
69 |
70 | 以 dBW 为单位的发送功率为
71 |
72 | $$
73 | P_{dBW}=10\lg{\frac{50W}{1W}}=17.0dBW
74 | $$
75 |
76 | 2. 衰减了
77 |
78 | $$
79 | L_{dB}=20\lg{f}+20\lg{d}-147.56=71.5dB
80 | $$
81 |
82 | 所以接收功率为
83 |
84 | $$
85 | P=47.0dBm-71.5dB=-24.5dBm
86 | $$
87 |
88 | 3. 距离 $d$ 变为 100 倍,则衰减增加 40dB,所以接收功率为
89 |
90 | $$
91 | P=-24.5dBm-40dB=-64.5dBm
92 | $$
93 |
94 | 4. 增益为 2,则接收功率也变为 2 倍,也即增大 3 dBm。所以接收功率为
95 |
96 | $$
97 | P=-64.5dBm+3dBm=-61.5dBm
98 | $$
99 |
100 | ## 第 6 题
101 |
102 | > 图中的波形图是用曼彻斯特编码后的二进制数据流。提取时钟信息,并写出其数据序列。
103 |
104 | 
105 |
106 | 从低到高跳变为 `0`,从高到低跳变为 `1`,所以数据序列为 `0001100101`。
107 |
108 | ## 第 7 题
109 |
110 | > 为什么在把数字数据编码成为模拟信号时,PCM 要比 DM 更合适?
111 |
112 | 1. PCM 直接量化样本值,DM 则是量化差值,后者无法适应高频且变化剧烈的信号;
113 | 2. PCM 的信噪比更高,传输质量好。
114 |
115 | ## 第 8 题
116 |
117 | > 调频广播电台的频率在 100MHz 附近、5G移动通信的频率在 3.5GHz 附近、Wi-Fi 信号的频率在 5.8GHz 附近。收音机、手机、Wi-Fi 设备的天线长度大约是多少?
118 | >
119 | > Wi-Fi 的 802.11n 标准,工作在 5GHz 频率,带宽达到 40MHz,数传速率如果是 150Mbps,那么要达到这么大的数传速率,信道的 SNR 不能小于多少 dB?
120 |
121 | 1. 理想天线的长度为信号的半波长,即
122 |
123 | $$
124 | L=\frac{c}{2f}
125 | $$
126 |
127 | - 收音机
128 |
129 | $$
130 | \frac{3\times10^8}{2\times 100\times 10^6}=1.5m
131 | $$
132 |
133 | - 手机
134 |
135 | $$
136 | \frac{3\times10^8}{2\times 3.5\times 10^9}=4.29cm
137 | $$
138 |
139 | - Wi-Fi 设备
140 |
141 | $$
142 | \frac{3\times10^8}{2\times 5.8\times 10^9}=2.59cm
143 | $$
144 |
145 | 1. 由香农公式有
146 |
147 | $$
148 | 150=40\lg{1+\frac{S}{N}}\Rightarrow \frac{S}{N}=2^{\frac{15}{4}}-1
149 | $$
150 |
151 | 所以
152 |
153 | $$
154 | SNR=10\lg{\frac{S}{N}}=10.95dB
155 | $$
156 |
157 | ## 第 9 题
158 |
159 | > 将载波信号用 $x_c(t)=A\cos(\omega_ct+\phi)$ 来表达,我们分别可以在幅度、频率和相位上调制另一路低频信号 $s(t)$,请分别指出这三种调制方式作用在载波信号的什么位置?
160 | >
161 | > 如果 $s(t)$ 是一个数字方波信号,调制后的信号波形会有怎样的典型波形?
162 |
163 | 1. 幅度:
164 |
165 | $$
166 | f(t)=\begin{cases}
167 | A\cos(\omega_ct+\phi),s(t)=1\\
168 | 0,s(t)=0
169 | \end{cases}
170 | $$
171 |
172 | 调制后会出现间隔不等的正弦波片段。
173 |
174 | 2. 频率:
175 |
176 | $$
177 | f(t)=\begin{cases}
178 | A\cos(\omega_{c_1}t+\phi),s(t)=1\\
179 | A\cos(\omega_{c_2}t+\phi),s(t)=0
180 | \end{cases}
181 | $$
182 |
183 | 调制后会出现周期不等的连续正弦波片段。
184 |
185 | 3. 相位:
186 |
187 | $$
188 | f(t)=\begin{cases}
189 | A\cos(\omega_ct+\phi_1),s(t)=1\\
190 | A\cos(\omega_ct+\phi_2),s(t)=0
191 | \end{cases}
192 | $$
193 |
194 | 调制后会出现相位突变的正弦波片段。
195 |
--------------------------------------------------------------------------------
/Unit2/exercise.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/exercise.pdf
--------------------------------------------------------------------------------
/Unit2/images/2021-12-13-13-40-52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/images/2021-12-13-13-40-52.png
--------------------------------------------------------------------------------
/Unit2/mindmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/mindmap.png
--------------------------------------------------------------------------------
/Unit2/vocabulary.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit2/vocabulary.pdf
--------------------------------------------------------------------------------
/Unit3/discussion.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit3/discussion.pdf
--------------------------------------------------------------------------------
/Unit3/discussion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit3/discussion.pptx
--------------------------------------------------------------------------------
/Unit3/exercise.md:
--------------------------------------------------------------------------------
1 | # 单元三习题
2 |
3 | ## 第 1 题
4 |
5 | > 请自拟一个 14 位长的二进制码串,计算其海明纠错编码。将编码后的码串某位翻转,利用海明码进行纠错。
6 |
7 | 自拟码串:`01 0010 1100 1001`
8 |
9 | | 序号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
10 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :------: | :------: | :---: | :------: | :------: | :------: |
11 | | 符号 | $P_1$ | $P_2$ | $D_1$ | $P_3$ | $D_2$ | $D_3$ | $D_4$ | $P_4$ | $D_5$ | $D_6$ | $D_7$ | $D_8$ | $D_9$ | $D_{10}$ | $D_{11}$ | $P_5$ | $D_{12}$ | $D_{13}$ | $D_{14}$ |
12 | | 数值 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
13 |
14 | 海明纠错编码:`11101`
15 |
16 | 翻转 1 位后的误码:`01 0110 1100 1001`
17 |
18 | | 序号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
19 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :------: | :------: | :---: | :------: | :------: | :------: |
20 | | 符号 | $P_1$ | $P_2$ | $D_1$ | $P_3$ | $D_2$ | $D_3$ | $D_4$ | $P_4$ | $D_5$ | $D_6$ | $D_7$ | $D_8$ | $D_9$ | $D_{10}$ | $D_{11}$ | $P_5$ | $D_{12}$ | $D_{13}$ | $D_{14}$ |
21 | | 收得 | 1 | 1 | 0 | 1 | 1 | 0 | **1** | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
22 | | 验得 | **0** | **0** | 0 | **0** | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
23 |
24 | 计算校验码时,第 1、2、4 位与得到的码串不同,所以可判定码串第 7 位出错,翻转后得到 `01 0010 1100 1001`,与原始码串相同。
25 |
26 | ## 第 2 题
27 |
28 | > 请自拟一个 10 位长的二进制码串。设 CRC 校验生成式为:$G(x)=x^4+x^3+1$。
29 | >
30 | > 1. 请计算出校验码。
31 | >
32 | > 2. 将编码后的码串某两位翻转,利用 CRC 校验进行检错。
33 |
34 | 自拟码串:`10 1110 0101`
35 |
36 | 1. CRC 校验生成式对应的二进制数:`11001`;则校验码应为 `10 1110 0101 0000` / `11001` 所得的余数,为 `0010`。
37 | 2. 将上一问得到的码串翻转 2 位,得 `10 0010 0101 0010`,接收方使用 `11001` 检错时,余数为 `0111`,不为 `0`,说明出错。
38 |
39 | ## 第 3 题
40 |
41 | > 设无线信道误码率为 $5\times 10^{-5}$,信道速率为 300Mbps,出现比特错误的平均时间间隔为多少?
42 |
43 | 平均 $2\times 10^4$ 位中会出现一比特错误,平均时间间隔为
44 |
45 | $$
46 | t=\frac{2\times 10^4}{300\times 1024^2}=6.36\times 10^{-5}s
47 | $$
48 |
49 | ## 第 4 题
50 |
51 | > 设滑动窗口协议的收发窗口都为 6,帧序号为 0-8 循环。双方在传输过程中发现了差错,使用选择性重传并进行了控制。什么情况下会出现发送方认为自己正确发送的帧数量,比接收方认为正确接收的数量多 2 个及以上,即例举一种可能的场景和演变过程。
52 |
53 | 如果是接收方认为自己正确接收的帧数比发送方认为正确发送的多2个及以上,那么有可能例如:
54 |
55 | - 发送方发送第 1、2 帧;接收方接收第 2 帧时出错,向发送方报错;
56 | - 发送方在收到报错信息前,以为自己没错,又发送了第 3、4 帧;
57 | - 发送方在第 5 帧前,收到了第 2 帧的报错,以为自己只发对了第 1 帧;
58 | - 但此时发送方已经接收到了正确的第 1、3、4 帧,只是第 3、4 帧被缓存了起来。
59 | - 此时,接收方认为自己正确接收的帧数比发送方认为正确发送的多2帧。
60 | - 如果RTT够高,还可能出现多 3、4...... 帧的情况。
61 |
62 | ## 第 5 题
63 |
64 | > 设某个信道上设计的滑窗协议最佳 $W_s$ 为 2000 字节,已知数据传输速率为 10Mbps,如果平均帧长为 200 字节:
65 | >
66 | > 1. 该信道的传输往返延时为多少?
67 | >
68 | > 2. 如果最小帧长度为 50 字节,这个滑动窗口协议的序号最小容量上限值为多少?(序号是从 0 开始编到容量上限,然后循环回来继续编号)
69 | >
70 | > 3. 发送窗口大小为多少帧?
71 |
72 | 1. 最坏的情况如下:发送方发送的第一个帧就错了,但直到发了最后一帧才收到接收方的报错。
73 |
74 | $$
75 | RTT=\frac{2000\times 8}{10\times 1024^2}=1.53ms
76 | $$
77 |
78 | 2. 由 $W_s$ 为 2000 字节、最小帧长为 50 字节,可知窗口内最多有 40 帧。又有发送窗口大小 $\le$ (序号容量 + 1) / 2,所以序号最小容量上限为79。
79 | 3. 发送窗口为 40 帧。
80 |
81 | ## 第 6 题
82 |
83 | > 假设当前网络情况稳定,TCP 协议持续稳定地滑动窗口,已测得 A、B 之间的 RTT 为 10ms,TCP 窗口大小为 2KB,请问,发送方测得的网速是多少?
84 |
85 | $$
86 | v=\frac{2\times 1024\times 8}{10\times 10^{-3}}=1.6Mbps
87 | $$
88 |
--------------------------------------------------------------------------------
/Unit3/exercise.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit3/exercise.pdf
--------------------------------------------------------------------------------
/Unit3/mindmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit3/mindmap.png
--------------------------------------------------------------------------------
/Unit3/vocabulary.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit3/vocabulary.pdf
--------------------------------------------------------------------------------
/Unit4/discussion.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/discussion.pdf
--------------------------------------------------------------------------------
/Unit4/discussion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/discussion.pptx
--------------------------------------------------------------------------------
/Unit4/exercise.md:
--------------------------------------------------------------------------------
1 | # 单元四习题
2 |
3 | ## 第 1 题
4 |
5 | > 假设帧长度固定为 30000 字节,数据传输速率为 1000Mbps;媒体最大长度为 50米,请计算:
6 | >
7 | > 1. ALOHA 协议下,冲突窗口为多长时间(即多大的时间内不能同时有两个帧)?
8 | >
9 | > 2. 采用 CSMA 以后,冲突窗口为多大?
10 | >
11 | > 3. 采用 CSMA/CD 技术以后,冲突窗口为多大?
12 | >
13 | > 4. 采用 CSMA/CD 技术,最大的冲突检测时间是多少?
14 |
15 | 1. ALOHA 协议出现冲突的情况是,该帧传输结束前,信道中出现了其它帧。
16 |
17 | $$
18 | t=\frac{30000\times 8}{1000\times 1024^2}=2.29\times 10^{-4}s
19 | $$
20 |
21 | 2. CSMA 协议出现冲突的情况是,该帧在介质中发送到另一端前,信道中出现了其它帧。
22 |
23 | $$
24 | t=\frac{50}{\frac{2}{3}\times 3\times 10^8}=2.5\times 10^{-7}s
25 | $$
26 |
27 | 3. CSMA/CD 协议的冲突窗口与 CSMA 相同。
28 |
29 | $$
30 | t=2.5\times 10^{-7}s
31 | $$
32 |
33 | 4. 发生冲突需要一段时间,源要知晓发生冲突还要等待相同的一段时间。
34 |
35 | $$
36 | t=5\times 10^{-7}s
37 | $$
38 |
39 | ## 第 2 题
40 |
41 | > 以太网标准中,典型数传速率为1000Mbps,使用块传输:即一次连续传输一块数据,块之间有时间间隔。以太网标准规定:一块数据(帧)最长为1518字节(含帧头和帧尾),最小为64字节,帧前有8字节物理层前导码,块与块之间的间隔最小为传输96bit的时间,那么这个信道上的最大有效数据传输速率是多少bps,最大帧速率是多少fps?(每秒钟最多的块数)
42 |
43 | 因为数据之外部分的字节数固定,所以要让有效数据传输速率尽量大,则需要数据部分尽量长,即取 1518 字节。
44 |
45 | $$
46 | v=\frac{1518-18}{1518+8+12}\times1000=975.3Mbps
47 | $$
48 |
49 | 因为数传速率固定,所以要传尽量多的帧,就要让单个帧尽量小,即取 64 字节。
50 |
51 | $$
52 | v=\frac{1000}{(64+8+12)\times 8}Mfps=1.5Mfps
53 | $$
54 |
55 | ## 第 3 题
56 |
57 | > 一大批ALOHA用户每秒产生100次请求,包括初始请求和重传的请求。以20ms为单位进行分时隙。
58 | >
59 | > 1. 首次成功率为多少?
60 | >
61 | > 2. k次冲突后成功的概率是多少?
62 | >
63 | > 3. 发送尝试次数的期望值是多少?
64 |
65 | 1. ALOHA 协议传输 k 次的成功次数服从泊松分布 $P(k)=\frac{2^k}{k!}e^{-2}$,所以首次成功率
66 |
67 | $$
68 | P(0)=e^{-2}
69 | $$
70 |
71 | 2. 由分布函数,概率为
72 |
73 | $$
74 | p=(1-e^{-2})^k e^{-2}
75 | $$
76 |
77 | 3. 使用泊松分布的期望值公式,可得
78 |
79 | $$
80 | E(X)=e^2
81 | $$
82 |
83 | ## 第 4 题
84 |
85 | > 请查阅网上资料,自学交换机生成树算法,完成本题。以下图中都是二层交换机,红色标识的线路为 100Mbps,黑色为 1000Mbps,开销分别为 19 和 4,各交换机的标识号见图。请查阅交换机生成树协议及算法的相关资料,完成各端口的设置,即得到生成树结果:根网桥,根端口,指定端口,阻塞端口。
86 | >
87 | > 图中网桥ID:xx.yy。xx表示优先级,管理员可以配置;yy是桥的MAC地址,图中没有用标准的6字节格式,使用了以简化的数值来表示。各端口的优先级都相同,则使用默认值。
88 |
89 | 
90 |
91 | 生成树的生成遵循以下原则:
92 |
93 | 1. 根网桥:
94 | - 网桥 ID 最小;
95 | - 若网桥 ID 相同,则 MAC 最小。
96 | 2. 根端口:
97 | - 根网桥有 0 个,非根网桥各有 1 个;
98 | - 到达根网桥的代价最小。
99 | 3. 指定端口:
100 | - 根网桥所有端口均为指定端口;
101 | - 每条线路均有且仅有 1 个指定端口;
102 | - 指定端口是非根端口;
103 | - 到达根网桥的代价最小。
104 | 4. 阻塞(备用)端口:
105 | - 非根且非指定的端口都是阻塞端口。
106 |
107 | | 网桥 ID | 根端口 | 指定端口 | 阻塞(备用)端口 |
108 | | :------: | :----: | :------: | :--------------: |
109 | | `100.19` | / | 1 2 3 | / |
110 | | `100.20` | 1 | / | 2 3 |
111 | | `101.1` | 1 | 2 3 | / |
112 | | `101.2` | 3 | 1 | 2 |
113 | | `200.3` | 2 | 1 | / |
114 |
115 | 
116 |
--------------------------------------------------------------------------------
/Unit4/exercise.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/exercise.pdf
--------------------------------------------------------------------------------
/Unit4/images/2021-12-13-20-38-02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/images/2021-12-13-20-38-02.png
--------------------------------------------------------------------------------
/Unit4/images/2021-12-14-11-35-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/images/2021-12-14-11-35-23.png
--------------------------------------------------------------------------------
/Unit4/mindmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/mindmap.png
--------------------------------------------------------------------------------
/Unit4/vocabulary.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit4/vocabulary.pdf
--------------------------------------------------------------------------------
/Unit5/discussion.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/discussion.pdf
--------------------------------------------------------------------------------
/Unit5/discussion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/discussion.pptx
--------------------------------------------------------------------------------
/Unit5/exercise.md:
--------------------------------------------------------------------------------
1 | # 单元五习题
2 |
3 | ## 第 1 题
4 |
5 | > A、B 两个节点相距 10 公里,平均数据传输速率为 5Mbps,中间经过 3 个路由器。如果网络规模为 10 万个节点,路由表按顺序检索方式,执行一条命令耗时 10ms,平均分组长度为 750 字节,经统计,平均正在通信的用户数量为 100 个左右。请分别计算当这些路由器采用虚电路交换技术和数据报交换技术下,从 A 到 B 的端到端延时(A 开始发送到 B 接收完第一个分组)。
6 |
7 | 传播延时:
8 |
9 | $$
10 | t_1=\frac{10\times 10^3}{\frac{2}{3}\times 3\times 10^8}=5\times 10^{-5}s
11 | $$
12 |
13 | 传输延时:
14 |
15 | $$
16 | t_2=\frac{750\times 8}{5\times 1024^2}=1.2\times 10^{-3}s
17 | $$
18 |
19 | 虚电路查表延时:
20 |
21 | $$
22 | t_3=\frac{1}{2}\times 100\times 10\times 10^{-3}=0.5s
23 | $$
24 |
25 | 数据报查表延时:
26 |
27 | $$
28 | t_4=\frac{1}{2}\times 10^5\times 10\times 10^{-3}=500s
29 | $$
30 |
31 | 不管对于虚电路还是数据报,延时都由以下部分组成:
32 |
33 | - 一次传播延时
34 | - 四次传输延时
35 | - 三次查表延时
36 |
37 | 虚电路延时为:
38 |
39 | $$
40 | t=t_1+4t_2+3t_3=1.50485s
41 | $$
42 |
43 | 数据报延时为:
44 |
45 | $$
46 | t=t_1+4t_2+3t_4=1500.00485s
47 | $$
48 |
49 | ## 第 2 题
50 |
51 | > 一个采用距离矢量路由选择算法的子网共有 6 个路由器(分别标记为 A、B、C、D、E 和 F),其中 C 与 B、D 和 E 直接相连。现在 C 路由器收到了来自以下相邻节点的路由信息:
52 | >
53 | > B: { A:5, C:8, D:12, E:6, F:2 }
54 | >
55 | > D: { A:16, B:12, C:6, E:9, F:10}
56 | >
57 | > E: {A:7, B:6, C:3, D:9, F:4}
58 | >
59 | > 已知 C 到 B、D和E 的距离分别为 6,3 和 5。请给出 C 的新路由表。
60 |
61 | 使用来自 B、D、E 的路由表,逐个与本地路由表对照,选择费用较小的那一条,最后可得:
62 |
63 | | 目的地 | 下一跳 | 度量 |
64 | | :----: | :----: | :---: |
65 | | A | B | 11 |
66 | | B | B | 6 |
67 | | D | D | 3 |
68 | | E | E | 5 |
69 | | F | B | 8 |
70 |
71 | ## 第 3 题
72 |
73 | > 一个如图的网络准备采用链路状态算法,请完成以下问题:
74 | >
75 | > 1. 各节点交互的信息是什么?(至少以两个节点为例)
76 | >
77 | > 2. 收集到所有节点的交互信息后,A节点如何计算出到其他节点的最短路径,需给出具体计算过程。
78 |
79 | 
80 |
81 | B:
82 | ```JSON
83 | {
84 | "A": 2,
85 | "C": 10,
86 | "E": 4,
87 | "F": 6
88 | }
89 | ```
90 | E:
91 | ```JSON
92 | {
93 | "A": 6,
94 | "B": 4,
95 | "H": 1,
96 | "I": 5
97 | }
98 | ```
99 |
100 | 初始:
101 | | 目的 | B | C | D | E | F | G | H | I |
102 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
103 | | 度量 | 2 | inf | inf | 6 | inf | inf | 4 | inf |
104 | | 下一跳 | B | / | / | E | / | / | H | / |
105 |
106 | 合并B路由表:
107 | | 目的 | B | C | D | E | F | G | H | I |
108 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
109 | | 度量 | 2 | 12 | inf | 6 | 8 | inf | 4 | inf |
110 | | 下一跳 | B | B | / | E | B | / | H | / |
111 |
112 | 合并H路由表:
113 | | 目的 | B | C | D | E | F | G | H | I |
114 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
115 | | 度量 | 2 | 12 | inf | 5 | 8 | inf | 4 | 13 |
116 | | 下一跳 | B | B | / | H | B | / | H | H |
117 |
118 | 合并E路由表:
119 | | 目的 | B | C | D | E | F | G | H | I |
120 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
121 | | 度量 | 2 | 12 | inf | 5 | 8 | inf | 4 | 10 |
122 | | 下一跳 | B | B | / | H | B | / | H | H |
123 |
124 | 合并F路由表:
125 | | 目的 | B | C | D | E | F | G | H | I |
126 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
127 | | 度量 | 2 | 12 | 14 | 5 | 8 | 13 | 4 | 10 |
128 | | 下一跳 | B | B | B | H | B | B | H | H |
129 |
130 | 合并I路由表:
131 | | 目的 | B | C | D | E | F | G | H | I |
132 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
133 | | 度量 | 2 | 12 | 14 | 5 | 8 | 13 | 4 | 10 |
134 | | 下一跳 | B | B | B | H | B | B | H | H |
135 |
136 | 合并C路由表:
137 | | 目的 | B | C | D | E | F | G | H | I |
138 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
139 | | 度量 | 2 | 12 | 14 | 5 | 8 | 13 | 4 | 10 |
140 | | 下一跳 | B | B | B | H | B | B | H | H |
141 |
142 | 合并G路由表:
143 | | 目的 | B | C | D | E | F | G | H | I |
144 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
145 | | 度量 | 2 | 12 | 14 | 5 | 8 | 13 | 4 | 10 |
146 | | 下一跳 | B | B | B | H | B | B | H | H |
147 |
148 | 合并D路由表:
149 | | 目的 | B | C | D | E | F | G | H | I |
150 | | :----: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
151 | | 度量 | 2 | 12 | 14 | 5 | 8 | 13 | 4 | 10 |
152 | | 下一跳 | B | B | B | H | B | B | H | H |
153 |
154 | ## 第 4 题
155 |
156 | > 假设三个 L2 交换机连成线状,每台交换机有 24 个百兆接口。请问:
157 | >
158 | > 1. 理想状态下,所有端口全线速、无阻塞工作,整个网络每秒的吞吐量能达多大?
159 | >
160 | > 2. 发送一个广播报文的代价,相当于同时转发多少个单播报文?
161 | >
162 | > 3. 同样是理想状态的所有端口全线速、无阻塞工作,网络吞吐量在广播报文的影响下,下降到最小为多少?
163 |
164 | 1. 整个网络对外开放的接口有 $24\times 3-4=68$ 个,这些端口无阻塞地以 100Mbps 速度工作,所以吞吐量为 6800Mbps。
165 | 2. 除了送来广播报文的端口,交换机要向所有端口发送该报文,即相当于同时转发 23 个单播报文。
166 | 3. 广播时,所有端口都要为广播报文让步,实际上同时只有一个端口在起作用,吞吐量下降到 100Mbps。
167 |
168 | ## 第 5 题
169 |
170 | > 一个采用了距离矢量算法的 IP 网络,假设有 20 台路由器;每台路由器有 4 个接口;有 20 个网络上有 2 个路由器,4 个网络上有 3 个路由器,剩下的都只连接 1 个路由器;每条路由信息包括目的网络号,子网掩码,距离,占用 12 个字节,使用 UDP 报文传输,总的头部 + 尾部开销 46 字节(MAC + IP + UDP),如果每隔 30 秒路由器会发布一次路由信息,请估算平均到每秒,路由信息的全网总开销是多少?单条线路上的开销是多少?
171 |
172 | 首先计算路由信息报文大小:40 个接口连 20 个网络,12 个接口连 4 个网络,总量为 52。所以单个路由信息报文有 $52\times 12=624$ 字节,加上头尾开销后共有 670 字节。
173 |
174 | 因为共有 80 个接口,所以全网总开销为
175 |
176 | $$
177 | Cost=670\times 80=53600B=52.34KB
178 | $$
179 |
180 | 单条线路的开销就是报文大小,为
181 |
182 | $$
183 | Cost=670B
184 | $$
185 |
186 | ## 第 6 题
187 |
188 | > 假设 4 个路由器组成一个两两连接、全连通的网络,采用扩散方法广播分组。假设每间隔 1 秒,各路由器发送一次分组。
189 | >
190 | > 1. 如果只是不向来路回传,经过 4 秒后,网上将有多少份分组(副本)待传?
191 | >
192 | > 2. 如果增加重复分组的判断,经过 4 秒后,还有分组待传吗,以及总共复制了多少份?
193 |
194 | 1. 如果不判重:
195 | - 第 1 秒,发送 3 份;
196 | - 第 2 秒,发送 6 份;
197 | - 第 3 秒,发送 12 份;
198 | - 第 4 秒,发送 24 份;
199 | 2. 如果判重:
200 | - 第 1 秒,发送 3 份;
201 | - 第 2 秒,发送 3 份;
202 | - 第 3 秒,发送 3 份;
203 | - 第 4 秒,发送 0 份;
204 |
205 | ## 第 7 题
206 |
207 | > IP 网络采用了不透明分段技术,假设途径 4 个网络,每个网络的 MTU 分别依次为 1000、700、1500 和 500 字节,假设 A 传输的原始 IP 分组为 3500 字节,请问目的端收到的分段情况,即每种大小的分段分别有多少?
208 |
209 | 1. 经过第 1 个网络:1000×3 + 500
210 | 2. 经过第 2 个网络:700×3 + 300×3 + 500
211 | 3. 经过第 3 个网络:700×3 + 300×3 + 500
212 | 4. 经过第 4 个网络:500×4 + 300×3 + 200×3
213 |
214 | 所以目的端会收到 500 字节分段 4 个,300、200 字节分段各 3 个。
215 |
--------------------------------------------------------------------------------
/Unit5/exercise.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/exercise.pdf
--------------------------------------------------------------------------------
/Unit5/images/2021-12-14-09-47-41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/images/2021-12-14-09-47-41.png
--------------------------------------------------------------------------------
/Unit5/mindmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/mindmap.png
--------------------------------------------------------------------------------
/Unit5/vocabulary.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrcaidev/computer-network-and-communication-technology/0c5c2ed6db1bad35863f0c434b8711ad2624244b/Unit5/vocabulary.pdf
--------------------------------------------------------------------------------