diff --git a/examples/scratchnetuser.py b/examples/scratchnetuser.py index 4b8b9fd..ccd20e9 100755 --- a/examples/scratchnetuser.py +++ b/examples/scratchnetuser.py @@ -38,12 +38,12 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ): h1intf, sintf2 = linkIntfs( h1, switch ) info( '*** Configuring control network\n' ) - controller.setIP( '10.0.123.1/24', cintf ) - switch.setIP( '10.0.123.2/24', sintf) + controller.setIP( '10.0.123.1/24', intf=cintf ) + switch.setIP( '10.0.123.2/24', intf=sintf) info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24', h0intf ) - h1.setIP( '192.168.123.2/24', h1intf ) + h0.setIP( '192.168.123.1/24', intf=h0intf ) + h1.setIP( '192.168.123.2/24', intf=h1intf ) info( '*** Network state:\n' ) for node in controller, switch, h0, h1: diff --git a/mininet/node.py b/mininet/node.py index add10f3..63fd26c 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -358,14 +358,20 @@ class Node( object ): 'has no interfaces\n' ) def intf( self, intf='' ): - """Return our interface object with given name, - or default intf if name is empty""" + """Return our interface object with given string name, + default intf if name is falsy (None, empty string, etc). + or the input intf arg. + + Having this fcn return its arg for Intf objects makes it + easier to construct functions with flexible input args for + interfaces (those that accept both string names and Intf objects). + """ if not intf: return self.defaultIntf() elif type( intf) is str: return self.nameToIntf[ intf ] else: - return None + return intf def connectionsTo( self, node): "Return [ intf1, intf2... ] for all intfs that connect self to node." @@ -425,7 +431,7 @@ class Node( object ): def setIP( self, ip, prefixLen=8, intf=None ): """Set the IP address for an interface. - intf: interface name + intf: intf or intf name ip: IP address as a string prefixLen: prefix length, e.g. 8 for /8 or 16M addrs""" # This should probably be rethought