From beb05a71c84849d813bee389576d67b1f63f2ebb Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Fri, 23 Mar 2012 18:17:49 -0700 Subject: [PATCH] Move dumpNetConnections to util() because it's useful! --- mininet/cli.py | 15 ++------------- mininet/util.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/mininet/cli.py b/mininet/cli.py index 058a330..6beb047 100644 --- a/mininet/cli.py +++ b/mininet/cli.py @@ -33,7 +33,7 @@ import sys from mininet.log import info, output, error from mininet.term import makeTerms -from mininet.util import quietRun, isShellBuiltin +from mininet.util import quietRun, isShellBuiltin, dumpNodeConnections class CLI( Cmd ): "Simple command-line interface to talk to nodes." @@ -109,21 +109,10 @@ class CLI( Cmd ): nodes = ' '.join( [ node.name for node in sorted( self.nodelist ) ] ) output( 'available nodes are: \n%s\n' % nodes ) - @staticmethod - def dump_connections( node ): - "Helper method: dump connections to node" - for intf in node.intfList(): - if intf.link: - intfs = [ intf.link.intf1, intf.link.intf2 ] - intfs.remove( intf ) - output( ' %s' % intfs[ 0 ].node ) def do_net( self, _line ): "List network connections." - for node in self.nodelist: - output( node.name, '<->' ) - self.dump_connections( node ) - output( '\n' ) + dumpNodeConnections( self.nodelist ) def do_sh( self, line ): "Run an external shell command" diff --git a/mininet/util.py b/mininet/util.py index bd61fae..04a91cb 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -187,6 +187,31 @@ def moveIntf( intf, node, printError=False, retries=3, delaySecs=0.001 ): printError: if true, print error""" retry( retries, delaySecs, moveIntfNoRetry, intf, node, printError ) +# Support for dumping network + +def dumpNodeConnections( nodes ): + "Dump connections to/from nodes." + + def dumpConnections( node ): + "Helper function: dump connections to node" + for intf in node.intfList(): + output( ' %s:' % intf ) + if intf.link: + intfs = [ intf.link.intf1, intf.link.intf2 ] + intfs.remove( intf ) + output( intfs[ 0 ] ) + else: + output( ' ' ) + + for node in nodes: + output( node.name ) + dumpConnections( node ) + output( '\n' ) + +def dumpNetConnections( net ): + "Dump connections in network" + nodes = net.controllers + net.switches + net.hosts + dumpNodeConnections( nodes ) # IP and Mac address formatting and parsing