Revision e8623fdc

View differences:

bin/mn
26 26
from mininet.net import Mininet, MininetWithControlNet, VERSION
27 27
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
28 28
                           NOX, RemoteController, DefaultController,
29
                           UserSwitch, OVSSwitch,
29
                           UserSwitch, OVSBridge, OVSSwitch,
30 30
                           OVSLegacyKernelSwitch, IVSSwitch )
31 31
from mininet.nodelib import LinuxBridge
32 32
from mininet.link import Link, TCLink
......
48 48
SWITCHDEF = 'ovsk'
49 49
SWITCHES = { 'user': UserSwitch,
50 50
             'ovs':  OVSSwitch,
51
             'ovsb' : OVSBridge,
51 52
             # Keep ovsk for compatibility with 2.0
52 53
             'ovsk': OVSSwitch,
53 54
             'ovsl': OVSLegacyKernelSwitch,
mininet/node.py
996 996
        self.deleteIntfs()
997 997

  
998 998

  
999
class OVSSwitch( Switch ):
1000
    "Open vSwitch switch. Depends on ovs-vsctl."
1001

  
1002
    def __init__( self, name, failMode='secure', datapath='kernel',
1003
                 inband=False, **params ):
1004
        """Init.
1005
           name: name for switch
1006
           failMode: controller loss behavior (secure|open)
1007
           datapath: userspace or kernel mode (kernel|user)
1008
           inband: use in-band control (False)"""
1009
        Switch.__init__( self, name, **params )
1010
        self.failMode = failMode
1011
        self.datapath = datapath
1012
        self.inband = inband
999
class OVSSwitchBase( Switch ):
1000
    'a base class for OVS switches; does not contain OpenFlow code at all'
1013 1001

  
1014 1002
    @classmethod
1015 1003
    def setup( cls ):
......
1045 1033
                  ' -- '.join( '--if-exists del-br %s' % s
1046 1034
                               for s in switches ) )
1047 1035

  
1048
    def dpctl( self, *args ):
1049
        "Run ovs-ofctl command"
1050
        return self.cmd( 'ovs-ofctl', args[ 0 ], self, *args[ 1: ] )
1051

  
1052 1036
    @staticmethod
1053 1037
    def TCReapply( intf ):
1054 1038
        """Unfortunately OVS and Mininet are fighting
......
1067 1051
        "Disconnect a data port"
1068 1052
        self.cmd( 'ovs-vsctl del-port', self, intf )
1069 1053

  
1054

  
1055
class OVSBridge( OVSSwitchBase ):
1056
    "OpenVSwitch Bridge (similar to OVSSwitch, but no OpenFlow)"
1057

  
1058
    def __init__( self, name, **kwargs ):
1059
        OVSSwitchBase.__init__( self, name, **kwargs )
1060

  
1061
    def connected( self ):
1062
        return True
1063

  
1064
    def start( self, controllers ):
1065
        if self.inNamespace:
1066
            raise Exception(
1067
                'OVS kernel switch does not work in a namespace' )
1068
        self.cmd( 'ovs-vsctl del-br', self )
1069
        intfs = ' '.join( '-- add-port %s %s ' % ( self, intf )
1070
                         for intf in self.intfList() if not intf.IP() )
1071
        cmd = ( 'ovs-vsctl add-br %s ' % self + intfs )
1072
        self.cmd( cmd )
1073
        for intf in self.intfList():
1074
            self.TCReapply( intf )
1075

  
1076
    def stop( self ):
1077
        self.cmd( 'ovs-vsctl del-br', self )
1078
        self.deleteIntfs()
1079

  
1080

  
1081
class OVSSwitch( OVSSwitchBase ):
1082
    "Open vSwitch switch using OpenFlow controller. Depends on ovs-vsctl."
1083

  
1084
    def __init__( self, name, failMode='secure', datapath='kernel',
1085
                 inband=False, **params ):
1086
        """Init.
1087
           name: name for switch
1088
           failMode: controller loss behavior (secure|open)
1089
           datapath: userspace or kernel mode (kernel|user)
1090
           inband: use in-band control (False)"""
1091
        OVSSwitchBase.__init__( self, name, **params )
1092
        self.failMode = failMode
1093
        self.datapath = datapath
1094
        self.inband = inband
1095

  
1096
    def dpctl( self, *args ):
1097
        "Run ovs-ofctl command"
1098
        return self.cmd( 'ovs-ofctl', args[ 0 ], self, *args[ 1: ] )
1099

  
1070 1100
    def controllerUUIDs( self ):
1071 1101
        "Return ovsdb UUIDs for our controllers"
1072 1102
        uuids = []

Also available in: Unified diff