在mininet的每个xterm窗口中自动运行脚本,可以通过以下步骤实现:
subprocess
模块来执行命令。xterm
命令创建xterm窗口,并在每个窗口中运行上一步中创建的Python脚本。例如:from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel
class MyTopo(Topo):
def build(self):
# 创建拓扑
if __name__ == '__main__':
setLogLevel('info')
topo = MyTopo()
net = Mininet(topo=topo, controller=RemoteController)
# 启动拓扑
net.start()
# 在每个xterm窗口中运行脚本
for host in net.hosts:
host.cmd('xterm -hold -e python auto_script.py &')
# 进入命令行界面
CLI(net)
# 停止拓扑
net.stop()
auto_script.py
是第一步中创建的Python脚本。xterm -hold -e
命令用于创建xterm窗口并在窗口中运行命令。&
符号用于在后台运行命令。这样,你就可以在mininet的每个xterm窗口中自动运行脚本了。
领取专属 10元无门槛券
手把手带您无忧上云