Revision 08cef003 mininet.py

View differences:

mininet.py
3 3
"""
4 4
Mininet: A simple networking testbed for OpenFlow!
5 5

  
6
Mininet creates simple OpenFlow test networks by using
6
Mininet creates scalable OpenFlow test networks by using
7 7
process-based virtualization and network namespaces. 
8 8

  
9
This file supports use of either the kernel or user space datapath
10
from the OpenFlow reference implementation. Up to 32 switches are
11
supported using the kernel datapath, and 512 (or more) switches are
12
supported via the user datapath.
13

  
14 9
Simulated hosts are created as processes in separate network
15 10
namespaces. This allows a complete OpenFlow network to be simulated on
16 11
top of a single Linux kernel.
......
23 18
Hosts have a network interface which is configured via ifconfig/ip
24 19
link/etc. with data network IP addresses (e.g. 192.168.123.2 )
25 20

  
21
This version supports both the kernel or user space datapaths
22
from the OpenFlow reference implementation.
23

  
26 24
In kernel datapath mode, the controller and switches are simply
27 25
processes in the root namespace.
28 26

  
......
48 46
Thoughts/TBD:
49 47

  
50 48
   It should be straightforward to add a function to read
51
   OpenFlowVMS  spec files, but I haven't done so yet.
49
   OpenFlowVMS spec files, but I haven't done so yet.
52 50
   For the moment, specifying configurations and tests in Python
53
   is straightforward and concise.
54
   Soon, we'll want to split the various subsystems (core,
51
   is straightforward and relatively concise.
52
   Soon, we may want to split the various subsystems (core,
55 53
   cli, tests, etc.) into multiple modules.
56
   We may be able to get better performance by using the kernel
57
   datapath (using its multiple datapath feature on multiple 
58
   interfaces.) This would eliminate the ofdatapath user processes.
59
   OpenVSwitch would still run at user level.
54
   We don't support nox nicely just yet - you have to hack this file
55
   or subclass things aggressively.
56
   We'd like to support OpenVSwitch as well as the reference
57
   implementation.
60 58
   
61 59
Bob Lantz
62 60
rlantz@cs.stanford.edu
......
65 63
11/19/09 Initial revision (user datapath only)
66 64
12/08/09 Kernel datapath support complete
67 65
12/09/09 Moved controller and switch routines into classes
66
12/12/09 Added subdivided network driver workflow
68 67
"""
69 68

  
70 69
from subprocess import call, check_call, Popen, PIPE, STDOUT
......
289 288
   def stopKernelDatapath( self ):
290 289
      "Terminate a switch using OpenFlow reference kernel datapath."
291 290
      quietRun( 'dpctl deldp ' + self.dp )
292
      for intf in self.intfs: quietRun( 'ip link del ' + intf )
291
      # In theory the interfaces should go away after we shut down.
292
      # However, this takes time, so we're better off to remove them
293
      # explicitly so that we won't get errors if we run before they
294
      # have been removed by the kernel. Unfortunately this is very slow.
295
      for intf in self.intfs:
296
         quietRun( 'ip link del ' + intf )
297
         sys.stdout.write( '.' ) ; flush()
293 298
      self.terminate()
294 299
   def start( self, controller ): 
295 300
      if self.dp is None: self.startUserDatapath( controller )
......
435 440
   def __init__( self, kernel=True, startAddr=( 192, 168, 123, 1) ):
436 441
      self.kernel, self.startAddr = kernel, startAddr
437 442
      # Check for kernel modules
438
      tun = quietRun( [ 'sh', '-c', 'lsmod | grep tun' ] )
439
      ofdatapath = quietRun( [ 'sh', '-c', 'lsmod | grep ofdatapath' ] )
440
      if tun == '' and not kernel: 
443
      modules = quietRun( 'lsmod' )
444
      if not kernel and 'tun' not in modules:
441 445
         print "*** Error: kernel module tun not loaded:",
442 446
         print " user datapath not supported"
443 447
         exit( 1 )
444
      if ofdatapath == '' and kernel:
445
         print "*** Error: ofdatapath not loaded:",
448
      if kernel and 'ofdatapath' not in modules:
449
         print "*** Error: kernel module ofdatapath not loaded:",
446 450
         print " kernel datapath not supported"
447 451
         exit( 1 )
448 452
      # Create network, but don't start things up yet!
......
551 555
# Grid network
552 556

  
553 557
class GridNet( Network ):
554
   "An N x M grid/mesh network of switches, with hosts at the edges."
558
   """An N x M grid/mesh network of switches, with hosts at the edges.
559
      This class also demonstrates creating a somewhat complicated
560
      topology."""
555 561
   def __init__( self, n, m, kernel=True, linear=False ):
556 562
      self.n, self.m, self.linear = n, m, linear and m == 1
557 563
      Network.__init__( self, kernel )
......
711 717
      print
712 718
      print "Interactive commands are not really supported yet,"
713 719
      print "so please limit commands to ones that do not"
714
      print "require user interaction, and that will terminate"
720
      print "require user interaction and will terminate"
715 721
      print "after a reasonable amount of time."
716 722
   def nodes( self, args ):
717 723
      "List available nodes"
......
725 731
      for switch in self.switches:
726 732
         print switch.name, "<->",
727 733
         for intf in switch.intfs:
728
            node, rintf = switch.connection[ intf ]
734
            node, remoteIntf = switch.connection[ intf ]
729 735
            print node.name,
730 736
         print
731 737
   def iperf( self, args ):

Also available in: Unified diff