gpt4 book ai didi

python - 无法在 Mininet 中设置 IP 地址

转载 作者:太空宇宙 更新时间:2023-11-04 01:00:25 25 4
gpt4 key购买 nike

我是 Python 和 Mininet 的新手。我一直在尝试使用 mininet 模拟网络拓扑。我正在尝试为网络中的每个主机分配 IP 地址,但出现属性错误。下面是我的代码

import sys
from mininet.topo import Topo
from mininet.node import Node

class MyTopo(Topo):
"customized topology example"
def __init__(self):
"custom topo creation"
#initialize topology
Topo.__init__(self)
H1=self.addHost('H1')
H3=self.addHost('H3')
H2=self.addHost('H2')
H4=self.addHost('H4')
S1=self.addSwitch('S1')
S2=self.addSwitch('S2')

self.addLink(H1,S1, bw=10, delay='2ms')
self.addLink(H2,S1, bw=20, delay='10ms')
self.addLink(H3,S2, bw=10, delay='2ms')
self.addLink(H4,S2, bw=20, delay='10ms')
self.addLink(S1,S2, bw=20, delay='2ms', losspct=10)

H1.setIP(self,None,'10.0.0.1',8)



topos={'mytopo':(lambda:MyTopo())}

出现以下错误

Caught exception. Cleaning up...
AttributeError: 'str' object has no attribute 'setIp'
----------------------------------------------------------------------- ---------
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs- openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'
*** Removing OVS datapathsovs-vsctl --timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o '(\w+-eth\w+)'
*** Cleanup complete.

谢谢

最佳答案

问题是,

mininet.topo.Topo.addHost

确实返回主机名(您传递给该方法)。所以你将不得不使用某物。像这样:

self.addHost('H1')
selg.g.node['H1'].addLink(...) # maybe the part with the node['H1'] does not fit perfectly...

看看this了解更多信息。

提示使用大量的 print() 来获取调试信息。例如:

debug=True
if(debug):print(someinfo)

编辑:

也许你想用

mininet.topo.Multigraph.add_edge

为此。

关于python - 无法在 Mininet 中设置 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33088549/

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