Better IP address selection for controllers
Previously we looked for 'eth0', but linux has renamed interfaces. Instead of looking by name, we now look for an interface which is the appropriate gateway to a remote server address. fixes #831
This commit is contained in:
+20
-5
@@ -843,11 +843,26 @@ class MininetCluster( Mininet ):
|
|||||||
def addController( self, *args, **kwargs ):
|
def addController( self, *args, **kwargs ):
|
||||||
"Patch to update IP address to global IP address"
|
"Patch to update IP address to global IP address"
|
||||||
controller = Mininet.addController( self, *args, **kwargs )
|
controller = Mininet.addController( self, *args, **kwargs )
|
||||||
# Update IP address for controller that may not be local
|
loopback = '127.0.0.1'
|
||||||
if ( isinstance( controller, Controller)
|
if ( not isinstance( controller, Controller ) or
|
||||||
and controller.IP() == '127.0.0.1'
|
controller.IP() != loopback ):
|
||||||
and ' eth0:' in controller.cmd( 'ip link show' ) ):
|
return
|
||||||
Intf( 'eth0', node=controller ).updateIP()
|
# Find route to a different server IP address
|
||||||
|
serverIPs = [ ip for ip in self.serverIP.values()
|
||||||
|
if ip is not controller.IP() ]
|
||||||
|
if not serverIPs:
|
||||||
|
return # no remote servers - loopback is fine
|
||||||
|
remoteIP = serverIPs[ 0 ]
|
||||||
|
# Route should contain 'dev <intfname>'
|
||||||
|
route = controller.cmd( 'ip route get', remoteIP,
|
||||||
|
'| egrep -o "dev\s[^[:space:]]+"' )
|
||||||
|
if not route:
|
||||||
|
raise Exception('addController: no route from', c0, 'to',
|
||||||
|
remoteIP )
|
||||||
|
intf = route.split()[ 1 ].strip()
|
||||||
|
debug( 'adding', intf, 'to', controller )
|
||||||
|
Intf( intf, node=controller ).updateIP()
|
||||||
|
debug( controller, 'IP address updated to', controller.IP() )
|
||||||
return controller
|
return controller
|
||||||
|
|
||||||
def buildFromTopo( self, *args, **kwargs ):
|
def buildFromTopo( self, *args, **kwargs ):
|
||||||
|
|||||||
Reference in New Issue
Block a user