Revision bec34e72 mininet/node.py

View differences:

mininet/node.py
1150 1150
        """Return ovsdb UUIDs for our controllers
1151 1151
           update: update cached value"""
1152 1152
        if not self._uuids or update:
1153
            controllers = self.vsctl( '-- get Bridge', self,
1153
            controllers = self.cmd( 'ovs-vsctl -- get Bridge', self,
1154 1154
                                    'Controller' ).strip()
1155 1155
            if controllers.startswith( '[' ) and controllers.endswith( ']' ):
1156 1156
                controllers = controllers[ 1 : -1 ]
......
1171 1171
        "Return OVS interface options for intf"
1172 1172
        opts = ''
1173 1173
        if not self.isOldOVS():
1174
            # ofport_request is not supported
1174
            # ofport_request is not supported on old OVS
1175 1175
            opts += ' ofport_request=%s' % self.ports[ intf ]
1176 1176
            # Patch ports don't work well with old OVS
1177 1177
            if isinstance( intf, OVSIntf ):
......
1182 1182

  
1183 1183
    def bridgeOpts( self ):
1184 1184
        "Return OVS bridge options"
1185
        opts = ''
1185
        opts = ( ' other_config:datapath-id=%s' % self.dpid +
1186
                 ' fail_mode=%s' % self.failMode )
1186 1187
        if not self.inband:
1187 1188
            opts += ' other-config:disable-in-band=true'
1188 1189
        if self.datapath == 'user':
......
1193 1194
            opts += ' stp_enable=true' % self
1194 1195
        return opts
1195 1196

  
1196
    # pylint: disable=too-many-branches
1197 1197
    def start( self, controllers ):
1198 1198
        "Start up a new OVS OpenFlow switch using ovs-vsctl"
1199 1199
        if self.inNamespace:
1200 1200
            raise Exception(
1201 1201
                'OVS kernel switch does not work in a namespace' )
1202 1202
        int( self.dpid, 16 )  # DPID must be a hex string
1203
        # Interfaces and controllers
1203
        # Command to add interfaces
1204 1204
        intfs = ''.join( ' -- add-port %s %s' % ( self, intf ) +
1205 1205
                         self.intfOpts( intf )
1206 1206
                         for intf in self.intfList()
1207 1207
                         if self.ports[ intf ] and not intf.IP() )
1208
        # Construct big ovs-vsctl command
1208
        # Command to create controller entries
1209 1209
        clist = [ ( self.name + c.name, '%s:%s:%d' %
1210 1210
                  ( c.protocol, c.IP(), c.port ) )
1211 1211
                  for c in controllers ]
......
1217 1217
            ccmd += ' max_backoff=%d' % self.reconnectms
1218 1218
        cargs = ' '.join( ccmd % ( name, target )
1219 1219
                         for name, target in clist )
1220
        # Controller ID list
1220 1221
        cids = ','.join( '@%s' % name for name, _target in clist )
1222
        # Try to delete any existing bridges with the same name
1221 1223
        if not self.isOldOVS():
1222 1224
            cargs += ' -- --if-exists del-br %s' % self
1223
        cmd = ( cargs +
1224
                ' -- add-br %s' % self +
1225
                ' -- set bridge %s controller=[%s]' % ( self, cids  ) +
1226
                self.bridgeOpts() +
1227
                intfs )
1228
        # Do it!!
1229
        self.vsctl( cmd )
1230
        # Reconnect quickly to controllers (1s vs. 15s max_backoff)
1231
        if self.isOldOVS() and self.reconnectms:
1232
            uuids = [ '-- set Controller %s max_backoff=%d' %
1233
                      ( uuid, self.reconnectms )
1234
                      for uuid in self.controllerUUIDs() ]
1235
            if uuids:
1236
                self.vsctl( *uuids )
1225
        # One ovs-vsctl command to rule them all!
1226
        self.vsctl( cargs +
1227
                    ' -- add-br %s' % self +
1228
                    ' -- set bridge %s controller=[%s]' % ( self, cids  ) +
1229
                    self.bridgeOpts() +
1230
                    intfs )
1231
        # XXX BROKEN - need to fix this!!
1237 1232
        # If necessary, restore TC config overwritten by OVS
1238
        for intf in self.intfList():
1239
            self.TCReapply( intf )
1240
    # pylint: enable=too-many-branches
1233
        # for intf in self.intfList():
1234
        # self.TCReapply( intf )
1241 1235

  
1242 1236
    def stop( self, deleteIntfs=True ):
1243 1237
        """Terminate OVS switch.
......
1305 1299
    def vsctl( self, *args, **kwargs ):
1306 1300
        "Append ovs-vsctl command to list for later execution"
1307 1301
        if self.started:
1308
            return OVSSwitch.vsctl( self, *args, **kwargs )
1302
            return super( OVSBridge, self).vsctl( *args, **kwargs )
1309 1303
        cmd = ' '.join( str( arg ).strip() for arg in args )
1310 1304
        self.commands.append( cmd )
1311 1305

  

Also available in: Unified diff