'Python code in visual studio showing "raise Exception( 'Could not find a default OpenFlow controller' )" error

I have just started with the mininet and trying to build networks using python. I have tried to run the code shown in the image and pasted here in the following. However, it is showing multiple errors. Can you please tell me where am I doing it wrong.

Code:

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel


class SingleSwitchTopo(Topo):
    "Single switch connected to n hosts."
    def build(self, n=2):
        switch = self.addSwitch('s1')
        # Python's range(N) generates 0..N-1
        for h in range(n):
            host = self.addHost('h%s' % (h + 1))
            self.addLink(host, switch)

def simpleTest():
    "Create and test a simple network"
    topo = SingleSwitchTopo(n=4)
    net = Mininet(topo)
    net.start()
    print( "Dumping host connections" )
    dumpNodeConnections(net.hosts)
    print( "Testing network connectivity" )
    net.pingAll()
    net.stop()


if __name__ == '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    simpleTest()

Terminal Output:

*** Creating network
*** Adding controller
Traceback (most recent call last):
  File "def_in_python.py", line 31, in <module>
    simpleTest()
  File "def_in_python.py", line 19, in simpleTest
    net = Mininet(topo)
  File "/usr/lib/python2.7/dist-packages/mininet/net.py", line 172, in __init__
    self.build()
  File "/usr/lib/python2.7/dist-packages/mininet/net.py", line 444, in build
    self.buildFromTopo( self.topo )
  File "/usr/lib/python2.7/dist-packages/mininet/net.py", line 411, in buildFromTopo
    self.addController( 'c%d' % i, cls )
  File "/usr/lib/python2.7/dist-packages/mininet/net.py", line 261, in addController
    controller_new = controller( name, **params )
  File "/usr/lib/python2.7/dist-packages/mininet/node.py", line 1544, in DefaultController
    raise Exception( 'Could not find a default OpenFlow controller' )
Exception: Could not find a default OpenFlow controller

enter image description here



Solution 1:[1]

You must install openvswitch-testcontroller.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Banescu Eduard