Revision 27da832d mininet/node.py

View differences:

mininet/node.py
1018 1018
OVSKernelSwitch = OVSSwitch
1019 1019

  
1020 1020

  
1021
class IVSSwitch(Switch):
1022
    """IVS virtual switch
1023
       Currently only works in the root namespace.
1024
    """
1025

  
1026
    def __init__( self, name, **kwargs ):
1027
        Switch.__init__( self, name, **kwargs )
1028
        self.process = None
1029
        if self.inNamespace:
1030
            error( "IVSSwitch currently only works"
1031
                   " in the root namespace.\n" )
1032
            exit( 1 )
1033

  
1034
    @classmethod
1035
    def setup( cls ):
1036
        "Make sure IVS is installed"
1037
        pathCheck( 'ivs-ctl', 'ivs',
1038
                   moduleName="Indigo Virtual Switch (projectfloodlight.org)" )
1039
        out, err, exitcode = errRun( 'ivs-ctl show' )
1040
        if exitcode:
1041
            error( out + err +
1042
                   'ivs-ctl exited with code %d\n' % exitcode +
1043
                   '*** The openvswitch kernel module might '
1044
                   'not be loaded. Try modprobe openvswitch.\n' )
1045
            exit( 1 )
1046

  
1047
    def start( self, controllers ):
1048
        "Start up a new IVS switch"
1049
        args = ['ivs']
1050
        args.extend( ['--name', self.name] )
1051
        args.extend( ['--dpid', self.dpid] )
1052
        args.extend( ['--verbose'] )
1053
        for intf in self.intfs.values():
1054
            if not intf.IP():
1055
                args.extend( ['-i', intf.name] )
1056
        for c in controllers:
1057
            args.extend( ['-c', '%s:%d' % (c.IP(), c.port)] )
1058

  
1059
        with open( '/tmp/ivs.%s.log' % self.name, 'w' ) as logfile:
1060
            with open( '/dev/null', 'w' ) as nullfile:
1061
                self.process = Popen( args, stdout=logfile, stderr=STDOUT,
1062
                                      stdin=nullfile, preexec_fn=os.setsid )
1063
        self.execed = False
1064

  
1065
    def stop( self ):
1066
        "Terminate IVS switch."
1067
        if self.process:
1068
            self.process.terminate()
1069
            self.process.wait()
1070
            self.process = None
1071
        self.deleteIntfs()
1072

  
1073
    def attach( self, intf ):
1074
        "Connect a data port"
1075
        self.cmd( 'ivs-ctl', 'add-port', '--datapath', self.name, intf )
1076

  
1077
    def detach( self, intf ):
1078
        "Disconnect a data port"
1079
        self.cmd( 'ivs-ctl', 'del-port', '--datapath', self.name, intf )
1080

  
1081
    def dpctl( self, *args ):
1082
        "Run dpctl command"
1083
        return "dpctl not supported\n" or args or self # satisfy pylint
1084

  
1085

  
1021 1086
class Controller( Node ):
1022 1087
    """A Controller is a Node that is running (or has execed?) an
1023 1088
       OpenFlow controller."""

Also available in: Unified diff