Clean up intfs in root NS, and avoid deleting HW intfs
It appears that under certain conditions, such as when a namespace exits, both ends of a veth pair may get dumped into the root namespace. We therefore now remove an interface both from its home namespace and from the root namespace.
This commit is contained in:
+4
-3
@@ -25,7 +25,7 @@ Link: basic link class for creating veth pairs
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.log import info, error, debug
|
from mininet.log import info, error, debug
|
||||||
from mininet.util import makeIntfPair
|
from mininet.util import makeIntfPair, quietRun
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -162,8 +162,9 @@ class Intf( object ):
|
|||||||
def delete( self ):
|
def delete( self ):
|
||||||
"Delete interface"
|
"Delete interface"
|
||||||
self.cmd( 'ip link del ' + self.name )
|
self.cmd( 'ip link del ' + self.name )
|
||||||
# Does it help to sleep to let things run?
|
if self.node.inNamespace:
|
||||||
sleep( 0.001 )
|
# Link may have been dumped into root NS
|
||||||
|
quietRun( 'ip link del ' + self.name )
|
||||||
|
|
||||||
def __repr__( self ):
|
def __repr__( self ):
|
||||||
return '<%s %s>' % ( self.__class__.__name__, self.name )
|
return '<%s %s>' % ( self.__class__.__name__, self.name )
|
||||||
|
|||||||
+5
-5
@@ -372,16 +372,16 @@ class Mininet( object ):
|
|||||||
if self.terms:
|
if self.terms:
|
||||||
info( '*** Stopping %i terms\n' % len( self.terms ) )
|
info( '*** Stopping %i terms\n' % len( self.terms ) )
|
||||||
self.stopXterms()
|
self.stopXterms()
|
||||||
info( '*** Stopping %i hosts\n' % len( self.hosts ) )
|
|
||||||
for host in self.hosts:
|
|
||||||
info( host.name + ' ' )
|
|
||||||
host.terminate()
|
|
||||||
info( '\n' )
|
|
||||||
info( '*** Stopping %i switches\n' % len( self.switches ) )
|
info( '*** Stopping %i switches\n' % len( self.switches ) )
|
||||||
for switch in self.switches:
|
for switch in self.switches:
|
||||||
info( switch.name + ' ' )
|
info( switch.name + ' ' )
|
||||||
switch.stop()
|
switch.stop()
|
||||||
info( '\n' )
|
info( '\n' )
|
||||||
|
info( '*** Stopping %i hosts\n' % len( self.hosts ) )
|
||||||
|
for host in self.hosts:
|
||||||
|
info( host.name + ' ' )
|
||||||
|
host.terminate()
|
||||||
|
info( '\n' )
|
||||||
info( '*** Stopping %i controllers\n' % len( self.controllers ) )
|
info( '*** Stopping %i controllers\n' % len( self.controllers ) )
|
||||||
for controller in self.controllers:
|
for controller in self.controllers:
|
||||||
info( controller.name + ' ' )
|
info( controller.name + ' ' )
|
||||||
|
|||||||
+11
-8
@@ -141,10 +141,10 @@ class Node( object ):
|
|||||||
|
|
||||||
def cleanup( self ):
|
def cleanup( self ):
|
||||||
"Help python collect its garbage."
|
"Help python collect its garbage."
|
||||||
if not self.inNamespace:
|
# Intfs may end up in root NS
|
||||||
for intfName in self.intfNames():
|
for intfName in self.intfNames():
|
||||||
if self.name in intfName:
|
if self.name in intfName:
|
||||||
quietRun( 'ip link del ' + intfName )
|
quietRun( 'ip link del ' + intfName )
|
||||||
self.shell = None
|
self.shell = None
|
||||||
|
|
||||||
# Subshell I/O, commands and control
|
# Subshell I/O, commands and control
|
||||||
@@ -391,16 +391,19 @@ class Node( object ):
|
|||||||
connections += [ ( intf, link.intf1 ) ]
|
connections += [ ( intf, link.intf1 ) ]
|
||||||
return connections
|
return connections
|
||||||
|
|
||||||
def deleteIntfs( self ):
|
def deleteIntfs( self, checkName=True ):
|
||||||
"Delete all of our interfaces."
|
"""Delete all of our interfaces.
|
||||||
|
checkName: only delete interfaces that contain our name"""
|
||||||
# In theory the interfaces should go away after we shut down.
|
# In theory the interfaces should go away after we shut down.
|
||||||
# However, this takes time, so we're better off removing them
|
# However, this takes time, so we're better off removing them
|
||||||
# explicitly so that we won't get errors if we run before they
|
# explicitly so that we won't get errors if we run before they
|
||||||
# have been removed by the kernel. Unfortunately this is very slow,
|
# have been removed by the kernel. Unfortunately this is very slow,
|
||||||
# at least with Linux kernels before 2.6.33
|
# at least with Linux kernels before 2.6.33
|
||||||
for intf in self.intfs.values():
|
for intf in self.intfs.values():
|
||||||
intf.delete()
|
# Protect against deleting hardware interfaces
|
||||||
info( '.' )
|
if ( self.name in intf.name ) or ( not checkName ):
|
||||||
|
intf.delete()
|
||||||
|
info( '.' )
|
||||||
|
|
||||||
# Routing support
|
# Routing support
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user