【问题标题】:How to run the commands inside the mininet prompt using python scripts from outside如何使用外部 python 脚本在 mininet 提示符内运行命令
【发布时间】:2017-04-01 00:26:06
【问题描述】:

我是 mininet 的新手。我想运行 mininet 命令以从“节点”、“转储”等 python 脚本运行。我可以创建拓扑,但不能通过我的脚本使用这些命令。我正在使用 Ubuntu 14.04。

import subprocess as sb
import os
print "Single Switch and 4 Hosts per switch topology"
print "Creation of topology"
os.system(" sudo mn --topo = single,4",shell=True)
os.system("nodes")

错误:

sh: 1: nodes: not found
32512

我不想通过python脚本创建拓扑,我只想使用mininet命令。

【问题讨论】:

  • mininet 有一个 pythonic API。您是否有理由要使用 bash 调用它?

标签: python mininet


【解决方案1】:

按照 nirOs 的建议,您应该使用 Mininet Python 库。通读https://github.com/mininet/mininet/wiki/Introduction-to-Mininet 以更好地了解如何创建拓扑。 创建后,您可以使用 hostObject.cmd('your command goes here') 。 mininet 中的每个主机都使用自己的命名空间创建。这个“cmd”在主机的命名空间中执行给定的命令。 例如 : host1.cmd("ifconfig") #这里返回主机的IP信息

【讨论】:

    【解决方案2】:

    很高兴我找到了这个问题。我有一个性质非常相似的子问题。我知道您可以使用例如从 python 向 mininet CLI 执行命令。 h1.cmd('ifconfig') ,但是有没有办法从 python 到 mininet> 提示符做同样的事情?即不将其指向拓扑中的特定主机(我正在模拟故障,因此某些主机已断开连接)。 net.cmd('python module.py') 之类的东西? @Abhimanyu singh @nir0s

    【讨论】:

    • 我建议您将此作为一个新问题提出。有你想做的具体例子。
    • @Ahmed 你找到问题的答案了吗?
    【解决方案3】:

    问题在于 mininet 是一个交互式 CLI。您不能简单地调用它,然后在交互式 CLI 阻塞时传递另一个命令。

    有办法解决这个问题。看这里:Wrapping an interactive CLI in python

    并检查pexpect 以更舒适地与交互式 CLI 交互。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多