我正在尝试在我的 mininet 脚本中静态设置主机的 MAC 地址。
下面是正在运行的脚本
from mininet.net import Mininet
from mininet.node import Node
from mininet.topo import Topo
class CustomTopo(Topo):
def build(self):
#statically assigned host mac addresses
h1 = self.addHost('h1', mac='D3:13:1C:1B:76:A0')
h2 = self.addHost('h2', mac='8B:94:91:62:F1:65')
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
self.addLink(s1,s2)
self.addLink(h1,s1)
self.addLink(h2,s2)
topo = CustomTopo()
topos = { 'customtopo': ( lambda: CustomTopo() ) }
但是,例如,在验证主机 h2 上的配置后,eth0 不存在静态分配的 mac 8B:94:91:62:F1:65。
sudo mn -c
sudo mn --custom script.py --topo customtopo --controller=remote
mininet> h2 ifconfig
h2-eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.2 netmask 255.0.0.0 broadcast 10.255.255.255
inet6 fe80::f4da:8dff:fe8d:c696 prefixlen 64 scopeid 0x20<link>
ether f6:da:8d:8d:c6:96 txqueuelen 1000 (Ethernet)
RX packets 40 bytes 5598 (5.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 676 (676.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
来自 mininet 邮件列表 这应该是设置 mac 地址的正确方法。
net = Mininet()
h1 = net.addHost( 'h1', ip='10.9/24', mac='00:00:00:00:00:09' )
h2 = net.addHost( 'h2' )
s1 = net.addSwitch( 's1' )
c0 = net.addController( 'c0' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.start()
print h1.cmd( 'ifconfig' )
CLI( net )
net.stop()
...
h1-eth0 链接 encap:以太网 HWaddr 00:00:00:00:00:09
inet 地址:10.0.0.9 广播:10.0.0.255 掩码:255.255.255.0
...
您的 MAC 地址被设置为广播地址,这在主机设备上无效。通过将它们更改为单播地址来修复它。
例如:
h2 = self.addHost('h2', mac='8A:94:91:62:F1:65')