Skip to content
Snippets Groups Projects
Commit 8d3c2859 authored by Brandon Heller's avatar Brandon Heller
Browse files

Add port status change command

parent e7c787b3
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
from subprocess import call from subprocess import call
from cmd import Cmd from cmd import Cmd
from mininet.log import info, output from mininet.log import info, output, error
class CLI( Cmd ): class CLI( Cmd ):
"Simple command-line interface to talk to nodes." "Simple command-line interface to talk to nodes."
...@@ -147,6 +147,15 @@ def do_dump( self, args ): ...@@ -147,6 +147,15 @@ def do_dump( self, args ):
for node in self.nodelist: for node in self.nodelist:
output( '%s\n' % node ) 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 ): def do_exit( self, args ):
"Exit" "Exit"
return 'exited by user command' return 'exited by user command'
......
...@@ -483,6 +483,33 @@ def iperfUdp( self, udpBw='10M' ): ...@@ -483,6 +483,33 @@ def iperfUdp( self, udpBw='10M' ):
"Run iperf UDP test." "Run iperf UDP test."
return self.iperf( l4Type='UDP', udpBw=udpBw ) 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 ): def interact( self ):
"Start network and run our simple CLI." "Start network and run our simple CLI."
self.start() self.start()
......
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