0

I have used Mininet to create a simple custom topology. It worked correctly When I was running it for the first time, but after that I received following error message:

Exception: Error creating interface pair (s1-eth1,h1-eth0): RTNETLINK answers: File exists

what is it and how can I solve it?

here is my topology:

from mininet.topo import Topo
from mininet.net import Mininet


class CustomTopo (Topo):

    def build(self):

        S1 = self.addSwitch('s1')

        H1 = self.addHost('h1')
        H2 = self.addHost('h2')

        self.addLink(S1, H1)
        self.addLink(S1, H2)


topo = CustomTopo()
net = Mininet(topo)
net.start()

topos = {'mytopo': CustomTopo}

and for more information I use Mininet 2.3.0d1

I run it by following command without remote controller and received another error: sudo mn --custom /home/bob/Desktop/Mtopo.py --topo=mytopo --mac

the error is: Exception: Please shut down the controller which is running on port 6653

I checked netstat -nl | grep 6653 but there is no active session on port 6653 and there is no other controller to shutdown.

Babak Memar
  • 37
  • 2
  • 12

2 Answers2

0

use this library:

from mininet.link import TCLink, Intf

and this when you add a link:

self.addLink(s1, h1, cls=TCLink)
dside
  • 98
  • 7
  • Unfortunately the error still remains, I also use 'sudo mn -c' but nothing happen. – Babak Memar May 30 '18 at 09:06
  • can you provide more details about using the script and the topo? – dside May 31 '18 at 10:01
  • Sure, you can see the script in main question and I saved it as Mtopo.py in desktop. To run it I use following command: **sudo mn --custom /home/bob/Desktop/Mtopo.py --topo=mytopo --mac** if you want more details, let me know what those are. @dside – Babak Memar May 31 '18 at 12:05
0

You actually start Mininet twice. Once in your script and the other with the command line. Either change your script to:

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.node import RemoteController

class CustomTopo (Topo):

    def build(self):

        S1 = self.addSwitch('s1')

        H1 = self.addHost('h1')
        H2 = self.addHost('h2')

        self.addLink(S1, H1)
        self.addLink(S1, H2)


topo = CustomTopo()
net = Mininet(topo, controller=lambda name: RemoteController(name, ip='127.0.0.1', protocol='tcp', port = 6633), autoSetMacs=True)
net.start()
CLI(net)
net.stop()

save to start_topology.py and run as

sudo python start_topology.run

or change your script to

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI


class CustomTopo (Topo):

    def build(self):

        S1 = self.addSwitch('s1')

        H1 = self.addHost('h1')
        H2 = self.addHost('h2')

        self.addLink(S1, H1)
        self.addLink(S1, H2)


topo = CustomTopo()
topos = {'mytopo': CustomTopo}

save to mytopo.py and run as

sudo mn --custom mytopo.py --topo=mytopo --mac --controller=remote,ip=127.0.0.1,port=6633

(change the IP and PORT for your controller accordingly)

Daniel
  • 440
  • 4
  • 13
  • Your answer is complete, thanks. I chose your first solution, just one question, in this case how can I assign MAC address to hosts? I mean exactly like when I use **sudo mn --mac**, I do not want random MAC address. – Babak Memar Jun 12 '18 at 12:57
  • You should add the parameter autoSetMacs=True to the Mininet constructor. I have edited my answer to include this. – Daniel Jun 12 '18 at 14:22
  • So I can use all parameters [http://mininet.org/api/classmininet_1_1net_1_1Mininet.html#a2b42ae2e15dceca476abf8ed9573834c] in constructor. Thanks a lot @Daniel – Babak Memar Jun 13 '18 at 07:41