Revision 98332cb6

View differences:

INSTALL
14 14
    sudo ln -s /home/openflow/mininet/netns /usr/local/bin/netns
15 15

  
16 16
  Installation is simplest with a distribution that includes a kernel
17
  which supports the CLONE_NETNS unshare flag by default. Debian 5.0+
18
  does; Ubuntu doesn't. If your kernel doesn't support it, you will need
19
  to build and install a kernel that does!
17
  which supports the CLONE_NETNS unshare flag by default. Debian 5.0+ does
18
  (e.g. current debian-testing release); Ubuntu doesn't. If your kernel
19
  doesn't support it, you will need to build and install a kernel that
20
  does!
20 21

  
21 22
- Mininet should probably be run either on a machine with
22 23
  no other important processes, or on a virtual machine
README
21 21
In order to run Mininet, you must have:
22 22

  
23 23
* A Linux 2.6.26 or greater kernel compiled with network namespace support
24
  enabled. (Debian 5.0 or greater should work)
24
  enabled. (debian-testing seems to have such a kernel.)
25 25

  
26 26
* The OpenFlow reference implementation (either the user or kernel
27 27
  datapath may be used, and the tun or ofdatapath kernel modules must be
......
48 48
- Some simple tests which can be run using someNetwork.run( test )
49 49
	
50 50
- A simple command-line interface which may be invoked on a network using
51
  .run( Cli )
51
  .run( Cli ). It provides useful diagnostic commands, as well as the
52
  ability to send a command to a node. For example,
53
  
54
  mininet> h11 ifconfig -a
55
  
56
  tells host h11 to run the command 'ifconfig -a'
52 57

  
53
- A 'cleanup' script to get rid of junk (interfaces, processes, etc.)
54
  which might be left around by mininet. Try this if things stop
55
  working!
58
- A 'cleanup' script to get rid of junk (interfaces, processes, files in
59
  /tmp, etc.) which might be left around by mininet. Try this if things
60
  stop working!
56 61
  
57 62
- Examples (in examples/ directory) to help you get started.
58 63

  
examples/scratchnetuser.py
1
#!/usr/bin/python
2

  
3
"""
4
Build a simple network from scratch, using mininet primitives.
5
This is more complicated than using the higher-level classes,
6
but it exposes the configuration details and allows cusomization.
7

  
8
This version uses the user datapath.
9
"""
10

  
11
from mininet import init, Node, createLink
12

  
13
def scratchNet( cname='controller', cargs='ptcp:'):
14
   # Create Network
15
   controller = Node( 'c0' )
16
   switch = Node( 's0')
17
   h0 = Node( 'h0' )
18
   h1 = Node( 'h1' )
19
   createLink( controller, switch )
20
   createLink( h0, switch )
21
   createLink( h1, switch )
22
   # Configure control network
23
   controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
24
   switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
25
   # Configure hosts
26
   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
27
   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
28
   # Start network using user datapath
29
   controller.cmdPrint( cname + ' ' + cargs + '&' )
30
   switch.cmdPrint( 'ifconfig lo 127.0.0.1' )
31
   switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ]) 
32
      + ' ptcp: &' )
33
   switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
34
   # Run test
35
   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
36
   # Stop network
37
   controller.cmdPrint( 'kill %' + cname)
38
   switch.cmdPrint( 'kill %ofdatapath' )
39
   switch.cmdPrint( 'kill %ofprotocol' )
40
   
41
if __name__ == '__main__':
42
   init()   
43
   scratchNet()
examples/sshd.py
1 1
#!/usr/bin/python
2 2

  
3 3
"""
4
Create a network and start sshd(8) on the hosts.
4
Create a network and start sshd(8) on each host.
5 5

  
6 6
While something like rshd(8) would be lighter and faster,
7 7
(and perfectly adequate on an in-machine network)
......
36 36
   for net in routes:
37 37
      root.cmdPrint( 'route add -net ' + net + ' dev ' + intf )
38 38

  
39
def startServers( network, server ):
40
   "Start network, and servers on each host."
39
def sshd( network ):
40
   "Start a network, connect it to root ns, and run sshd on all hosts."
41 41
   connectToRootNS( network, network.switches[ 0 ] )
42
   for host in network.hosts: host.cmdPrint( server )
43

  
44
if __name__ == '__main__':
45
   init()
46
   network = TreeNet( depth=1, fanout=4, kernel=True )
47
   startServers( network, '/usr/sbin/sshd' )
42
   for host in network.hosts: host.cmd( 'sshd -D &' )
48 43
   print
49 44
   print "*** Hosts are running sshd at the following addresses:"
50 45
   print
......
52 47
   print
53 48
   print "*** Press return to shut down network: ",
54 49
   readline()
50
   for host in network.hosts: host.cmd( 'kill %sshd')
55 51
   network.stop()
52
   
53
if __name__ == '__main__':
54
   init()
55
   network = TreeNet( depth=1, fanout=4, kernel=True )
56
   sshd( network )
examples/xterms.py
7 7

  
8 8
import os, re
9 9
from subprocess import Popen
10
from mininet import init, TreeNet, Cli, quietRun
10
from mininet import init, TreeNet, quietRun
11 11

  
12 12
def makeXterm( node, title ):
13 13
   "Run screen on a node, and hook up an xterm."
14
   node.cmdPrint( 'screen -dmS ' + node.name )
15 14
   title += ': ' + node.name
16 15
   if not node.inNamespace: title += ' (root)'
17
   cmd = [ 'xterm', '-title', title ]
18
   cmd += [ '-e', 'screen', '-D', '-RR', '-S', node.name ]
16
   cmd = [ 'xterm', '-title', title, '-e' ]
17
   if not node.execed:
18
      node.cmdPrint( 'screen -dmS ' + node.name )
19
      cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
20
   else:
21
      cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
19 22
   return Popen( cmd )
20 23

  
21 24
def cleanUpScreens():
......
28 31
         quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
29 32
   
30 33
def makeXterms( nodes, title ):
31
   terms = []
32
   for node in nodes:
33
      if not node.execed:
34
         terms += [ makeXterm( node, title ) ]
35
   return terms
34
   return [ makeXterm( node, title) for node in nodes]
36 35

  
37 36
def xterms( controllers, switches, hosts ):
38 37
   cleanUpScreens()
39
   terms = []
40
   terms += makeXterms( controllers, 'controller' )
38
   terms = makeXterms( controllers, 'controller' )
41 39
   terms += makeXterms( switches, 'switch' )
42 40
   terms += makeXterms( hosts, 'host' )
43 41
   # Wait for xterms to exit
mininet.py
136 136
   def terminate( self ):
137 137
      self.cleanup()
138 138
      os.kill( self.pid, signal.SIGKILL )
139
   def stop( self ): self.terminate()
139 140
   def waitReadable( self ): self.pollOut.poll()
140 141
   def sendCmd( self, cmd ):
141 142
      """Send a command, followed by a command to echo a sentinel,
......
198 199
      return intfName
199 200
   def setIP( self, intf, ip, bits ):
200 201
      "Set an interface's IP address."
201
      result = self.cmd( [ 'ifconfig', intf, ip + bits, 'up' ] )
202
      result = self.cmdPrint( [ 'ifconfig', intf, ip + bits, 'up' ] )
202 203
      self.ips[ intf ] = ip
203 204
      return result
204 205
   def setHostRoute( self, ip, intf ):
......
246 247
   def start( self, controller='controller', args='ptcp:' ):
247 248
      "Start <controller> <args> on controller, logging to /tmp/cN.log"
248 249
      cout = '/tmp/' + self.name + '.log'
249
      self.cmdPrint( controller + ' ' + args + 
250
      self.cmdPrint( 'exec ' + controller + ' ' + args + 
250 251
         ' 1> ' + cout + ' 2> ' + cout + ' &' )
252
      self.execed = True
251 253
   def stop( self, controller='controller' ):
252 254
      "Stop controller cprog on controller"
253
      self.cmd( "kill %" + controller )  
255
      self.terminate()
256
      # self.cmd( "kill %" + controller )  
254 257
         
255 258
class Switch( Node ):
256 259
   """A Switch is a Node that is running (or has execed)

Also available in: Unified diff