【发布时间】:2019-01-31 11:24:18
【问题描述】:
我需要使用 Mininet Python API 在不同的主机上执行命令。
我已尝试同时使用 API 并使用 subprocess 和 pexpect 运行它,以确保 Mininet 配置没有问题。
net = Mininet()
s1 = net.addSwitch('s1')
for n in range(1,4):
h = net.addHost('h%s' % n)
net.addLink(h, s1)
net.addController('c0', controller=RemoteController, ip='127.0.0.1',
port=6653)
net.start()
h1 = net.get('h1')
h1.cmd('ping h2')
这不会执行命令h1 ping h2(用Wireshark检查)
另一方面,这确实有效:
child = pexpect.spawn('sudo mn --topo single,3 --controller remote')
child.expect('mininet>')
print child.before
time.sleep(5)
child.sendline('h1 ping h2')
time.sleep(60)
由于我试图实现的性质,我需要使用 API 而不是 pexpect(发送多个命令,以便不同的主机同时发送流量。在我的测试中,似乎 pexpect 只能执行一个命令一个接一个)。
为什么h1.cmd('ping h2') 不起作用?
【问题讨论】:
-
intro 示例建议您应该使用
h1.cmd('ping h2'),因为该命令已被定向到 h1。 -
@meuh 好地方,但不幸的是 ping 仍然没有出现在 wireshark 中