Add OVSLink/--link ovs, which uses OVS patch links when possible
This commit is contained in:
@@ -30,7 +30,7 @@ from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
|
|||||||
UserSwitch, OVSSwitch, OVSBridge,
|
UserSwitch, OVSSwitch, OVSBridge,
|
||||||
OVSLegacyKernelSwitch, IVSSwitch )
|
OVSLegacyKernelSwitch, IVSSwitch )
|
||||||
from mininet.nodelib import LinuxBridge
|
from mininet.nodelib import LinuxBridge
|
||||||
from mininet.link import Link, TCLink
|
from mininet.link import Link, TCLink, OVSLink
|
||||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||||
from mininet.topolib import TreeTopo, TorusTopo
|
from mininet.topolib import TreeTopo, TorusTopo
|
||||||
from mininet.util import customConstructor, splitArgs
|
from mininet.util import customConstructor, splitArgs
|
||||||
@@ -82,7 +82,8 @@ CONTROLLERS = { 'ref': Controller,
|
|||||||
|
|
||||||
LINKDEF = 'default'
|
LINKDEF = 'default'
|
||||||
LINKS = { 'default': Link,
|
LINKS = { 'default': Link,
|
||||||
'tc': TCLink }
|
'tc': TCLink,
|
||||||
|
'ovs': OVSLink }
|
||||||
|
|
||||||
|
|
||||||
# optional tests to run
|
# optional tests to run
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Link: basic link class for creating veth pairs
|
|||||||
|
|
||||||
from mininet.log import info, error, debug
|
from mininet.log import info, error, debug
|
||||||
from mininet.util import makeIntfPair, quietRun
|
from mininet.util import makeIntfPair, quietRun
|
||||||
|
import mininet.node
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class Intf( object ):
|
class Intf( object ):
|
||||||
@@ -453,6 +454,38 @@ class Link( object ):
|
|||||||
def __str__( self ):
|
def __str__( self ):
|
||||||
return '%s<->%s' % ( self.intf1, self.intf2 )
|
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 ):
|
class TCLink( Link ):
|
||||||
"Link with symmetric TC interfaces configured via opts"
|
"Link with symmetric TC interfaces configured via opts"
|
||||||
def __init__( self, node1, node2, port1=None, port2=None,
|
def __init__( self, node1, node2, port1=None, port2=None,
|
||||||
|
|||||||
+14
-1
@@ -58,7 +58,7 @@ from mininet.log import info, error, warn, debug
|
|||||||
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
|
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
|
||||||
numCores, retry, mountCgroups )
|
numCores, retry, mountCgroups )
|
||||||
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
|
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 re import findall
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
@@ -1147,6 +1147,18 @@ class OVSSwitch( Switch ):
|
|||||||
return True
|
return True
|
||||||
return self.failMode == 'standalone'
|
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 ):
|
def start( self, controllers ):
|
||||||
"Start up a new OVS OpenFlow switch using ovs-vsctl"
|
"Start up a new OVS OpenFlow switch using ovs-vsctl"
|
||||||
if self.inNamespace:
|
if self.inNamespace:
|
||||||
@@ -1159,6 +1171,7 @@ class OVSSwitch( Switch ):
|
|||||||
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
||||||
'-- set Interface %s ' % intf +
|
'-- set Interface %s ' % intf +
|
||||||
'ofport_request=%s ' % self.ports[ intf ]
|
'ofport_request=%s ' % self.ports[ intf ]
|
||||||
|
+ self.patchOpts( intf )
|
||||||
for intf in self.intfList()
|
for intf in self.intfList()
|
||||||
if self.ports[ intf ] and not intf.IP() )
|
if self.ports[ intf ] and not intf.IP() )
|
||||||
clist = ' '.join( '%s:%s:%d' % ( c.protocol, c.IP(), c.port )
|
clist = ' '.join( '%s:%s:%d' % ( c.protocol, c.IP(), c.port )
|
||||||
|
|||||||
Reference in New Issue
Block a user