0

I get the following error:

Traceback (most recent call last):

File "./ryuLinearTopo.py", line 6, in

class LinearTopo(Topo):

File "./ryuLinearTopo.py", line 32, in LinearTopo

simpleTest()

File "./ryuLinearTopo.py", line 21, in simpleTest

topo = LinearTopo(k=4)

NameError: global name 'LinearTopo' is not defined

When I run the following code:

#!/usr/bin/python

from mininet.topo import Topo

from mininet.net import Mininet

from mininet.util import irange,dumpNodeConnections

from mininet.log import setLogLevel

class LinearTopo(Topo):



    def __init__(self, k=2, **opts):

        super(LinearTopo, self).__init__(**opts)

        self.k = k

        lastSwitch = None

        for i in irange(1, k):

            host = self.addHost('h%s' % i)

            switch = self.addSwitch('s%s' % i)

            self.addLink( host, switch)

            if lastSwitch:

                self.addLink( switch, lastSwitch)

            lastSwitch = switch



    def simpleTest():

        topo = LinearTopo(k=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()
Hamza Farrukh
  • 57
  • 1
  • 10

1 Answers1

0

You are having a problem with identation. In your code, all the methods are defined inside your LinearTopo class. You want to define them outside the scope of the class like this:

#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel

class LinearTopo(Topo):
    def __init__(self, k=2, **opts):
        super(LinearTopo, self).__init__(**opts)
        self.k = k
        lastSwitch = None
        for i in irange(1, k):
            host = self.addHost('h%s' % i)
            switch = self.addSwitch('s%s' % i)
            self.addLink( host, switch)
            if lastSwitch:
                self.addLink( switch, lastSwitch)
            lastSwitch = switch

def simpleTest():
    topo = LinearTopo(k=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
    simpleTest()
    setLogLevel('info')

This question should have been tagged mininet, not Ryu, as it is strictly a mininet related question.

Hafager
  • 30
  • 3