# 基于广播网络实验内容
## 实验内容
1、实现节点广播的 broadcast_packet 函数
2、验证广播网络能够正常运行
- 从一个端节点 ping 另一个端节点
3、验证广播网络的效率
- 在 three_nodes_bw.py 进行 iperf 测量
- 两种场景:
H1: iperf client; H2, H3: servers (h1 同时向 h2 和 h3 测量)
H1: iperf server; H2, H3: clients (h2 和 h3 同时向 h1 测量)
自己动手构建环形拓扑,验证该拓扑下节点广播会产生数据包环路
## 设计思路及结果验证
### 实现节点广播
#### 设计思路
本实验需要在已有代码框架的基础上实现 `main.c` 中的 `broadcast_packet` 函数。
注意到,如要实现广播网路,则非接受节点若收到数据包,需要将数据包从其他端口转发出去。因此,该函数的伪代码如下:
```
foreach iface in iface_list:
if iface != rx_iface:
iface_send_packet(iface, packet, len);
```
(注:`iface_list` 保存所有端口的信息)
在该实验中,该函数的具体实现如下:
```c
void broadcast_packet(iface_info_t *iface, const char *packet, int len)
{
// TODO: broadcast packet
fprintf(stdout, "TODO: broadcast packet here.\n");
iface_info_t * iface_entry = NULL;
list_for_each_entry(iface_entry, &instance->iface_list, list) {
if (iface_entry -> fd != iface -> fd) {
iface_send_packet(iface_entry, packet, len);
}
}
}
```
其中,`instance_iface` 保存所有端口的信息,iface_list 中的表项利用 fd 来进行区分。
#### 结果验证
利用 `three_nodes_bw.py` 拓扑文件打开 `Mininet`,互相 `ping` 三个节点使之能通,测试结果如下:
###### `h1` 节点 ping `h2` 节点和 `h3` 节点:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/07a4dc1cc6f5fa455bf960f1d3311c28.writebug)
上图中 `10.0.0.2` 和 `10.0.0.3` 分别表示 `h2` 和 `h3` 节点。如图,`h1` 节点可以 `ping` 通 `h2` 节点和 `h3` 节点。
###### `h2` 节点 ping `h1` 节点和 `h3` 节点:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/17eaaddac5b62fa98ca7b26d3dc6b9e9.writebug)
上图中 `10.0.0.1` 和 `10.0.0.3` 分别表示 `h1` 和 `h3` 节点。如图,`h2` 节点可以 `ping` 通 `h1` 节点和 `h3` 节点。
###### `h3` 节点 ping `h1` 节点和 `h2` 节点:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/60813ff560fa51cfe1df5f43e941b3a0.writebug)
上图中 `10.0.0.1` 和 `10.0.0.2` 分别表示 `h1` 和 `h2` 节点。如图,`h3` 节点可以 `ping` 通 `h1` 节点和 `h2` 节点。
##### 进行 iperf 测试,验证广播网络的链路利用效率,测试结果如下:
###### `h1`: `iperf client`; `h2`,`h3`: `iperf servers`:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/a77333e5491619f5157538c13c3133b0.writebug)
上图中 `h1` 节点同时向 `h2` 节点和 `h3` 节点测量,可以看出 `h1` 节点时向 `h2` 节点和 `h3` 节点的发送带宽分别为 `2.92Mbps` 和 `3.89Mbps`。`h2` 节点和 `h3` 节点的接收带宽分别为 `2.89Mbps` 和 `3.88Mbps`。
而在拓扑文件中,`h1 -> b1` 的带宽为 `20Mbps`,`b1 -> h2` 的带宽为 `10Mbps`,`b1 -> h3` 的带宽为 `10Mbps`。因此带宽的利用率为 `34.05%`。
###### `h1`: `iperf server`; `h2`,`h3`: `iperf client`:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/a322ec55bfa0d9593f95d75a0fb6c33f.writebug)
上图中 `h2` 节点和 `h3` 节点同时向 `h1` 节点测量,可以看出 `h1` 节点时接收 `h2` 节点和 `h3` 节点的接收带宽分别为 `4.14Mbps` 和 `3.76Mbps`。`h2` 节点和 `h3` 节点的发送带宽分别为 `4.31Mbps` 和 `3.82Mbps`。
同样的,在拓扑文件中,`h1 -> b1` 的带宽为 `20Mbps`,`b1 -> h2` 的带宽为 `10Mbps`,`b1 -> h3` 的带宽为 `10Mbps`。因此带宽的利用率为 `39.5%`。
### 构建环形拓扑网络
#### 设计思路
本实验的代码在 `three_nodes_bw.py` 代码的基础上进行改写,实现在 `circle_topo.py` 中,构建了一个各节点间带宽为 20Mbps 的环形拓扑。关键代码实现如下:
```python
class BroadcastTopo(Topo):
def build(self):
h1 = self.addHost('h1')
h2 = self.addHost('h2')
b1 = self.addHost('b1')
b2 = self.addHost('b2')
b3 = self.addHost('b3')
self.addLink(h1, b1, bw=20)
self.addLink(h2, b2, bw=20)
self.addLink(b1, b2, bw=20)
self.addLink(b1, b3, bw=20)
self.addLink(b2, b3, bw=20)
if __name__ == '__main__':
check_scripts()
topo = BroadcastTopo()
net = Mininet(topo = topo, link = TCLink, controller = None)
h1, h2, b1, b2, b3 = net.get('h1', 'h2', 'b1', 'b2', 'b3')
h1.cmd('ifconfig h1-eth0 10.0.0.1/8')
h2.cmd('ifconfig h2-eth0 10.0.0.2/8')
clearIP(b1)
clearIP(b2)
clearIP(b3)
for h in [ h1, h2, b1, b2, b3 ]:
h.cmd('./scripts/disable_offloading.sh')
h.cmd('./scripts/disable_ipv6.sh')
net.start()
CLI(net)
net.stop()
```
#### 结果验证
通过 `h1# ping -c 1 10.0.0.2` 指令,抓包看到一个数据包不断被转发,测试结果如下图:
`h1` 显示结果:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/2897dcb8e7807a06495908292b1dfd71.writebug)
`h2` 利用 `wireshark` 抓包结果:
![](https://www.writebug.com/myres/static/uploads/2022/9/18/db22bdff0ec26c56196fcec1a182517e.writebug)
![](https://www.writebug.com/myres/static/uploads/2022/9/18/2ecdfd10fb01905fe0af322fc853f85f.writebug)
由上图可知,数据包在该环形拓扑中被不断转发。
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源包含文件:设计报告word+源码 本实验需要在已有代码框架的基础上实现 main.c 中的 broadcast_packet 函数。详细介绍参考:https://blog.csdn.net/newlw/article/details/126921241
资源推荐
资源详情
资源评论
收起资源包目录
基于广播网络实验内容.zip (29个子文件)
assets
h2_exp04_2_wireshark_2.jpg 721KB
h2_exp04_2_wireshark_1.jpg 713KB
h3_exp04_1_ping.jpg 317KB
h1_exp04_1_client_iperf.jpg 644KB
h1_exp04_1_ping.jpg 317KB
h1_exp04_2_circle_topo.jpg 105KB
h2_exp04_1_ping.jpg 260KB
h1_exp04_1_server_iperf.jpg 606KB
lecture
04-实验中可能会遇到的问题.docx 17KB
04-广播网络实验.pptx 505KB
LICENSE 1KB
report
计算机网络实验报告04-广播网络实验报告.docx 2.7MB
计算机网络实验报告04-广播网络实验报告.pdf 3.84MB
code
04-broadcast
hub-reference 26KB
three_nodes_bw.py 2KB
main.c 6KB
include
base.h 416B
types.h 180B
list.h 1KB
ether.h 388B
log.h 723B
headers.h 440B
list_example.c 823B
hub-reference.32 20KB
Makefile 78B
circle_topo.py 2KB
scripts
disable_ipv6.sh 103B
disable_offloading.sh 328B
README.md 5KB
共 29 条
- 1
shejizuopin
- 粉丝: 1w+
- 资源: 1288
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页