Skip to content

Commit 8b6bff6

Browse files
committed
add switch lab
1 parent d9622bf commit 8b6bff6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+948
-156
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ pip3 install sphinx_rtd_theme --user
1515
1616
# make
1717
make html
18+
# For Windows use 'sphinx-build -M html . docs' to make
1819
```

Diff for: docs/doctrees/environment.pickle

24.9 KB
Binary file not shown.

Diff for: docs/doctrees/index.doctree

109 Bytes
Binary file not shown.

Diff for: docs/doctrees/lab-manuals/dns_server.doctree

-473 Bytes
Binary file not shown.

Diff for: docs/doctrees/lab-manuals/gbn_sender.doctree

269 Bytes
Binary file not shown.

Diff for: docs/doctrees/lab-manuals/sr_sender.doctree

-190 Bytes
Binary file not shown.

Diff for: docs/doctrees/lab-manuals/switch.doctree

34.5 KB
Binary file not shown.

Diff for: docs/doctrees/lab-manuals/tester.doctree

83 Bytes
Binary file not shown.

Diff for: docs/doctrees/platform/intro.doctree

83 Bytes
Binary file not shown.

Diff for: docs/doctrees/platform/student_manual.doctree

622 Bytes
Binary file not shown.
6.83 KB
Binary file not shown.
Binary file not shown.

Diff for: docs/html/_sources/index.rst.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ OpenNetLab USTC 2023 Documentation
2222
./lab-manuals/dns_server.rst
2323
./lab-manuals/gbn_sender.rst
2424
./lab-manuals/sr_sender.rst
25+
./lab-manuals/switch.rst

Diff for: docs/html/_sources/lab-manuals/dns_server.rst.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DNS(Domain Name System)是互联网中用于将域名(例如www.example.co
2020
Getting Started
2121
---------------
2222

23-
1. :download:`下载实验资源 <./resources/dns.zip>` ,解压后进入dns文件夹,其中包含两个子文件夹,:file:`resource` 文件夹中包含完成该实现所需阅读的文档以及实验报告模板,:file:`code` 文件夹中包含基础的实验代码模板。实验代码包含如下文件:
23+
1. :download:`下载实验资源 <./resources/dns.zip>` ,解压后进入dns文件夹,其中包含基础的实验代码模板。实验代码包含如下文件:
2424

2525
- :file:`main.py` :本地调试运行文件。
2626
- :file:`ipconf.txt` : 本地调试配置文件。
@@ -143,7 +143,7 @@ Testing
143143
完成程序基本功能的调试后,可以运行可执行文件 `tester` 进行多个测试用例评测,更详细的使用说明见 `相关文档 <./tester.html>`_
144144

145145

146-
2. `提交代码进行远程评测 <../platform/intro.html>`_
146+
2. `提交代码进行远程评测 <http://20.247.32.90>`_
147147

148148

149149

Diff for: docs/html/_sources/lab-manuals/gbn_sender.rst.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Go-Back-N是自动重复请求(ARQ)协议的一个特定实例,在该协议中
2222
Getting Started
2323
---------------
2424

25-
1. :download:`下载实验资源 <./resources/gbn.zip>` ,解压后进入gbn文件夹,其中包含 :file:`code` 文件夹,包含基础的实验代码模板。实验代码包含如下文件:
25+
1. :download:`下载实验资源 <./resources/gbn.zip>` ,解压后进入gbn文件夹,其中包含基础的实验代码模板。实验代码包含如下文件:
2626

2727
- :file:`main.py` :本地调试运行文件;
2828
- :file:`receiver.py` :接收方文件,无需修改;
@@ -199,4 +199,4 @@ Testing
199199

200200
完成程序基本功能的调试后,可以运行可执行文件 `tester` 进行多个测试用例评测,更详细的使用说明见 `相关文档 <./tester.html>`_
201201

202-
2. `提交代码进行远程评测 <../platform/intro.html>`_
202+
2. `提交代码进行远程评测 <http://20.247.32.90>`_

Diff for: docs/html/_sources/lab-manuals/sr_sender.rst.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Overview
2121
Getting Started
2222
---------------
2323

24-
1. :download:`下载实验资源 <./resources/sr.zip>` ,解压后进入sr文件夹,其中包含两个子文件夹,:file:`resource` 文件夹中包含完成该实现所需阅读的文档以及实验报告模板,:file:`code` 文件夹中包含基础的实验代码模板。实验代码包含如下文件:
24+
1. :download:`下载实验资源 <./resources/sr.zip>` ,解压后进入sr文件夹,其中包含基础的实验代码模板。实验代码包含如下文件:
2525

2626
- :file:`main.py` :本地调试运行文件;
2727
- :file:`receiver.py` :接收方文件,无需修改;
@@ -202,4 +202,4 @@ Testing
202202

203203
完成程序基本功能的调试后,可以运行可执行文件 `tester` 进行多个测试用例评测,更详细的使用说明见 `相关文档 <./tester.html>`_
204204

205-
2. `提交代码进行远程评测 <../platform/intro.html>`_
205+
2. `提交代码进行远程评测 <http://20.247.32.90>`_

Diff for: docs/html/_sources/lab-manuals/switch.rst.txt

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
:标题: DNS Server 实验说明
2+
3+
:作者:
4+
- dingzf
5+
- zhangxinyv
6+
7+
:时间: 2024年4月23日
8+
9+
==============
10+
Switch Lab
11+
==============
12+
13+
Overview
14+
========
15+
16+
17+
交换机工作在数据链路层,在交换机收到数据帧后,根据帧的目的MAC地址和交换机内部的帧交换表对帧进行处理,包括:明确的转发,即交换机知道应当从哪个/哪些端口转发该帧(单播,多播,广播);盲目的转发,即交换机不知道应当从哪个端口转发帧,只能将其通过除进入交换机的接口外的其他所有接口转发(也称为泛洪);明确的丢弃,即交换机知道不应该转发该帧,将其丢弃。交换机是一种即插即用的设备,其内部的帧交换表是通过自学习算法自动地逐渐建立起来的。
18+
19+
在这个实验中,你的任务是实现一个搭建在OpenNetLab上的交换机,该交换机具有自学习功能,可以逐渐学习MAC地址对应的端口以建立帧交换表。
20+
21+
22+
Getting Started
23+
---------------
24+
25+
1. :download:`下载实验资源 <./resources/switch.zip>` ,解压后进入文件夹,其中包含基础的实验代码模板。实验代码包含如下文件:
26+
27+
- :file:`main.py` :本地调试运行文件。
28+
- :file:`framegenerator.py` :帧发送方文件,无需修改。
29+
- :file:`endpoint.py` :帧接收方文件, `TODO` 部分待编写。
30+
- :file:`switch.py` : 自学习的MAC交换机文件,TODO部分待编写。
31+
- :file:`testcases.json` :本地评测配置文件。
32+
- :file:`tester` :本地评测运行文件,使用说明见相关文档。
33+
34+
2. 阅读实验任务,完成代码模板中 `TODO` 部分的代码片段。
35+
36+
3. 进行本地测试,完成本地测试后将代码提交到OpenNetLab在线平台进行远程评测。
37+
38+
4. 推荐实验环境:Linux操作系统,Python版本3.6以上。
39+
40+
Tasks
41+
-----
42+
43+
在这个实验中,framegenerator从待发送的帧列表中获取endpoint的MAC地址,并向其发送帧,你需要按照如下规则实现endpoint.py 和switch.py中的put方法的设计:
44+
45+
- 在endpoint.py中,put方法表示接收来自switch的帧,并根据帧的frame_type进行相应处理。
46+
47+
- 若frame_type为DATA,打印收到的数据帧Id
48+
- 若frame_type为BROADCAST
49+
50+
- 检查目的mac地址是否与endpoint的mac地址相同,若相同则返回一个ACK帧给switch
51+
- 否则,不做处理
52+
53+
- 在switch.py中,put方法表示接收来自framegenerator的数据帧和endpoint确认帧,并根据帧的frame_type进行相应处理。
54+
55+
- 首先,你需要根据实际需求,选择合适的数据结构先实现switch的forward_table(转发表),要求至少包含mac地址和对应的端口号
56+
- 若frame_type为DATA
57+
58+
- 检查forward_table中是否存在mac地址和对应的端口号
59+
- 若存在,则将帧转发到对应的端口
60+
- 否则,将广播帧转发到除源端口外的所有端口
61+
62+
- 若frame_type为ACK
63+
64+
- 将帧的mac地址和对应的端口号添加到forward_table中
65+
66+
67+
该实验 `TODO` 部分的伪代码如下:
68+
69+
.. code-block:: text
70+
71+
# endpoint
72+
function put(frame){
73+
# process the reception of frames
74+
receive frame from switch
75+
if frame_type is DATA{
76+
print frame_id
77+
}
78+
else if frame_type is BROADCAST{
79+
check the destination mac_addr
80+
if mac_addr is the same as endpoint's mac_addr{
81+
return an ACK frame to switch
82+
}
83+
else{
84+
pass
85+
}
86+
}
87+
88+
89+
# switch
90+
forward_table to be define #根据需求选择合适的数据结构实现转发表
91+
function put(frame){
92+
# process the reception of frames
93+
receive frame from framegenerator or endpoint
94+
if frame_type is DATA{
95+
check forward_table
96+
if mac_addr and it's port in forward_table{
97+
forward the frame to the port
98+
}
99+
else{
100+
forward BROADCAST frame to all the port except the source port
101+
}
102+
}
103+
else if frame_type is ACK{
104+
add the entry into forward_table
105+
}
106+
107+
108+
------------
109+
110+
Tips
111+
====
112+
113+
1.switch.py和framegenerator.py中一些属性和方法的解释:
114+
115+
116+
.. py:attribute:: self.env
117+
:noindex:
118+
119+
程序运行的环境。
120+
121+
.. py:attribute:: self.debug
122+
:noindex:
123+
124+
控制运行过程中日志信息输出,可以设置为True以方便调试。
125+
126+
.. py:attribute:: self.proc
127+
:noindex:
128+
129+
客户端的进程;
130+
131+
.. py:attribute:: self.outs
132+
:noindex:
133+
134+
交换机转发帧的端口日志记录;
135+
136+
.. py:attribute:: self.outs
137+
:noindex:
138+
139+
交换机的输出端口;
140+
141+
.. py:attribute:: self.frame_type
142+
:noindex:
143+
144+
数据帧的类型,有DATA,BROADCAST,ACK三种;
145+
146+
.. py:function:: run(self, env)
147+
:noindex:
148+
149+
在给定的环境中运行客户端。
150+
151+
@参数: env - 程序的运行环境
152+
153+
.. py:function:: dprint(self, msg)
154+
:noindex:
155+
156+
打印运行日志信息。
157+
158+
@参数: msg - 需要打印的信息
159+
160+
.. py:function:: forward(self, port_num, frame):
161+
:noindex:
162+
163+
向给定端口转发帧,并记录转发的端口信息。
164+
165+
@参数: port_num - 转发端口号
166+
@参数: frame - 数据帧
167+
168+
169+
170+
171+
2.framegenerator、switch、endpoint之间均通过Wire完成帧的传输,其中framegenerator和switch之间有一条Wire,endpoint和switch之间各有两条Wire。
172+
173+
3.若switch.log与expected_res一致,则说明设计成功。
174+
175+
176+
------------
177+
178+
Testing
179+
=======
180+
181+
1. 进行本地测试
182+
183+
在本机运行 *main.py* 程序。 *main.py* 程序会使用本地的一个测试用例对switch及endpoint的正确性进行评测并输出运行日志。
184+
185+
.. code-block:: shell
186+
187+
python3 main.py
188+
189+
190+
.. note::
191+
`main.py` 首先实例化类 `Environment` ,创建一个基于事件的网络模拟执行环境。然后 `main.py` 在模拟环境中实例化 FrameGenerator、EndPoint 、Switch类,并将三者连接进行帧传输。
192+
193+
194+
完成程序基本功能的调试后,可以运行可执行文件 `tester` 进行多个测试用例评测,更详细的使用说明见 `相关文档 <./tester.html>`_
195+
196+
197+
1. `提交代码进行远程评测 <http://20.247.32.90>`_
198+
199+
200+
201+

Diff for: docs/html/_static/basic.css

+22
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ a.headerlink {
237237
visibility: hidden;
238238
}
239239

240+
a:visited {
241+
color: #551A8B;
242+
}
243+
240244
h1:hover > a.headerlink,
241245
h2:hover > a.headerlink,
242246
h3:hover > a.headerlink,
@@ -670,6 +674,16 @@ dd {
670674
margin-left: 30px;
671675
}
672676

677+
.sig dd {
678+
margin-top: 0px;
679+
margin-bottom: 0px;
680+
}
681+
682+
.sig dl {
683+
margin-top: 0px;
684+
margin-bottom: 0px;
685+
}
686+
673687
dl > dd:last-child,
674688
dl > dd:last-child > :last-child {
675689
margin-bottom: 0;
@@ -738,6 +752,14 @@ abbr, acronym {
738752
cursor: help;
739753
}
740754

755+
.translated {
756+
background-color: rgba(207, 255, 207, 0.2)
757+
}
758+
759+
.untranslated {
760+
background-color: rgba(255, 207, 207, 0.2)
761+
}
762+
741763
/* -- code displays --------------------------------------------------------- */
742764

743765
pre {

Diff for: docs/html/_static/documentation_options.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var DOCUMENTATION_OPTIONS = {
2-
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
1+
const DOCUMENTATION_OPTIONS = {
32
VERSION: '1.0',
43
LANGUAGE: 'en',
54
COLLAPSE_INDEX: false,

Diff for: docs/html/_static/pygments.css

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left:
1717
.highlight .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
1818
.highlight .gd { color: #A00000 } /* Generic.Deleted */
1919
.highlight .ge { font-style: italic } /* Generic.Emph */
20+
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
2021
.highlight .gr { color: #E40000 } /* Generic.Error */
2122
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
2223
.highlight .gi { color: #008400 } /* Generic.Inserted */

Diff for: docs/html/_static/searchtools.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ const _removeChildren = (element) => {
5757
const _escapeRegExp = (string) =>
5858
string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
5959

60-
const _displayItem = (item, searchTerms) => {
60+
const _displayItem = (item, searchTerms, highlightTerms) => {
6161
const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
62-
const docUrlRoot = DOCUMENTATION_OPTIONS.URL_ROOT;
6362
const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
6463
const docLinkSuffix = DOCUMENTATION_OPTIONS.LINK_SUFFIX;
6564
const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
65+
const contentRoot = document.documentElement.dataset.content_root;
6666

6767
const [docName, title, anchor, descr, score, _filename] = item;
6868

@@ -75,20 +75,24 @@ const _displayItem = (item, searchTerms) => {
7575
if (dirname.match(/\/index\/$/))
7676
dirname = dirname.substring(0, dirname.length - 6);
7777
else if (dirname === "index/") dirname = "";
78-
requestUrl = docUrlRoot + dirname;
78+
requestUrl = contentRoot + dirname;
7979
linkUrl = requestUrl;
8080
} else {
8181
// normal html builders
82-
requestUrl = docUrlRoot + docName + docFileSuffix;
82+
requestUrl = contentRoot + docName + docFileSuffix;
8383
linkUrl = docName + docLinkSuffix;
8484
}
8585
let linkEl = listItem.appendChild(document.createElement("a"));
8686
linkEl.href = linkUrl + anchor;
8787
linkEl.dataset.score = score;
8888
linkEl.innerHTML = title;
89-
if (descr)
89+
if (descr) {
9090
listItem.appendChild(document.createElement("span")).innerHTML =
9191
" (" + descr + ")";
92+
// highlight search terms in the description
93+
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
94+
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
95+
}
9296
else if (showSearchSummary)
9397
fetch(requestUrl)
9498
.then((responseData) => responseData.text())
@@ -97,6 +101,9 @@ const _displayItem = (item, searchTerms) => {
97101
listItem.appendChild(
98102
Search.makeSearchSummary(data, searchTerms)
99103
);
104+
// highlight search terms in the summary
105+
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
106+
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
100107
});
101108
Search.output.appendChild(listItem);
102109
};
@@ -115,14 +122,15 @@ const _finishSearch = (resultCount) => {
115122
const _displayNextItem = (
116123
results,
117124
resultCount,
118-
searchTerms
125+
searchTerms,
126+
highlightTerms,
119127
) => {
120128
// results left, load the summary and display it
121129
// this is intended to be dynamic (don't sub resultsCount)
122130
if (results.length) {
123-
_displayItem(results.pop(), searchTerms);
131+
_displayItem(results.pop(), searchTerms, highlightTerms);
124132
setTimeout(
125-
() => _displayNextItem(results, resultCount, searchTerms),
133+
() => _displayNextItem(results, resultCount, searchTerms, highlightTerms),
126134
5
127135
);
128136
}
@@ -360,7 +368,7 @@ const Search = {
360368
// console.info("search results:", Search.lastresults);
361369

362370
// print the results
363-
_displayNextItem(results, results.length, searchTerms);
371+
_displayNextItem(results, results.length, searchTerms, highlightTerms);
364372
},
365373

366374
/**

0 commit comments

Comments
 (0)