Statistics
| Branch: | Tag: | Revision:

mininet / examples / xterms.py @ 748e35d5

History | View | Annotate | Download (1.06 KB)

1
#!/usr/bin/python
2

    
3
"Create a network and run an xterm (connected via screen) on each host."
4

    
5
import os
6
from subprocess import Popen
7
from mininet import init, TreeNet, Cli, quietRun
8

    
9
def makeXterm( node, title ):
10
   "Run screen on a node, and hook up an xterm."
11
   node.cmdPrint( 'screen -dmS ' + node.name )
12
   cmd = 'xterm -title ' + title + ':' + node.name
13
   cmd += ' -e screen -D -RR -S ' + node.name
14
   return Popen( cmd.split( ' ' ) )
15

    
16
def makeXterms( nodes, title ):
17
   terms = []
18
   for node in nodes:
19
      if not node.execed:
20
         terms += [ makeXterm( node, title ) ]
21
   return terms
22

    
23
def xterms( controllers, switches, hosts ):
24
   terms = []
25
   terms += makeXterms( controllers, 'controller' )
26
   terms += makeXterms( switches, 'switch' )
27
   terms += makeXterms( hosts, 'host' )
28
   # Wait for completion
29
   for term in terms:
30
      os.waitpid( term.pid, 0 )
31
   
32
def treeXterms():
33
   print "Running xterms on", os.environ[ 'DISPLAY' ]
34
   network = TreeNet( depth=2, fanout=4, kernel=True )
35
   network.run( xterms )
36
      
37
if __name__ == '__main__':
38
   init()
39
   treeXterms()