Move init() into Mininet() and remove calls (since called automatically.)

Note: we should probably rename it "setup()" to avoid confusion.
This commit is contained in:
Bob Lantz
2012-03-09 14:10:20 -08:00
parent e3c074b881
commit 8e3699eca6
7 changed files with 31 additions and 41 deletions
+16 -18
View File
@@ -146,7 +146,7 @@ class Mininet( object ):
self.terms = [] # list of spawned xterm processes
init() # Initialize Mininet if necessary
Mininet.init() # Initialize Mininet if necessary
self.built = False
if topo and build:
@@ -527,6 +527,21 @@ class Mininet( object ):
self.stop()
return result
inited = False
@classmethod
def init( cls ):
"Initialize Mininet"
if cls.inited:
return
if os.getuid() != 0:
# Note: this script must be run as root
# Perhaps we should do so automatically!
print "*** Mininet must run as root."
exit( 1 )
fixLimits()
cls.inited = True
class MininetWithControlNet( Mininet ):
@@ -592,21 +607,4 @@ class MininetWithControlNet( Mininet ):
exit( 1 )
info( '\n' )
# pylint thinks inited is unused
# pylint: disable-msg=W0612
def init():
"Initialize Mininet."
if init.inited:
return
if os.getuid() != 0:
# Note: this script must be run as root
# Perhaps we should do so automatically!
print "*** Mininet must run as root."
exit( 1 )
fixLimits()
init.inited = True
init.inited = False
# pylint: enable-msg=W0612
+4 -4
View File
@@ -499,7 +499,7 @@ class CPULimitedHost( Host ):
"Set a cgroup parameter and return its value"
cmd = 'cgset -r %s.%s=%s /%s' % (
resource, param, value, self.name )
out = quietRun( cmd )
quietRun( cmd )
nvalue = int( self.cgroupGet( param, resource ) )
if nvalue != value:
error( '*** error: cgroupSet: %s set to %s instead of %s\n'
@@ -568,11 +568,11 @@ class CPULimitedHost( Host ):
# Reset to unlimited
quota = -1
# Set cgroup's period and quota
nperiod = self.cgroupSet( pstr, period )
nquota = self.cgroupSet( qstr, quota )
self.cgroupSet( pstr, period )
self.cgroupSet( qstr, quota )
if sched == 'rt':
# Set RT priority if necessary
nchrt = self.chrt( prio=20 )
self.chrt( prio=20 )
info( '(%s %d/%dus) ' % ( sched, quota, period ) )
def config( self, cpu=None, sched=None, **params ):
+2 -5
View File
@@ -5,8 +5,8 @@
import unittest
from mininet.net import init, Mininet
from mininet.node import Host, Controller, ControllerParams
from mininet.net import Mininet
from mininet.node import Host, Controller
from mininet.node import UserSwitch, OVSKernelSwitch
from mininet.topo import SingleSwitchTopo, LinearTopo
from mininet.log import setLogLevel
@@ -21,7 +21,6 @@ class testSingleSwitch( unittest.TestCase ):
def testMinimal( self ):
"Ping test with both datapaths on minimal topology"
init()
for switch in SWITCHES.values():
mn = Mininet( SingleSwitchTopo(), switch, Host, Controller )
dropped = mn.run( mn.ping )
@@ -29,7 +28,6 @@ class testSingleSwitch( unittest.TestCase ):
def testSingle5( self ):
"Ping test with both datapaths on 5-host single-switch topology"
init()
for switch in SWITCHES.values():
mn = Mininet( SingleSwitchTopo( k=5 ), switch, Host, Controller )
dropped = mn.run( mn.ping )
@@ -41,7 +39,6 @@ class testLinear( unittest.TestCase ):
def testLinear5( self ):
"Ping test with both datapaths on a 5-switch topology"
init()
for switch in SWITCHES.values():
mn = Mininet( LinearTopo( k=5 ), switch, Host, Controller )
dropped = mn.run( mn.ping )