Automatically load kernel module dependencies
Before this commit, you'd have to manually insert the kernel module for OVS or OF kernel modules, and you couldn't run one regression test with all 3. Now, these are kmod insert/remove is handled automatically.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"Module dependency utility functions for Mininet."
|
||||
|
||||
from mininet.util import quietRun
|
||||
from mininet.log import info, error, debug
|
||||
|
||||
def lsmod():
|
||||
"Return output of lsmod."
|
||||
return quietRun( 'lsmod' )
|
||||
|
||||
def rmmod( mod ):
|
||||
"""Return output of lsmod.
|
||||
mod: module string"""
|
||||
return quietRun( [ 'rmmod', mod ] )
|
||||
|
||||
def modprobe( mod ):
|
||||
"""Return output of modprobe
|
||||
mod: module string"""
|
||||
return quietRun( [ 'modprobe', mod ] )
|
||||
|
||||
OF_KMOD = 'ofdatapath'
|
||||
OVS_KMOD = 'openvswitch_mod'
|
||||
TUN = 'tun'
|
||||
|
||||
def moduleDeps( subtract = [], add = [] ):
|
||||
"""Handle module dependencies.
|
||||
subtract: string or list of module names to remove, if already loaded
|
||||
add: string or list of module names to add, if not already loaded"""
|
||||
if type( subtract ) is str:
|
||||
subtract = [ subtract ]
|
||||
if type( add ) is str:
|
||||
add = [ add ]
|
||||
for mod in subtract:
|
||||
if mod in lsmod():
|
||||
info( '*** Removing ' + mod + '\n' )
|
||||
rmmodOutput = rmmod( mod )
|
||||
if rmmodOutput:
|
||||
error( 'Error removing ' + mod + '\n%s' % rmmodOutput )
|
||||
exit( 1 )
|
||||
if mod in lsmod():
|
||||
error( 'Failed to remove ' + mod + '; still there!\n' )
|
||||
exit( 1 )
|
||||
for mod in add:
|
||||
if mod not in lsmod():
|
||||
info( '*** Loading ' + mod + '\n' )
|
||||
modprobeOutput = modprobe( mod )
|
||||
if modprobeOutput:
|
||||
error( 'Error inserting ' + mod + ';\n See INSTALL.\n%s' %
|
||||
modprobeOutput )
|
||||
exit( 1 )
|
||||
if mod not in lsmod():
|
||||
error( 'Failed to insert ' + mod + '\n' )
|
||||
exit( 1 )
|
||||
else:
|
||||
debug( '*** ' + mod + ' already loaded\n' )
|
||||
@@ -151,6 +151,8 @@ class Mininet( object ):
|
||||
self.dps = 0 # number of created kernel datapaths
|
||||
self.terms = [] # list of spawned xterm processes
|
||||
|
||||
switch.setup()
|
||||
|
||||
if build:
|
||||
self.build()
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ from time import sleep
|
||||
|
||||
from mininet.log import info, error, debug
|
||||
from mininet.util import quietRun, makeIntfPair, moveIntf, isShellBuiltin
|
||||
from mininet.moduledeps import moduleDeps, OVS_KMOD, OF_KMOD, TUN
|
||||
|
||||
class Node( object ):
|
||||
"""A virtual network node is simply a shell in a network namespace.
|
||||
@@ -397,6 +398,11 @@ class UserSwitch( Switch ):
|
||||
name: name for the switch"""
|
||||
Switch.__init__( self, name, **kwargs )
|
||||
|
||||
@staticmethod
|
||||
def setup():
|
||||
"Ensure any dependencies are loaded; if not, try to load them."
|
||||
moduleDeps( add = TUN )
|
||||
|
||||
def start( self, controllers ):
|
||||
"""Start OpenFlow reference user datapath.
|
||||
Log to /tmp/sN-{ofd,ofp}.log.
|
||||
@@ -448,6 +454,11 @@ class KernelSwitch( Switch ):
|
||||
" in the root namespace." )
|
||||
exit( 1 )
|
||||
|
||||
@staticmethod
|
||||
def setup():
|
||||
"Ensure any dependencies are loaded; if not, try to load them."
|
||||
moduleDeps( subtract = OVS_KMOD, add = OF_KMOD )
|
||||
|
||||
def start( self, controllers ):
|
||||
"Start up reference kernel datapath."
|
||||
ofplog = '/tmp/' + self.name + '-ofp.log'
|
||||
@@ -508,6 +519,11 @@ class OVSKernelSwitch( Switch ):
|
||||
" in the root namespace." )
|
||||
exit( 1 )
|
||||
|
||||
@staticmethod
|
||||
def setup():
|
||||
"Ensure any dependencies are loaded; if not, try to load them."
|
||||
moduleDeps( subtract = OF_KMOD, add = OVS_KMOD )
|
||||
|
||||
def start( self, controllers ):
|
||||
"Start up kernel datapath."
|
||||
ofplog = '/tmp/' + self.name + '-ofp.log'
|
||||
|
||||
@@ -7,10 +7,13 @@ import unittest
|
||||
|
||||
from mininet.net import init, Mininet
|
||||
from mininet.node import KernelSwitch, Host, Controller, ControllerParams
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo
|
||||
|
||||
# temporary, until user-space side is tested
|
||||
SWITCHES = { 'kernel': KernelSwitch }
|
||||
SWITCHES = { 'kernel': KernelSwitch,
|
||||
'user': UserSwitch,
|
||||
'ovsk': OVSKernelSwitch }
|
||||
|
||||
|
||||
class testSingleSwitch( unittest.TestCase ):
|
||||
|
||||
Reference in New Issue
Block a user