2017-04-20 3 views
0

J'obtiens l'erreur suivante:retraçage (le plus récent appel dernier) Erreur dans le logiciel RYU réseau Définie

retraçage (appel le plus récent en dernier):

Fichier « ./ryuLinearTopo.py », ligne 6, dans

classe LinearTopo (Topo):

fichier "./ryuLinearTopo.py", ligne 32, dans LinearTopo

simpletest()

Fichier "./ryuLinearTopo.py", ligne 21, dans simpletest

Topo = LinearTopo (k = 4)

NameError: nom global 'LinearTopo' est pas défini

Quand je lance le code suivant:

#!/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() 

Répondre

0

Vous rencontrez un problème avec l'identification. Dans votre code, toutes les méthodes sont définies dans votre classe LinearTopo. Vous voulez les définir en dehors du cadre de la classe comme ceci:

#!/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') 

Cette question aurait dû être étiqueté MININET, pas Ryu, car il est strictement une question liée à la MININET.