Add port status change command

This commit is contained in:
Brandon Heller
2010-03-13 06:30:53 -08:00
parent e7c787b343
commit 8d3c2859e4
2 changed files with 37 additions and 1 deletions
+10 -1
View File
@@ -33,7 +33,7 @@ Bugs/limitations:
from subprocess import call
from cmd import Cmd
from mininet.log import info, output
from mininet.log import info, output, error
class CLI( Cmd ):
"Simple command-line interface to talk to nodes."
@@ -147,6 +147,15 @@ class CLI( Cmd ):
for node in self.nodelist:
output( '%s\n' % node )
def do_link( self, args ):
"Bring a link up or down."
if len(args) != 3:
error( 'invalid number of args: link [up down] end1 end2\n' )
elif args[ 0 ] not in [ 'up', 'down' ]:
error( 'invalid type: link [up down] end1 end2\n' )
else:
self.mn.link( *args )
def do_exit( self, args ):
"Exit"
return 'exited by user command'
+27
View File
@@ -483,6 +483,33 @@ class Mininet( object ):
"Run iperf UDP test."
return self.iperf( l4Type='UDP', udpBw=udpBw )
def link( self, type, src, dst ):
"""Change link status.
type: string {up, down}
src: string
dst: string"""
if src not in self.nameToNode:
error( 'src not in network: %s\n' % src )
elif dst not in self.nameToNode:
error( 'dst not in network: %s\n' % dst )
else:
srcNode = self.nameToNode[ src ]
dstNode = self.nameToNode[ dst ]
srcID = int( src[ 1: ] )
dstID = int( dst[ 1: ] )
if self.topo.port( srcID, dstID ) is None:
error( 'src and dst not connected: %s %s\n' % ( src, dst) )
else:
srcPort, dstPort = self.topo.port( srcID, dstID )
srcIntf = srcNode.intfs[ srcPort ]
dstIntf = dstNode.intfs[ dstPort ]
result = srcNode.cmd( [ 'ifconfig', srcIntf, type ] )
if result:
error( 'link src status change failed: %s\n' % result )
result = dstNode.cmd( [ 'ifconfig', dstIntf, type ] )
if result:
error( 'link dst status change failed: %s\n' % result )
def interact( self ):
"Start network and run our simple CLI."
self.start()