Add OVSLink/--link ovs, which uses OVS patch links when possible

This commit is contained in:
Bob Lantz
2015-01-15 02:07:00 -08:00
parent 127f35a9bc
commit c069542c5c
3 changed files with 50 additions and 3 deletions
+33
View File
@@ -26,6 +26,7 @@ Link: basic link class for creating veth pairs
from mininet.log import info, error, debug
from mininet.util import makeIntfPair, quietRun
import mininet.node
import re
class Intf( object ):
@@ -453,6 +454,38 @@ class Link( object ):
def __str__( self ):
return '%s<->%s' % ( self.intf1, self.intf2 )
class OVSIntf( Intf ):
"Patch interface on an OVSSwitch"
def ifconfig( self, cmd ):
if cmd == 'up':
"OVSIntf is always up"
return
else:
raise Exception( 'OVSIntf cannot do ifconfig ' + cmd )
class OVSLink( Link ):
"Link that makes patch links between OVSSwitches"
def __init__( self, node1, node2, **kwargs ):
"See Link.__init__() for options"
self.isPatchLink = False
if ( type( node1 ) is mininet.node.OVSSwitch and
type( node2 ) is mininet.node.OVSSwitch ):
self.isPatchLink = True
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
Link.__init__( self, node1, node2, **kwargs )
def makeIntfPair( self, *args, **kwargs ):
"Usually delegated to OVSSwitch"
if self.isPatchLink:
return None, None
else:
return Link.makeIntfPair( *args, **kwargs )
class TCLink( Link ):
"Link with symmetric TC interfaces configured via opts"
def __init__( self, node1, node2, port1=None, port2=None,
+14 -1
View File
@@ -58,7 +58,7 @@ from mininet.log import info, error, warn, debug
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
numCores, retry, mountCgroups )
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
from mininet.link import Link, Intf, TCIntf
from mininet.link import Link, Intf, TCIntf, OVSIntf
from re import findall
from distutils.version import StrictVersion
@@ -1147,6 +1147,18 @@ class OVSSwitch( Switch ):
return True
return self.failMode == 'standalone'
@staticmethod
def patchOpts( intf ):
"Return OVS patch port options (if any) for intf"
if type( intf ) is not OVSIntf:
# Ignore if it's not a patch link
return ''
intf1, intf2 = intf.link.intf1, intf.link.intf2
peer = intf1 if intf1 != intf else intf2
return ( '-- set Interface %s type=patch '
'-- set Interface %s options:peer=%s ' %
( intf, intf, peer ) )
def start( self, controllers ):
"Start up a new OVS OpenFlow switch using ovs-vsctl"
if self.inNamespace:
@@ -1159,6 +1171,7 @@ class OVSSwitch( Switch ):
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
'-- set Interface %s ' % intf +
'ofport_request=%s ' % self.ports[ intf ]
+ self.patchOpts( intf )
for intf in self.intfList()
if self.ports[ intf ] and not intf.IP() )
clist = ' '.join( '%s:%s:%d' % ( c.protocol, c.IP(), c.port )