Skip to content
Snippets Groups Projects
Commit bd558875 authored by Bob Lantz's avatar Bob Lantz
Browse files

Add net['h1'] and for node in net support

thanks to Brian O'Connor for reminder + suggestion
closes #114
parent 31fe4f1b
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,7 @@
import select
import signal
from time import sleep
from itertools import chain
from mininet.cli import CLI
from mininet.log import info, error, debug, output
......@@ -216,8 +217,8 @@ def addController( self, name='c0', controller=None, **params ):
self.nameToNode[ name ] = controller_new
return controller_new
# BL: is this better than just using nameToNode[] ?
# Should it have a better name?
# BL: We now have four ways to look up nodes
# This may (should?) be cleaned up in the future.
def getNodeByName( self, *args ):
"Return node(s) with given name(s)"
if len( args ) == 1:
......@@ -228,6 +229,15 @@ def get( self, *args ):
"Convenience alias for getNodeByName"
return self.getNodeByName( *args )
# Even more convenient syntax for node lookup and iteration
def __getitem__( self, *args ):
"""net [ name ] operator: Return node(s) with given name(s)"""
return self.getNodeByName( *args )
def __iter__( self ):
"return iterator over nodes"
return chain( self.hosts, self.switches, self.controllers )
def addLink( self, node1, node2, port1=None, port2=None,
cls=None, **params ):
""""Add a link from node1 to node2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment