我是 mininet 和 python 的新手。我想在 mininet 中执行一个 python 脚本,但我不知道我们如何在 mininet 中运行 python 脚本以及在哪里存储 .py 文件以便从 mininet 调用。
有什么想法吗?
小智 5
当您打开 mininet 时,只需键入以下内容即可导航到自定义文件夹:
cd mininet/custom
Run Code Online (Sandbox Code Playgroud)
然后输入:
ls
Run Code Online (Sandbox Code Playgroud)
这将显示自定义文件中的当前文件。
然后你可以使用nano文本编辑器来创建或编辑一个 python/text 文件,例如你可以输入:
nano custom.py
Run Code Online (Sandbox Code Playgroud)
它将打开具有使用 python 代码示例的自定义文件。然后您可以退出它并将其另存为新文件。
这就是我开始编辑和编写 python 代码的方式,一旦你学会了如何使用 putty SSH mininet,它就会变得更容易。
祝你好运
我是这样做的。复制并粘贴以下代码或下载此文件:Simple_Pkt_Topo.py。
__author__ = 'Ehsan'
from mininet.node import CPULimitedHost
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import setLogLevel, info
from mininet.node import RemoteController
from mininet.cli import CLI
"""
Instructions to run the topo:
1. Go to directory where this fil is.
2. run: sudo -E python Simple_Pkt_Topo.py.py
The topo has 4 switches and 4 hosts. They are connected in a star shape.
"""
class SimplePktSwitch(Topo):
"""Simple topology example."""
def __init__(self, **opts):
"""Create custom topo."""
# Initialize topology
# It uses the constructor for the Topo cloass
super(SimplePktSwitch, self).__init__(**opts)
# Add hosts and switches
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')
# Adding switches
s1 = self.addSwitch('s1', dpid="0000000000000001")
s2 = self.addSwitch('s2', dpid="0000000000000002")
s3 = self.addSwitch('s3', dpid="0000000000000003")
s4 = self.addSwitch('s4', dpid="0000000000000004")
# Add links
self.addLink(h1, s1)
self.addLink(h2, s2)
self.addLink(h3, s3)
self.addLink(h4, s4)
self.addLink(s1, s2)
self.addLink(s1, s3)
self.addLink(s1, s4)
def run():
c = RemoteController('c', '0.0.0.0', 6633)
net = Mininet(topo=SimplePktSwitch(), host=CPULimitedHost, controller=None)
net.addController(c)
net.start()
CLI(net)
net.stop()
# if the script is run directly (sudo custom/optical.py):
if __name__ == '__main__':
setLogLevel('info')
run()
Run Code Online (Sandbox Code Playgroud)
然后你可以通过使用来运行拓扑
sudo -E python <nameofthefile>
Run Code Online (Sandbox Code Playgroud)
现在,您可以用来sudo -E python Simple_Pkt_Topo.py启动迷你网。
这是教程链接。
请注意,您需要一个控制器。如果您需要相关说明,请告诉我。
希望能帮助到你。
| 归档时间: |
|
| 查看次数: |
23430 次 |
| 最近记录: |