Skip to content

Commit 15b482e

Browse files
author
Brandon Heller
committed
Support gnome terminals too
Caution: code is incomplete - can't set a default type from the CLI and in some places the phrase xterm should be replaced by terminal.
1 parent e540ab5 commit 15b482e

4 files changed

Lines changed: 75 additions & 56 deletions

File tree

mininet/cli.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from cmd import Cmd
3535

3636
from mininet.log import info, output, error
37-
from mininet.xterm import makeXterms
37+
from mininet.term import makeTerms
3838

3939

4040
class CLI( Cmd ):
@@ -163,17 +163,23 @@ def do_link( self, args ):
163163
else:
164164
self.mn.configLinkStatus( *args )
165165

166-
def do_xterm( self, args ):
167-
"Spawn xterm for the given node."
166+
def do_term( self, args ):
167+
"Spawn terminal for the given node."
168168
args = args.split()
169169
if not args:
170-
error( 'please specify node list: xterm node1 node2 ...\n' )
170+
error( 'please specify node list: term [type] node1 node2 ...\n' )
171171
else:
172+
if args[ 0 ] in [ 'xterm', 'gnome' ]:
173+
term = args[ 0 ]
174+
args = args[ 1: ]
175+
else:
176+
term = 'xterm'
172177
for arg in args:
173178
if arg not in self.nodemap:
174179
error( 'arg not in network: %s\n' % arg )
175180
else:
176-
self.mn.terms += makeXterms( [ self.nodemap[ arg ] ] )
181+
node = self.nodemap[ arg ]
182+
self.mn.terms += makeTerms( [ node ], term = term )
177183

178184
def do_exit( self, args ):
179185
"Exit"

mininet/net.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
mininet.topolib, and a Controller which the switches will connect
6868
to. Several configuration options are provided for functions such as
6969
automatically setting MAC addresses, populating the ARP table, or
70-
even running a set of xterms to allow direct interaction with nodes.
70+
even running a set of terminals to allow direct interaction with nodes.
7171
7272
After the network is created, it can be started using start(), and a
7373
variety of useful tasks maybe performed, including basic connectivity
@@ -95,7 +95,7 @@
9595
from mininet.node import ControllerParams
9696
from mininet.util import quietRun, fixLimits
9797
from mininet.util import createLink, macColonHex, ipStr, ipParse
98-
from mininet.xterm import cleanUpScreens, makeXterms
98+
from mininet.term import cleanUpScreens, makeTerms
9999

100100
DATAPATHS = [ 'kernel' ] # [ 'user', 'kernel' ]
101101

@@ -310,19 +310,19 @@ def build( self ):
310310
info( '*** Configuring hosts\n' )
311311
self.configHosts()
312312
if self.xterms:
313-
self.startXterms()
313+
self.startTerms()
314314
if self.autoSetMacs:
315315
self.setMacs()
316316
if self.autoStaticArp:
317317
self.staticArp()
318318

319-
def startXterms( self ):
320-
"Start an xterm for each node."
321-
info( "*** Running xterms on %s\n" % os.environ[ 'DISPLAY' ] )
319+
def startTerms( self ):
320+
"Start a terminal for each node."
321+
info( "*** Running terms on %s\n" % os.environ[ 'DISPLAY' ] )
322322
cleanUpScreens()
323-
self.terms += makeXterms( self.controllers, 'controller' )
324-
self.terms += makeXterms( self.switches, 'switch' )
325-
self.terms += makeXterms( self.hosts, 'host' )
323+
self.terms += makeTerms( self.controllers, 'controller' )
324+
self.terms += makeTerms( self.switches, 'switch' )
325+
self.terms += makeTerms( self.hosts, 'host' )
326326

327327
def stopXterms( self ):
328328
"Kill each xterm."

mininet/term.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Terminal creation and cleanup.
3+
Utility functions to run a term (connected via screen(1)) on each host.
4+
5+
Requires GNU screen(1) and xterm(1).
6+
Optionally uses gnome-terminal.
7+
"""
8+
9+
import re
10+
from subprocess import Popen
11+
12+
from mininet.log import error
13+
from mininet.util import quietRun
14+
15+
def makeTerm( node, title = '', term = 'xterm' ):
16+
"""Run screen on a node, and hook up an xterm.
17+
node: Node object
18+
title: base title
19+
returns: process created"""
20+
title += ': ' + node.name
21+
if not node.inNamespace:
22+
title += ' (root)'
23+
cmd = ''
24+
if term == 'xterm':
25+
cmd = [ 'xterm', '-title', title, '-e' ]
26+
elif term == 'gnome':
27+
cmd = [ 'gnome-terminal', '--title', title, '-e' ]
28+
else:
29+
error( 'invalid terminal type: %s' % term )
30+
return
31+
if not node.execed:
32+
node.cmd( 'screen -dmS ' + node.name)
33+
#cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
34+
# Compress these for gnome-terminal, which expects one token to follow
35+
# the -e option .
36+
cmd += [ 'screen -D -RR -S ' + node.name ]
37+
else:
38+
cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
39+
return Popen( cmd )
40+
41+
def cleanUpScreens():
42+
"Remove moldy old screen sessions."
43+
r = r'(\d+.[hsc]\d+)'
44+
output = quietRun( 'screen -ls' ).split( '\n' )
45+
for line in output:
46+
m = re.search( r, line )
47+
if m:
48+
quietRun( 'screen -S ' + m.group( 1 ) + ' -X quit' )
49+
50+
def makeTerms( nodes, title = '', term = 'xterm' ):
51+
"""Create terminals.
52+
nodes: list of Node objects
53+
title: base title for each
54+
returns: list of created terminal processes"""
55+
return [ makeTerm( node, title, term ) for node in nodes ]

mininet/xterm.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)