diff --git a/examples/cluster.py b/examples/cluster.py index 078dca4..d2764e9 100755 --- a/examples/cluster.py +++ b/examples/cluster.py @@ -843,11 +843,26 @@ class MininetCluster( Mininet ): def addController( self, *args, **kwargs ): "Patch to update IP address to global IP address" controller = Mininet.addController( self, *args, **kwargs ) - # Update IP address for controller that may not be local - if ( isinstance( controller, Controller) - and controller.IP() == '127.0.0.1' - and ' eth0:' in controller.cmd( 'ip link show' ) ): - Intf( 'eth0', node=controller ).updateIP() + loopback = '127.0.0.1' + if ( not isinstance( controller, Controller ) or + controller.IP() != loopback ): + return + # 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 ' + 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 def buildFromTopo( self, *args, **kwargs ):