diff --git a/bin/mn b/bin/mn index a8ae5a8..8dd0d41 100755 --- a/bin/mn +++ b/bin/mn @@ -81,19 +81,30 @@ class MininetRunner( object ): self.parseArgs() self.setup() self.begin() - - def parseCustomFile( self, custom ): - "Parse custom file and add params before parsing cmd-line options." - if os.path.isfile( custom ): - execfile( custom, globals(), globals() ) - if 'topos' in globals(): TOPOS.update( topos ) - if 'switches' in globals(): SWITCHES.update( switches ) - if 'hosts' in globals(): HOSTS.update( hosts ) - if 'controllers' in globals(): CONTROLLERS.update( controllers ) - if 'validate' in globals(): self.validate = validate + + def setCustom( self, name, value ): + print "got", self, name, value + if name in ( 'topos', 'switches', 'hosts', 'controllers' ): + # Update dictionaries + param = name.upper() + globals()[ param ].update( value ) + elif name == 'validate': + # Add custom validate function + self.validate = value else: - raise Exception( 'could not find custom file: %s' % custom ) - + # Add or modify global variable or class + globals()[ name ] = value + + def parseCustomFile( self, fileName ): + "Parse custom file and add params before parsing cmd-line options." + custom = {} + if os.path.isfile( fileName ): + execfile( fileName, custom, custom ) + for name in custom: + self.setCustom( name, custom[ name ] ) + else: + raise Exception( 'could not find custom file: %s' % fileName ) + def parseArgs( self ): """Parse command-line args and return options object. returns: opts parse options dict""" @@ -161,7 +172,7 @@ class MininetRunner( object ): port=self.options.port ) if self.validate: - self.validate(self.options) + self.validate( self.options ) controllerParams = ControllerParams( 0x0a000000, 8 ) # 10.0.0.0/8 inNamespace = self.options.inNamespace diff --git a/custom/custom_example.py b/custom/custom_example.py index 49e2394..9603533 100644 --- a/custom/custom_example.py +++ b/custom/custom_example.py @@ -13,10 +13,10 @@ topology enables one to pass in '--topo=mytopo' from the command line. from mininet.topo import Topo, Node class MyTopo( Topo ): - """Simple topology example.""" + "Simple topology example." def __init__( self, enable_all = True ): - """Create custom topo.""" + "Create custom topo." # Add default members to class. super( MyTopo, self ).__init__() @@ -42,4 +42,6 @@ class MyTopo( Topo ): self.enable_all() -topos = { 'mytopo': ( lambda: MyTopo() ) } \ No newline at end of file +topos = { 'mytopo': MyTopo } + +# topos = { 'mytopo': ( lambda: MyTopo() ) } \ No newline at end of file diff --git a/mininet/cli.py b/mininet/cli.py index 469f4b1..f28904d 100644 --- a/mininet/cli.py +++ b/mininet/cli.py @@ -88,8 +88,7 @@ class CLI( Cmd ): def do_net( self, args ): "List network connections." - for switchDpid in self.mn.topo.switches(): - switch = self.mn.nodes[ switchDpid ] + for switch in self.mn.switches: info( '%s <->', switch.name ) for intf in switch.intfs: node = switch.connection[ intf ] diff --git a/mininet/net.py b/mininet/net.py index 5666442..4d4dfcb 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -303,14 +303,14 @@ class Mininet( object ): ip = topo.ip( hostId ) host = self.addHost( name, defaultIp=ip, defaultMac=mac ) self.idToNode[ hostId ] = host - info( name ) + info( name + ' ' ) info( '\n*** Adding switches:\n' ) for switchId in sorted( topo.switches() ): name = 's' + topo.name( switchId ) mac = macColonHex( switchId) if self.setMacs else None switch = self.addSwitch( name, defaultMac=mac ) self.idToNode[ switchId ] = switch - info( name ) + info( name + ' ' ) info( '\n*** Adding edges:\n' ) for srcId, dstId in sorted( topo.edges() ): src, dst = self.idToNode[ srcId ], self.idToNode[ dstId ]