gpt4 book ai didi

bash - 在 Mininet 中批量执行命令

转载 作者:行者123 更新时间:2023-12-05 02:18:38 27 4
gpt4 key购买 nike

给定一个 Mininet 网络,我想模拟流,例如使用 iperf。为此,我可以运行以下命令:

h5 iperf3 -s -p 1337 &
h6 iperf3 -s -p 1338 &
h1 iperf3 -c h5 -n 10G -b 11M -p 1337 &
h2 iperf3 -c h6 -n 10G -b 11M -p 1338 &

在 Mininet CLI 中,h1h2 ... 代表 Mininet 拓扑上的主机。如果 Mininet 命令以主机 ID 开头,则该命令将像在该主机上一样运行。为方便起见,以后出现的任何 ID 都将替换为其 IP 地址。

这些命令有效,但我还没有找到使它们自动化的方法。我可以运行一个可以调用 bash 命令的 python 脚本,但是上面的命令会中断,因为上下文无法理解 mininet ID。手动输入所有这些内容很烦人,即使是复制粘贴工作也是如此。

有没有办法向 mininet CLI 发送一批命令?

最佳答案

Mininet documentation可以使用脚本__init__ CLI 模式。脚本的每一行都将在 CLI 中执行,不会因用户输入而停止。粗略浏览本文档会发现 CLI 用于解释和执行命令的各个方法。

这是一个例子:

myScript = "genTraffic.sh"
CLI(net, script=myScript) # Batch mode script execution
CLI(net) # Send user in the CLI for additional manual actions

我使用的脚本与问题中发布的脚本相同,带有前置 Ping,让网络 Controller 和 Mininet 有时间“看到”对方。

h1 ping h5 -c 3
h2 ping h6 -c 3
h5 iperf3 -s -p 1337 &
h6 iperf3 -s -p 1338 &
h1 iperf3 -c h5 -n 10G -b 11M -p 1337 &
h2 iperf3 -c h6 -n 10G -b 11M -p 1338 &

Host 和 Switch python 对象也有一个名为 cmd 的方法。这是在输入以例如开头的命令时使用的方法。 Mininet CLI 中的 h1s1。我相信使用一系列 cmd 调用等同于批处理脚本方法。

额外提示:如果您想在 CLI 中使用 h1s1 之类的标记,而不用相关的 IP 地址替换它,您可以转义 token :\h1

关于bash - 在 Mininet 中批量执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com