Change makeTerm() to tunnel X11 using socat if needed

For local display, allow local root access
For remote display, tunnel with socat/mnexec
This should enable *wireshark in hosts* and fix #119
This commit is contained in:
Bob Lantz
2013-03-22 15:48:51 -07:00
parent 4b8b4b73e1
commit a0f69d98df
4 changed files with 42 additions and 34 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ Depends:
${misc:Depends}, ${misc:Depends},
${python:Depends}, ${python:Depends},
${shlibs:Depends} ${shlibs:Depends}
Recommends: iperf, openvswitch-controller Recommends: iperf, openvswitch-controller, socat
Description: Process-based network emulator Description: Process-based network emulator
Mininet is a network emulator which uses lightweight Mininet is a network emulator which uses lightweight
virtualization to create virtual networks for rapid virtualization to create virtual networks for rapid
+1 -1
View File
@@ -36,7 +36,7 @@ def cleanup():
info( "*** Removing junk from /tmp\n" ) info( "*** Removing junk from /tmp\n" )
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' ) sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
info( "*** Removing old screen sessions\n" ) info( "*** Removing old X11 tunnels\n" )
cleanUpScreens() cleanUpScreens()
info( "*** Removing excess kernel datapaths\n" ) info( "*** Removing excess kernel datapaths\n" )
+39 -31
View File
@@ -1,60 +1,68 @@
""" """
Terminal creation and cleanup. Terminal creation and cleanup.
Utility functions to run a term (connected via screen(1)) on each host. Utility functions to run a terminal (connected via socat(1)) on each host.
Requires GNU screen(1) and xterm(1). Requires socat(1) and xterm(1).
Optionally uses gnome-terminal. Optionally uses gnome-terminal.
""" """
import re
from subprocess import Popen from subprocess import Popen
from os import environ
from mininet.log import error from mininet.log import error
from mininet.util import quietRun from mininet.util import quietRun, errRun
def quoteArg( arg ): def tunnelX11( node, display=None):
"Quote an argument if it contains spaces." """Create an X11 tunnel from node:6000 to the root host
return repr( arg ) if ' ' in arg else arg display: display on root host (optional)
returns: node $DISPLAY, Popen object for tunnel"""
if display is None:
display = environ[ 'DISPLAY' ]
host, screen = display.split( ':' )
# Unix sockets should work
if not host or host == 'unix':
# GDM3 doesn't put credentials in .Xauthority,
# so allow root to just connect
quietRun( 'xhost +si:localuser:root' )
return display, None
else:
# Create a tunnel for the TCP connection
port = 6000 + int( float ( screen ) )
connection = r'TCP\:%s\:%s' % ( host, port )
cmd = [ "socat", "TCP-LISTEN:%d,fork,reuseaddr" % port,
"EXEC:'mnexec -a 1 socat STDIO %s'" % connection ]
return 'localhost:' + screen, node.popen( cmd )
def makeTerm( node, title='Node', term='xterm' ): def makeTerm( node, title='Node', term='xterm', display=None ):
"""Run screen on a node, and hook up a terminal. """Create an X11 tunnel to the node and start up a terminal.
node: Node object node: Node object
title: base title title: base title
term: 'xterm' or 'gterm' term: 'xterm' or 'gterm'
returns: process created""" returns: two Popen objects, tunnel and terminal"""
title += ': ' + node.name title += ': ' + node.name
if not node.inNamespace: if not node.inNamespace:
title += ' (root)' title += ' (root)'
cmds = { cmds = {
'xterm': [ 'xterm', '-title', title, '-e' ], 'xterm': [ 'xterm', '-title', title, '-display' ],
'gterm': [ 'gnome-terminal', '--title', title, '-e' ] 'gterm': [ 'gnome-terminal', '--title', title, '--display' ]
} }
if term not in cmds: if term not in cmds:
error( 'invalid terminal type: %s' % term ) error( 'invalid terminal type: %s' % term )
return return
if not node.execed: display, tunnel = tunnelX11( node, display )
node.cmd( 'screen -dmS ' + 'mininet.' + node.name) term = node.popen( cmds[ term ] + [ display ] )
args = [ 'screen', '-D', '-RR', '-S', 'mininet.' + node.name ] return [ tunnel, term ] if tunnel else [ term ]
else:
args = [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
if term == 'gterm':
# Compress these for gnome-terminal, which expects one token
# to follow the -e option
args = [ ' '.join( [ quoteArg( arg ) for arg in args ] ) ]
return Popen( cmds[ term ] + args )
def cleanUpScreens(): def cleanUpScreens():
"Remove moldy old screen sessions." "Remove moldy socat X11 tunnels."
r = r'(\d+\.mininet\.[hsc]\d+)' errRun( "pkill -9 -f mnexec.*socat" )
output = quietRun( 'screen -ls' ).split( '\n' )
for line in output:
m = re.search( r, line )
if m:
quietRun( 'screen -S ' + m.group( 1 ) + ' -X quit' )
def makeTerms( nodes, title='Node', term='xterm' ): def makeTerms( nodes, title='Node', term='xterm' ):
"""Create terminals. """Create terminals.
nodes: list of Node objects nodes: list of Node objects
title: base title for each title: base title for each
returns: list of created terminal processes""" returns: list of created tunnel/terminal processes"""
return [ makeTerm( node, title, term ) for node in nodes ] terms = []
for node in nodes:
terms += makeTerm( node, title, term )
return terms
+1 -1
View File
@@ -122,7 +122,7 @@ function kernel_clean {
# Install Mininet deps # Install Mininet deps
function mn_deps { function mn_deps {
echo "Installing Mininet dependencies" echo "Installing Mininet dependencies"
$install gcc make screen psmisc xterm ssh iperf iproute telnet \ $install gcc make socat psmisc xterm ssh iperf iproute telnet \
python-setuptools python-networkx cgroup-bin ethtool help2man \ python-setuptools python-networkx cgroup-bin ethtool help2man \
pyflakes pylint pep8 pyflakes pylint pep8