unusualsuspect
unusualsuspect

Reputation: 15

Mininet static host mac addresses are not set from script

I’m attempting to statically set mac addresses for my hosts in my mininet script.

below is the script being ran

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() ) }

But upon verifying the configuration on the host h2 for example, the statically assigned mac 8B:94:91:62:F1:65 is not present for eth0.

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

from the mininet mailing list this should be the proper way to set the mac address.

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 Link encap:Ethernet HWaddr 00:00:00:00:00:09
inet addr:10.0.0.9 Bcast:10.0.0.255 Mask:255.255.255.0 ...

Upvotes: 1

Views: 1284

Answers (1)

bmailbox
bmailbox

Reputation: 1

Your MAC addresses are set as Broadcast addresses, which is invalid on host devices. Fix it by changing them to Unicast addresses.

For example: h2 = self.addHost('h2', mac='8A:94:91:62:F1:65')

Upvotes: 0

Related Questions